Setting stateVariableFilter parameters when using the ProcessorDuplicator

Hi all,
I need help to understand how to set the parameters of a stateVariableFilter of the juce_dsp module, when used in conjunction with a processorDuplicator and a GUI to input the parameters.

In my PluginProcessor.h I have :

enum
{
    noiseIndex,
    filterIndex,
    masterGainIndex
};

using Filter = juce::dsp::IIR::Filter<float>;
using FilterCoefs = juce::dsp::IIR::Coefficients<float>;

juce::dsp::ProcessorChain<MyCustomNoiseGenerator<float>, juce::dsp::ProcessorDuplicator<Filter, FilterCoefs>, juce::dsp::Gain<float>> processorChain;

The issue arises when I try to access the filter to set the parameters in an updateFilter() function of the PluginProcessor.cpp. I can’t get the right syntax (what I am missing?) to achieve something like this (which is obviously wrong):

void MyNoiseFiltersAudioProcessor::updateFilter()
{
    
    int menuChoice = *filterMenuParameter;
    int cutoff = *cutoffParameter;
    int res = *resonanceParameter;
    
    if (menuChoice == 0)
    {
        processorChain.get<filterIndex>().state->type = dsp::StateVariableFilter::Parameters<float>::Type::lowPass;
  
        processorChain.get<filterIndex>().state->setCutOffFrequency (lastSampleRate, cutoff, res);
        
    }

Any suggestion?

Not sure if you are still looking for a solution, but this should work

(1) define a filter using a processor duplicator

dsp::ProcessorDuplicator<dsp::StateVariableFilter::Filter <float>, dsp::StateVariableFilter::Parameters <float>> filter;

(2) set it up

filter.state->type = dsp::StateVariableFilter::Parameters<float>::Type::lowPass;
filter.state->setCutOffFrequency(getSampleRate(), filterState->cutOffFreq, filterState->resonance);

(3) and have it do some work (processBlock())

dsp::AudioBlock<float> audioBlock (audioBuffer);
dsp::ProcessContextReplacing<float> context = audioBlock;
filter.process(context);

You can hold your filter state in a struct like in this example, which in turn could be a value tree state listener or similar that connects to the UI

1 Like