Goodmorning there,
i am trying to use dsp::FFT
I have managed to apply forward and inverse with perfect results in 44100 sampleRate and 448 samples/buffer using the following code.
I choose 7th order FFT so that FFTSize is an integer product of buffer’s samples. If i dont do that, the last window will remain incomplete.
How do we cope with different sample rates and different buffer sizes for this to work?
processor.h:
fftOrder = 7,
fftSize = 1 << fftOrder // FFT size = 64 = buffer samples/7
std::unique_ptr<dsp::FFT> myFFT;
float fifo[fftSize];
float fftData[2 * fftSize];
int fifoIndex = 0;
processor.cpp/constructor:
//initialise FFT obgject
myFFT.reset(new dsp::FFT(fftOrder));
processor.cpp/processBlock:
for (int channel = 0; channel < totalNumInputChannels; ++channel){
auto* channelData = buffer.getWritePointer (channel);
for (int i = 0; i < buffer.getNumSamples(); i++) {
//fill fft array
fifo[fifoIndex] = channelData[i];
fifoIndex++;
//when fft window is full
if (fifoIndex == fftSize)
{
//reset window index
fifoIndex = 0;
//create FFT input data in appropriate size
zeromem(fftData, sizeof(fftData));
memcpy(fftData, fifo, sizeof(fifo));
//perform forward FFT on fftData
myFFT->performRealOnlyForwardTransform(fftData, true);
//fftData now contains frequency domain information
//perform inverse FFT on frequency domain information fftData
myFFT->performRealOnlyInverseTransform(fftData);
//write fftData back to audio buffer
for (int j = 0; j < (fftSize); j++){
channelData[(i - fftSize + 1) + j] =fftData[j];
}
}