grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.58k stars 322 forks source link

FIR gives NaNs #786

Closed jcelerier closed 2 years ago

jcelerier commented 2 years ago

Hi, I was trying to check all the guitarix dsp and found out that the FIR part here (https://github.com/brummer10/guitarix/blob/master/trunk/src/faust/orangedarkterror.dsp ) consistently causes NaNs ; my DSP-fu is not good enough to know if it's an issue in the dsp code or in faust so I'm also pinging @brummer10 .. thanks !

here's the extracted part on faustide:

https://faustide.grame.fr/?autorun=1&voices=0&name=untitled&inline=aW1wb3J0KCJzdGRmYXVzdC5saWIiKTsKCi8vIGdlbmVyYXRlZCBhdXRvbWF0aWNhbGx5Ci8vIERPIE5PVCBNT0RJRlkhCmRlY2xhcmUgaWQgIm9yYW5nZWRhcmt0ZXJyb3IiOwpkZWNsYXJlIG5hbWUgIlB1c2ggUHVsbCBFTDg0IjsKZGVjbGFyZSBzaG9ydG5hbWUgIk9yYW5nZURhcmtUZXJyb3IiOwpkZWNsYXJlIGRlc2NyaXB0aW9uICJQdXNoIFB1bGwgRUw4NCI7CmRlY2xhcmUgc2FtcGxlcmF0ZSAiOTYwMDAiOwoKaW1wb3J0KCJzdGRmYXVzdC5saWIiKTsKCnAxID0gZmkuaWlyKChiMC9hMCxiMS9hMCxiMi9hMCxiMy9hMCxiNC9hMCksKGExL2EwLGEyL2EwLGEzL2EwLGE0L2EwKSkgIHdpdGggewogICAgTG9nUG90KGEsIHgpID0gYmEuaWYoYSwgKGV4cChhICogeCkgLSAxKSAvIChleHAoYSkgLSAxKSwgeCk7CiAgICBJbnZlcnRlZChiLCB4KSA9IGJhLmlmKGIsIDEgLSB4LCB4KTsKICAgIHMgPSAwLjk5MzsKICAgIGZzID0gbWEuU1I7CiAgICBwcmUgPSBfOwoKCiAgICBiMCA9IGZzKihmcyooZnMqKC02LjU3Mzc3MzMzNjY1NzI3ZS0xOSpmcyAtIDQuMDE2MDcyMDEwNzAxNTVlLTE3KSAtIDQuMzc4NjU1OTAz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MgPSBmcyoocG93KGZzLDIpKigtNy40NzgyOTE1MjY0OTY0N2UtMTkqZnMgKyAxLjM2NDAyMDgxNDU3MjZlLTE2KSAtIDEuMzAyMjA4Mjc5ODM2NDdlLTEzKSArIDEuODk0NTcwNTYxNTg1MjdlLTE2OwoKICAgIGE0ID0gZnMqKGZzKihmcyooMS44Njk1NzI4ODE2MjQxMmUtMTkqZnMgLSA2LjgyMDEwNDA3Mjg2MzAxZS0xNykgKyA0LjUzNDU0MDEzOTYxMjY0ZS0xNSkgLSA2LjUxMTA0MTM5OTE4MjM3ZS0xNCkgKyA0LjczNjQyNjQwMzk2MzE5ZS0xNzsKfTsKCgpwcm9jZXNzID0gYmEucHVsc2VuKDEsIDEwMDAwKSA6IHBtLmRqZW1iZSg2MCwgMC4zLCAwLjQsIDEpIDogcDE7

brummer10 commented 2 years ago

Hi

This filter needs to be build with double precision and needs to run at 96kHz.

That wouldn't work within the faustide.

In my implementation I use a fixed rate resampler therefore.

To make it work with lower Sample Rates it needs to be split into lower order iir filters.

regards

hermann

Am 22.08.22 um 12:35 schrieb Jean-Michaël Celerier:

Hi, I was trying to check all the guitarix dsp and found out that the FIR part here (https://github.com/brummer10/guitarix/blob/master/trunk/src/faust/orangedarkterror.dsp ) consistently causes NaNs ; my DSP-fu is not good enough to know if it's an issue in the dsp code or in faust so I'm also pinging @brummer10 https://github.com/brummer10 .. thanks !

here's the extracted part on faustide:

https://faustide.grame.fr/?autorun=1&voices=0&name=untitled&inline=aW1wb3J0KCJzdGRmYXVzdC5saWIiKTsKCi8vIGdlbmVyYXRlZCBhdXRvbWF0aWNhbGx5Ci8vIERPIE5PVCBNT0RJRlkhCmRlY2xhcmUgaWQgIm9yYW5nZWRhcmt0ZXJyb3IiOwpkZWNsYXJlIG5hbWUgIlB1c2ggUHVsbCBFTDg0IjsKZGVjbGFyZSBzaG9ydG5hbWUgIk9yYW5nZURhcmtUZXJyb3IiOwpkZWNsYXJlIGRlc2NyaXB0aW9uICJQdXNoIF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uKDEsIDEwMDAwKSA6IHBtLmRqZW1iZSg2MCwgMC4zLCAwLjQsIDEpIDogcDE7

— Reply to this email directly, view it on GitHub https://github.com/grame-cncm/faust/issues/786, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUPITRWLR7HMVN7VM67FG3V2NJYFANCNFSM57HEJ33Q. You are receiving this because you were mentioned.Message ID: @.***>

sletz commented 2 years ago

NaN or INF can be generated by division by 0 or other kind of "out of domain" math operations. We cannot completely solve that at the compilation time, one of the reason is the "still not perfect" interval computation associated to signals. The best we can do right now is help developers understand what happens, with different tools described here: https://faustdoc.grame.fr/manual/debugging/