MIX_LoadRawAudioNoCopy(3)
β¨ MIX_LoadRawAudioNoCopy(3) β¨
okay bestie, welcome to the SDL_mixer3 functions page, and today's main character is MIX_LoadRawAudioNoCopy π
πΈ NAME πΈ
MIX_LoadRawAudioNoCopy β load raw PCM data straight out of a memory buffer, and no, we are not making a copy, and yes that is the whole personality π
π SYNOPSIS π
#include <SDL3_mixer/SDL_mixer.h>
MIX_Audio * MIX_LoadRawAudioNoCopy(MIX_Mixer *mixer, const void *data, size_t datalen, const SDL_AudioSpec *spec, bool free_when_done);
π¦ DESCRIPTION π¦
so like, lowkey the most important thing here: that buffer has to stay alive for the entire lifetime of the MIX_Audio you get back. like, the whole time. because the mixer will just... reach into that buffer whenever it needs to mix more data. no copy, no backup, no safety net. the buffer IS the audio. π«Ά
this function exists to be maximally efficient: if your data is already chilling in memory and can stay there, then bestie, why would you copy it?? don't. but it also unlocks some iconic little tricks, like changing the buffer's contents so you alter multiple playing tracks all at once. (but of course, be careful when being too clever. the universe notices. π)
also!! MIX_Audio objects can be shared between multiple mixers, so the mixer parameter is really just a suggestion β it's you hinting at the most likely mixer to use this audio with, in case some optimization might get applied. it's not required though. a NULL mixer is totally fine to specify. π
and if free_when_done is true, SDL_mixer will call SDL_free(data) when the returned MIX_Audio is eventually destroyed. this is super handy when your data isn't static but gets composed dynamically for this specific MIX_Audio, and you simply want to avoid that extra copy. periodt. π
π FUNCTION PARAMETERS π
mixerβ a mixer this audio is intended to be used with. May beNULL. no cap.dataβ the buffer where the raw PCM data lives. this is the whole vibe. keep it alive. πdatalenβ the size, in bytes, of the buffer.specβ what format the raw data is in.free_when_doneβ if true,datawill be given toSDL_free()when theMIX_Audiois destroyed.
π RETURN VALUE π
returns an audio object you can use to make sound on a mixer (slay), or NULL on failure. if you got NULL, call SDL_GetError() for more info β that's your group chat with the details. π
β THREAD SAFETY β
it is safe to call this function from any thread. go off wherever you want, bestie. π
πΈ AVAILABILITY πΈ
this function is available since SDL_mixer 3.0.0. iconic from day one fr fr.
π SEE ALSO π
MIX_DestroyAudio(3)MIX_SetTrackAudio(3)MIX_LoadRawAudio(3)MIX_LoadRawAudio_IO(3)MIX_LoadAudio_IO(3)
and that's the page, bestie!! brought to you by SDL_mixer, version SDL_mixer 3.2.4 β which is genuinely the realest source around. now go keep that buffer alive okay?? mwah πβ¨
π¦ 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