No Matches
Plugin Reset

Before getting into details about audio processing, we need to think about what happens after the user loads the plugin, but before audio data streams through it. One of the most important pieces of information we need is the current sample rate of the audio that will be processed through the plugin. Knowing the sample rate is critical for many of our calculations. This usually includes filter coefficients and delay-buffer sizes. The various API's each provide a mechanism for retrieving the current sample rate and this will depend on the API manufacturer. In some systems, the sample rate might change during the course of a DAW session and in others it must be locked down and set prior to the sessions creation. In all cases, the sample rate will not change while the audio is streaming into the plugin.

The PluginCore implements a reset function that is called during the plugin initialization, and then again any time the sample rate changes. It is also called in some APIs if the user stops and then restarts audio playback. There is some grey area here as well, based on how the DAW designers interpret the plugin API, or how the DAW itself operates and handles files with different sample rates. However, we can be sure that the reset function will be called at least once at initialization. You can find the reset function implementation in the plugincore.cpp file just below the initPluginParameters( ) function.

When you create your project, the function will have a default implementation shown here:

bool PluginCore::reset(ResetInfo& resetInfo)
// --- save for audio processing
// --- other reset inits
return PluginBase::reset(resetInfo);
AudioProcDescriptor audioProcDescriptor
current audio processing description
Definition: pluginbase.h:417
virtual bool reset(ResetInfo &resetInfo)
initialize object for a new run of audio; called just before audio streams
Definition: pluginbase.cpp:71
virtual bool reset(ResetInfo &resetInfo)
initialize object for a new run of audio; called just before audio streams
Definition: plugincore.cpp:66
double sampleRate
sample rate
Definition: pluginstructures.h:1237
uint32_t bitDepth
wav file bit depth (not supported in all APIs)
Definition: pluginstructures.h:1238
Sample rate and bit-depth information that is passed during the reset( ) function.
Definition: pluginstructures.h:181
uint32_t bitDepth
bit depth (not available in all APIs)
Definition: pluginstructures.h:192
double sampleRate
sample rate
Definition: pluginstructures.h:191

The reset function argument is a ResetInfo structure reference. This simple structure has only two members, one for the sample rate and one for the bit-depth. The bit-depth information is not available in all APIs, and is somewhat of a legacy attribute, dating back to the fixed-point processing days and early plugin APIs, so we will ignore it in our plugins here. However, if you are writing a plugin that needs to know if the audio file feeding it is 16-bit versus 24-bit and the API allows it, then you may use this information accordingly. You can see from the default implementation that the sample rate is stored on our audioProcDescriptor member variable, and you can access this value at any time and from any function in the core.

After storing the sample rate, your plugin may need to perform other resetting operations including:

  • re-calculating filter coefficients based on a new sample rate
  • flushing delay registers and buffers of old audio data so it is not used during the next processing run
  • re-sizing buffers that are sample-rate dependent (like the circular buffers we use for delay and reverb plugins)
  • resetting pointers, index values or anything else to prepare for a fresh audio processing cycle
    Nothing in our volume plugin's functionality is going to require sample rate updates or resetting for fresh audio runs, so here we will not bother with it. However, in most of the plugin projects, there will be something to adjust based on the sample rate so we will include the reset function as part of the other audio processing function descriptions.