MIX_SetTrackAudioStream(3)
β¨ MIX_SetTrackAudioStream β¨
okay bestie, so this one lives in the SDL_mixer3 functions family (yes, the manual is literally called SDL_mixer3 FUNCTIONS) π and it's genuinely one of the most main-character moves in the whole library. Let's get into it.
πΈ NAME πΈ
MIX_SetTrackAudioStream β set a MIX_Track's input to an SDL_AudioStream. that's the whole job. she does one thing and she does it flawlessly π
π SYNOPSIS π
#include <SDL3_mixer/SDL_mixer.h>
bool MIX_SetTrackAudioStream(MIX_Track *track, SDL_AudioStream *stream);
β¨ DESCRIPTION β¨
okay so here's the tea π: using an audio stream means your app can generate any type of audio, in any format β maybe procedurally, maybe on-demand, whatever β and mix it in with all the other tracks. it's giving "I make my own sound from scratch and I still sit at the cool table." no cap.
when a track uses an audio stream, it will call SDL_GetAudioStreamData as it needs more audio to mix. so your app has options, bestie:
- buffer data to the stream ahead of time, or
- set a callback on the stream to provide data as needed.
for the deets, please refer to SDL's documentation. iykyk π«Ά
π¨ a given audio stream may only be assigned to a single track at a time!! duplicate assignments won't return an error (rude, I know), but assigning a stream to multiple tracks will cause each track to read from the stream arbitrarily β and that causes confusion and incorrect mixing. literally chaos. do not do this. π
once a track has a valid input, it can start mixing sound by calling MIX_PlayTrack(), or possibly MIX_PlayTag(). slay β¨
calling this function with a NULL audio stream is legal, and it 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 like, she'll catch the vibe check on her own. π
it is legal to change the input of a track while it's playing β however, some states, like loop points, may cease to make sense with the new audio. π in such a case, one can call MIX_PlayTrack again to adjust parameters. fixed! iconic.
the provided audio stream must remain valid until the track no longer needs it β either by changing the track's input or destroying the track. no dangling, fr fr. π
π¦ FUNCTION PARAMETERS π¦
trackβ the track on which to set a new audio input. (the one getting the glow-up β¨)streamβ the audio stream to use as the track's input. (the glow-up itself π)
π RETURN VALUE π
returns true on success, false on error β and if it's false, call SDL_GetError() for details. she'll tell you what went wrong, just ask π₯Ί
π THREAD SAFETY π
it is safe to call this function from any thread. multi-threaded queen behavior, we love to see it π
β AVAILABILITY β
this function is available since SDL_mixer 3.0.0. ancient. legendary. a classic π
and that's the whole page, bestie!! from the SDL_mixer crew, version SDL_mixer 3.2.4 β go forth and stream ur audio responsibly πβ¨ππ¦
π¦ 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