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)
FSOUND_Init(44100, 32, 0);
mp_Mp3Stream = FSOUND_Stream_Open("Mover.mp3",0,0,0);
mp_beatDetection = new Fmod_BeatDetectionUnit();
int Fmod_BeatDetectionUnit::M_plugIntoFmod(FSOUND_STREAM* pStream)
FSOUND_DSPUNIT* mp_dspFFTUnit = FSOUND_DSP_GetFFTUnit();
int fftPriority = FSOUND_DSP_GetPriority(mp_dspFFTUnit);
FSOUND_DSPUNIT* mp_dspBeatUnit = FSOUND_Stream_CreateDSP(pStream, (FSOUND_DSPCALLBACK) sM_beatDetection, fftPriority+1, (void*)this);
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);
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.
PS : Using Fmod 3 on Windows XP (SP2) ( with Directx 9.0b installed)
- v3ga asked 13 years ago
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.
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.
Please login first to submit.