# Using getParameterData//getParameterFloar to save spectrum in a float

**URL:** <https://qa.fmod.com/t/using-getparameterdata-getparameterfloar-to-save-spectrum-in-a-float/11924>\
**Category:** FMOD Engine\
**Created:** [May 17, 2015, 2:26pm UTC](https://qa.fmod.com/t/using-getparameterdata-getparameterfloar-to-save-spectrum-in-a-float/11924 "2015-05-17T14:26:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![custodio](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@custodio](https://qa.fmod.com/u/custodio)\
**Post date:** [May 17, 2015, 2:26pm UTC](https://qa.fmod.com/t/using-getparameterdata-getparameterfloar-to-save-spectrum-in-a-float/11924/1 "2015-05-17T14:26:22Z")

</div>

Hi, I’m trying to save the Spectrum in my FMOD\_DSP\_PARAMETER\_FFT but I’m only receiving the spectrum full of zeros, if you can watch my mistake I will agree.

```
FMOD::System *system;
FMOD::Sound *sound1;
FMOD::Channel *channel = 0;
FMOD::ChannelGroup *mastergroup;
FMOD::ChannelControl *control;
FMOD::DSP *mydsp, *dsphead, *dspchannelmixer;
FMOD::DSPConnection *conection;
FMOD_RESULT result;
unsigned int version;
result = FMOD::System_Create(&system);
result = system->getVersion(&version);

result = system->init(32, FMOD_INIT_NORMAL, NULL);
result = system->createSound("MySong.mp3",FMOD_DEFAULT, 0, &sound1);
result = sound1->setMode(FMOD_LOOP_NORMAL);
result = system->playSound(sound1, 0, true, &channel);

/*
Create the DSP effect.
*/
result = system->getMasterChannelGroup(&mastergroup);
result = system->createDSPByType(FMOD_DSP_TYPE_FFT, &mydsp);

result = system->getMasterChannelGroup(&mastergroup);
result = mastergroup->addDSP(0, mydsp);

result = mydsp->setBypass(true);
result = mydsp->setActive(true);

char s[256];
unsigned int len;
float freq[32];

float fft = 0;
std::vector<float> fftheights;
float m_spectrum_data[FFT_NUM_BINS];

while (1) { //program loop

unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = 0;
bool paused = 0;
int channelsplaying = 0;
  if (channel)
  {
    FMOD::Sound *currentsound = 0;
    result = channel->setPaused(false);
    result = channel->setMute(false);
    result = channel->isPlaying(&playing);
    result = channel->getPaused(&paused);
    result = channel->setVolume(0.5);
    result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
    channel->getCurrentSound(&currentsound);
    if (currentsound)
    {
      result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);

      
    }
  }

  system->getChannelsPlaying(&channelsplaying);

  FMOD_DSP_PARAMETER_FFT *fftparameter;
  float val;
  char s[256];
  unsigned int len;
  float *data = 0;
  float freq[32];
  int rate, chan, nyquist;
  int windowsize = 1024;

  result = system->getSoftwareFormat(&rate, 0, 0);
  

  result = mydsp->setParameterInt(FMOD_DSP_FFT_WINDOWTYPE, FMOD_DSP_FFT_WINDOW_TRIANGLE);

  result = mydsp->setParameterInt(FMOD_DSP_FFT_WINDOWSIZE, windowsize);

  result = mydsp->getParameterFloat(FMOD_DSP_FFT_DOMINANT_FREQ, &val, 0, 0);

  result = mydsp->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)&fftparameter, &len, s, 256);

  nyquist = windowsize / 2;

  for (chan = 0; chan < 2; chan++)
  {
    float average = 0.0f;
    float power = 0.0f;

    for (int i = 0; i < nyquist - 1; ++i)
    {
      float hz = i * (rate * 0.5f) / (nyquist - 1);
      int index = i + (16384 * chan);

      if (fftparameter->spectrum[chan][i] > 0.0001f) // arbitrary cutoff to filter out noise
      {
        average += data[index] * hz;
        power += data[index];
      }
    }

    if (power > 0.001f)
    {
      freq[chan] = average / power;
    }
    else
    {
      freq[chan] = 0;
    }
  }
  printf("\ndom freq = %d : %.02f %.02f\n", (int)val, freq[0], freq[1]);
}

```

My fftparameter-\>spectrum is always an array of zero values and I don’t know if I’m not making well the addition of DSPs to the channel…  
Please, in case that you can correct this, can you do it without modify the sound that is playing??  
Thank you.

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [May 18, 2015, 5:23am UTC](https://qa.fmod.com/t/using-getparameterdata-getparameterfloar-to-save-spectrum-in-a-float/11924/2 "2015-05-18T05:23:11Z")

</div>

1. Call system::update() in your program loop.
2. Don’t bypass the FFT dsp.
