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
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.
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.