Butterworth LP produces noise
aybe opened this issue · comments
I made a half-band filter, so 11025Hz for 44100Hz; however, there's something wrong with the output: one can hear pops and crackles.
I tried a lower order such as 4, checked everything but it's the same, unwanted noise in output.
Crafted a sample example: https://github.com/aybe/IIR1Test, you can clearly hear the difference with fir.wav
, a 461 taps FIR filter.
What do you think? Could there be something wrong in the implementation or am I missing something about IIR filters quality?
Thank you.
The IIR Butterworth filter has been stable for 10years so it's very unlikely there is something wrong there.
https://github.com/aybe/IIR1Test/blob/master/IIR1Test/IIR1Test.cpp#L47 you use a copy contructor here which copies over the state of the filter which is then discarded here: https://github.com/aybe/IIR1Test/blob/master/IIR1Test/IIR1Test.cpp#L59. So you reset the state of the filter after a frame and messing with its memory.
In a nutshell you need to use references.
What @berndporr said 😃
Actually I see this all the time from old dinosaurs like me who are too often automatically typing last-century C programs with C++ spelling, or the new programmers who came to C++ via Python and therefore really love auto. I was going to say you don't need an int i
at all, but you do because you are using it to calculate a source buffer offset here. Normally you could use a foreach construct (as in for ( thing : iterable )
) but not with this loop body. I think you need to use auto& filter {filters[i]};
or some such. I'd have considered a straight-forward 2D array for sourceBuffer
and targetBuffer
too, as the maximum size is defined by a constexpr, but I don't think that has anything to do with the clicks.
Two things at play here:
- I really need a serious course on C++ (coming from C#)
- Visual Studio indeed showed the issue but ReSharper hid it, bug reported
Thank you!🥳