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

**URL:** https://qa.fmod.com/t/array-full-of-zeros-when-i-try-to-get-the-spectrum-of-a-music/12812
**Category:** FMOD Engine
**Created:** [November 12, 2016, 4:45pm UTC](https://qa.fmod.com/t/array-full-of-zeros-when-i-try-to-get-the-spectrum-of-a-music/12812 "2016-11-12T16:45:25Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Olzindel](https://avatars.discourse-cdn.com/v4/letter/o/76d3ee/32.png) [@Olzindel](https://qa.fmod.com/u/Olzindel)
#### Post date: [November 12, 2016, 4:45pm UTC](https://qa.fmod.com/t/array-full-of-zeros-when-i-try-to-get-the-spectrum-of-a-music/12812/1 "2016-11-12T16:45:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)
#### Post date: [November 14, 2016, 11:30pm UTC](https://qa.fmod.com/t/array-full-of-zeros-when-i-try-to-get-the-spectrum-of-a-music/12812/2 "2016-11-14T23:30:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Olzindel](https://avatars.discourse-cdn.com/v4/letter/o/76d3ee/32.png) [@Olzindel](https://qa.fmod.com/u/Olzindel)
#### Post date: [November 15, 2016, 4:45pm UTC](https://qa.fmod.com/t/array-full-of-zeros-when-i-try-to-get-the-spectrum-of-a-music/12812/3 "2016-11-15T16:45:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)
#### Post date: [November 16, 2016, 3:51am UTC](https://qa.fmod.com/t/array-full-of-zeros-when-i-try-to-get-the-spectrum-of-a-music/12812/4 "2016-11-16T03:51:03Z")

</div>

> [@](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![Olzindel](https://avatars.discourse-cdn.com/v4/letter/o/76d3ee/32.png) [@Olzindel](https://qa.fmod.com/u/Olzindel)
#### Post date: [November 17, 2016, 3:09am UTC](https://qa.fmod.com/t/array-full-of-zeros-when-i-try-to-get-the-spectrum-of-a-music/12812/5 "2016-11-17T03:09:47Z")

</div>

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");

```

}

---

<div class="post-metadata">

### Author: ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)
#### Post date: [November 18, 2016, 12:17am UTC](https://qa.fmod.com/t/array-full-of-zeros-when-i-try-to-get-the-spectrum-of-a-music/12812/6 "2016-11-18T00:17:41Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Olzindel](https://avatars.discourse-cdn.com/v4/letter/o/76d3ee/32.png) [@Olzindel](https://qa.fmod.com/u/Olzindel)
#### Post date: [November 18, 2016, 4:44pm UTC](https://qa.fmod.com/t/array-full-of-zeros-when-i-try-to-get-the-spectrum-of-a-music/12812/7 "2016-11-18T16:44:57Z")

</div>

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
