0
0

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)
{
FMOD_RESULT result;

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

result = m_system->setSoftwareFormat(44100,FMOD_SOUND_FORMAT_PCM16,FMOD_SPEAKERMODE_STEREO,0,FMOD_DSP_RESAMPLER_LINEAR);

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)      

#define BINSIZE      (SPECTRUMRANGE / (float)SPECTRUMSIZE)

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)
{
    m_channel[p_nIndex]->setPosition(nPosition,FMOD_TIMEUNIT_MS);

    m_system->update();

    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)
    {
        m_pMusicIndicator[p_nIndex]->AddNode(dominanthz,nPosition);
    }

    oldDominanthz= dominanthz;

    nPosition+= TIME_ANALYSE_RANGE;
}

}[/code:kpr50x8n]

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
0
0

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.