MIX_SetTrackAudio(3)

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

πŸ’– MIX_SetTrackAudio(3) πŸ’–

okay bestie, welcome to the SDL_mixer3 FUNCTIONS corner of the manual, where today's main character is MIX_SetTrackAudio πŸŽ€


✨ NAME ✨

MIX_SetTrackAudio β€” sets a MIX_Track's input to a MIX_Audio. that's it, that's the whole job, and she does it flawlessly πŸ’…


✨ SYNOPSIS ✨

#include <SDL3_mixer/SDL_mixer.h>

bool MIX_SetTrackAudio(MIX_Track *track, MIX_Audio *audio);

✨ DESCRIPTION ✨

so, a MIX_Audio is audio data just sitting in RAM (it might still be in a compressed form, no biggie). and here's the iconic part: one single MIX_Audio can be assigned to multiple tracks at once. sharing is caring, we love to see it 🫢

once a track has a valid input, it can actually start mixing sound by calling MIX_PlayTrack(), or maybe MIX_PlayTag(). that's the moment it wakes up and becomes the moment ✨

calling this function with a NULL audio input? totally legal, bestie, don't worry. it just removes any input from the track. and if the track was currently playing, the next time the mixer runs it'll notice and mark the track as stopped, calling any assigned MIX_TrackStoppedCallback. so heads up if you've got a callback riding along πŸ‘€

it's also legal to change the input of a track while it's playing, but ngl, some states β€” like loop points β€” may cease to make sense with the new audio. lowkey awkward. in such a case, you can just call MIX_PlayTrack again to adjust parameters. problem solved, slay πŸ’–

and the best bit: the track will hold a reference to the provided MIX_Audio, so it is safe to call MIX_DestroyAudio() on it while the track is still using it. the track will drop its reference (and possibly free the resources) once it is no longer using the MIX_Audio. no use-after-free jumpscare, we stay winning πŸ˜­πŸ‘‘


✨ FUNCTION PARAMETERS ✨

  • track β€” the track on which to set a new audio input. (the one getting the glow-up πŸ’«)
  • audio β€” the new audio input to set. May be NULL. (NULL is fine, she's valid fr fr)

✨ RETURN VALUE ✨

returns true on success, false on error. and if it errors? call SDL_GetError() for details, because she will absolutely tell you what went wrong πŸ”


✨ THREAD SAFETY ✨

it is safe to call this function from any thread. go off, queen 🌈


✨ AVAILABILITY ✨

this function is available since SDL_mixer 3.0.0. retro? no. iconic? yes ⭐


and that's the whole page, bestie πŸ¦‹ you understood it perfectly, obviously.

signing off from SDL_mixer 3.2.4, page MIX_SetTrackAudio(3) β€” stay safe, stay thread-safe, and go mix something gorgeous πŸ’œπŸŽ€βœ¨

πŸ“¦ where this page comes from