FFT behaving strangely

I’m trying to use JUCE’s FFT and everything’s good, it’s picking up the right frequencies etc, but it’s jumping up and down all the time when there’s no movement in the input. If I input a pure sine wave it jumps up and down rapidly from almost zero to its peak. Also, if I open another plugin in Ableton at the same time the GUI freezes. If anyone could point out where I’m going wrong I’d be very grateful:

  class FFTn
{
public:
    FFTn() : w(13)
    {
    }
    dsp::FFT w;

};

////////////////////////////////////////////////

FFTn v;

for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
    auto* channelData = buffer.getReadPointer (channel);

    // ..do something to the data...
    for (int i = 0; i < buffer.getNumSamples(); i++) {

        inF[i % 8192] = channelData[i];

        if (bufCount >= 8192)
        {
            v.w.performRealOnlyForwardTransform(inF, true);
            for (int r = 0; r < 8192; r++)
            {
                result[r] = -abs(inF[r]);
            }
            bufCount = 0;
            for (int rs = 0; rs < 8192; rs++) {
                inF[rs] = 0;
            }
        }
        
        bufCount++;
    }
}

Thank you!

I may have missed something, but you don’t appear to be setting the FFT size anywhere. And should inF be filled with bufCount being the index? ‘i’ (numSamples) might not get more than size 1 in some hosts.

1 Like

The FFT size is set in the constructor of the FFTn class which the poster has written. But there appears to be other issues in the code, like using a single object for multiple audio channels (maybe even a single object for all the plugin instances, is the FFTn v actually a global variable?), no windowing for the audio put into the FFT etc.

1 Like

Oh, I didn’t see the top class definition. But yeah, it’s all a bit wrong.

1 Like

Also none of the GUI/drawing code is shown, there could be issues in that too. For example, how is that synchronized with the audio code so that it draws from just the current finished analysis results and not some intermediate state?

1 Like

Thanks for your responses, using the frequency only version of the fft sorted it. :slight_smile:

I like to think of the incoming buffer as a continuous stream, not in blocks.
FL Studio for example, can have numSamples as low as one sample in length! - Always a good DAW to test, especially with its fast load times.
If you are in stereo, you’ll need to fill two buffers before doing two FFTs.