Problem getting Spectrum in newer fmod versions

Hi guys,

I’ve been working on a project using fmod in it for more than a year. Unfortnately I had to format my computer and downloaded the latest version of fmod studio that has quite a few changes in using its syntax.

Now I’m not capable of getting the spectrum out of a sound. In the earlier version I used this way http://52.88.2.202/questions/question/forum-40164 wich was working really great. But in recent fmod versions the same source code is not working anymore. While the old method to write the spectrum into a buffer was like:

char s[256];
unsigned int len;
float *data = 0;
float freq[32];

result = dspfft->getParameterData(FMOD_DSP_FFT_SPECTRUM, (void **)&data, &len, s, 256);

the newer Version substitutes the FMOD_DSP_FFT_SPECTRUM with FMOD_DSP_FFT_SPECTRUMDATA and more importantly requires a different Buffer Parameter to write the spectrum through, which I guess is the FMOD_DSP_PARAMETER_FFT. But I don’t know how to use it.

I found this article http://52.88.2.202/questions/question/dsp-getparameterdata-silent-crash-unity that says it goes like this (I’m using Visual C++):

System::IntPtr unmanagedData;
    unsigned int unmanagedDataLen = 0;
    result = spectrum->getParameterData(FMOD.DSP_FFT.SPECTRUMDATA, (void **)& unmanagedData, unmanagedDataLen);
    FMOD_DSP_PARAMETER_FFT waveFormBuffer = (FMOD_DSP_PARAMETER_FFT)Marshal::PtrToStructure(unmanagedData, FMOD_DSP_PARAMETER_FFT::typeid);

But this goes nowhere. First I don’t understand why would I pass a managed pointer to a function that writes unmanaged data into it. Can’t I pass directly a FMOD_DSP_PARAMETER_FFT structure to the getParameterData method? Secondly, the PtrToStructure function can’t be used / compiled this way, since the FMOD_DSP_PARAMETER_FFT is not a managed type and the return type is also a managed System::Object, which can’t be converted to an unmanaged FMOD_DSP_PARAMETER_FFT structure.

Can somebody please give me a short example how to get the spectrum in latest releases? It would be also very helpful for other users to provide a spectrum example in future fmod studio api releases.

On the other hand, up to which version can I use my old syntax using the big float buffer? Is this version still available for download?

Thanks in advance for your help

FMOD_DSP_PARAMETER_FFT *fft;
fftdsp->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)&fft, 0, 0, 0));
for (int channel = 0; channel < fft->numchannels; channels++)
{
    for (int bin = 0; bin < fft->length; bin++)
    {
        float val = fft->spectrum[channel][bin];
    }
}

Thank you, that was exactly what I needed. Now it works perfectly again :slight_smile: