Get sound file length

I load .wav and .ogg files using Mix_LoadWAV. Is there any way to get the duration of the sound file once it’s been loaded?

You can calculate the length of a Mix_Chunk in seconds by dividing yourChunk->alen by (frequency * channels * SDL_AUDIO_BITSIZE(format) / 8) where frequency, channels and format are the values that you passed to Mix_OpenAudio.

2 Likes