Recursive filters lockup and remedy
Posted: Wed Sep 20, 2017 2:54 am
Hi gang,
We all use recursive filters (biquads and such) because they are so efficient. However, one disadvantage is that if you feed such a device with invalid data (such as the result of a division by zero), it will lock up because NaNs (Not a Number) will forever feed back. In that case, the only remedy is to interrupt the audio stream.
Of course it is best to avoid NaNs in the first place, but you are not always in control. One possible workaround is to block incoming NaNs from polluting the subsequent signal path. In the schematic below, the NaN Blocker replaces NaNs by zeros, while passing valid stream data unchanged.
If you have a complex schematic with many recursive components, it might be difficult to place potentially many NaN blockers at the right spots. Then you might analyze the audio stream at the end and clear audio on NaN detection there. The schematic below has a module which does exactly this.
Let me repeat: avoid NaNs in the first place if possible. A division by zero may be due to lack of a proper initialization (happened to me before).
Have fun!
Edit; Upgraded version to take care of division by zero.
We all use recursive filters (biquads and such) because they are so efficient. However, one disadvantage is that if you feed such a device with invalid data (such as the result of a division by zero), it will lock up because NaNs (Not a Number) will forever feed back. In that case, the only remedy is to interrupt the audio stream.
Of course it is best to avoid NaNs in the first place, but you are not always in control. One possible workaround is to block incoming NaNs from polluting the subsequent signal path. In the schematic below, the NaN Blocker replaces NaNs by zeros, while passing valid stream data unchanged.
If you have a complex schematic with many recursive components, it might be difficult to place potentially many NaN blockers at the right spots. Then you might analyze the audio stream at the end and clear audio on NaN detection there. The schematic below has a module which does exactly this.
Let me repeat: avoid NaNs in the first place if possible. A division by zero may be due to lack of a proper initialization (happened to me before).
Have fun!
Edit; Upgraded version to take care of division by zero.