AudioBuffer::setSize() uses avoidReallocating = false by default, so as far as I can tell, any change in numSamples reallocates the buffer on the audio thread. A sequence of variable-sized blocks like 64 - 4 - 60 - 64 would allocate 3 times.
Variable block sizes are explicitly allowed by the AudioProcessor doc so this seems unexpected…
Is there a reason it doesn’t pass avoidReallocating = true, since prepareToPlay() already allocates for the maximum block size?
with the defaults (keepExistingContent = false, avoidReallocating = false). In AudioBuffer::setSize, whenever newNumSamples != size, the non-keep path only reuses the memory if avoidReallocating is true and allocatedBytes >= newTotalBytes. Otherwise it allocates a new HeapBlock. So 64 → 4 → 60 → 64 allocates on every size change. prepareBuffers() already sizes this buffer for the max block size, so passing avoidReallocating = true should be safe:
It would also be worth checking whether the channel count can grow past what prepareBuffers() allocated. If it can, it would still allocate, but that’s a separate case.
You can confirm it by running the graph under RTSan or a malloc hook with varying block sizes.