mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-13 19:54:39 +00:00
Extract loop into static method.
Performance boost as compiler is no longer updating member variable every pass through the loop.
This commit is contained in:
parent
05eb694c0a
commit
052fd1c407
@ -36,15 +36,7 @@ class ChannelStatsCollector {
|
||||
public:
|
||||
template<typename Callback>
|
||||
void feed(const buffer_c16_t& src, Callback callback) {
|
||||
auto src_p = simd32_ptr(src.p);
|
||||
const auto end_p = simd32_ptr(&src.p[src.count]);
|
||||
while(src_p < end_p) {
|
||||
const uint32_t sample = *(src_p++);
|
||||
const uint32_t mag_sq = __SMUAD(sample, sample);
|
||||
if( mag_sq > max_squared ) {
|
||||
max_squared = mag_sq;
|
||||
}
|
||||
}
|
||||
max_squared = compute_max_squared(src, max_squared);
|
||||
count += src.count;
|
||||
|
||||
const size_t samples_per_update = src.sampling_rate * update_interval;
|
||||
@ -63,6 +55,24 @@ private:
|
||||
static constexpr float update_interval { 0.1f };
|
||||
uint32_t max_squared { 0 };
|
||||
size_t count { 0 };
|
||||
|
||||
static uint32_t compute_max_squared(
|
||||
const buffer_c16_t& src,
|
||||
uint32_t max_squared
|
||||
) {
|
||||
auto p = simd32_ptr(src.p);
|
||||
const auto end_p = simd32_ptr(&src.p[src.count]);
|
||||
|
||||
while(p < end_p) {
|
||||
const uint32_t sample = *(p++);
|
||||
const uint32_t mag_sq = __SMUAD(sample, sample);
|
||||
if( mag_sq > max_squared ) {
|
||||
max_squared = mag_sq;
|
||||
}
|
||||
}
|
||||
|
||||
return max_squared;
|
||||
}
|
||||
};
|
||||
|
||||
#endif/*__CHANNEL_STATS_COLLECTOR_H__*/
|
||||
|
Loading…
Reference in New Issue
Block a user