AudioBuffer allocates at each audio callback if channels > 32


When constructing an AudioBuffer from an existing pre-allocated data to refer to I would expect it not to allocate.
This would allow to nicely wrap the buffer, passed by the audio driver, in a juce::AudioBuffer and use its methods to process the audio.

However, I realised that when the number of audio channels exceeds 32 the AudioBuffer constructor calls a malloc on each audio callback.

This is because the array AudioSampleBuffer::preallocatedChannelSpace has fixed lenght 32 and AudioSampleBuffer::allocateChannels() will always reallocate the channel pointer array if the number of channels passed at constructor exceeds this value.

Any workaround for that ?

Pre-allocate the audio buffer along with the data it wraps?

1 Like