Well, since you asked, this is how I handle a voice number change.
In my synth I have about 100 voices for a single instrument, say a piano type synth. The voices aren’t tha big, I’d say well under 100byte each. (Remember we’re talking about voices here, not the individual sounds, which might be several 100MB each if they contain samples.
So if I think I’ll need more for an instruments I’ll just make sure there will be enough of them allocated in prepareToPlay() or wherever I do the plug-in’s initialisation. This way I never have to do it mid playing. 1000 or even 10 000 of them (voices) would hardly get noticed in the ram footprint of the plugin compared to all the shit stuff like gif-knobs or bitmapped background images some people tend to put in their plug-ins before they even get started.
So you shouldn’t need to increase the number of voices (at least not I, and you asked what other were doing, remember…)
The other way around, decreasing number of voices might however be neccessary, while not every daw/computer could handle all to many voices at the same time.
But I don’t see that would be a problem. Probably you have something like this in your synth:
handleNoteOn()
{
if (auto voice = getFreeVoice())
{
voice->loadWithProperSound();
}
else
{
/* skip this note while to many voices are already playing
* or free one already playing (note stealing)
*/
}
}
MyVoiceClass *getFreeVoice()
{
if (numVoicesInUse < numberUserHaveSetInGUI)
{
numVoicesInUse++;
return nextFreeVoice();
}
return nullptr;
}
and the render function might look something like this:
void processBlock()
{
for (i = 0 i < numVoicesInUse; ++i)
voice[i]->loadedSound->render();
}
Then just set numberUserHaveSetInGUI in your gui to something between
lowestNumberThatsUsable < numberUserHaveSetInGUI < number allocated in prepareToplay.
I don’t even think you’d need an atomic for that.
That’s how I do it. Hope this will be of any help for you. I guess what I’m aiming at is if you need to stop the music in mid play, rethink your solution, there’s probably a better, less intrusive way to handel the change…