MIX_GetAudioDuration(3)

πŸ“¦
version 3.2.4 Β· 2 versions
, in fedora 44

πŸ’– MIX_GetAudioDuration(3) πŸ’–

okay bestie, so this one lives in the SDL_mixer3 girlies (the functions section, iykyk) and it's literally all about one thing: how long is this audio actually gonna play for? Not in vibes, not in "ehh like three minutes?" β€” in sample frames. ✨


🌸 NAME 🌸

MIX_GetAudioDuration β€” get the length of a MIX_Audio's playback in sample frames. that's it, that's the whole job πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3_mixer/SDL_mixer.h>

Sint64 MIX_GetAudioDuration(MIX_Audio *audio);

#define MIX_DURATION_UNKNOWN -1
#define MIX_DURATION_INFINITE -2

πŸ’… DESCRIPTION πŸ’…

soooo if you're the type who likes properties, this same info is also available via the MIX_PROP_METADATA_DURATION_FRAMES_NUMBER property. But it's such a common thing to want that they just went ahead and gave us a cute lil accessor function. obsessed. 🫢

Now β€” the important part, bestie, don't skip this: this reports the length of the data in sample frames. Why does that matter? Because that's what makes sample-perfect mixing possible. periodt. But here's the catch, and it's giving important: sample frames are only meaningful as a measure of time if you also know the sample rate (aka the frequency). No sample rate, no timeline. If you wanna convert from sample frames to milliseconds, go use MIX_AudioFramesToMS(). πŸ’–

Also, not every audio file format can even tell you the complete length of the data it's gonna produce when it decodes. Some literally can't calculate it. Some might produce infinite audio, which is a whole mood honestly. 😭

And there's more (ngl, it's a little messy): some file formats can only report duration as a unit of time, which means SDL_mixer might have to estimate the sample frames from that. Less precision = the reported duration might be off by a few sample frames in either direction. πŸ’€ So like… close enough, but not exact-exact.

If a duration is known, you'll get a value >= 0. But it might also hand you MIX_DURATION_UNKNOWN or MIX_DURATION_INFINITE. Slay, or mystery. You'll find out. πŸ”₯


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • audio β€” the audio you're querying. the one you're asking "so how long are you, babe?" πŸ’œ

⭐ RETURN VALUE ⭐

Returns the length of the audio in sample frames, OR MIX_DURATION_UNKNOWN, OR MIX_DURATION_INFINITE. Three possible outcomes, main character energy, no in-between. πŸ‘‘


🧚 THREAD SAFETY 🧚

It is safe to call this function from any thread. yes bestie, ANY thread. go wild, no cap. 🌈


πŸ“ AVAILABILITY πŸ“

This function has been available since SDL_mixer 3.0.0. been iconic since day one fr fr. πŸ‘‘


quick recap so you don't have to scroll: MIX_Audio in, sample frames out (Sint64), MIX_DURATION_UNKNOWN is -1, MIX_DURATION_INFINITE is -2, and if you need ms, it's MIX_AudioFramesToMS(). you got this πŸ’–

and that's the whole page, bestie β€” brought to you by SDL_mixer 3.2.4, the SDL_mixer crowd, and the MIX_GetAudioDuration(3) manual. love that for us. mwah πŸ’…βœ¨

πŸ“¦ where this page comes from