is it possible to get the time length of a loaded chunk in SDL_mixer? In
seconds, ticks, or the like?
/* untested code follows… */
Uint32 getChunkTimeMilliseconds(Mix_Chunk chunk)
{
Uint32 points = 0;
Uint32 frames = 0;
int freq = 0;
Uint16 fmt = 0;
int chans = 0;
/ Chunks are converted to audio device format… /
if (!Mix_QuerySpec(&freq, &fmt, &chans))
return 0; / never called Mix_OpenAudio()?! */
/* bytes / samplesize == sample points */
points = (chunk->alen / ((fmt & 0xFF) / 8));
/* sample points / channels == sample frames */
frames = (points / chans);
/* (sample frames * 1000) / frequency == play length in ms */
return (frames * 1000) / freq);
}
–ryan.