Best way to create an dsp::AudioBlock


what is the best way to create an AudioBlock? I have a class where I need that AudioBlock to store the result of an dsp::FIR::Filter.process() without changing any existing signals…

At the moment I use

myAudioBlock = juce::dsp::AudioBlock<float>(new float*{
 new float [numberOfSamples] }, 1, numberOfSamples);

but I wanted to ask if there is a better way to do that :wink:


no no no no… that’ll just leak. You really need to get a better grip on how you manage object lifetimes in C++!

AudioBlock is for use when you have some memory and need to refer to it, but it doesn’t own or manage the memory. If you need a block that owns the memory itself (and which can allocate it for you), then use AudioBuffer instead.

When I started using the Dsp stuff it was confusing to me as well, maybe the class name choice was not optimal… Something like AudioBlockDesc or AudioBlockDescriptor might have been better?

And please ignore the AudioBlock (HeapBlock()). This will allocate the moment the AudioBlock is created (via HeapBlock, it will not re-use a HeapBlock). But at least it will make sure, that the memory doesn’t leak. I don’t know what it is meant for TBH.

And for the question:

void processBlock (AudioBuffer<float>& buffer, MidiMessages&)
    dsp::AudioBlock block (buffer):


@jules You’re right, I need more experience :sweat_smile: … I noticed that it leaks from visual leak detector…

dsp::ProcessContextNonReplacing needs an AudioBlock, doesn’t it?

I want to do

 firFilter.process(juce::dsp::ProcessContextNonReplacing<float>(inputAudioBlock, myAudioBlock)); 

Thanks @daniel , so I have to create an AudioBuffer and then use it to initialise an AudioBlock, right?

If you need something to buffer yes. When you just process dsp in your processor, you just create a block referencing the incoming buffer, put it into a context and call the process method of your dsp processor or chain.

Here is an example in the juce repository:


Thank you very much, you helped me a lot! :grinning: