I found this: http://www.gamedev.net/reference/progra … detection/

I think I understand it so far. I’m looking to implement algorithm #2, however I do not know how to do so with fmod. If anyone is willing to help, it would be greatly appreciated.

EDIT: I’m using

FSOUND_GetCurrentLevels(0, left_data[i], right_data[i]);

to obtain sound data from the song being played, but any time I try to implement the algorithm, the instant energy is always smaller than the local energy, so no beats are detected.

- moon_rabbits asked 10 years ago

- You must login to post comments

I think you need to get the wave data. The function you are using just gets the left and right volume. You need to actually get the sample data. With this version of FMOD i believe you need to get the wave data by creating a DSP callback. If you use FMOD_EX then its much simpler.

I tried a bit of beat detection a few years ago, but I havent messed with it since and it certainly wasnt as sophisticated as these algorithms.

- nci answered 10 years ago

- You must login to post comments

Here goes an example, I used this spectrum for the frequency based beat detection and also could help you finding the way for implementing sample/time based ones (http://www.fftw.org for calculating FFT):

double* soundsystem::getspectrum(void) {

void *p1,*p2;

unsigned int blen1,blen2,actpos;

int i,*pi1,*pi2;

```
FSOUND_SAMPLE *sample = FSOUND_GetCurrentSample(0);
// 0 - 34816
actpos = FSOUND_GetCurrentPosition (0);
if(oldpos != actpos) {
FSOUND_Sample_Lock (sample,oldpos*4,1024*4,&p1,&p2,&blen1,&blen2);
pi1 = (int *)p1;
pi2 = (int *)p2;
// Mix left and right channel
for(i = 0 ; i < 1024 ; i++) {
m[i] = (((pi1[i] >> 16) & 0x0000FFFF) + (pi1[i] & 0x0000FFFF))/2.0;
}
plan_forward = fftw_plan_dft_r2c_1d(n, m, fftwout, FFTW_ESTIMATE);
fftw_execute(plan_forward);
for(i = 0 ; i < fft_size ; i++) {
fft[i] = sqrt(fftwout[i+1][0]*fftwout[i+1][0] +
fftwout[i+1][1]*fftwout[i+1][1]);
}
FSOUND_Sample_Unlock(sample,p1,p2,blen1,blen2);
oldpos = actpos;
}
return fft;
```

}

- glertxundi answered 10 years ago

- You must login to post comments

**Your Answer**

Please login first to submit.