0
0

Hi guys,
I ran into a problem while trying to integrate my own dsp unit (beat detection) in Fmod dsp chain. I successfully activated the FFT unit and plugged my own callback function, whose priority was set to FFT unit priority + 1. In this function, I’ve just planned to get the spectrum values ( FSOUND_DSP_GetSpectrum() ) and then analyze those datas. According to the documentation of Fmod, datas are roughly sent to sound device every 25 ms, passing through the dsp chain.
So I put a little timer counter in my own unit, expecting it would effectively measure 25 ms delay between each call. Everything just worked fine, except the callback gets called every 400 ms … I believe such a delay is not really adequate to compute instant energy for beat detection (replay rate for a stream was set to 44100 Hz).

Here is the code I use (c++) (Error checking was removed)
[code:1yhtt4ah]
FSOUND_Init(44100, 32, 0);
mp_Mp3Stream = FSOUND_Stream_Open("Mover.mp3",0,0,0);
mp_beatDetection = new Fmod_BeatDetectionUnit();
mp_beatDetection->M_plugIntoFmod(mp_Mp3Stream);
FSOUND_Stream_Play(0,mp_Mp3Stream);

int Fmod_BeatDetectionUnit::M_plugIntoFmod(FSOUND_STREAM* pStream)
{
FSOUND_DSPUNIT* mp_dspFFTUnit = FSOUND_DSP_GetFFTUnit();
FSOUND_DSP_SetActive(mp_dspFFTUnit,TRUE);
int fftPriority = FSOUND_DSP_GetPriority(mp_dspFFTUnit);
FSOUND_DSPUNIT* mp_dspBeatUnit = FSOUND_Stream_CreateDSP(pStream, (FSOUND_DSPCALLBACK) sM_beatDetection, fftPriority+1, (void*)this);
FSOUND_DSP_SetActive(mp_dspBeatUnit,TRUE);
return 0;
}

void* Fmod_BeatDetectionUnit::sM_beatDetection(void originalbuffer,void *newbuffer,int length,void *userdata)
{
Fmod_BeatDetectionUnit
pThis = (Fmod_BeatDetectionUnit*) userdata;
float dt = getTimeAndDelta(); // in seconds
printf("Fmod_BeatDetectionUnit::sM_beatDetection(), dt=%1.4f s, length=%d\n", dt, length);
return newbuffer;
}

[/code:1yhtt4ah]

Output prints “Fmod_BeatDetectionUnit::sM_beatDetection(), dt=0.3986 s, length=17408”, var “dt” being around 0.400 at each call.

I am surely missing an obvious thing, but why is there such a delay ?
Thanks for your help and ideas.

Julien.

PS : Using Fmod 3 on Windows XP (SP2) ( with Directx 9.0b installed)

  • You must to post comments
0
0

Hi guys,
I tried different approaches , mainly by trying different combinations of flags in FSOUND_init(). I downloaded the latest package and upgraded. Nothing happened, the DSP unit is called every 400 ms.

[code:wof04p8z]
printf("FSOUND_DSP_GetBufferLength()=%d\n", FSOUND_DSP_GetBufferLength());
printf("FSOUND_DSP_GetBufferLengthTotal()=%d\n", FSOUND_DSP_GetBufferLengthTotal());
[/code:wof04p8z]

FSOUND_DSP_GetBufferLength() returns 1024 (which is roughly 25ms at 44,1 kHz) while FSOUND_DSP_GetBufferLengthTotal() returns 4096.

Does anybody have a clue? Thanks for reading.

  • You must to post comments
0
0

Thanks, this is working fine now.
Wow, this was a big obvious thing I didn’t see 😕

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.