SDL Mixer - getting current volume/beat

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?

Sounds like you’ll need to do some FFT (fast fourier transforms) to change
the sound from a series of amplitutes over time to a set of frequencies over
time… from this you might be able to isolate the ‘beat’ you want to pick
up on.

Another option is to have a text file / data file / array pre-determined for
when these particular beats are supposed to occur. IE: a list of times
from the start of the sound for when to do somethings. That’ll involve you
having to note when you want each particular event to occur on a sheet of
paper or something, tho… and for each track you wanna do this kind of
thing with.

Other options include using a tracked format (mod/s3m/xm/it) and to have
events occur at particular pattern/rows, etc – but might be beyond the
scope of what sdl_mixer might be able to provide (i’m not keen on sdl_mixer
itself).

-WillOn 5/18/06, Phil Steinmeyer wrote:

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?


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl