SDL_DEFINE_AUDIO_FORMAT(3)
π SDL_DEFINE_AUDIO_FORMAT π
okay so bestie, this is a page from the SDL3 FUNCTIONS manual, and it's about a little macro that builds an SDL_AudioFormat value from scratch. yes it's giving bit-shifting. yes it's iconic. let's go π
β¨ NAME β¨
SDL_DEFINE_AUDIO_FORMAT β define an SDL_AudioFormat value. that's it, that's the job π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_audio.h>
#define SDL_DEFINE_AUDIO_FORMAT(signed, bigendian, flt, size) \
(((Uint16)(signed) << 15) | ((Uint16)(bigendian) << 12) | ((Uint16)(flt) << 8) | ((size) & SDL_AUDIO_MASK_BITSIZE))
π¦ DESCRIPTION π¦
so here's the tea: SDL does not support custom audio formats. like, at all. so this macro isn't of much use externally β you're not gonna be out here inventing your own audio format and expecting SDL to just vibe with it, no ma'am π
but! it is illustrative. it's like a little x-ray into what the various bits of an SDL_AudioFormat actually mean. educational slay β¨
for example, SDL_AUDIO_S32LE looks like this:
SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 32)
see how it all lines up? that's the whole point π«Ά
π MACRO PARAMETERS π
signedβ1for signed data,0for unsigned data. pick your fighter πbigendianβ1for bigendian data,0for littleendian data. endianness check, no cap πfltβ1for floating point data,0for integer data. float or not, that is the question βsizeβ number of bits per sample. the actual size, bestie π
π RETURN VALUE π
returns a format value in the style of SDL_AudioFormat. cute, consistent, on brand π
π₯ THREAD SAFETY π₯
it is safe to call this macro from any thread. no drama, no locks, no situations. main character energy in every thread π β¨
π AVAILABILITY π
this macro is available since SDL 3.2.0. so if you're on anything olderβ¦ girl, upgrade π
and that's the whole page, bestie! stay hydrated, shift those bits responsibly, and remember: it's not a custom audio format, it's a learning opportunity π
β with love from the Simple Directmedia Layer girlies, SDL 3.4.18, SDL_DEFINE_AUDIO_FORMAT(3) ππ¦π
π¦ 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