VST plugin: using FFT on an arbitrary size audio input buffer, how?
I am interested in programming VST plugin and have basic knowledge of audio dsp and FFT.
I would like to use VST.Net and I am wondering how to implement the FFT effect. The process code looks like
public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
If I am correct, usually the FFT will be applied on the input, some processing will be done on the FFT'd data, and then the inverse FFT will create a processed audio buffer.
But since the FFT works with the specified buffering, which is likely to be different from the (arbitrary) number of I / O samples, how would you handle this?
a source to share
FFT requires your buffer size to be two, but to get around this you just have to implement an internal buffer and work with it. For example:
// MyNiftyPlugin.h
#define MY_NUM_CHANNELS 2
#define MY_FFT_BUFFER_SIZE 1024
class MyNiftyPlugin : public AudioEffectX {
// ... stuff ...
private:
float internalBuffer[MY_NUM_CHANNELS][MY_FFT_BUFFER_SIZE];
long internalBufferIndex;
};
And then in your process loop:
// MyNiftyPlugin.cpp
void process(float **input, float **output, long sampleFrames) {
for(int frame = 0; frame < sampleFrames; ++frame) {
for(int channel = 0; channel < MY_NUM_CHANNELS; ++channel) {
internalBuffer[channel][internalBufferIndex] = inputs[channel][frame];
}
if(++internalBufferIndex > MY_FFT_BUFFER_SIZE) {
doFftStuff(...);
internalBufferIndex = 0;
}
}
}
This will introduce a little lag in your plugin, but the performance gain you can achieve by knowing the compile-time FFT buffer size makes it useful.
Also, this is a good way for hosts like FL Studio (also known as "Fruity Loops"), which are known to call a process () with a different block each time.
a source to share