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 β€” 1 for signed data, 0 for unsigned data. pick your fighter πŸ’€
  • bigendian β€” 1 for bigendian data, 0 for littleendian data. endianness check, no cap 🌈
  • flt β€” 1 for floating point data, 0 for 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