MIX_LoadRawAudio(3)
β¨ 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 beNULL. (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 π§
MIX_DestroyAudio(3)MIX_SetTrackAudio(3)MIX_LoadRawAudio_IO(3)MIX_LoadRawAudioNoCopy(3)MIX_LoadAudio_IO(3)
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
- 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