Juce fft

Hi all,

I have a few questions about the built-in JUCE FFT, as I'm having trouble using it.

So as a very basic example, I initialise the FFT object with an order of 9 and inverse=false. I create an array that is twice the size of the fft size and fill the first half of it with the input buffer and the second half with zeros. Then, I perform an FFT on it using performRealOnlyForwardTransform(), which AFAIK, returns an interleaved array of real and imaginary components. I then take this array and perform an IFFT using performRealOnlyInverseTransform and store the first half of the result in the output buffer. So theoretically, whatever audio passes through it should remain unchanged. However, it seems like the result of the IFFT contains values outside the range of -1 to 1 and I get a very distorted result.

Do we need to normalise the output of the IFFT? Also, what does the inverse boolean do? Do I need to set it to true in order to be able to perform an IFFT? I get a jassert error when I do. :/




This works:

int main (int, char*[]) {
    FFT fft{ 2/*bitstrength*/, false /*isInverse*/ };
    FFT inv{ 2/*bitstrength*/, true  /*isInverse*/ };
    float data[8] = {1,2,3,4, 0,0,0,0}; // time data
    struct FreqData { float mag, phase; };
    auto freqdata = (FreqData*)data;
    DBG(data[0]); DBG(data[1]); DBG(data[2]); DBG(data[3]); // 1 2 3 4
    return 0;


Didn't realise we're suppose to have two different FFT instances, one for forward and one for inverse. Thanks!

It still doesn't work for me.

I have created two global variables ​in the header file like so:

FFT invFFT;  

Then instantiated them in the constructor like so:

    invFFT(9, true),
    forFFT(9, false)
    //nothing here.

And then I use them like so. But I'm getting a jassert error. It seems like the inverse FFT enters the forward transform for some reason as the config object says inverse=true. fftInput is of length 1024 and I populate it with zeros before using it.

for (int channel = 0; channel < getTotalNumInputChannels(); ++channel){

    for(unsigned int n=0; n<512; n++){
        fftInput[n] = buffer.getReadPointer(channel)[n];



    for(unsigned int n=0; n<512; n++){
       buffer.getWritePointer(channel)[n] = fftInput[n];


Any idea why this doesn't work?

Hmm, first you create two variables, then you instantiate them. What's the difference?

I'm guessing you mean member variables rather than global variables.

Maybe you can evolve from my working example to your example over several small steps where you can check the result at each stage.

i.e. Get it working on a dummy waveform before applying it in an actual real-time audio render callback.

Maybe paste the whole file...


PS You will probably want to replace those loops with memcpy once you have it working

Hey pi,

I have copied and pasted your code into the processBlock function, but I still get the same error.

Please find attached a few screenshots. I tried redownloading JUCE and creating a new project but I get the same error over and over again.

Maybe an important detail is that I'm using REAPER 32-bit as the Xcode scheme for debugging and it works fine on other effects.


Thanks again,


PS, yeah I'm planning on replacing those. Just wanted to be completely sure I'm doing everything correctly.

Well first I declare them and then instantiate them using the FFT constructor.

BaptisteB solved a similar issue here: http://www.juce.com/forum/topic/issue-fft-plugin-inverse-transformation

Maybe that helps... using perform instead of performRealOnlyForwardTransform helped him...

Good Luck...

You should try pulling from github. See this recent commit :-)


What an unfortunate typo :D. I downloaded the latest version from the JUCE website but now I'll work with github repo directly.