Hello FMOD people.

I’m developing a technique to analyse an audio stream to be able to construct a game level from the music information. I was able to gather amplitude information and have no problem displaying the spectrum analysis on screen in realtime. But doing it in offline dosen’t want to work.

Here a portion of my code :

[code:kpr50x8n]void SpectrumAnalysis(int p_nIndex)

result = m_system->init(100, FMOD_INIT_NORMAL, 0);   


result = m_system->setOutput(FMOD_OUTPUTTYPE_NOSOUND_NRT); 

m_sound= NULL;
result = m_system->createSound("../musik.mp3", FMOD_SOFTWARE, 0, &m_sound);

#define TIME_ANALYSE_RANGE  10 //Not sure what is the best to put here...

#define OUTPUTRATE          44100
#define SPECTRUMSIZE        512

#define SPECTRUMRANGE       ((float)OUTPUTRATE / 2.0f)      


static float spectrum[SPECTRUMSIZE];
float        dominanthz = 0;
float        max;
int          dominantnote = 0;
float        binsize = BINSIZE;
int          bin= 0;

unsigned int nPosition= 0;

unsigned int nLenght;

m_sound->getLength(&nLenght, FMOD_TIMEUNIT_MS);

result= m_system->playSound(FMOD_CHANNEL_FREE, m_sound, false, &m_channel[p_nIndex]);

while(nPosition < nLenght)


    result= m_channel[p_nIndex]->getSpectrum(spectrum, SPECTRUMSIZE, 0, FMOD_DSP_FFT_WINDOW_TRIANGLE);

    max = 0;

    for (int count = 0; count < SPECTRUMSIZE; count++)
        if (spectrum[count] > 0.01f && spectrum[count] > max)
            max = spectrum[count];
            bin = count;

    dominanthz  = (float)bin * BINSIZE;       

    static float oldDominanthz= 0;

    if (abs(oldDominanthz - dominanthz) > 3.0f)

    oldDominanthz= dominanthz;

    nPosition+= TIME_ANALYSE_RANGE;


If you have any pointer or idea of where the problem could be, I’ll be glad to hear from experienced user.

Have a nice day all ! 😛

  • You must to post comments

Firstly you should make sure you check every FMOD function return code, it can give important information about what you are doing wrong.

I see you are calling System::setSoftwareFormat and System::setOutput, both of these calls need to occur before System::init to take any effect.

Also don’t use FMOD_SPEAKERMODE_STEREO for numoutputchannels, that enumeration doesn’t belong here (however it does just so happen to be equal to 2). You probably don’t wan’t to invoke speaker mode raw though, I would recommend setting that at 0 unless you are aware of the side affects.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.