DSP Module IIR Filtering sample by sample

Hello,

I am new to coding and am trying to create a plugin with a stereo Low Pass Filter in it. I am trying to use the dsp module to do this. I have tried to copy from the dsp module demo example. However, I need my filter to process sample by sample so I am trying to use the processSample method. When I do this it doesn’t do any filtering! Would anyone be able to guide me into setting this up pelase?

Can you show your current code?

So I create a LPF-L and LPF-R in the private section of my audioprocessor.h

Then in the constructor in the cpp I give these filters coefficients for a given cutoff and sample rate.

Then I use the processSample in the applyDelay function that I have taken from the JuceDemoPlugin.

At the moment I am testing the plugin on a mono channel, and I can’t get it to do any filtering.

processSample in the DSP module IIR filter returns a sample, it doesn’t modify the sample passed in. You are not storing the returned sample anywhere.

You also need to set the coefficients in the prepareToPlay. I don’t believe that in the constructor you already have the sample rate value available. This was a headache for me a few months ago.

Thank you it is filtering now!

I need to use the setCoefficients() method to set the coefficients right?

First I have to do this to generate the coefficients. Then I pass this into setCoefficients?
lpfLpointer = dsp::IIR::Coefficients::makeFirstOrderLowPass (getSampleRate(), 5000 );

In the reference guide, the following is given
’void IIRFilter::setCoefficients ( const IIRCoefficients & newCoefficients )’

How do I apply this method to my lowPassFilterL filter?

Thanks!

I know its a noob question, but if anyone could help me it would be much appreciated! I am still struggling with this!

Take a look at: https://juce.com/doc/classdsp_1_1IIR_1_1Filter
As you can see, the filters you use have a public attribute called coefficients. You can simply replace this pointer with the one you get with dsp::IIR::Coefficients::makeFirstOrderLowPass (getSampleRate(), 5000 );

Thanks Daniel!

So I’ve written this within my processblock function

if (MajorParamChange)
{

    lowPassFilterL.reset();
    lpfValue = ((*myValueTree->getRawParameterValue("lpfFq")));
    lowPassFilterL.coefficients = dsp::IIR::Coefficients<float>::makeFirstOrderLowPass (getSampleRate(), lpfValue );

So in theory if I move my slider it should change the filtering? However it doens’t seem to do anything? Is there something else I need to do? Something I’ve missed? Or have I just implemented this wrong?

quick guess: try to dereference both sides:
*lowPassFilterL.coefficients = *dsp::IIR::Coefficients<float>::makeFirstOrderLowPass (getSampleRate(), lpfValue );
can’t test it right now

Unfortunately that doesn’t seem to fix it :frowning:

I had the same problem, Fabian’s hint worked for me (click on the topic to get it better formatted):

Sorry I don’t understand that code…

myfiltername.get doesn’t seem to be a valid method?

and also if I try…
myfiltername.state = *NewCoefficients;

I got the following errors:

  1. ‘state’ is a private member of ‘juce::dsp::IIR::Filter’
  2. Assigning to ‘float *’ from incompatible type ‘ReferencedType’ (aka ‘juce::dsp::IIR::Coefficients’)

Btw I am not using processorduplicator, I have created two mono filters. I need to do sample by sample processing and when you use precessorduplicator you can’t do that.
https://juce.com/doc/structdsp_1_1ProcessorDuplicator

I am sorry, I wrongly assumed it would work the same. I looked at the docs, but I would have ended up the same way like you did.

Good luck.