Array full of zeros when i try to get the spectrum of a music

Hello,
I’m trying to get the spectrum of a music that I am playing. So i made this function (C language):

void GetSpectrum(FMOD_SYSTEM *system,int Spectrum[],FMOD_CHANNEL *channel)
{
    FMOD_DSP *dspFFT;
    FMOD_DSP_PARAMETER_FFT *fftparameter;
    FMOD_RESULT result;
    FMOD_BOOL bypass=0,actif=1;
    int len=512;



    result=FMOD_System_CreateDSPByType(system,FMOD_DSP_TYPE_FFT,&dspFFT);
    ERRCHECK(result);


    result=FMOD_DSP_SetParameterInt(dspFFT,FMOD_DSP_FFT_WINDOWTYPE,FMOD_DSP_FFT_WINDOW_TRIANGLE);
    ERRCHECK(result);

    result=FMOD_DSP_SetParameterInt(dspFFT,FMOD_DSP_FFT_WINDOWSIZE,512);
    ERRCHECK(result);

    result=FMOD_Channel_AddDSP(channel,FMOD_CHANNELCONTROL_DSP_HEAD,dspFFT);
    ERRCHECK(result);

    result=FMOD_System_Update(system);
    ERRCHECK(result);


    result=FMOD_DSP_SetActive(dspFFT,actif);
    ERRCHECK(result);

    result=FMOD_DSP_SetBypass(dspFFT,bypass);
    ERRCHECK(result);

    result=FMOD_DSP_GetParameterData(dspFFT,FMOD_DSP_FFT_SPECTRUMDATA,&fftparameter,&len,NULL,0);
    ERRCHECK(result);
}

Unfortunaly, that gives me only an array full of zeros. Does anyone got a solution to my problem ?

P.S.: Please, excuse my bad english.

You have to create/add the DSP once, then call FMOD_DSP_GetParameterData in realtime, every time your update loop happens.

It is not a one off call. You call it continuously and it will change as the music plays.

The first time you call it it will probably be all zeroes because the music hasnt started yet.

1 Like

Thanks for your answer !

In order to test the function, I assigned a key (q on my keyboard) which call this function. But even if the music is playing, I still got this array full of those stupid zeros… Therefore I don’t think that the problem is because the music doesn’t play. But i may be wrong. Sorry if I didn’t get what you mean.

you’re calling it directly after creating it. It won’t have time to process in the system.

Create it first THEN get the spectrum on your key. dont keep creating the object each time.

1 Like

Ok i got it ! No more zero ! But no i have incredible huge numbers (like this one : 18730383245949875098769859401356820402843921296264573530200071497301346439423675784557603925206290482594135453810548559095756062870434891324118686624044041485775885929731896735271126585147654144.000000).
Here is my function :

void GetSpectrum(FMOD_SYSTEM *system,FMOD_CHANNEL *channel,FMOD_DSP *dspFFT,FMOD_DSP_PARAMETER_FFT *fftparameter)
{
FMOD_RESULT result;

result=FMOD_System_Update(system);
ERRCHECK(result);
int i;
printf("Spectrum : \n");

for(i=0 ;i < 256 ;i++)
    printf("%f   ",fftparameter->spectrum[i]);
printf("\n");

}

its possible you’re passing garbage/the wrong pointer to your function. You didnt specify how you called that function.
Check the dominant frequency parameter first to make sure the fft is working on the signal properly. It should change over time.

1 Like

After hours of pain, i think I got this ! My problem was that I didn’t used my FFT_Parameter proprely : I thought that fftparameter->spectrum was just a simple array. But it isn’t ! Thanks a lot !
Sincerly