SDL_audio_c.h File Reference
`#include "../SDL_internal.h"`
Include dependency graph for SDL_audio_c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

struct | SDL_AudioTypeFilters
struct | SDL_AudioRateFilters

## Functions

SDL_AudioFormat | SDL_FirstAudioFormat (SDL_AudioFormat format)
SDL_AudioFormat | SDL_NextAudioFormat (void)
void | SDL_CalculateAudioSpec (SDL_AudioSpec *spec)
int | SDL_RunAudio (void *audiop)

## Variables

const SDL_AudioTypeFilters | sdl_audio_type_filters []
const SDL_AudioRateFilters | sdl_audio_rate_filters []

## Function Documentation

void SDL_CalculateAudioSpec | ( | SDL_AudioSpec * | spec | ) |

Definition at line 1419 of file SDL_audio.c.

References AUDIO_U8, SDL_AudioSpec::channels, SDL_AudioSpec::format, SDL_AudioSpec::samples, SDL_AUDIO_BITSIZE, SDL_AudioSpec::silence, and SDL_AudioSpec::size.

Referenced by open_audio_device(), and prepare_audiospec().

{
switch (spec->format) {
case AUDIO_U8:
spec->silence = 0x80;
break;
default:
spec->silence = 0x00;
break;
}
spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
spec->size *= spec->channels;
spec->size *= spec->samples;
}
SDL_AudioSpec::silence
Uint8 silence
Definition: SDL_audio.h:173
SDL_AudioSpec::samples
Uint16 samples
Definition: SDL_audio.h:174
AUDIO_U8
#define AUDIO_U8
Definition: SDL_audio.h:89
SDL_AudioSpec::channels
Uint8 channels
Definition: SDL_audio.h:172
SDL_AUDIO_BITSIZE
#define SDL_AUDIO_BITSIZE(x)
Definition: SDL_audio.h:75
SDL_AudioSpec::size
Uint32 size
Definition: SDL_audio.h:176
SDL_AudioSpec::format
SDL_AudioFormat format
Definition: SDL_audio.h:171

SDL_AudioFormat SDL_FirstAudioFormat | ( | SDL_AudioFormat | format | ) |

Definition at line 1398 of file SDL_audio.c.

References format_idx, format_idx_sub, format_list, NUM_FORMATS, and SDL_NextAudioFormat().

{
for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
if (format_list[format_idx][0] == format) {
break;
}
}
format_idx_sub = 0;
return SDL_NextAudioFormat();
}
format_idx_sub
static int format_idx_sub
Definition: SDL_audio.c:1373
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
format_idx
static int format_idx
Definition: SDL_audio.c:1372
format_list
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1374
SDL_NextAudioFormat
SDL_AudioFormat SDL_NextAudioFormat(void)
Definition: SDL_audio.c:1410
NUM_FORMATS
#define NUM_FORMATS
Definition: SDL_audio.c:1371

SDL_AudioFormat SDL_NextAudioFormat | ( | void |  | ) |

Definition at line 1410 of file SDL_audio.c.

References format_idx, format_idx_sub, format_list, and NUM_FORMATS.

Referenced by SDL_FirstAudioFormat().

{
if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
return 0;
}
return format_list[format_idx][format_idx_sub++];
}
format_idx_sub
static int format_idx_sub
Definition: SDL_audio.c:1373
format_idx
static int format_idx
Definition: SDL_audio.c:1372
format_list
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1374
NUM_FORMATS
#define NUM_FORMATS
Definition: SDL_audio.c:1371

int SDL_RunAudio | ( | void * | audiop | ) |

Definition at line 595 of file SDL_audio.c.

References SDL_AudioCVT::buf, SDL_AudioSpec::callback, SDL_AudioDevice::convert, SDL_AudioDevice::enabled, SDL_AudioDevice::fake_stream, SDL_AudioSpec::freq, SDL_AudioDriverImpl::GetDeviceBuf, SDL_AudioDriver::impl, SDL_AudioCVT::len, SDL_AudioCVT::len_cvt, SDL_AudioDevice::mixer_lock, SDL_AudioCVT::needed, NULL, SDL_AudioDevice::paused, SDL_AudioDriverImpl::PlayDevice, SDL_AudioSpec::samples, SDL_ConvertAudio, SDL_Delay, SDL_LockMutex, SDL_memcpy, SDL_memset, SDL_SetThreadPriority, SDL_THREAD_PRIORITY_HIGH, SDL_ThreadID, SDL_UnlockMutex, SDLCALL, SDL_AudioDevice::shutdown, SDL_AudioSpec::silence, SDL_AudioSpec::size, SDL_AudioDevice::spec, SDL_AudioDevice::threadid, SDL_AudioDriverImpl::ThreadInit, SDL_AudioSpec::userdata, void, SDL_AudioDriverImpl::WaitDevice, and SDL_AudioDriverImpl::WaitDone.

Referenced by open_audio_device().

{
SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
const int silence = (int) device->spec.silence;
const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq);
const int stream_len = (device->convert.needed) ? device->convert.len : device->spec.size;
Uint8 *stream;
void *udata = device->spec.userdata;
void (SDLCALL *fill) (void *, Uint8 *, int) = device->spec.callback;
/* The audio mixing is always a high priority thread */
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
/* Perform any thread setup */
device->threadid = SDL_ThreadID();
current_audio.impl.ThreadInit(device);
/* Loop, filling the audio buffers */
while (!device->shutdown) {
/* Fill the current buffer with sound */
if (device->convert.needed) {
stream = device->convert.buf;
} else if (device->enabled) {
stream = current_audio.impl.GetDeviceBuf(device);
} else {
/* if the device isn't enabled, we still write to the
fake_stream, so the app's callback will fire with
a regular frequency, in case they depend on that
for timing or progress. They can use hotplug
now to know if the device failed. */
stream = NULL;
}
if (stream == NULL) {
stream = device->fake_stream;
}
/* !!! FIXME: this should be LockDevice. */
SDL_LockMutex(device->mixer_lock);
if (device->paused) {
SDL_memset(stream, silence, stream_len);
} else {
(*fill) (udata, stream, stream_len);
}
SDL_UnlockMutex(device->mixer_lock);
/* Convert the audio if necessary */
if (device->enabled && device->convert.needed) {
SDL_ConvertAudio(&device->convert);
stream = current_audio.impl.GetDeviceBuf(device);
if (stream == NULL) {
stream = device->fake_stream;
} else {
SDL_memcpy(stream, device->convert.buf,
device->convert.len_cvt);
}
}
/* Ready current buffer for play and change current buffer */
if (stream == device->fake_stream) {
SDL_Delay(delay);
} else {
current_audio.impl.PlayDevice(device);
current_audio.impl.WaitDevice(device);
}
}
/* Wait for the audio to drain. */
current_audio.impl.WaitDone(device);
return 0;
}
SDL_ThreadID
#define SDL_ThreadID
Definition: SDL_dynapi_overrides.h:479
SDL_LockMutex
#define SDL_LockMutex
Definition: SDL_dynapi_overrides.h:266
SDL_AudioDevice::mixer_lock
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:171
SDL_AudioCVT::len
int len
Definition: SDL_audio.h:207
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_AudioSpec::silence
Uint8 silence
Definition: SDL_audio.h:173
SDL_AudioCVT::buf
Uint8 * buf
Definition: SDL_audio.h:206
stream
GLuint GLuint stream
Definition: SDL_opengl_glext.h:1776
SDL_AudioDevice::shutdown
int shutdown
Definition: SDL_sysaudio.h:163
SDL_AudioDevice::threadid
SDL_threadID threadid
Definition: SDL_sysaudio.h:175
SDL_AudioDriverImpl::PlayDevice
void(* PlayDevice)(_THIS)
Definition: SDL_sysaudio.h:75
SDL_AudioSpec::samples
Uint16 samples
Definition: SDL_audio.h:174
SDL_AudioDriverImpl::WaitDevice
void(* WaitDevice)(_THIS)
Definition: SDL_sysaudio.h:74
SDL_AudioDevice::spec
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:150
current_audio
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_THREAD_PRIORITY_HIGH
Definition: SDL_thread.h:62
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:393
SDL_AudioDriverImpl::ThreadInit
void(* ThreadInit)(_THIS)
Definition: SDL_sysaudio.h:73
SDL_AudioSpec::freq
int freq
Definition: SDL_audio.h:170
SDL_ConvertAudio
#define SDL_ConvertAudio
Definition: SDL_dynapi_overrides.h:95
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_AudioCVT::needed
int needed
Definition: SDL_audio.h:202
SDL_AudioSpec::callback
SDL_AudioCallback callback
Definition: SDL_audio.h:177
SDL_AudioDevice::fake_stream
Uint8 * fake_stream
Definition: SDL_sysaudio.h:168
SDL_Delay
#define SDL_Delay
Definition: SDL_dynapi_overrides.h:490
SDL_AudioSpec::size
Uint32 size
Definition: SDL_audio.h:176
SDL_AudioCVT::len_cvt
int len_cvt
Definition: SDL_audio.h:208
NULL
#define NULL
Definition: begin_code.h:143
void
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Definition: SDL_dynapi_procs.h:93
SDL_AudioDriver::impl
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
SDL_AudioDevice
Definition: SDL_sysaudio.h:143
SDL_AudioDevice::paused
int paused
Definition: SDL_sysaudio.h:164
SDL_AudioDriverImpl::GetDeviceBuf
Uint8 *(* GetDeviceBuf)(_THIS)
Definition: SDL_sysaudio.h:77
SDL_AudioSpec::userdata
void * userdata
Definition: SDL_audio.h:178
SDL_UnlockMutex
#define SDL_UnlockMutex
Definition: SDL_dynapi_overrides.h:268
SDL_AudioDevice::enabled
int enabled
Definition: SDL_sysaudio.h:162
SDL_AudioDevice::convert
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:153
SDLCALL
#define SDLCALL
Definition: SDL_internal.h:31
SDL_SetThreadPriority
#define SDL_SetThreadPriority
Definition: SDL_dynapi_overrides.h:481
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:392
SDL_AudioDriverImpl::WaitDone
void(* WaitDone)(_THIS)
Definition: SDL_sysaudio.h:78

## Variable Documentation

const SDL_AudioRateFilters sdl_audio_rate_filters[]

Definition at line 15702 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioResampleCVT().

const SDL_AudioTypeFilters sdl_audio_type_filters[]

Definition at line 2195 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVT().