MIX_SetTrackRawIOStream(3)

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

πŸ’– MIX_SetTrackRawIOStream(3) πŸ’–

okay bestie, welcome to the SDL_mixer3 FUNCTIONS section of the manual, and today's main character is MIX_SetTrackRawIOStream πŸŽ€


✨ NAME ✨

MIX_SetTrackRawIOStream β€” set a MIX_Track's input to an SDL_IOStream that's feeding you raw PCM data πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3_mixer/SDL_mixer.h>

bool MIX_SetTrackRawIOStream(MIX_Track *track, SDL_IOStream *io, const SDL_AudioSpec *spec, bool closeio);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so first things first, bestie: this is not the recommended way to set a track's input. Like, at all. πŸ™ˆ But it does have one very specific little slay of a use case: a large file, played once, that has to be read from disk in small chunks as needed. That's the vibe. That's the scenario.

In most cases though? You're way better off creating a MIX_Audio ahead of time and calling MIX_SetTrackAudio() instead. fr fr.

Also worth knowing: MIX_SetTrackAudioStream() can _also_ hand raw PCM audio to a track, but via an SDL_AudioStream. That one might be preferable, unless your data is already coming directly from an SDL_IOStream. iykyk.

The stream you hand over here should provide audio in raw PCM format. no cap.

⚠️ A given IOStream may only be assigned to a single track at a time. Duplicate assignments won't return an error β€” but if you assign one stream to multiple tracks, each track will read from that stream arbitrarily, which causes confusion and incorrect mixing. it's giving chaos πŸ’€

Once a track has a valid input, it can start mixing sound by calling MIX_PlayTrack(), or possibly MIX_PlayTag(). 🎢

Calling this function with a NULL stream is legal, and it removes any input from the track. If the track was currently playing, the next time the mixer runs it'll notice this and mark the track as stopped, calling any assigned MIX_TrackStoppedCallback. bye bestie πŸ‘‹

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. glow-up moment ✨

🫢 The provided stream must remain valid until the track no longer needs it β€” either by changing the track's input or by destroying the track.

πŸ’… FUNCTION PARAMETERS πŸ’…

  • track β€” the track on which to set a new audio input πŸ‘‘
  • io β€” the new i/o stream to use as the track's input 🌊
  • spec β€” the format of the PCM data that the SDL_IOStream will provide 🎚️
  • closeio β€” if true, close the stream when done with it πŸ”’

⭐ RETURN VALUE ⭐

Returns true on success, false on error. If it's giving error, call SDL_GetError() for details 😭


🧚 THREAD SAFETY 🧚

It is safe to call this function from any thread. multitasking queen 🐝


🌈 AVAILABILITY 🌈

This function is available since SDL_mixer 3.0.0. vintage but iconic ✨


πŸ“ SEE ALSO πŸ“


and that's the whole page, bestie!! πŸ’œ this was SDL_mixer β€” specifically SDL_mixer 3.2.4, dated with the MIX_SetTrackRawIOStream(3) page, so go forth and stream that raw PCM responsibly. mwah πŸŽ€πŸ’–

πŸ“¦ where this page comes from