Performance of IIR filters on silence #258
-
|
Hi Dan & team, I've got an issue with performance of IIR filters when processing silence. I've done hours of troubleshooting but haven't been able to find the root cause. Application: Audio DSP Symptom: Processing audio (sound) works fine and performs very well. When I stop playback in JRiver, my app continues receiving buffers from CoreAudio and the samples are all zero values, as expected. At this time, CPU usage of my app and the elapsed time to process samples increase by roughly an order of magnitude. Troubleshooting: The issue occurs when processing sample sets with all zero values (silence). I use IIR filters to perform bass management and room correction. Both suffer the performance problem. My bass management implementation (also see #245): Filter definitions (performed only once during setup): My sample_rate is 96000 Filter application (performed on every sample set): "lf" and "input" parameters are declared as univector Again, these filters perform very well with actual sound. The performance is only poor on silence. Is my implementation sensible or is there an issue in the KFR implementation? I can also post details of the room correction filters if that would help. Thanks in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Hi, You can use an RAII helper to set CPU flags during audio processing: struct fp_mode_scope {
fp_mode_scope() noexcept : csr(_mm_getcsr()) {
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
}
~fp_mode_scope() noexcept {
_mm_setcsr(csr);
}
fp_mode_scope(const fp_mode_scope&) noexcept = delete;
fp_mode_scope& operator=(const fp_mode_scope&) noexcept = delete;
uint32_t csr;
}; |
Beta Was this translation helpful? Give feedback.
-
|
Answered by Dan above |
Beta Was this translation helpful? Give feedback.
Hi,
You likely encountered the classic denormals problem. When a filter is fed with zeros, the filter's delay line can produce very small values known as denormals. These denormals can significantly degrade floating-point performance.
If you can tolerate negligible precision loss, you can configure the CPU to flush denormals to zero. This restores high performance for all floating-point operations within the IIR filter.
This issue is not related to KFR or how you use KFR and may happen with any code that produces very small numbers.
You can use an RAII helper to set CPU flags during audio processing: