# Host block size for audio plugins

**URL:** <https://forum.juce.com/t/host-block-size-for-audio-plugins/30949>\
**Category:** Audio Plugins\
**Created:** [December 19, 2018, 7:47pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949 "2018-12-19T19:47:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![wub](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wub/32/2908_2.png) [@wub](https://forum.juce.com/u/wub)\
**Post date:** [December 19, 2018, 7:47pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/1 "2018-12-19T19:47:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![holy-city](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@holy-city](https://forum.juce.com/u/holy-city)\
**Post date:** [December 19, 2018, 7:51pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/2 "2018-12-19T19:51:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wub](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wub/32/2908_2.png) [@wub](https://forum.juce.com/u/wub)\
**Post date:** [December 19, 2018, 8:26pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/3 "2018-12-19T20:26:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bwall](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bwall/32/618_2.png) [@bwall](https://forum.juce.com/u/bwall)\
**Post date:** [December 19, 2018, 8:27pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/4 "2018-12-19T20:27:59Z")

</div>

Please note also that the block size can be zero!

---

<div class="post-metadata">

**Author:** ![wub](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wub/32/2908_2.png) [@wub](https://forum.juce.com/u/wub)\
**Post date:** [December 20, 2018, 5:14pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/5 "2018-12-20T17:14:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [December 20, 2018, 5:23pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/6 "2018-12-20T17:23:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![holy-city](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@holy-city](https://forum.juce.com/u/holy-city)\
**Post date:** [December 20, 2018, 5:30pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/7 "2018-12-20T17:30:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [December 20, 2018, 5:56pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/8 "2018-12-20T17:56:25Z")

</div>

> [@Holy\_City](#):
>
> I’m not particularly sure _why_ hosts want to use variable buffer sizes during playback

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

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [December 20, 2018, 6:00pm UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/9 "2018-12-20T18:00:08Z")

</div>

> [@Holy\_City](#):
>
> I’m not particularly sure _why_ hosts want to use variable buffer sizes during playback

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.

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [December 21, 2018, 9:59am UTC](https://forum.juce.com/t/host-block-size-for-audio-plugins/30949/10 "2018-12-21T09:59:18Z")

</div>

> [@wub](#):
>
> 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.

…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
