mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-05 04:31:02 -05: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:
|
public:
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void feed(const buffer_c16_t& src, Callback callback) {
|
void feed(const buffer_c16_t& src, Callback callback) {
|
||||||
auto src_p = simd32_ptr(src.p);
|
max_squared = compute_max_squared(src, max_squared);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count += src.count;
|
count += src.count;
|
||||||
|
|
||||||
const size_t samples_per_update = src.sampling_rate * update_interval;
|
const size_t samples_per_update = src.sampling_rate * update_interval;
|
||||||
@ -63,6 +55,24 @@ private:
|
|||||||
static constexpr float update_interval { 0.1f };
|
static constexpr float update_interval { 0.1f };
|
||||||
uint32_t max_squared { 0 };
|
uint32_t max_squared { 0 };
|
||||||
size_t count { 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__*/
|
#endif/*__CHANNEL_STATS_COLLECTOR_H__*/
|
||||||
|
Loading…
Reference in New Issue
Block a user