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