SDL_AudioSpec(3)

πŸ’– SDL_AudioSpec β€” the audio spec struct, bestie πŸ’–

okay so this is SDL_AudioSpec, straight out of the SDL API Reference, and it's literally the blueprint for how your audio data is shaped. it's giving "audio DNA". no cap. πŸŽ€


🌸 NAME 🌸

SDL_AudioSpec β€” the Audio Specification Structure, aka the lil struct that tells everyone what your sound actually is ✨


πŸ¦‹ STRUCTURE DEFINITION πŸ¦‹

here's the whole thing, character for character, don't touch a single semicolon:

typedef struct{
  int freq;
  Uint16 format;
  Uint8 channels;
  Uint8 silence;
  Uint16 samples;
  Uint32 size;
  void (*callback)(void *userdata, Uint8 *stream, int len);
  void *userdata;
} SDL_AudioSpec;

πŸ’… STRUCTURE DATA πŸ’…

every field, one by one, we're going through them all because we're thorough queens πŸ‘‘

  • freq β€” audio frequency, in samples per second 🎡
  • format β€” the audio data format
  • channels β€” how many channels: 1 is mono, 2 is stereo
  • silence β€” the audio buffer silence value (this one gets calculated for you, don't stress)
  • samples β€” audio buffer size, measured in samples
  • size β€” audio buffer size in bytes (also calculated, also not your problem πŸ’–)
  • callback(..) β€” the callback function that fills the audio buffer
  • userdata β€” a pointer to the user data that gets passed to that callback function 🫢

✨ DESCRIPTION ✨

so the SDL_AudioSpec structure is what you use to describe the format of some audio data. it's used by SDL_OpenAudio and SDL_LoadWAV. here's the tea tho: all the fields get used by SDL_OpenAudio, but only freq, format, samples and channels get used by SDL_LoadWAV. we're gonna detail those common members right here, no gatekeeping 🌈

  • freq β€” the number of samples sent to the sound device every second. common values are 11025, 22050 and 44100. the higher the better, periodt πŸ”₯
  • format β€” specifies the size and type of each sample element. the options are:
    • AUDIO_U8
    • AUDIO_S8
    • AUDIO_U16 or AUDIO_U16LSB
    • AUDIO_S16 or AUDIO_S16LSB
    • AUDIO_U16MSB
    • AUDIO_S16MSB
    • AUDIO_U16SYS
    • AUDIO_S16SYS
  • channels β€” the number of seperate sound channels (yes, that's how it's spelled in the source, we keep it 100). 1 is mono (single channel), 2 is stereo (dual channel) 🎧
  • samples β€” when you use this with SDL_OpenAudio, this refers to the size of the audio buffer in samples. a sample is a chunk of audio data of the size specified in format, mulitplied by the number of channels (again: that's the original spelling, we do not edit the ancestors πŸ’€). but when the SDL_AudioSpec is used with SDL_LoadWAV, samples gets set to 4096. iconic behavior honestly

πŸ‘‘ SEE ALSO πŸ‘‘

SDL_OpenAudio, SDL_LoadWAV

go read those too, iykyk πŸ’œ


ok bestie that's the whole page, every flag and field accounted for, nothing skipped, we ate and left no crumbs πŸ“

mwah πŸ’‹ this was SDL_AudioSpec(3) from the SDL API Reference β€” written by the SDL girlies, dated Tue 11 Sep 2001, 22:58. yeah, 2001. vintage. still slaps. bye pookie 🧚✨

πŸ“¦ where this page comes from