PDA

View Full Version : SDL Mixer - getting current volume/beat


Phil Steinmeyer
05-18-2006, 12:18 PM
I want to have a certain visual effect in my game correspond to the beats in my music. I'm using SDL Mixer and an OGG for music.

So I need to determine the beat frequency/current 'beat' position.

The music is roughly 3 beats per second (but it's not entirely constant throughout the song). The beat is quite pronounced, and for my purposes, it's dominant enough that I can ignore the other instruments in the song. I can essentially . Looking at the song in a wave editing program, it appears that I can get what I need by determining the peak volume in the last N milliseconds - let's say N is 10. i.e. the Music peaks with every beat (the beat is quite pronounced in the song I'm using).

So, I need something like 'GetCurrentVolume', where volume is the volume within the song at the current instant, (rather than, say the global volume that all sound or music is being played at). But GetCurrentVolume wouldn't be quite right either, as the volume is moving up and down at the frequency of the bass drum, so really what I need to do is grab a chunk of the music data just played (or about to be played), and find the peak volume within that chunk.

I see this function:
Mix_Chunk * SDLCALL Mix_GetChunk(int channel)
which seems like maybe it would help me do what I need, but I don't know what channel to pass it to get music data. AFAIK, none of the music play stuff returns a channel - it seems like music runs differently from normal sounds anyways, so I'm not sure if this is the right function.

Anybody know how to get the data I need?

HairyTroll
05-18-2006, 01:17 PM
Beat Detection Algorithms (http://www.gamedev.net/reference/programming/features/beatdetection/), and FFTW (http://www.fftw.org/).

Phil Steinmeyer
05-18-2006, 01:49 PM
Yeah, at the moment, it's not the algorithm so much as the means of getting the needed data out of SDL_Mixer. Anybody know how to do it?

mahlzeit
05-18-2006, 01:59 PM
Maybe you can use SDL_Sound: http://icculus.org/SDL_sound/

Phil Steinmeyer
05-18-2006, 02:41 PM
Mix_SetPostMix does the trick - it gives me the sound buffer fully mixed. Since I'm not playing sound FX other than music at the time I need this, that's good enough for me.