tags:

views:

225

answers:

1

I'm getting interested in programming a VST plugin, and I have a basic knowledge of audio dsp's and FFT's.

I'd like to use VST.Net, and I'm wondering how to implement an FFT-based effect. The process-code looks like

public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)

If I'm correct, normally the FFT would be applied on the input, some processing would be done on the FFT'd data, and then an inverse-FFT would create the processed soundbuffer.

But since the FFT works on a specified buffersize that will most probably be different then the (arbitrary) amount of input/output-samples, how would you handle this ?

A: 

FFT requires that your buffer size is a power of two, but to get around this you should just implement an internal buffer and work with that instead. So for instance:

// 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 impose a bit of latency in your plugin, but the performance boost you can achieve by knowing the buffer size for FFT during compile time makes it worthwhile.

Also, this is a good workaround for hosts like FL Studio (aka "Fruity Loops") which are known to call process() with different blocksizes every time.

Nik Reiman
Bah, I just noticed that you're working in C#, but I gave you C++ example code. But whatever, the algorithm is pretty simple here and should give you a general idea as to what I mean.
Nik Reiman