MIX_SetTrackAudio(3)
π 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 beNULL. (NULLis 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
- fedora 44: SDL3_mixer-doc 3.2.4-3.fc44 Β· Zlib AND (GPL-2.0-or-later OR LGPL-2.0-or-later)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms