IIRFilter aliasing

I have a set of hpf and lpfs, they do filter the audio as expected but lots of crackling happens. I think I must be missing something or not be using the filters correctly in the processBlock but I’m not sure what I’m doing wrong

In processor’s private: ([2], one for each channel)
IIRFilter highpassFilter[2];
IIRFilter lowpassFilter[2];

I then set initial values in the constructor. highpassFilter[0].setCoefficients(IIRCoefficients::makeHighPass(iSampleRate, hpfFreq)); highpassFilter[1].setCoefficients(IIRCoefficients::makeHighPass(iSampleRate, hpfFreq)); lowpassFilter[0].setCoefficients(IIRCoefficients::makeLowPass(iSampleRate, lpfFreq)); lowpassFilter[1].setCoefficients(IIRCoefficients::makeLowPass(iSampleRate, lpfFreq));

I also use .setCoefficients at the top of processBlock so they’re updated once each buffer. hpfFreq and lpfFreq are changed with parameters.

and then later in processBlock, outside of any loop I use these
highpassFilter[0].processSamples(buffer.getWritePointer(0), buffer.getNumSamples()); highpassFilter[1].processSamples(buffer.getWritePointer(1), buffer.getNumSamples()); lowpassFilter[0].processSamples(buffer.getWritePointer(0), buffer.getNumSamples()); lowpassFilter[1].processSamples(buffer.getWritePointer(1), buffer.getNumSamples());

I think you may want to look at refactoring your code a little. Rather than having 2 of everything, you can use a nested for loop in the process block to iterate through your read/write pointers and iir filters and do everything in one, rather than explicitly spelling out the processing on channel 0 and 1. Check this vid it will explain how…

Another option is to use dsp::ProcessorDuplicator Which will take the mono dsp::IIRFilter and extend it to stereo or your output configuration. If you need assistance check this vid on how I use it with the dsp::StateVariableFilter. I hope that helps!

IIRFilter is the older version, before the dsp module came out. So ProcessorDuplicator will not play with that one.
The dsp module one is called dsp::IIR::Filter

It’s worth checking it out, newer, better performance etc…

To the OP, I don’t see anything obvious, but if you change the IIRCoefficients in big steps, the results will be audible. In which case you will have to blend between the coefficient sets (I haven’t done this yet).

Maybe save the values of hpfFreq and lpfFreq and set the coefficients only, if they have changed. Maybe that helps…

1 Like

I do have the frequency smoothed so it doesn’t have too sudden changes but I could play with the speed of this thanks.

I’m trying to use the dsp::stateVariableFilter which I use in a class and pluginProcessor needs to access the filter object so I can call class.filter.process(block) but using a filter getter like below doesn’t work. Apologies I’m new to these aThing<blah::blah, blah:blah> style things
1dsp::ProcessorDuplicator<dsp::StateVariableFilter::Filter<double>, dsp::StateVariableFilter::Parameters<float>> effects::getFilter(int channel) const
{ return stateVariableFilter; }
Error code:
'juce::dsp::StateVariableFilter::Filter<double>::Filter(juce::dsp::StateVariableFilter::Filter<double> &&)': cannot convert argument 1 from 'juce::ReferenceCountedObjectPtr<juce::dsp::StateVariableFilter::Parameters<float>>' to 'juce::dsp::StateVariableFilter::Parameters<double> *' (compiling source file ..\..\Source\effects.cpp)