Juce Synthesiser heap allocates in audio thread?

Found this curious bit in the Juce Synthesiser code, in the findVoiceToSteal method :

Array<SynthesiserVoice*> usableVoices;
usableVoices.ensureStorageAllocated (voices.size());

Isn’t that going to cause a heap allocation in code that runs in the audio thread?
It could of course be argued that if a voice has to be stolen, there’s a likelihood some kind of audio glitch is going to happen anyway and the allocation potentially causing a glitch isn’t going to matter much in addition.

However, couldn’t this be fixed by just having the usableVoices array as a member variable of the Synthesiser class?

3 Likes

Looks like MPESynthesiser::findVoiceToSteal uses the same pattern…

1 Like

OK there is a fix for this in our review pipeline. Thanks for reporting.

3 Likes

This is now fixed with commit 87d5197 on the develop branch.

4 Likes

Nice one, thanks Fabian!

1 Like