Host block size for audio plugins


#1

Are there any rules or common practices concerning the number of samples per block passed from a host to a plugin? Is the size typically a power of 2? What are some common values? I have been experimenting with the JUCE FFT engine and have been setting the FFT size to the smallest power of 2 that can hold the block or group of blocks as the case may be.


#2

There are no rules, and the hosts won’t use a constant size either (the size you get is just a maximum).

I think if you’re using FFTs the standard approach is to write the incoming samples into a ring buffer and take the FFT of that, rather than working directly with whatever the host sends you.


#3

I am not surprised to hear this. I will proceed with caution! Thanks!


#4

Please note also that the block size can be zero!


#5

Just to make sure I got it straight, the value passed to the method prepareToPlay as samplesPerBlock is an upper bound on the block size and may be zero. The value obtained by buffer.getNumSamples in processBlock is the actual number of samples in the current block and may vary from block to block. Oder?


#6

I have never seen the buffer size from prepareToPlay be zero but I guess it could be possible with a MIDI-only plugin, for example.

The number of samples you have to read from the input and produce to the output of the plugin is the number of samples in the buffer given to processBlock.


#7

Yup that’s how it works. Most hosts don’t go too crazy, iirc the biggest discrepancies show up with offline rendering. I’m not particularly sure why hosts want to use variable buffer sizes during playback, but it’s explicitly stated by the plugin API documentation that the buffer size is an upper limit and the hosts will do whatever they want.


#8

Some hosts will use a smaller block size while automation curves are changing to help with accuracy.


#9

Besides the automation envelope accuracy issue mentioned by G-Mon, hosts may implement their transport looping so that partial buffer sizes compared to the usual buffer size are involved at the loop switch point.


#10

…and also this can be zero even for plug-ins that process audio (i.e. not only MIDI).

Can’t remember which DAW on which OS, but I’m sure this has been reported as a possible occurrence so take that in consideration as well.
IIRC, it was the first processBlock() called immediately after prepareToPlay() in that case, then all the following ones were called with a numSamples > 0