I'm sure the "IIRCoefficients::" part is irrelevant
It's not, because a static method has no access to member variables. So calling makePeakFilter does not set any coefficients. You can check that using the debugger or print out the coefficients before and after the makePeakFilter call, if you doubt that.
Instead the makePeakFilter method returns a new IIRCoefficients instance with the required coefficients. You see that in the source code:
... and the big (but common) mistake is using the same filter object for multiple channels. You need an array of IIRCoefficients objects and use a different one for each channel.
Hmm, I figured out why it was muted. The filter is only being modified/set when prepareToPlay is called. How do I manipulate the cutoff frequency while audio is actually playing? I have set up a slider to control my cutoffFrequency member variable in AudioProcessor. I can only hear the cutoff change after prepareToPlay has been called… I tried calling setCoefficients in processBlock but that didn’t seem to work either. I’ve also tried calling it in sliderValueChanged which does not seem to work again.
Are you also calling setCoefficients on the filter? You don’t need to store the coefficients extra, you can call directly: lowPassFilterL.setCoefficients (IIRCoefficients::makeLowPass (sampleRate, cutoffFrequency));
Only changing your setLeftCoeffs variable doesn’t change the filter…
When I call directly like that, firstly I get screaming feedback (I am clearing the buffer in processBlock to attempt to avoid this), then when I force a call to prepareToPlay after changing the cutoff slider I get the same behaviour as previously described. Should I be calling setCoefficients in processBlock? I’m only calling setCoefficients in prepareToPlay currently…
OK, I fixed it by storing the coeffs in setLeftCoeffs in prepareToPlay and calling setCoefficients directly on the filter in processBlock. Seems to be ok now.
Because IIRCoefficients::makeLowPass() is a static member. It cannot change the instance (i.e. set coefficients inside the instance), even if you are calling it with an instance, see e.g.
static members - cppreference.com
Static member functions:
Static member functions are not associated with any object. When called, they have no this pointer.
I modified my code significantly since this was posted. I figured I only need to set the coefficients when something changes, so I created a processor.setFilterProperties() method and set the coefficients for the filter here. This method is called by the editor in sliderValueChanged() when I change the slider.
void MyAudioProcessor::setFilterProperties()
{
switch (filterType)
{
case shelf:
myFilter.setCoefficients(IIRCoefficients::makeLowShelf(sampleRate, cutoffFreq.getNextValue(), resonance.getNextValue(), gainLevel.getNextValue()));
break;
case lowPass:
myFilter.setCoefficients(IIRCoefficients::makeLowPass(sampleRate, cutoffFreq.getNextValue()));
break;
case highPass:
myFilter.setCoefficients(IIRCoefficients::makeHighPass(sampleRate, cutoffFreq.getNextValue()));
break;
case peak:
myFilter.setCoefficients(IIRCoefficients::makePeakFilter(sampleRate, cutoffFreq.getNextValue(), resonance.getNextValue(), gainLevel.getNextValue()));
break;
}
}
So now prepareToPlay() looks something like this:
void MyAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
myFilter.reset();
}
processBlock() looks something like this:
void MyAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
// In case we have more outputs than inputs, this code clears any output
// channels that didn't contain input data.
for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
buffer.clear(i, 0, buffer.getNumSamples());
for (int i = 0; i < numChannels; i++)
{
myFilter.processSamples(buffer.getWritePointer(channel), buffer.getNumSamples());
}
}
This worked for me. I’ve extended it to a multi-band EQ plug-in.