Can I create a context for DSP processor from a bufferToFill.buffer?

I have created an Audio File Player and I want to be able to filter that signal.
In the getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill) I have a reference to the buffer where that signal is.
I am using an IIR filter (dsp::StateVariableTPTFilter) and I want to create an AudioBlock/ Context to pass this buffer through this filter but because bufferToFill.buffer is a reference to the buffer, I don’t know how to create that context. I would need the buffer name itself to do something like:

auto audioBlock = juce::dsp::AudioBlock<float>(filteredBuffer);
auto context = juce::dsp::ProcessContextReplacing<float>(audioBlock);

To filter sample per sample is something that never works for me, I don’t know what I do wrong, that is why I would like to do it processing the Context block.

Could someone clarify my doubt?
Thank you so much

You are almmost there, but you need to take the startSample and numSamples into account:

auto audioBlock = juce::dsp::AudioBlock<float>(*bufferToFill.buffer)
     .getSubBlock (bufferToFill.startSample, bufferToFill.numSamples);
1 Like

Hi Daniel, this is working well now. Thank you so much.
Just one more question for futures developments.
Right now my fixed Cutoff frequency is set on PrepareToPlay. If I would like to add a Slider to set the Cutoff frequency on real-time, Should the Cutoff frequency be set inside the getNextAudioBlock()? Or can this be always in PrepareToPlay even if this parameter is going to be changed while the audio is being played?

Thank you,

If you only set it in prepareToPlay, then it won’t change with changes of the slider.
When the value changes, it is your obligation to create new coefficients for your filter.

Connecting Slider to DSSP in plugins is a different topic, just to make you aware of it.

And it is guaranteed, that prepareToPlay is called once before playback, but after that it is up to the host. It has nothing to do with the actual host transport play.

1 Like