SDL_Mixer - reading millisecond length of sound file

Is there any way to do this using SDL_Mixer or SDL?
As mentioned in previous thread, there seemed to be some issue calculating this, wasn’t sure if the issue still applies or not.
Need to know for the project I’m working on currently.
M@

ALmixer has this feature.

I forgot how much information is available to you in an SDL_Mixer
chunk. If you know things like total bytes, sample rate, and number of
channels, you can calculate the length yourself for sounds. But you
won’t be able to use this information for music/streams.

Thanks,
EricOn 5/11/14, mattbentley wrote:

Is there any way to do this using SDL_Mixer or SDL?
As mentioned in previous thread, there seemed to be some issue calculating
this, wasn’t sure if the issue still applies or not.
Need to know for the project I’m working on currently.
M@


Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

Eric Wing wrote:

I forgot how much information is available to you in an SDL_Mixer
chunk. If you know things like total bytes, sample rate, and number of
channels, you can calculate the length yourself for sounds. But you
won’t be able to use this information for music/streams.

Thanks I’ll look into it, although the impression I got from the prev thread on the subject was that this method of calculation doesn’t always work. But I expect for standard 44k 16-bit files it maybe should(?) work?
Will see.

Alright, so with 44k 16-bit stereo audio,
can decode the length of a mix_chunk via mix_chunk->alen - ie:

alen/((44100*2(bytes)*2(stereo))/1000)

or

(double)alen/176.4

gives the millisecond length of the clip.
Not sure why this isn’t already a function in SDL_Mixer.