Allocation of a memory block

Dear experts,

I want to implement resampling inside my plugin. To do this, I need to allocate memory 4 times larger than data.numSamples * sizeof(double).
If I look at the newSetup.maxSamplesPerBlock value inside the setupProcessing() function, I see that different hosts are passing different values.
If I focus on this value, then it is not optimal, since it can reach 16384 (tested experimentally). This is a very suboptimal memory consumption, since I will have to allocate 1638448 = 524288 bytes. Moreover, inside the process() function it may be completely different size: data.numSamples can be on the order of 1024.

Where can I find out the actual (not maximum, but actual) number of samples, other than the process () function?
After all, I can’t allocate memory inside a process() function - it will take a lot of time and the thread will crash.
What to do in this situation?

You need to use the number from setupProcessing. The host will fill the maxSamplesPerBlock as high as your process function may be called from it. And as you correctly stated, you cannot allocate memory on the realtime thread. As the value you get in processData.numSamples can vary from call to call you need to allocate the maximum possible.

1 Like

Thanks for the answer!
I checked in Cakewalk - data.numSamples = 1920 in the process function.

It turns out (in Cakewalk) it depends on the driver settings. I can set it to any value from 480 to 12000. And this value never changes unless I change the driver setting.
I don’t know how other hosts work, but I think this value is set once (in setupProcessing) and does not change during playback.

Other host may work a little bit different, but they all guarantee that the number of samples in the process function never exceeds that of the processSetup.maxSamplesPerBlock.

1 Like