Juce filters issue- i cant get a smooth movement when rotating the knob

Hi everybody,
I am using designIIRLowpassHighOrderButterworthMethod and designIIRHighpassHighOrderButterworthMethod filters.

using filterDuplicator = juce::dsp::ProcessorDuplicator<juce::dsp::IIR::Filter<float>, juce::dsp::IIR::Coefficients<float>>;
using filterChain      = juce::dsp::ProcessorChain<filterDuplicator, filterDuplicator>;

// Low cutoff filter is a High Pass Filter
filterChain lowCutoffFilter;
// High cutoff filter is a Low Pass Filter
filterChain highCutoffFilter;

and here are my update funstions:

**void** FilterPlugin ::updateLowCutoffFilter ( **float** cutoffFrequency)

{

 ReferenceCountedArray<juce::dsp::IIR::Coefficients< **float** >> lowCutoffFilterCoeffArray = 
juce::dsp::FilterDesign< **float** >::designIIRHighpassHighOrderButterworthMethod (cutoffFrequency, spec.sampleRate, 3);

*lowCutoffFilter.get<0>().state = *lowCutoffFilterCoeffArray.getObjectPointerUnchecked (0);

*lowCutoffFilter.get<1>().state = *lowCutoffFilterCoeffArray.getObjectPointerUnchecked (1);

 lowCutoffFilter.prepare (spec);

 lowCutoffFilter.reset();

}

/** Update high cutoff filter center frequency

**@param** cutOffFrequency frequency at 3dB

*/

**void** FilterPlugin::updateHighCutoffFilter ( **float** cutoffFrequency)

{

   ReferenceCountedArray<juce::dsp::IIR::Coefficients< **float** >> highCutoffFilterCoeffArray = 
  juce::dsp::FilterDesign< **float** >::designIIRLowpassHighOrderButterworthMethod (cutoffFrequency, spec.sampleRate, 3);

 *highCutoffFilter.get<0>().state = *highCutoffFilterCoeffArray.getObjectPointerUnchecked (0);

 *highCutoffFilter.get<1>().state = *highCutoffFilterCoeffArray.getObjectPointerUnchecked (1);

  highCutoffFilter.prepare (spec);

 highCutoffFilter.reset();

}

I am updating the filters in parameterChanged method but i have a small but annoying issue.
When i try to rotate the knobs and change the cutoff frequencies, it creates bumps and damage the sound.

https://drive.google.com/drive/folders/1r_jqnLmDU0VjZiukxnwhDWvMaRkfM9he?usp=sharing

I put a video that shows that it does when i try to rotate the knobs. Is there any body else had the same issue here?

Hi @trengineer !

Have you tried to smooth the cutoff frequency parameter?
Try to see juce::SmoothedValue

However, if you’re trying to build a IIR frequency-variable filter, I suggest you to see other efficient implementations, like juce::dsp::StateVariableFilter or juce::dsp::FirstOrderTPTFilter

Thank you very much :pray:
I will check them :slight_smile:
It may have something to do with these filter types but i am not sure.

Try not resetting and preparing the filters when you update the parameters. The reset/prepare will zero out the signal history of the filter, which will obviously cause problems in the sound. However, that might not fix the sound problems completely. Like was suggested above, you should maybe try out the filter types that have been designed to allow their parameters to be changed while the audio is playing.

2 Likes

Thank you for reply. I just saw it, sorry.

I tried not to call reset and prepare every time i change the frequency but unfortunately it didn’t work :confused: