SDL Wiki
(This is the legacy documentation for stable SDL2, the current stable version; SDL3 is the current development version.)

SDL_AudioSpec

The calculated values in this structure are calculated by SDL_OpenAudio().

Header File

Defined in [SDL_audio.h](https://github.com/libsdl-org/SDL/blob/SDL2/include/SDL_audio.h), but apps should _only_ `#include "SDL.h"`!

Syntax

typedef struct SDL_AudioSpec
{
    int freq;                   /**< DSP frequency -- samples per second */
    SDL_AudioFormat format;     /**< Audio data format */
    Uint8 channels;             /**< Number of channels: 1 mono, 2 stereo */
    Uint8 silence;              /**< Audio buffer silence value (calculated) */
    Uint16 samples;             /**< Audio buffer size in sample FRAMES (total samples divided by channel count) */
    Uint16 padding;             /**< Necessary for some compile environments */
    Uint32 size;                /**< Audio buffer size in bytes (calculated) */
    SDL_AudioCallback callback; /**< Callback that feeds the audio device (NULL to use SDL_QueueAudio()). */
    void *userdata;             /**< Userdata passed to callback (ignored for NULL callbacks). */
} SDL_AudioSpec;

Remarks

For multi-channel audio, the default SDL channel mapping is: 2: FL FR (stereo) 3: FL FR LFE (2.1 surround) 4: FL FR BL BR (quad) 5: FL FR LFE BL BR (4.1 surround) 6: FL FR FC LFE SL SR (5.1 surround - last two can also be BL BR) 7: FL FR FC LFE BC SL SR (6.1 surround) 8: FL FR FC LFE BL BR SL SR (7.1 surround)

Code Examples

SDL_AudioSpec want, have;
SDL_AudioDeviceID dev;

SDL_memset(&want, 0, sizeof(want)); /* or SDL_zero(want) */
want.freq = 48000;
want.format = AUDIO_F32;
want.channels = 2;
want.samples = 4096;
want.callback = MyAudioCallback;  // you wrote this function elsewhere.
dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE);

Data Fields

int

freq

DSP frequency (samples per second); see Remarks for details

SDL_AudioFormat

format

audio data format; see Remarks for details

Uint8

channels

number of separate sound channels: see Remarks for details

Uint8

silence

audio buffer silence value (calculated)

Uint16

samples

audio buffer size in samples (power of 2); see Remarks for details

Uint32

size

audio buffer size in bytes (calculated)

SDL_AudioCallback

callback

the function to call when the audio device needs more data; see Remarks for details

void*

userdata

a pointer that is passed to callback (otherwise ignored by SDL)


CategoryAPI, CategoryAPIStruct, CategoryStruct, CategoryAudio


[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.