How to set sample rate in a VST3 plugin

222 Views Asked by At

I try to create a vst3 plugin that can resample audio data to a given sample rate. Just like the "Resampling Plugin" of Wavelab.

How can a vst3 plugin change the output sample rate?

A further problem is that I have only one sample count: "data.numSamples". For the sample rate conversion the input and output sample count differs.

Is it even possible that vst3 plugins have different sample counts for input and output?

I wonder how the Wavelab Resampling Plugin manages this.

I tried to change the output sampling rate in the "setupProcessing" method, but this doesn't have any effect:


tresult PLUGIN_API MyPlugin::setupProcessing(ProcessSetup& newSetup)
{   
    newSetup.sampleRate = 48000.0;  
    processSetup.sampleRate = 48000.0;  
    return AudioEffect::setupProcessing(newSetup);
}
1

There are 1 best solutions below

1
ThomasG On

To change the output sample rate of a VST3 plugin, you need to modify the processSetup.sampleRate parameter of the setupProcessing method. However, changing the sample rate alone will not resample the audio data. You also need to modify the number of samples in each buffer to match the new sample rate.

For resampling, you can use a resampling algorithm such as linear interpolation or sinc interpolation. There are many libraries available for resampling, such as libsamplerate or SOX. You can incorporate one of these libraries into your VST3 plugin to perform the resampling.

Regarding the issue of having a different number of input and output samples, this is indeed possible in VST3 plugins. You can specify the number of input and output channels and the number of samples per channel in the setupProcessing method. In the process method, you can then process each input buffer and generate the corresponding output buffer with the appropriate number of samples.

As for how the Wavelab Resampling Plugin manages this, it likely uses a resampling algorithm similar to the ones mentioned above and adjusts the number of samples in each buffer accordingly.

tresult PLUGIN_API MyPlugin::setupProcessing(ProcessSetup& newSetup)
{   
    // Set the output sample rate to 48000 Hz
    newSetup.sampleRate = 48000.0;  

    // Save the updated process setup for later use
    processSetup = newSetup;

    // Call the base class setupProcessing method
    return AudioEffect::setupProcessing(newSetup);
}

In this version of the code, you're correctly updating the processSetup member variable to store the updated processing setup, and we're returning the result of the base class setupProcessing method. This should allow your plugin to correctly update the output sample rate to 48000 Hz. Remember to also implement the resampling algorithm and adjust the number of samples in each buffer as needed to correctly resample the audio data.