how to get Spectrum Data, including amplitudes, with FMOD_DSP_PARAMETER_FFT

Hi,

I can’t seem to use FMOD’s FFT function correctly. Also I am wondering how to get the amplitude values.

I play a sound with playSound, set the volume, add the FFT DSP, and then in each frame of my display function (infinite loop) I query the spectrum with the following:

void display(){

for (int i = 0; i < soundVec.size(); i++){
FMOD::Channel* cChannel = soundVec[i].getChannel();
FMOD::DSP* cDSP = soundVec[i].getDSP(); // the FFT DSP
cDSP->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)fft, 0, 0, 0);

    if (fullspectrum == true) {      // if getting fullSpectrum
        for (int i = 0; i < 2; i++){
            for (int j = 0; j < 32; j++){                
                freqVal = fft->spectrum[i][j];
                // do something with freqVal
                }
            }
        }


    else {   // if getting only Dominant Frequency.. ** THIS WORKS **
        cDSP->getParameterFloat(FMOD_DSP_FFT_DOMINANT_FREQ, &dfft, 0, 0);
        // float amplitude = ?
        // do something with dom freq (dfft)
    }
    cChannel->setPaused(false);
}

This gives me all very low frequency values - if I try multiplying them by 2000000000, I get some sound, but only one frequency, not a full spectrum.

Getting the dominant frequency seems to work fine.

Is it necessary to set the Window attributes? Should i be doing something with the Nyquist limit?

I realize I don’t really understand the FFT. But I hope to use it!
Any help would be greatly appreciated,

Jake

You should be calling the getParameterData function once, but you have it inside a loop? The data is a snapshot of the sound at the time. When did you call it, before or after/during the sound start?

Brett,

Are you saying I should be calling
cDSP->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)fft, 0, 0, 0);
in the display function but outside of the two for-loops? Or outside the display function? The display function is called once per program frame in my main loop.

When I play the sound by (keyboard) triggering a function newSound(), I add a corresponding Sound object that I store in a vector. Each program frame, in display(), I go through the vector and unpause the channels of all the Sounds, and do some spectral analysis. I added a reduction of my display function in the original post.

outside of any loops, there’s no reason to put it in a loop, what would you be iterating against? The code you now have above is better, but im not sure if your 2 loops are right still.

Are you using ‘2’ because the sounds are always stereo?
Are you using 32 because you assume there are only 32 entries? The number of entries there will be the number of entries in the FMOD_DSP_PARAMETER_FFT struct, usually controlled by FMOD_DSP_FFT_WINDOWSIZE.
Maybe its possible this is 2048 or and the values you are picking out are only the first 32 (low bass).

Ok, it’s much closer to working but I still have a couple questions:

  1. All of the frequencies are very low, even for 2000 < j < 2048 in spectrum[1][j]. For some reason, if I multiply the frequencies by ~ 10^7 I get audible sound. Do you have any idea why this might be?

  2. How can I query the respective amplitudes for each frequency component?

Thanks for helping me out with this.

The bin values are 0 to 1, what do you mean by audible sound? You can draw them all and get a representation of all the frequency components. The documentation already tells you #2. http://www.fmod.org/documentation/#content/generated/FMOD_DSP_PARAMETER_FFT.html “length
[r] Number of entries in this spectrum window. Divide this by the output rate to get the hz per entry.”

Answer in comments above ^^^