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.
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.
I am not surprised to hear this. I will proceed with caution! Thanks!
Please note also that the block size can be zero!
Just to make sure I got it straight, the value passed to the method
samplesPerBlock is an upper bound on the block size and may be zero. The value obtained by
processBlock is the actual number of samples in the current block and may vary from block to block. Oder?
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.
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.
Some hosts will use a smaller block size while automation curves are changing to help with accuracy.
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.
…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