What do you put in this section to get the plug-in to “free up spare memory”?
void DemoAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
Thanks!
What do you put in this section to get the plug-in to “free up spare memory”?
void DemoAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
Thanks!
Free up any memory you may have allocated in prepareToPlay(), numChannelsChanged(), etc.
For example, I often use vectors to hold DSP processes like filters. I allocate the memory in numChannelsChanged() so I can have one processor for each channel and then I call .clear() on them in releaseResources().
Hi, sorry for bumping this older conversation. I just now realized how I could use vectors for memory allocation, specifically the way you were talking about it.
Basically what I am trying to emulate is how FabFilter’s Pro-Q 3 creates a new filter in the PluginProcessor and its associated GUI components in the PluginEditor, using them however needed by the user, up to 24 filters (each mono/stereo/surround). I assume they are doing this dynamically, or at least doing so would save space at compile time.
If I allocate new filters in prepareToPlay(), how do I make sure prepare to play is called every time the user adds another set of filters?
Thank you for your help!
You can’t force prepareToPlay to be called by the host from the plugin itself. You could of course call the method directly from your own code, but that would be messy in all kinds of ways.
The easiest solution is to just preallocate up to the maximum amount of needed filters from the start. (Do you think the filters really use so much memory that would be a problem?)
Otherwise, you will need to come up with some kind of thread safe solution which allows you to dynamically increase/decrease the number of allocated filters.
is it 100% reliable that if releaseRes is called there’ll be another prepareToPlay call next time the plugin is used.
also when is releaseRes called? when the plugin is bypassed, when it’s entirely deactivated but not removed, or when there hasn’t been audio running through it for a while?
The easiest is to just ignore releaseResources even exists and use RAII wrappers for any dynamic allocations (juce::AudioBuffer, std::vector, std::unique/shared_ptr etc). Then any needed deallocations can happen either when prepareToPlay is called again or when the plugin is destroyed.
Yeah tbh I don’t think I ever actually use releaseResources() like that, but it is the correct place to do it when you need to.
No idea if it’s guaranteed for prepareToPlay() to be called again after, possibly depends on the host, but I’d assume it’d be a buggy host that failed to call it after releasing resources.
yeah that’s what i’m doing so far, but since this function exists at all it must be useful for at least one thing and i want to know what exactly the limitation of this function is. or is it part of the vst standard that is not used by anyone anymore, like this whole program change stuff?
if not then i have absolutely no idea what it is good for tbh