Using FFTW3


Hey all

I'm trying to FFTW's fourier analysis library in a project heavily dependant on JUCE for all signal buffers. It appears that fftw's transform algorithms take standard float[] arrays as input buffers (whether calculations are made in-place or out). The AudioSampleBuffer object passed from processor to processor throughout the JUCE architecture contains all of this data, but not in a way that FFTW can read.


How do I get the data stream out of the AudioSampleBuffer in a form that a FFT algorithm can recognize as a valid input?



getReadPointer() returns a float pointer, which should do the job.

If you need float[] arrays (which I understand are two dimensional float arrays), you can do something like:

const float *data[2] = { buffer.getReadPointer(0, 0), buffer.getReadPointer(1, 0) };

However they are not guaruanteed to be aligned, but I don't know if FFTW assumes alignment.




Yeah, If I remember correctly, FFTW uses interleaved arrays, and the Juce returned pointer will be to a contiguous array.

Meaning, you will have to write a quick translation (cycle through the Juce array and copy the floats over to a new interleaved array for processing).  You also need to condition the array with a windowing function (see FFTW docs for that). 


The reason for this is that some calculation used for calculating FFTs are much faster when using interleaved data.


Also - FFTW is good, I would also put in a recomendation for kissFFT (which is a bit easier to use than FFTW IMHO, and arguably just as fast).  It also uses interleaved data, so you would have to do the translation either way.


To add to what Aaron said, if it helps any and can apply (since I’ve no knowledge of these libraries), JUCE provides functions for interleaving and deinterleaving.