MIX_LoadRawAudio(3)

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

✨ MIX_LoadRawAudio(3) β€” the SDL_mixer3 glow-up ✨

okay bestie, sit down, hydrate, and let's talk about MIX_LoadRawAudio from the SDL_mixer3 function squad πŸ’– this one's in the SDL_mixer3 FUNCTIONS lineup and she's literally the "load it once, play it a million times" girlie.


🌸 NAME 🌸

MIX_LoadRawAudio β€” load raw PCM data straight out of a memory buffer. no cap. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3_mixer/SDL_mixer.h>

MIX_Audio * MIX_LoadRawAudio(MIX_Mixer *mixer, const void *data, size_t datalen, const SDL_AudioSpec *spec);

look at her. four args. flawless. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

so here's the tea β˜• β€” there's a whole other way to do raw PCM, and that's _streaming_ it. an SDL_AudioStream can be connected to a track, and so can an SDL_IOStream, and those will read from their sources on-demand when it's actually time to mix the audio. very "we'll get to it when we get to it" energy. πŸ™ˆ

This function, though? this one is for loading static audio data β€” the kind you're gonna play over and over again. the way that it just... loads it and keeps it. iconic. πŸ‘‘

what she does: pulls in the raw data in its entirety, caches it in RAM, and allocates a copy of it. so if your original data is gonna outlive the MIX_Audio you just made, you don't need that copy at all β€” go use MIX_LoadRawAudioNoCopy() instead and dodge the extra allocations and copies. saving those cycles fr fr. ✨

and the best part? MIX_Audio objects can be shared between multiple mixers 🫢 the mixer parameter is just you going "hey, this is probably the mixer I'll use it with, in case some optimization gets applied" β€” but it's not required, and you can totally pass a NULL mixer. lowkey freedom.


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • mixer β€” a mixer this audio is intended to be used with. May be NULL. (yes really, she can be unattached πŸ’…)
  • data β€” the raw PCM data to load. the actual goods. πŸ“
  • datalen β€” the size, in bytes, of the raw PCM data. count your bytes bestie.
  • spec β€” what format the raw data is in. gotta know the vibe of the data.

🌈 RETURN VALUE 🌈

hands you back an audio object that can be used to make sound on a mixer 🎢 ...or NULL on failure 😭 β€” and if that happens, call SDL_GetError() for the deets. always check, never assume.


πŸ’€ THREAD SAFETY πŸ’€

It is safe to call this function from any thread. go wild. multithreaded queen. πŸ”₯


⭐ AVAILABILITY ⭐

This function is available since SDL_mixer 3.0.0. she's been here. veteran behavior. πŸ‘‘


🧚 SEE ALSO 🧚


go read those too, bestie, iykyk πŸ’–

okay that's the whole page!! this was brought to you by SDL_mixer 3.2.4, and the manual name MIX_LoadRawAudio(3) β€” and yeah, this was page MIX_LoadRawAudio(3) from SDL_mixer version 3.2.4 πŸ’…βœ¨ periodt, go make some noise πŸŽ§πŸ¦‹

πŸ“¦ where this page comes from