got it working, finally… ill delete the previous mis-information that i was attempting
the code is definitely not optimized but i can clean it later;
using State = juce::AudioProcessorValueTreeState;
using Filter = juce::dsp::IIR::Filter<float>;
using FilterDesign = juce::dsp::FilterDesign<float>;
using Coeff = juce::dsp::IIR::Coefficients<float>;
using Duplicate = juce::dsp::ProcessorDuplicator<Filter, Coeff>;
The way a butterworth filter works is basically applying multiple filters on top of eachother, so the way you implement this is
juce::dsp::ProcessorChain < Duplicate, Duplicate, Duplicate, Duplicate > chain;
now this, is for a maximum of 4 filters, you can remove or add more. depending on different orders.
…
auto order = 2 * (p.filter_order + 1);
auto coeff = FilterDesign::designIIRHighpassHighOrderButterworthMethod(p.filter_freq, sampleRate, order);
chain.setBypassed<0>(true);
chain.setBypassed<1>(true);
chain.setBypassed<2>(true);
chain.setBypassed<3>(true);
switch (p.filter_order)
{
case ORDER_12:
*chain.get<0>().state = *coeff[0];
chain.setBypassed<0>(false);
break;
case ORDER_24:
*chain.get<0>().state = *coeff[0];
chain.setBypassed<0>(false);
*chain.get<1>().state = *coeff[1];
chain.setBypassed<1>(false);
break;
case ORDER_36:
*chain.get<0>().state = *coeff[0];
chain.setBypassed<0>(false);
*chain.get<1>().state = *coeff[1];
chain.setBypassed<1>(false);
*chain.get<2>().state = *coeff[2];
chain.setBypassed<2>(false);
break;
case ORDER_48:
*chain.get<0>().state = *coeff[0];
chain.setBypassed<0>(false);
*chain.get<1>().state = *coeff[1];
chain.setBypassed<1>(false);
*chain.get<2>().state = *coeff[2];
chain.setBypassed<2>(false);
*chain.get<3>().state = *coeff[3];
chain.setBypassed<3>(false);
break;
}
by disabling the filters before we process, we can then run a quick check to see how many filters should be used and then enabled and set coefficients as we need.
the switch here is saying
if( we are using an order of 12dB we only want 1 filter )
if( we are using an order of 24dB we want 2 filters, so we set filter 1 and 2 to enabled and use the coefficents for the FilterDesign[0] with the first, and FilterDesign[1] with the second… and so on )
…
The order is
2 → multiply by → order(index in enum) → +1
so this works out to → 2 * (0 + 1) → 2 * (1 + 1) → …
the index in the enum is the index of the filter “StringArray” for db/octave in your parameter tree. If you need any more help, let me know
here is the project on Github, un-optimized. Github Project