DRAFT

SDL_AudioSpec

A structure that contains the audio output format. It also contains a callback that is called when the audio device needs more data.

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: 1 = mono, 2 = stereo

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

Code Examples

You can add your code example here

Remarks

*
The SDL_AudioSpec structure is used to describe the format of some audio data. This structure is used by SDL_OpenAudio() and SDL_LoadWAV(). While all fields are used by SDL_OpenAudio(), only freq, format, channels, and samples are used by SDL_LoadWAV().

freq specifies the number of samples sent to the sound device per second. Common values are 11025, 22050 and 44100. The higher the better.

format specifies the size and type of each sample element and may be one of the following:

  • Defaults to LSB byte order -or- Basic ???

    AUDIO_U8

    unsigned 8-bit samples.

    AUDIO_S8

    signed 8-bit samples.

    AUDIO_U16 or AUDIO_U16LSB

    not supported by all hardware (unsigned 16-bit little-endian)

    AUDIO_S16 or AUDIO_S16LSB

    not supported by all hardware (signed 16-bit little-endian)

    AUDIO_U16MSB

    not supported by all hardware (unsigned 16-bit big-endian)

    AUDIO_S16MSB

    not supported by all hardware (signed 16-bit big-endian)

    int32 support

    AUDIO_S32 or AUDIO_S32LSB

    32-bit integer samples

    AUDIO_S32MSB

    as above, but big-endian byte order

    float32 support

    AUDIO_F32 or AUDIO_F32LSB

    32-bit floating point samples

    AUDIO_F32MSB

    as above, but big-endian byte order

    Native audio byte ordering

    AUDIO_U16SYS

    either AUDIO_U16LSB or AUDIO_U16MSB depending on hardware CPU endianness

    AUDIO_S16SYS

    either AUDIO_S16LSB or AUDIO_S16MSB depending on hardware CPU endianness

    AUDIO_S32SYS

    either AUDIO_S32LSB or AUDIO_S32MSB depending on hardware CPU endianness

    AUDIO_F32SYS

    either AUDIO_F32LSB or AUDIO_F32MSB depending on hardware CPU endianness

samples specifies a unit of audio data. When used 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 multiplied by the number of channels. When the SDL_AudioSpec is used with SDL_LoadWAV() samples is set to 4096.
*

The values silence and size are calculated by SDL_OpenAudio().

Stereo samples are stored in a LRLRLR ordering.

The function prototype for callback is:

  • void SDL_AudioCallback(void*  userdata,
                           Uint8* stream,
                           int    len)
  • where its parameters are:

    userdata

    an application-specific parameter saved in the SDL_AudioSpec structure

    stream

    a pointer to the audio data buffer filled in by SDL_AudioCallback()

    len

    the length of that buffer in bytes

Once the callback returns, the buffer will no longer be valid.


CategoryStruct, CategoryAudio

SDL_AudioSpec (last edited 2011-12-12 19:15:47 by SheenaSmith)

Feedback
Please include your contact information if you'd like to receive a reply.
Submit