MIX_TrackMSToFrames(3)

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

✨ MIX_TrackMSToFrames(3) ✨

okay bestie, so this one lives in the SDL_mixer3 FUNCTIONS section of the manual, and it's literally the glow-up translator between milliseconds and sample frames πŸ’–


πŸŽ€ NAME πŸŽ€

MIX_TrackMSToFrames β€” convert milliseconds to sample frames for a track's current format πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3_mixer/SDL_mixer.h>

Sint64 MIX_TrackMSToFrames(MIX_Track *track, Sint64 ms);

🌸 DESCRIPTION 🌸

So here's the tea: this function does the math based on the track's current input format. And no cap, that format can change β€” it changes whenever the track's input changes, and it also changes if that input switches formats mid-stream (the iconic example: decoding a file that's literally two MP3s concatenated together 🫠). So it's giving "read the room, not your assumptions."

Now, the sad part 😭 β€” on various errors it returns -1:

  • MIX_Init() was not called
  • the track is NULL

Also, if the track has no input, it returns -1. And if ms is < 0, it returns -1 too. Basically if anything is off, it's a -1, periodt.


πŸ’œ FUNCTION PARAMETERS πŸ’œ

  • track β€” the track to query πŸ‘‘
  • ms β€” the milliseconds to convert to track-specific sample frames ⏱️

⭐ RETURN VALUE ⭐

Returns the converted number of sample frames, or -1 for errors / no input. When you get that -1, call SDL_GetError() for the details, bestie πŸ”


🧚 THREAD SAFETY 🧚

It is safe to call this function from any thread 🌈 β€” go off, no gatekeeping here.


πŸ‘‘ AVAILABILITY πŸ‘‘

This function is available since SDL_mixer 3.0.0 ⭐


πŸ“ SEE ALSO πŸ“


mwah πŸ’‹ that's the whole page, and it's from SDL_mixer 3.2.4, dated SDL_mixer β€” the OG source/version and date line, but make it cute. stay slay, go convert some frames πŸŽ€βœ¨

πŸ“¦ where this page comes from