SDL_MixAudio(3)
π SDL_MixAudio π
okay bestie, so this one's from the SDL3 FUNCTIONS family, and it's literally the girl who mixes your audio for you β¨
πΈ NAME πΈ
SDL_MixAudio β mixes audio data in a specified format. that's it, that's the job, she does it flawlessly π
π SYNOPSIS π
#include <SDL3/SDL_audio.h>
bool SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32 len, float volume);
look at her, so clean, so iconic π
π¦ DESCRIPTION π¦
so what she does is: she takes an audio buffer src β that's len bytes of format data β and mixes it into dst, and the way she does that is by performing addition, volume adjustment, and overflow clipping. no cap. and the buffer pointed to by dst has to also be len bytes of format data, so keep those two matching, bestie π€
she's provided for convenience β you can totally mix your own audio data if you want to be extra, that's your main character moment β¨
β οΈ do NOT use this function for mixing together more than two streams of sample data. like, seriously. the output from repeatedly applying this function may be distorted by clipping, because there's no accumulator with greater range than the input. (not to mention it's also just a straight up inefficient way of doing it π). so, two streams max. periodt.
ok and here's a thing people get wrong all the time, it's a common misconception that this function is required to write audio data to an output stream in an audio callback. and like β sure, you can do that, but SDL_MixAudio() is really only needed when you're mixing a single audio stream with a volume adjustment. that's her whole thing π
π FUNCTION PARAMETERS π
dstβ the destination for the mixed audio π«Άsrcβ the source audio buffer to be mixed β¨formatβ theSDL_AudioFormatstructure representing the desired audio format πlenβ the length of the audio buffer in bytes πvolumeβ ranges from0.0-1.0, and should be set to1.0for full audio volume π (so1.0= loud and proud,0.0= silence, you get it)
β RETURN VALUE β
returns true on success or false on failure π and if she fails, call SDL_GetError() for more information β she'll tell you what went wrong, she's not mysterious like that.
π THREAD SAFETY π
it is safe to call this function from any thread. multitasking queen, we love to see it π
π AVAILABILITY π
this function has been available since SDL 3.2.0 π±
π§ SEE ALSO π§
hmm, the original didn't send us any SEE ALSO girlies, so that's a wrap on the cross-refs β but you already know SDL_GetError() from the return value section, iykyk π
and that's the whole page!! written by the fine folks over at Simple Directmedia Layer, from SDL 3.4.18, dated SDL_MixAudio(3) π stay mixed, stay clipped-free, mwah π πβ¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms