SDL  2.0
SDL_audio.c File Reference
#include "../SDL_internal.h"
#include "SDL.h"
#include "SDL_audio.h"
#include "SDL_audio_c.h"
#include "SDL_audiomem.h"
#include "SDL_sysaudio.h"
+ Include dependency graph for SDL_audio.c:

Go to the source code of this file.

Macros

#define _THIS   SDL_AudioDevice *_this
 
#define DEFAULT_OUTPUT_DEVNAME   "System audio output device"
 
#define DEFAULT_INPUT_DEVNAME   "System audio capture device"
 
#define FILL_STUB(x)
 
#define CHECK_FMT_STRING(x)   if (SDL_strcmp(string, #x) == 0) return AUDIO_##x
 
#define NUM_FORMATS   10
 

Functions

static SDL_AudioDeviceget_audio_device (SDL_AudioDeviceID id)
 
static void SDL_AudioDetectDevices_Default (void)
 
static void SDL_AudioThreadInit_Default (_THIS)
 
static void SDL_AudioWaitDevice_Default (_THIS)
 
static void SDL_AudioPlayDevice_Default (_THIS)
 
static int SDL_AudioGetPendingBytes_Default (_THIS)
 
static Uint8SDL_AudioGetDeviceBuf_Default (_THIS)
 
static void SDL_AudioWaitDone_Default (_THIS)
 
static void SDL_AudioCloseDevice_Default (_THIS)
 
static void SDL_AudioDeinitialize_Default (void)
 
static void SDL_AudioFreeDeviceHandle_Default (void *handle)
 
static int SDL_AudioOpenDevice_Default (_THIS, void *handle, const char *devname, int iscapture)
 
static SDL_INLINE SDL_bool is_in_audio_device_thread (SDL_AudioDevice *device)
 
static void SDL_AudioLockDevice_Default (SDL_AudioDevice *device)
 
static void SDL_AudioUnlockDevice_Default (SDL_AudioDevice *device)
 
static void finalize_audio_entry_points (void)
 
static int add_audio_device (const char *name, void *handle, SDL_AudioDeviceItem **devices, int *devCount)
 
static SDL_INLINE int add_capture_device (const char *name, void *handle)
 
static SDL_INLINE int add_output_device (const char *name, void *handle)
 
static void free_device_list (SDL_AudioDeviceItem **devices, int *devCount)
 
void SDL_AddAudioDevice (const int iscapture, const char *name, void *handle)
 
void SDL_OpenedAudioDeviceDisconnected (SDL_AudioDevice *device)
 
static void mark_device_removed (void *handle, SDL_AudioDeviceItem *devices, SDL_bool *removedFlag)
 
void SDL_RemoveAudioDevice (const int iscapture, void *handle)
 
static void free_audio_queue (SDL_AudioBufferQueue *buffer)
 
static void SDL_BufferQueueDrainCallback (void *userdata, Uint8 *stream, int _len)
 
int SDL_QueueAudio (SDL_AudioDeviceID devid, const void *_data, Uint32 len)
 
Uint32 SDL_GetQueuedAudioSize (SDL_AudioDeviceID devid)
 
void SDL_ClearQueuedAudio (SDL_AudioDeviceID devid)
 
int SDL_RunAudio (void *devicep)
 
static SDL_AudioFormat SDL_ParseAudioFormat (const char *string)
 
int SDL_GetNumAudioDrivers (void)
 
const char * SDL_GetAudioDriver (int index)
 
int SDL_AudioInit (const char *driver_name)
 
const char * SDL_GetCurrentAudioDriver ()
 
static void clean_out_device_list (SDL_AudioDeviceItem **devices, int *devCount, SDL_bool *removedFlag)
 
int SDL_GetNumAudioDevices (int iscapture)
 
const char * SDL_GetAudioDeviceName (int index, int iscapture)
 
static void close_audio_device (SDL_AudioDevice *device)
 
static int prepare_audiospec (const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
 
static SDL_AudioDeviceID open_audio_device (const char *devname, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes, int min_id)
 
int SDL_OpenAudio (SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
 
SDL_AudioDeviceID SDL_OpenAudioDevice (const char *device, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes)
 
SDL_AudioStatus SDL_GetAudioDeviceStatus (SDL_AudioDeviceID devid)
 
SDL_AudioStatus SDL_GetAudioStatus (void)
 
void SDL_PauseAudioDevice (SDL_AudioDeviceID devid, int pause_on)
 
void SDL_PauseAudio (int pause_on)
 
void SDL_LockAudioDevice (SDL_AudioDeviceID devid)
 
void SDL_LockAudio (void)
 
void SDL_UnlockAudioDevice (SDL_AudioDeviceID devid)
 
void SDL_UnlockAudio (void)
 
void SDL_CloseAudioDevice (SDL_AudioDeviceID devid)
 
void SDL_CloseAudio (void)
 
void SDL_AudioQuit (void)
 
SDL_AudioFormat SDL_FirstAudioFormat (SDL_AudioFormat format)
 
SDL_AudioFormat SDL_NextAudioFormat (void)
 
void SDL_CalculateAudioSpec (SDL_AudioSpec *spec)
 
void SDL_MixAudio (Uint8 *dst, const Uint8 *src, Uint32 len, int volume)
 

Variables

static SDL_AudioDriver current_audio
 
static SDL_AudioDeviceopen_devices [16]
 
AudioBootStrap BSD_AUDIO_bootstrap
 
AudioBootStrap DSP_bootstrap
 
AudioBootStrap ALSA_bootstrap
 
AudioBootStrap PULSEAUDIO_bootstrap
 
AudioBootStrap QSAAUDIO_bootstrap
 
AudioBootStrap SUNAUDIO_bootstrap
 
AudioBootStrap ARTS_bootstrap
 
AudioBootStrap ESD_bootstrap
 
AudioBootStrap NACLAUD_bootstrap
 
AudioBootStrap NAS_bootstrap
 
AudioBootStrap XAUDIO2_bootstrap
 
AudioBootStrap DSOUND_bootstrap
 
AudioBootStrap WINMM_bootstrap
 
AudioBootStrap PAUDIO_bootstrap
 
AudioBootStrap HAIKUAUDIO_bootstrap
 
AudioBootStrap COREAUDIO_bootstrap
 
AudioBootStrap SNDMGR_bootstrap
 
AudioBootStrap DISKAUD_bootstrap
 
AudioBootStrap DUMMYAUD_bootstrap
 
AudioBootStrap DCAUD_bootstrap
 
AudioBootStrap DART_bootstrap
 
AudioBootStrap NDSAUD_bootstrap
 
AudioBootStrap FUSIONSOUND_bootstrap
 
AudioBootStrap ANDROIDAUD_bootstrap
 
AudioBootStrap PSPAUD_bootstrap
 
AudioBootStrap SNDIO_bootstrap
 
AudioBootStrap EmscriptenAudio_bootstrap
 
static const AudioBootStrap *const bootstrap []
 
static int format_idx
 
static int format_idx_sub
 
static SDL_AudioFormat format_list [NUM_FORMATS][NUM_FORMATS]
 

Macro Definition Documentation

#define _THIS   SDL_AudioDevice *_this

Definition at line 31 of file SDL_audio.c.

#define CHECK_FMT_STRING (   x)    if (SDL_strcmp(string, #x) == 0) return AUDIO_##x

Referenced by SDL_ParseAudioFormat().

#define DEFAULT_INPUT_DEVNAME   "System audio capture device"

Definition at line 38 of file SDL_audio.c.

Referenced by open_audio_device(), and SDL_AudioDetectDevices_Default().

#define DEFAULT_OUTPUT_DEVNAME   "System audio output device"

Definition at line 37 of file SDL_audio.c.

Referenced by open_audio_device(), and SDL_AudioDetectDevices_Default().

#define FILL_STUB (   x)
Value:
if (current_audio.impl.x == NULL) { \
current_audio.impl.x = SDL_Audio##x##_Default; \
}
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
#define NULL
Definition: begin_code.h:143
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120

Referenced by finalize_audio_entry_points().

#define NUM_FORMATS   10

Definition at line 1371 of file SDL_audio.c.

Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().

Function Documentation

static int add_audio_device ( const char *  name,
void handle,
SDL_AudioDeviceItem **  devices,
int *  devCount 
)
static

Definition at line 293 of file SDL_audio.c.

References SDL_AudioDriver::detectionLock, SDL_AudioDeviceItem::handle, SDL_AudioDeviceItem::name, SDL_AudioDeviceItem::next, NULL, retval, SDL_assert, SDL_INLINE, SDL_LockMutex, SDL_malloc, SDL_strlcpy, SDL_strlen, and SDL_UnlockMutex.

Referenced by add_capture_device(), and add_output_device().

294 {
295  int retval = -1;
296  const size_t size = sizeof (SDL_AudioDeviceItem) + SDL_strlen(name) + 1;
298  if (item == NULL) {
299  return -1;
300  }
301 
302  SDL_assert(handle != NULL); /* we reserve NULL, audio backends can't use it. */
303 
304  item->handle = handle;
305  SDL_strlcpy(item->name, name, size - sizeof (SDL_AudioDeviceItem));
306 
308  item->next = *devices;
309  *devices = item;
310  retval = (*devCount)++;
312 
313  return retval;
314 }
#define SDL_strlcpy
#define SDL_LockMutex
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:101
GLuint const GLchar * name
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
GLsizeiptr size
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:123
SDL_bool retval
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
#define SDL_strlen
#define SDL_UnlockMutex
#define SDL_malloc
static SDL_INLINE int add_capture_device ( const char *  name,
void handle 
)
static

Definition at line 317 of file SDL_audio.c.

References add_audio_device(), SDL_AudioDriver::inputDeviceCount, SDL_AudioDriver::inputDevices, and SDL_INLINE.

Referenced by SDL_AddAudioDevice().

318 {
319  /* !!! FIXME: add this later. SDL_assert(current_audio.impl.HasCaptureSupport);*/
321 }
GLuint const GLchar * name
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
static int add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices, int *devCount)
Definition: SDL_audio.c:293
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:129
static SDL_INLINE int add_output_device ( const char *  name,
void handle 
)
static

Definition at line 324 of file SDL_audio.c.

References add_audio_device(), SDL_AudioDriver::outputDeviceCount, and SDL_AudioDriver::outputDevices.

Referenced by SDL_AddAudioDevice().

325 {
327 }
GLuint const GLchar * name
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
static int add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices, int *devCount)
Definition: SDL_audio.c:293
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:128
static void clean_out_device_list ( SDL_AudioDeviceItem **  devices,
int *  devCount,
SDL_bool removedFlag 
)
static

Definition at line 779 of file SDL_audio.c.

References SDL_AudioDeviceItem::handle, SDL_AudioDeviceItem::next, NULL, SDL_FALSE, and SDL_free().

Referenced by SDL_GetNumAudioDevices().

780 {
781  SDL_AudioDeviceItem *item = *devices;
782  SDL_AudioDeviceItem *prev = NULL;
783  int total = 0;
784 
785  while (item) {
786  SDL_AudioDeviceItem *next = item->next;
787  if (item->handle != NULL) {
788  total++;
789  prev = item;
790  } else {
791  if (prev) {
792  prev->next = next;
793  } else {
794  *devices = next;
795  }
796  SDL_free(item);
797  }
798  item = next;
799  }
800 
801  *devCount = total;
802  *removedFlag = SDL_FALSE;
803 }
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:101
void SDL_free(void *mem)
#define NULL
Definition: begin_code.h:143
static void close_audio_device ( SDL_AudioDevice device)
static

Definition at line 873 of file SDL_audio.c.

References SDL_AudioCVT::buf, SDL_AudioDevice::buffer_queue_head, SDL_AudioDevice::buffer_queue_pool, SDL_AudioDriverImpl::CloseDevice, SDL_AudioDevice::convert, SDL_AudioDevice::enabled, SDL_AudioDevice::fake_stream, free_audio_queue(), SDL_AudioDriver::impl, SDL_AudioDevice::mixer_lock, SDL_AudioCVT::needed, NULL, SDL_AudioDevice::opened, SDL_DestroyMutex, SDL_FreeAudioMem, SDL_WaitThread, SDL_AudioDevice::shutdown, and SDL_AudioDevice::thread.

Referenced by open_audio_device(), and SDL_CloseAudioDevice().

874 {
875  device->enabled = 0;
876  device->shutdown = 1;
877  if (device->thread != NULL) {
878  SDL_WaitThread(device->thread, NULL);
879  }
880  if (device->mixer_lock != NULL) {
881  SDL_DestroyMutex(device->mixer_lock);
882  }
883  SDL_FreeAudioMem(device->fake_stream);
884  if (device->convert.needed) {
885  SDL_FreeAudioMem(device->convert.buf);
886  }
887  if (device->opened) {
889  device->opened = 0;
890  }
891 
894 
895  SDL_FreeAudioMem(device);
896 }
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:171
Uint8 * buf
Definition: SDL_audio.h:206
#define SDL_FreeAudioMem
Definition: SDL_audiomem.h:24
SDL_AudioBufferQueue * buffer_queue_pool
Definition: SDL_sysaudio.h:180
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_AudioBufferQueue * buffer_queue_head
Definition: SDL_sysaudio.h:178
Uint8 * fake_stream
Definition: SDL_sysaudio.h:168
#define NULL
Definition: begin_code.h:143
static void free_audio_queue(SDL_AudioBufferQueue *buffer)
Definition: SDL_audio.c:423
void(* CloseDevice)(_THIS)
Definition: SDL_sysaudio.h:79
#define SDL_DestroyMutex
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
SDL_Thread * thread
Definition: SDL_sysaudio.h:174
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:153
#define SDL_WaitThread
static void finalize_audio_entry_points ( void  )
static

Definition at line 262 of file SDL_audio.c.

References FILL_STUB.

Referenced by SDL_AudioInit().

263 {
264  /*
265  * Fill in stub functions for unused driver entry points. This lets us
266  * blindly call them without having to check for validity first.
267  */
268 
269 #define FILL_STUB(x) \
270  if (current_audio.impl.x == NULL) { \
271  current_audio.impl.x = SDL_Audio##x##_Default; \
272  }
273  FILL_STUB(DetectDevices);
274  FILL_STUB(OpenDevice);
275  FILL_STUB(ThreadInit);
276  FILL_STUB(WaitDevice);
277  FILL_STUB(PlayDevice);
278  FILL_STUB(GetPendingBytes);
279  FILL_STUB(GetDeviceBuf);
280  FILL_STUB(WaitDone);
281  FILL_STUB(CloseDevice);
282  FILL_STUB(LockDevice);
283  FILL_STUB(UnlockDevice);
284  FILL_STUB(FreeDeviceHandle);
285  FILL_STUB(Deinitialize);
286 #undef FILL_STUB
287 }
#define FILL_STUB(x)
static void free_audio_queue ( SDL_AudioBufferQueue buffer)
static

Definition at line 423 of file SDL_audio.c.

References SDL_AudioBufferQueue::next, SDL_free(), and SDLCALL.

Referenced by close_audio_device(), SDL_ClearQueuedAudio(), and SDL_QueueAudio().

424 {
425  while (buffer) {
426  SDL_AudioBufferQueue *next = buffer->next;
427  SDL_free(buffer);
428  buffer = next;
429  }
430 }
struct SDL_AudioBufferQueue * next
Definition: SDL_sysaudio.h:66
void SDL_free(void *mem)
static void free_device_list ( SDL_AudioDeviceItem **  devices,
int *  devCount 
)
static

Definition at line 330 of file SDL_audio.c.

References SDL_AudioDriverImpl::FreeDeviceHandle, SDL_AudioDeviceItem::handle, SDL_AudioDriver::impl, SDL_AudioDeviceItem::next, NULL, and SDL_free().

Referenced by SDL_AudioQuit().

331 {
332  SDL_AudioDeviceItem *item, *next;
333  for (item = *devices; item != NULL; item = next) {
334  next = item->next;
335  if (item->handle != NULL) {
337  }
338  SDL_free(item);
339  }
340  *devices = NULL;
341  *devCount = 0;
342 }
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:101
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void SDL_free(void *mem)
#define NULL
Definition: begin_code.h:143
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
void(* FreeDeviceHandle)(void *handle)
Definition: SDL_sysaudio.h:82
static SDL_AudioDevice* get_audio_device ( SDL_AudioDeviceID  id)
static

Definition at line 150 of file SDL_audio.c.

References NULL, SDL_arraysize, and SDL_SetError.

Referenced by SDL_ClearQueuedAudio(), SDL_CloseAudioDevice(), SDL_GetAudioDeviceStatus(), SDL_GetQueuedAudioSize(), SDL_LockAudioDevice(), SDL_MixAudio(), SDL_OpenedAudioDeviceDisconnected(), SDL_PauseAudioDevice(), SDL_QueueAudio(), and SDL_UnlockAudioDevice().

151 {
152  id--;
153  if ((id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL)) {
154  SDL_SetError("Invalid audio device ID");
155  return NULL;
156  }
157 
158  return open_devices[id];
159 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
GLuint id
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
static SDL_INLINE SDL_bool is_in_audio_device_thread ( SDL_AudioDevice device)
static

Definition at line 231 of file SDL_audio.c.

References SDL_FALSE, SDL_ThreadID, SDL_TRUE, SDL_AudioDevice::thread, and SDL_AudioDevice::threadid.

Referenced by SDL_AudioLockDevice_Default(), and SDL_AudioUnlockDevice_Default().

232 {
233  /* The device thread locks the same mutex, but not through the public API.
234  This check is in case the application, in the audio callback,
235  tries to lock the thread that we've already locked from the
236  device thread...just in case we only have non-recursive mutexes. */
237  if (device->thread && (SDL_ThreadID() == device->threadid)) {
238  return SDL_TRUE;
239  }
240 
241  return SDL_FALSE;
242 }
#define SDL_ThreadID
SDL_threadID threadid
Definition: SDL_sysaudio.h:175
SDL_Thread * thread
Definition: SDL_sysaudio.h:174
static void mark_device_removed ( void handle,
SDL_AudioDeviceItem devices,
SDL_bool removedFlag 
)
static

Definition at line 390 of file SDL_audio.c.

References SDL_AudioDeviceItem::handle, SDL_AudioDeviceItem::next, NULL, SDL_assert, and SDL_TRUE.

Referenced by SDL_RemoveAudioDevice().

391 {
392  SDL_AudioDeviceItem *item;
393  SDL_assert(handle != NULL);
394  for (item = devices; item != NULL; item = item->next) {
395  if (item->handle == handle) {
396  item->handle = NULL;
397  *removedFlag = SDL_TRUE;
398  return;
399  }
400  }
401 }
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:101
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
static SDL_AudioDeviceID open_audio_device ( const char *  devname,
int  iscapture,
const SDL_AudioSpec desired,
SDL_AudioSpec obtained,
int  allowed_changes,
int  min_id 
)
static

Definition at line 962 of file SDL_audio.c.

References SDL_AudioDriverImpl::AllowsArbitraryDeviceNames, SDL_AudioCVT::buf, SDL_AudioDevice::buffer_queue_pool, SDL_AudioSpec::callback, SDL_AudioSpec::channels, close_audio_device(), SDL_AudioDevice::convert, SDL_AudioBufferQueue::datalen, DEFAULT_INPUT_DEVNAME, DEFAULT_OUTPUT_DEVNAME, SDL_AudioDriver::detectionLock, SDL_AudioDevice::enabled, SDL_AudioDevice::fake_stream, SDL_AudioSpec::format, SDL_AudioSpec::freq, SDL_AudioDeviceItem::handle, SDL_AudioDriverImpl::HasCaptureSupport, i, SDL_AudioDevice::id, SDL_AudioDriver::impl, SDL_AudioDriver::inputDevices, SDL_AudioDevice::iscapture, SDL_AudioCVT::len, SDL_AudioCVT::len_cvt, SDL_AudioCVT::len_mult, SDL_AudioCVT::len_ratio, SDL_AudioDevice::mixer_lock, SDL_AudioDeviceItem::name, SDL_AudioCVT::needed, SDL_AudioBufferQueue::next, SDL_AudioDeviceItem::next, NULL, SDL_AudioDriverImpl::OnlyHasDefaultInputDevice, SDL_AudioDriverImpl::OnlyHasDefaultOutputDevice, SDL_AudioDriverImpl::OpenDevice, SDL_AudioDevice::opened, SDL_AudioDriver::outputDevices, SDL_AudioDevice::paused, prepare_audiospec(), SDL_AudioDriverImpl::ProvidesOwnCallbackThread, SDL_AudioSpec::samples, SDL_AllocAudioMem, SDL_arraysize, SDL_assert, SDL_AUDIO_ALLOW_CHANNELS_CHANGE, SDL_AUDIO_ALLOW_FORMAT_CHANGE, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE, SDL_AUDIOBUFFERQUEUE_PACKETLEN, SDL_BufferQueueDrainCallback(), SDL_BuildAudioCVT, SDL_CalculateAudioSpec(), SDL_CloseAudioDevice(), SDL_CreateMutex, SDL_CreateThread, SDL_FALSE, SDL_getenv, SDL_INIT_AUDIO, SDL_LockMutex, SDL_malloc, SDL_OutOfMemory, SDL_RunAudio(), SDL_SetError, SDL_snprintf, SDL_strcmp, SDL_TRUE, SDL_UnlockMutex, SDL_WasInit, SDL_zerop, SDL_AudioSpec::size, SDL_AudioDriverImpl::SkipMixerLock, SDL_AudioDevice::spec, SDL_AudioBufferQueue::startpos, SDL_AudioDevice::thread, and SDL_AudioSpec::userdata.

Referenced by SDL_OpenAudio(), and SDL_OpenAudioDevice().

965 {
966  SDL_AudioDeviceID id = 0;
967  SDL_AudioSpec _obtained;
968  SDL_AudioDevice *device;
969  SDL_bool build_cvt;
970  void *handle = NULL;
971  Uint32 stream_len;
972  int i = 0;
973 
974  if (!SDL_WasInit(SDL_INIT_AUDIO)) {
975  SDL_SetError("Audio subsystem is not initialized");
976  return 0;
977  }
978 
979  if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
980  SDL_SetError("No capture support");
981  return 0;
982  }
983 
984  /* Find an available device ID... */
985  for (id = min_id - 1; id < SDL_arraysize(open_devices); id++) {
986  if (open_devices[id] == NULL) {
987  break;
988  }
989  }
990 
991  if (id == SDL_arraysize(open_devices)) {
992  SDL_SetError("Too many open audio devices");
993  return 0;
994  }
995 
996  if (!obtained) {
997  obtained = &_obtained;
998  }
999  if (!prepare_audiospec(desired, obtained)) {
1000  return 0;
1001  }
1002 
1003  /* If app doesn't care about a specific device, let the user override. */
1004  if (devname == NULL) {
1005  devname = SDL_getenv("SDL_AUDIO_DEVICE_NAME");
1006  }
1007 
1008  /*
1009  * Catch device names at the high level for the simple case...
1010  * This lets us have a basic "device enumeration" for systems that
1011  * don't have multiple devices, but makes sure the device name is
1012  * always NULL when it hits the low level.
1013  *
1014  * Also make sure that the simple case prevents multiple simultaneous
1015  * opens of the default system device.
1016  */
1017 
1018  if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
1019  if ((devname) && (SDL_strcmp(devname, DEFAULT_INPUT_DEVNAME) != 0)) {
1020  SDL_SetError("No such device");
1021  return 0;
1022  }
1023  devname = NULL;
1024 
1025  for (i = 0; i < SDL_arraysize(open_devices); i++) {
1026  if ((open_devices[i]) && (open_devices[i]->iscapture)) {
1027  SDL_SetError("Audio device already open");
1028  return 0;
1029  }
1030  }
1031  } else if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
1032  if ((devname) && (SDL_strcmp(devname, DEFAULT_OUTPUT_DEVNAME) != 0)) {
1033  SDL_SetError("No such device");
1034  return 0;
1035  }
1036  devname = NULL;
1037 
1038  for (i = 0; i < SDL_arraysize(open_devices); i++) {
1039  if ((open_devices[i]) && (!open_devices[i]->iscapture)) {
1040  SDL_SetError("Audio device already open");
1041  return 0;
1042  }
1043  }
1044  } else if (devname != NULL) {
1045  /* if the app specifies an exact string, we can pass the backend
1046  an actual device handle thingey, which saves them the effort of
1047  figuring out what device this was (such as, reenumerating
1048  everything again to find the matching human-readable name).
1049  It might still need to open a device based on the string for,
1050  say, a network audio server, but this optimizes some cases. */
1051  SDL_AudioDeviceItem *item;
1053  for (item = iscapture ? current_audio.inputDevices : current_audio.outputDevices; item; item = item->next) {
1054  if ((item->handle != NULL) && (SDL_strcmp(item->name, devname) == 0)) {
1055  handle = item->handle;
1056  break;
1057  }
1058  }
1060  }
1061 
1063  /* has to be in our device list, or the default device. */
1064  if ((handle == NULL) && (devname != NULL)) {
1065  SDL_SetError("No such device.");
1066  return 0;
1067  }
1068  }
1069 
1070  device = (SDL_AudioDevice *) SDL_AllocAudioMem(sizeof(SDL_AudioDevice));
1071  if (device == NULL) {
1072  SDL_OutOfMemory();
1073  return 0;
1074  }
1075  SDL_zerop(device);
1076  device->id = id + 1;
1077  device->spec = *obtained;
1078  device->enabled = 1;
1079  device->paused = 1;
1080  device->iscapture = iscapture;
1081 
1082  /* Create a mutex for locking the sound buffers */
1084  device->mixer_lock = SDL_CreateMutex();
1085  if (device->mixer_lock == NULL) {
1086  close_audio_device(device);
1087  SDL_SetError("Couldn't create mixer lock");
1088  return 0;
1089  }
1090  }
1091 
1092  if (current_audio.impl.OpenDevice(device, handle, devname, iscapture) < 0) {
1093  close_audio_device(device);
1094  return 0;
1095  }
1096  device->opened = 1;
1097 
1098  /* See if we need to do any conversion */
1099  build_cvt = SDL_FALSE;
1100  if (obtained->freq != device->spec.freq) {
1101  if (allowed_changes & SDL_AUDIO_ALLOW_FREQUENCY_CHANGE) {
1102  obtained->freq = device->spec.freq;
1103  } else {
1104  build_cvt = SDL_TRUE;
1105  }
1106  }
1107  if (obtained->format != device->spec.format) {
1108  if (allowed_changes & SDL_AUDIO_ALLOW_FORMAT_CHANGE) {
1109  obtained->format = device->spec.format;
1110  } else {
1111  build_cvt = SDL_TRUE;
1112  }
1113  }
1114  if (obtained->channels != device->spec.channels) {
1115  if (allowed_changes & SDL_AUDIO_ALLOW_CHANNELS_CHANGE) {
1116  obtained->channels = device->spec.channels;
1117  } else {
1118  build_cvt = SDL_TRUE;
1119  }
1120  }
1121 
1122  /* If the audio driver changes the buffer size, accept it.
1123  This needs to be done after the format is modified above,
1124  otherwise it might not have the correct buffer size.
1125  */
1126  if (device->spec.samples != obtained->samples) {
1127  obtained->samples = device->spec.samples;
1128  SDL_CalculateAudioSpec(obtained);
1129  }
1130 
1131  if (build_cvt) {
1132  /* Build an audio conversion block */
1133  if (SDL_BuildAudioCVT(&device->convert,
1134  obtained->format, obtained->channels,
1135  obtained->freq,
1136  device->spec.format, device->spec.channels,
1137  device->spec.freq) < 0) {
1138  close_audio_device(device);
1139  return 0;
1140  }
1141  if (device->convert.needed) {
1142  device->convert.len = (int) (((double) device->spec.size) /
1143  device->convert.len_ratio);
1144 
1145  device->convert.buf =
1146  (Uint8 *) SDL_AllocAudioMem(device->convert.len *
1147  device->convert.len_mult);
1148  if (device->convert.buf == NULL) {
1149  close_audio_device(device);
1150  SDL_OutOfMemory();
1151  return 0;
1152  }
1153  }
1154  }
1155 
1156  /* Allocate a fake audio memory buffer */
1157  stream_len = (device->convert.needed) ? device->convert.len_cvt : 0;
1158  if (device->spec.size > stream_len) {
1159  stream_len = device->spec.size;
1160  }
1161  SDL_assert(stream_len > 0);
1162  device->fake_stream = (Uint8 *)SDL_AllocAudioMem(stream_len);
1163  if (device->fake_stream == NULL) {
1164  close_audio_device(device);
1165  SDL_OutOfMemory();
1166  return 0;
1167  }
1168 
1169  if (device->spec.callback == NULL) { /* use buffer queueing? */
1170  /* pool a few packets to start. Enough for two callbacks. */
1171  const int packetlen = SDL_AUDIOBUFFERQUEUE_PACKETLEN;
1172  const int wantbytes = ((device->convert.needed) ? device->convert.len : device->spec.size) * 2;
1173  const int wantpackets = (wantbytes / packetlen) + ((wantbytes % packetlen) ? packetlen : 0);
1174  for (i = 0; i < wantpackets; i++) {
1176  if (packet) { /* don't care if this fails, we'll deal later. */
1177  packet->datalen = 0;
1178  packet->startpos = 0;
1179  packet->next = device->buffer_queue_pool;
1180  device->buffer_queue_pool = packet;
1181  }
1182  }
1183 
1185  device->spec.userdata = device;
1186  }
1187 
1188  /* add it to our list of open devices. */
1189  open_devices[id] = device;
1190 
1191  /* Start the audio thread if necessary */
1193  /* Start the audio thread */
1194  char name[64];
1195  SDL_snprintf(name, sizeof (name), "SDLAudioDev%d", (int) device->id);
1196 /* !!! FIXME: this is nasty. */
1197 #if defined(__WIN32__) && !defined(HAVE_LIBC)
1198 #undef SDL_CreateThread
1199 #if SDL_DYNAMIC_API
1200  device->thread = SDL_CreateThread_REAL(SDL_RunAudio, name, device, NULL, NULL);
1201 #else
1202  device->thread = SDL_CreateThread(SDL_RunAudio, name, device, NULL, NULL);
1203 #endif
1204 #else
1205  device->thread = SDL_CreateThread(SDL_RunAudio, name, device);
1206 #endif
1207  if (device->thread == NULL) {
1208  SDL_CloseAudioDevice(device->id);
1209  SDL_SetError("Couldn't create audio thread");
1210  return 0;
1211  }
1212  }
1213 
1214  return device->id;
1215 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
SDL_AudioDeviceID id
Definition: SDL_sysaudio.h:147
#define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE
Definition: SDL_audio.h:140
#define SDL_LockMutex
GLuint id
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:171
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
Uint8 * buf
Definition: SDL_audio.h:206
#define SDL_BuildAudioCVT
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:101
#define SDL_CreateMutex
double len_ratio
Definition: SDL_audio.h:210
#define DEFAULT_INPUT_DEVNAME
Definition: SDL_audio.c:38
SDL_AudioBufferQueue * buffer_queue_pool
Definition: SDL_sysaudio.h:180
Uint16 samples
Definition: SDL_audio.h:174
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:150
GLuint const GLchar * name
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
int SDL_RunAudio(void *devicep)
Definition: SDL_audio.c:595
#define SDL_zerop(x)
Definition: SDL_stdinc.h:356
#define SDL_AUDIO_ALLOW_CHANNELS_CHANGE
Definition: SDL_audio.h:142
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:123
SDL_bool
Definition: SDL_stdinc.h:126
#define DEFAULT_OUTPUT_DEVNAME
Definition: SDL_audio.c:37
struct SDL_AudioBufferQueue * next
Definition: SDL_sysaudio.h:66
Uint8 channels
Definition: SDL_audio.h:172
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
static int prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
Definition: SDL_audio.c:905
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
Definition: SDL_audio.c:1419
#define SDL_AllocAudioMem
Definition: SDL_audiomem.h:23
SDL_AudioCallback callback
Definition: SDL_audio.h:177
Uint8 * fake_stream
Definition: SDL_sysaudio.h:168
#define SDL_CreateThread
#define SDL_getenv
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:128
Uint32 size
Definition: SDL_audio.h:176
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
#define SDL_assert(condition)
Definition: SDL_assert.h:167
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
Definition: SDL_sysaudio.h:72
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
#define SDL_INIT_AUDIO
Definition: SDL.h:76
Uint32 SDL_AudioDeviceID
Definition: SDL_audio.h:303
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
SDL_AudioFormat format
Definition: SDL_audio.h:171
void * userdata
Definition: SDL_audio.h:178
#define SDL_AUDIO_ALLOW_FORMAT_CHANGE
Definition: SDL_audio.h:141
#define SDL_snprintf
#define SDL_UnlockMutex
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
#define SDL_malloc
#define SDL_strcmp
SDL_Thread * thread
Definition: SDL_sysaudio.h:174
#define SDL_WasInit
void SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1329
#define SDL_AUDIOBUFFERQUEUE_PACKETLEN
Definition: SDL_sysaudio.h:58
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:153
static void SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int _len)
Definition: SDL_audio.c:433
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:129
static void close_audio_device(SDL_AudioDevice *device)
Definition: SDL_audio.c:873
static int prepare_audiospec ( const SDL_AudioSpec orig,
SDL_AudioSpec prepared 
)
static

Definition at line 905 of file SDL_audio.c.

References AUDIO_S16, SDL_AudioSpec::channels, SDL_AudioSpec::format, SDL_AudioSpec::freq, SDL_AudioSpec::samples, SDL_atoi, SDL_CalculateAudioSpec(), SDL_getenv, SDL_memcpy, SDL_ParseAudioFormat(), and SDL_SetError.

Referenced by open_audio_device().

906 {
907  SDL_memcpy(prepared, orig, sizeof(SDL_AudioSpec));
908 
909  if (orig->freq == 0) {
910  const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY");
911  if ((!env) || ((prepared->freq = SDL_atoi(env)) == 0)) {
912  prepared->freq = 22050; /* a reasonable default */
913  }
914  }
915 
916  if (orig->format == 0) {
917  const char *env = SDL_getenv("SDL_AUDIO_FORMAT");
918  if ((!env) || ((prepared->format = SDL_ParseAudioFormat(env)) == 0)) {
919  prepared->format = AUDIO_S16; /* a reasonable default */
920  }
921  }
922 
923  switch (orig->channels) {
924  case 0:{
925  const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
926  if ((!env) || ((prepared->channels = (Uint8) SDL_atoi(env)) == 0)) {
927  prepared->channels = 2; /* a reasonable default */
928  }
929  break;
930  }
931  case 1: /* Mono */
932  case 2: /* Stereo */
933  case 4: /* surround */
934  case 6: /* surround with center and lfe */
935  break;
936  default:
937  SDL_SetError("Unsupported number of audio channels.");
938  return 0;
939  }
940 
941  if (orig->samples == 0) {
942  const char *env = SDL_getenv("SDL_AUDIO_SAMPLES");
943  if ((!env) || ((prepared->samples = (Uint16) SDL_atoi(env)) == 0)) {
944  /* Pick a default of ~46 ms at desired frequency */
945  /* !!! FIXME: remove this when the non-Po2 resampling is in. */
946  const int samples = (prepared->freq / 1000) * 46;
947  int power2 = 1;
948  while (power2 < samples) {
949  power2 *= 2;
950  }
951  prepared->samples = power2;
952  }
953  }
954 
955  /* Calculate the silence and size of the audio specification */
956  SDL_CalculateAudioSpec(prepared);
957 
958  return 1;
959 }
Uint16 samples
Definition: SDL_audio.h:174
#define SDL_memcpy
Uint8 channels
Definition: SDL_audio.h:172
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
Definition: SDL_audio.c:1419
GLsizei samples
#define SDL_atoi
#define SDL_getenv
#define SDL_SetError
SDL_AudioFormat format
Definition: SDL_audio.h:171
#define AUDIO_S16
Definition: SDL_audio.h:96
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:147
static SDL_AudioFormat SDL_ParseAudioFormat(const char *string)
Definition: SDL_audio.c:670
void SDL_AddAudioDevice ( const int  iscapture,
const char *  name,
void handle 
)

Definition at line 347 of file SDL_audio.c.

References add_capture_device(), add_output_device(), SDL_AUDIODEVICEADDED, SDL_ENABLE, SDL_GetEventState, SDL_PushEvent, and SDL_zero.

Referenced by SDL_AudioDetectDevices_Default().

348 {
349  const int device_index = iscapture ? add_capture_device(name, handle) : add_output_device(name, handle);
350  if (device_index != -1) {
351  /* Post the event, if desired */
354  SDL_zero(event);
355  event.adevice.type = SDL_AUDIODEVICEADDED;
356  event.adevice.which = device_index;
357  event.adevice.iscapture = iscapture;
358  SDL_PushEvent(&event);
359  }
360  }
361 }
static SDL_INLINE int add_output_device(const char *name, void *handle)
Definition: SDL_audio.c:324
#define SDL_ENABLE
Definition: SDL_events.h:718
GLuint const GLchar * name
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
struct _cl_event * event
#define SDL_PushEvent
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
static SDL_INLINE int add_capture_device(const char *name, void *handle)
Definition: SDL_audio.c:317
General event structure.
Definition: SDL_events.h:521
static void SDL_AudioCloseDevice_Default ( _THIS  )
static

Definition at line 209 of file SDL_audio.c.

210 { /* no-op. */
211 }
static void SDL_AudioDeinitialize_Default ( void  )
static

Definition at line 214 of file SDL_audio.c.

215 { /* no-op. */
216 }
static void SDL_AudioDetectDevices_Default ( void  )
static

Definition at line 164 of file SDL_audio.c.

References DEFAULT_INPUT_DEVNAME, DEFAULT_OUTPUT_DEVNAME, SDL_AudioDriverImpl::HasCaptureSupport, SDL_AudioDriver::impl, SDL_AudioDriverImpl::OnlyHasDefaultInputDevice, SDL_AudioDriverImpl::OnlyHasDefaultOutputDevice, SDL_AddAudioDevice(), SDL_assert, SDL_FALSE, and SDL_TRUE.

165 {
166  /* you have to write your own implementation if these assertions fail. */
169 
170  SDL_AddAudioDevice(SDL_FALSE, DEFAULT_OUTPUT_DEVNAME, (void *) ((size_t) 0x1));
172  SDL_AddAudioDevice(SDL_TRUE, DEFAULT_INPUT_DEVNAME, (void *) ((size_t) 0x2));
173  }
174 }
GLuint GLfloat GLfloat GLfloat x1
#define DEFAULT_INPUT_DEVNAME
Definition: SDL_audio.c:38
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
GLfixed GLfixed x2
#define DEFAULT_OUTPUT_DEVNAME
Definition: SDL_audio.c:37
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
void SDL_AddAudioDevice(const int iscapture, const char *name, void *handle)
Definition: SDL_audio.c:347
static void SDL_AudioFreeDeviceHandle_Default ( void handle)
static

Definition at line 219 of file SDL_audio.c.

220 { /* no-op. */
221 }
static Uint8* SDL_AudioGetDeviceBuf_Default ( _THIS  )
static

Definition at line 198 of file SDL_audio.c.

References NULL.

199 {
200  return NULL;
201 }
#define NULL
Definition: begin_code.h:143
static int SDL_AudioGetPendingBytes_Default ( _THIS  )
static

Definition at line 192 of file SDL_audio.c.

193 {
194  return 0;
195 }
int SDL_AudioInit ( const char *  driver_name)

Definition at line 711 of file SDL_audio.c.

References AudioBootStrap::demand_only, SDL_AudioDriver::desc, AudioBootStrap::desc, SDL_AudioDriverImpl::DetectDevices, SDL_AudioDriver::detectionLock, finalize_audio_entry_points(), i, SDL_AudioDriver::impl, AudioBootStrap::init, SDL_AudioDriver::name, AudioBootStrap::name, NULL, SDL_AudioQuit(), SDL_CreateMutex, SDL_getenv, SDL_INIT_AUDIO, SDL_SetError, SDL_strlen, SDL_strncasecmp, SDL_WasInit, and SDL_zero.

712 {
713  int i = 0;
714  int initialized = 0;
715  int tried_to_init = 0;
716 
718  SDL_AudioQuit(); /* shutdown driver if already running. */
719  }
720 
723 
724  /* Select the proper audio driver */
725  if (driver_name == NULL) {
726  driver_name = SDL_getenv("SDL_AUDIODRIVER");
727  }
728 
729  for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
730  /* make sure we should even try this driver before doing so... */
731  const AudioBootStrap *backend = bootstrap[i];
732  if ((driver_name && (SDL_strncasecmp(backend->name, driver_name, SDL_strlen(driver_name)) != 0)) ||
733  (!driver_name && backend->demand_only)) {
734  continue;
735  }
736 
737  tried_to_init = 1;
739  current_audio.name = backend->name;
740  current_audio.desc = backend->desc;
741  initialized = backend->init(&current_audio.impl);
742  }
743 
744  if (!initialized) {
745  /* specific drivers will set the error message if they fail... */
746  if (!tried_to_init) {
747  if (driver_name) {
748  SDL_SetError("Audio target '%s' not available", driver_name);
749  } else {
750  SDL_SetError("No available audio device");
751  }
752  }
753 
755  return -1; /* No driver was available, so fail. */
756  }
757 
759 
761 
762  /* Make sure we have a list of devices available at startup. */
764 
765  return 0;
766 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
const char * name
Definition: SDL_sysaudio.h:114
void(* DetectDevices)(void)
Definition: SDL_sysaudio.h:71
const char * name
Definition: SDL_sysaudio.h:191
#define SDL_CreateMutex
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
#define SDL_strncasecmp
static void finalize_audio_entry_points(void)
Definition: SDL_audio.c:262
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:123
const char * desc
Definition: SDL_sysaudio.h:118
void SDL_AudioQuit(void)
Definition: SDL_audio.c:1345
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
#define SDL_getenv
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
static const AudioBootStrap *const bootstrap[]
Definition: SDL_audio.c:76
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
#define SDL_INIT_AUDIO
Definition: SDL.h:76
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
#define SDL_strlen
int(* init)(SDL_AudioDriverImpl *impl)
Definition: SDL_sysaudio.h:193
const char * desc
Definition: SDL_sysaudio.h:192
#define SDL_WasInit
static void SDL_AudioLockDevice_Default ( SDL_AudioDevice device)
static

Definition at line 245 of file SDL_audio.c.

References is_in_audio_device_thread(), SDL_AudioDevice::mixer_lock, and SDL_LockMutex.

246 {
247  if (!is_in_audio_device_thread(device)) {
248  SDL_LockMutex(device->mixer_lock);
249  }
250 }
#define SDL_LockMutex
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:171
static SDL_INLINE SDL_bool is_in_audio_device_thread(SDL_AudioDevice *device)
Definition: SDL_audio.c:231
static int SDL_AudioOpenDevice_Default ( _THIS  ,
void handle,
const char *  devname,
int  iscapture 
)
static

Definition at line 225 of file SDL_audio.c.

References SDL_INLINE, and SDL_Unsupported.

226 {
227  return SDL_Unsupported();
228 }
#define SDL_Unsupported()
Definition: SDL_error.h:53
static void SDL_AudioPlayDevice_Default ( _THIS  )
static

Definition at line 187 of file SDL_audio.c.

188 { /* no-op. */
189 }
void SDL_AudioQuit ( void  )

Definition at line 1345 of file SDL_audio.c.

References SDL_AudioDriverImpl::Deinitialize, SDL_AudioDriver::detectionLock, free_device_list(), i, SDL_AudioDriver::impl, SDL_AudioDriver::inputDeviceCount, SDL_AudioDriver::inputDevices, SDL_AudioDriver::name, NULL, SDL_AudioDriver::outputDeviceCount, SDL_AudioDriver::outputDevices, SDL_arraysize, SDL_CloseAudioDevice(), SDL_DestroyMutex, and SDL_zero.

Referenced by SDL_AudioInit().

1346 {
1348 
1349  if (!current_audio.name) { /* not initialized?! */
1350  return;
1351  }
1352 
1353  for (i = 0; i < SDL_arraysize(open_devices); i++) {
1354  if (open_devices[i] != NULL) {
1355  SDL_CloseAudioDevice(i+1);
1356  }
1357  }
1358 
1361 
1362  /* Free the driver data */
1364 
1366 
1369 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
const char * name
Definition: SDL_sysaudio.h:114
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:123
void(* Deinitialize)(void)
Definition: SDL_sysaudio.h:83
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:128
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
#define NULL
Definition: begin_code.h:143
static void free_device_list(SDL_AudioDeviceItem **devices, int *devCount)
Definition: SDL_audio.c:330
#define SDL_DestroyMutex
Uint32 SDL_AudioDeviceID
Definition: SDL_audio.h:303
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
void SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1329
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:129
static void SDL_AudioThreadInit_Default ( _THIS  )
static

Definition at line 177 of file SDL_audio.c.

178 { /* no-op. */
179 }
static void SDL_AudioUnlockDevice_Default ( SDL_AudioDevice device)
static

Definition at line 253 of file SDL_audio.c.

References is_in_audio_device_thread(), SDL_AudioDevice::mixer_lock, and SDL_UnlockMutex.

254 {
255  if (!is_in_audio_device_thread(device)) {
256  SDL_UnlockMutex(device->mixer_lock);
257  }
258 }
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:171
#define SDL_UnlockMutex
static SDL_INLINE SDL_bool is_in_audio_device_thread(SDL_AudioDevice *device)
Definition: SDL_audio.c:231
static void SDL_AudioWaitDevice_Default ( _THIS  )
static

Definition at line 182 of file SDL_audio.c.

183 { /* no-op. */
184 }
static void SDL_AudioWaitDone_Default ( _THIS  )
static

Definition at line 204 of file SDL_audio.c.

205 { /* no-op. */
206 }
static void SDL_BufferQueueDrainCallback ( void userdata,
Uint8 stream,
int  _len 
)
static

Definition at line 433 of file SDL_audio.c.

References SDL_AudioDevice::buffer_queue_head, SDL_AudioDevice::buffer_queue_pool, SDL_AudioDevice::buffer_queue_tail, SDL_AudioBufferQueue::data, SDL_AudioBufferQueue::datalen, SDL_AudioBufferQueue::next, NULL, SDL_AudioDevice::queued_bytes, SDL_assert, SDL_memcpy, SDL_memset, SDL_min, SDL_AudioSpec::silence, SDL_AudioDevice::spec, and SDL_AudioBufferQueue::startpos.

Referenced by open_audio_device(), SDL_GetQueuedAudioSize(), and SDL_QueueAudio().

434 {
435  /* this function always holds the mixer lock before being called. */
436  Uint32 len = (Uint32) _len;
437  SDL_AudioDevice *device = (SDL_AudioDevice *) userdata;
439 
440  SDL_assert(device != NULL); /* this shouldn't ever happen, right?! */
441  SDL_assert(_len >= 0); /* this shouldn't ever happen, right?! */
442 
443  while ((len > 0) && ((buffer = device->buffer_queue_head) != NULL)) {
444  const Uint32 avail = buffer->datalen - buffer->startpos;
445  const Uint32 cpy = SDL_min(len, avail);
446  SDL_assert(device->queued_bytes >= avail);
447 
448  SDL_memcpy(stream, buffer->data + buffer->startpos, cpy);
449  buffer->startpos += cpy;
450  stream += cpy;
451  device->queued_bytes -= cpy;
452  len -= cpy;
453 
454  if (buffer->startpos == buffer->datalen) { /* packet is done, put it in the pool. */
455  device->buffer_queue_head = buffer->next;
456  SDL_assert((buffer->next != NULL) || (buffer == device->buffer_queue_tail));
457  buffer->next = device->buffer_queue_pool;
458  device->buffer_queue_pool = buffer;
459  }
460  }
461 
462  SDL_assert((device->buffer_queue_head != NULL) == (device->queued_bytes != 0));
463 
464  if (len > 0) { /* fill any remaining space in the stream with silence. */
465  SDL_assert(device->buffer_queue_head == NULL);
466  SDL_memset(stream, device->spec.silence, len);
467  }
468 
469  if (device->buffer_queue_head == NULL) {
470  device->buffer_queue_tail = NULL; /* in case we drained the queue entirely. */
471  }
472 }
#define SDL_min(x, y)
Definition: SDL_stdinc.h:345
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
Uint8 silence
Definition: SDL_audio.h:173
GLuint GLuint stream
SDL_AudioBufferQueue * buffer_queue_pool
Definition: SDL_sysaudio.h:180
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:150
GLenum GLsizei len
SDL_AudioBufferQueue * buffer_queue_head
Definition: SDL_sysaudio.h:178
SDL_AudioBufferQueue * buffer_queue_tail
Definition: SDL_sysaudio.h:179
#define SDL_memcpy
struct SDL_AudioBufferQueue * next
Definition: SDL_sysaudio.h:66
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
GLuint buffer
Uint8 data[SDL_AUDIOBUFFERQUEUE_PACKETLEN]
Definition: SDL_sysaudio.h:63
#define SDL_memset
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().

1420 {
1421  switch (spec->format) {
1422  case AUDIO_U8:
1423  spec->silence = 0x80;
1424  break;
1425  default:
1426  spec->silence = 0x00;
1427  break;
1428  }
1429  spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
1430  spec->size *= spec->channels;
1431  spec->size *= spec->samples;
1432 }
Uint8 silence
Definition: SDL_audio.h:173
Uint16 samples
Definition: SDL_audio.h:174
#define AUDIO_U8
Definition: SDL_audio.h:89
Uint8 channels
Definition: SDL_audio.h:172
#define SDL_AUDIO_BITSIZE(x)
Definition: SDL_audio.h:75
Uint32 size
Definition: SDL_audio.h:176
SDL_AudioFormat format
Definition: SDL_audio.h:171
void SDL_ClearQueuedAudio ( SDL_AudioDeviceID  dev)

Drop any queued audio data waiting to be sent to the hardware.

Immediately after this call, SDL_GetQueuedAudioSize() will return 0 and the hardware will start playing silence if more audio isn't queued.

This will not prevent playback of queued audio that's already been sent to the hardware, as we can not undo that, so expect there to be some fraction of a second of audio that might still be heard. This can be useful if you want to, say, drop any pending music during a level change in your game.

You may not queue audio on a device that is using an application-supplied callback; calling this function on such a device is always a no-op. You have to use the audio callback or queue audio with SDL_QueueAudio(), but not both.

You should not call SDL_LockAudio() on the device before clearing the queue; SDL handles locking internally for this function.

This function always succeeds and thus returns void.

Parameters
devThe device ID of which to clear the audio queue.
See also
SDL_QueueAudio
SDL_GetQueuedAudioSize

Definition at line 573 of file SDL_audio.c.

References SDL_AudioDevice::buffer_queue_head, SDL_AudioDevice::buffer_queue_tail, free_audio_queue(), get_audio_device(), SDL_AudioDriver::impl, SDL_AudioDriverImpl::LockDevice, NULL, SDL_AudioDevice::queued_bytes, SDLCALL, and SDL_AudioDriverImpl::UnlockDevice.

574 {
575  SDL_AudioDevice *device = get_audio_device(devid);
577  if (!device) {
578  return; /* nothing to do. */
579  }
580 
581  /* Blank out the device and release the mutex. Free it afterwards. */
582  current_audio.impl.LockDevice(device);
583  buffer = device->buffer_queue_head;
584  device->buffer_queue_tail = NULL;
585  device->buffer_queue_head = NULL;
586  device->queued_bytes = 0;
588 
589  free_audio_queue(buffer);
590 }
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:81
SDL_AudioBufferQueue * buffer_queue_head
Definition: SDL_sysaudio.h:178
SDL_AudioBufferQueue * buffer_queue_tail
Definition: SDL_sysaudio.h:179
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:80
#define NULL
Definition: begin_code.h:143
static void free_audio_queue(SDL_AudioBufferQueue *buffer)
Definition: SDL_audio.c:423
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
GLuint buffer
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150
void SDL_CloseAudio ( void  )

This function shuts down audio processing and closes the audio device.

Definition at line 1339 of file SDL_audio.c.

References SDL_CloseAudioDevice().

1340 {
1342 }
void SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1329
void SDL_CloseAudioDevice ( SDL_AudioDeviceID  devid)

Definition at line 1329 of file SDL_audio.c.

References close_audio_device(), get_audio_device(), and NULL.

Referenced by open_audio_device(), SDL_AudioQuit(), and SDL_CloseAudio().

1330 {
1331  SDL_AudioDevice *device = get_audio_device(devid);
1332  if (device) {
1333  close_audio_device(device);
1334  open_devices[devid - 1] = NULL;
1335  }
1336 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
#define NULL
Definition: begin_code.h:143
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150
static void close_audio_device(SDL_AudioDevice *device)
Definition: SDL_audio.c:873
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().

1399 {
1400  for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
1401  if (format_list[format_idx][0] == format) {
1402  break;
1403  }
1404  }
1405  format_idx_sub = 0;
1406  return SDL_NextAudioFormat();
1407 }
static int format_idx_sub
Definition: SDL_audio.c:1373
static int format_idx
Definition: SDL_audio.c:1372
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1374
SDL_AudioFormat SDL_NextAudioFormat(void)
Definition: SDL_audio.c:1410
#define NUM_FORMATS
Definition: SDL_audio.c:1371
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
const char* SDL_GetAudioDeviceName ( int  index,
int  iscapture 
)

Get the human-readable name of a specific audio device. Must be a value between 0 and (number of audio devices-1). Only valid after a successfully initializing the audio subsystem. The values returned by this function reflect the latest call to SDL_GetNumAudioDevices(); recall that function to redetect available hardware.

The string returned by this function is UTF-8 encoded, read-only, and managed internally. You are not to free it. If you need to keep the string for any length of time, you should make your own copy of it, as it will be invalid next time any of several other SDL functions is called.

Definition at line 833 of file SDL_audio.c.

References SDL_AudioDriver::detectionLock, SDL_AudioDriverImpl::HasCaptureSupport, i, SDL_AudioDriver::impl, SDL_AudioDriver::inputDeviceCount, SDL_AudioDriver::inputDevices, SDL_AudioDeviceItem::next, NULL, SDL_AudioDriver::outputDeviceCount, SDL_AudioDriver::outputDevices, retval, SDL_assert, SDL_INIT_AUDIO, SDL_LockMutex, SDL_SetError, SDL_UnlockMutex, and SDL_WasInit.

834 {
835  const char *retval = NULL;
836 
837  if (!SDL_WasInit(SDL_INIT_AUDIO)) {
838  SDL_SetError("Audio subsystem is not initialized");
839  return NULL;
840  }
841 
842  if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
843  SDL_SetError("No capture support");
844  return NULL;
845  }
846 
847  if (index >= 0) {
848  SDL_AudioDeviceItem *item;
849  int i;
850 
854  if (index < i) {
855  for (i--; i > index; i--, item = item->next) {
856  SDL_assert(item != NULL);
857  }
858  SDL_assert(item != NULL);
859  retval = item->name;
860  }
862  }
863 
864  if (retval == NULL) {
865  SDL_SetError("No such device");
866  }
867 
868  return retval;
869 }
#define SDL_LockMutex
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:101
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:123
SDL_bool retval
GLuint index
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:128
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
#define SDL_INIT_AUDIO
Definition: SDL.h:76
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
#define SDL_UnlockMutex
#define SDL_WasInit
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:129
SDL_AudioStatus SDL_GetAudioDeviceStatus ( SDL_AudioDeviceID  devid)

Definition at line 1257 of file SDL_audio.c.

References SDL_AudioDevice::enabled, get_audio_device(), SDL_AudioDevice::paused, SDL_AUDIO_PAUSED, SDL_AUDIO_PLAYING, and SDL_AUDIO_STOPPED.

Referenced by SDL_GetAudioStatus().

1258 {
1259  SDL_AudioDevice *device = get_audio_device(devid);
1261  if (device && device->enabled) {
1262  if (device->paused) {
1263  status = SDL_AUDIO_PAUSED;
1264  } else {
1265  status = SDL_AUDIO_PLAYING;
1266  }
1267  }
1268  return status;
1269 }
SDL_AudioStatus
Definition: SDL_audio.h:368
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150
const char* SDL_GetAudioDriver ( int  index)

Definition at line 702 of file SDL_audio.c.

References AudioBootStrap::name, NULL, and SDL_GetNumAudioDrivers().

703 {
704  if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
705  return bootstrap[index]->name;
706  }
707  return NULL;
708 }
int SDL_GetNumAudioDrivers(void)
Definition: SDL_audio.c:696
const char * name
Definition: SDL_sysaudio.h:191
GLuint index
static const AudioBootStrap *const bootstrap[]
Definition: SDL_audio.c:76
#define NULL
Definition: begin_code.h:143
SDL_AudioStatus SDL_GetAudioStatus ( void  )

Definition at line 1273 of file SDL_audio.c.

References SDL_GetAudioDeviceStatus().

1274 {
1275  return SDL_GetAudioDeviceStatus(1);
1276 }
SDL_AudioStatus SDL_GetAudioDeviceStatus(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1257
const char* SDL_GetCurrentAudioDriver ( void  )

This function returns the name of the current audio driver, or NULL if no driver has been initialized.

Definition at line 772 of file SDL_audio.c.

References SDL_AudioDriver::name.

773 {
774  return current_audio.name;
775 }
const char * name
Definition: SDL_sysaudio.h:114
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
int SDL_GetNumAudioDevices ( int  iscapture)

Get the number of available devices exposed by the current driver. Only valid after a successfully initializing the audio subsystem. Returns -1 if an explicit list of devices can't be determined; this is not an error. For example, if SDL is set up to talk to a remote audio server, it can't list every one available on the Internet, but it will still allow a specific host to be specified to SDL_OpenAudioDevice().

In many common cases, when this function returns a value <= 0, it can still successfully open the default device (NULL for first argument of SDL_OpenAudioDevice()).

Definition at line 807 of file SDL_audio.c.

References SDL_AudioDriver::captureDevicesRemoved, clean_out_device_list(), SDL_AudioDriver::detectionLock, SDL_AudioDriver::inputDeviceCount, SDL_AudioDriver::inputDevices, SDL_AudioDriver::outputDeviceCount, SDL_AudioDriver::outputDevices, SDL_AudioDriver::outputDevicesRemoved, retval, SDL_FALSE, SDL_INIT_AUDIO, SDL_LockMutex, SDL_UnlockMutex, and SDL_WasInit.

808 {
809  int retval = 0;
810 
811  if (!SDL_WasInit(SDL_INIT_AUDIO)) {
812  return -1;
813  }
814 
816  if (iscapture && current_audio.captureDevicesRemoved) {
818  }
819 
820  if (!iscapture && current_audio.outputDevicesRemoved) {
823  }
824 
827 
828  return retval;
829 }
#define SDL_LockMutex
SDL_bool captureDevicesRemoved
Definition: SDL_sysaudio.h:124
static void clean_out_device_list(SDL_AudioDeviceItem **devices, int *devCount, SDL_bool *removedFlag)
Definition: SDL_audio.c:779
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:123
SDL_bool retval
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:128
SDL_bool outputDevicesRemoved
Definition: SDL_sysaudio.h:125
#define SDL_INIT_AUDIO
Definition: SDL.h:76
#define SDL_UnlockMutex
#define SDL_WasInit
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:129
int SDL_GetNumAudioDrivers ( void  )

Definition at line 696 of file SDL_audio.c.

References SDL_arraysize.

Referenced by SDL_GetAudioDriver().

697 {
698  return SDL_arraysize(bootstrap) - 1;
699 }
static const AudioBootStrap *const bootstrap[]
Definition: SDL_audio.c:76
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
Uint32 SDL_GetQueuedAudioSize ( SDL_AudioDeviceID  dev)

Get the number of bytes of still-queued audio.

This is the number of bytes that have been queued for playback with SDL_QueueAudio(), but have not yet been sent to the hardware.

Once we've sent it to the hardware, this function can not decide the exact byte boundary of what has been played. It's possible that we just gave the hardware several kilobytes right before you called this function, but it hasn't played any of it yet, or maybe half of it, etc.

You may not queue audio on a device that is using an application-supplied callback; calling this function on such a device always returns 0. You have to use the audio callback or queue audio with SDL_QueueAudio(), but not both.

You should not call SDL_LockAudio() on the device before querying; SDL handles locking internally for this function.

Parameters
devThe device ID of which we will query queued audio size.
Returns
Number of bytes (not samples!) of queued audio.
See also
SDL_QueueAudio
SDL_ClearQueuedAudio

Definition at line 557 of file SDL_audio.c.

References SDL_AudioSpec::callback, get_audio_device(), SDL_AudioDriverImpl::GetPendingBytes, SDL_AudioDriver::impl, SDL_AudioDriverImpl::LockDevice, SDL_AudioDevice::queued_bytes, retval, SDL_BufferQueueDrainCallback(), SDL_AudioDevice::spec, and SDL_AudioDriverImpl::UnlockDevice.

558 {
559  Uint32 retval = 0;
560  SDL_AudioDevice *device = get_audio_device(devid);
561 
562  /* Nothing to do unless we're set up for queueing. */
563  if (device && (device->spec.callback == SDL_BufferQueueDrainCallback)) {
564  current_audio.impl.LockDevice(device);
565  retval = device->queued_bytes + current_audio.impl.GetPendingBytes(device);
567  }
568 
569  return retval;
570 }
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:150
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:81
SDL_bool retval
SDL_AudioCallback callback
Definition: SDL_audio.h:177
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:80
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
int(* GetPendingBytes)(_THIS)
Definition: SDL_sysaudio.h:76
static void SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int _len)
Definition: SDL_audio.c:433
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150
void SDL_LockAudio ( void  )

Definition at line 1307 of file SDL_audio.c.

References SDL_LockAudioDevice().

1308 {
1310 }
void SDL_LockAudioDevice(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1297
void SDL_LockAudioDevice ( SDL_AudioDeviceID  devid)

Definition at line 1297 of file SDL_audio.c.

References get_audio_device(), SDL_AudioDriver::impl, and SDL_AudioDriverImpl::LockDevice.

Referenced by SDL_LockAudio().

1298 {
1299  /* Obtain a lock on the mixing buffers */
1300  SDL_AudioDevice *device = get_audio_device(devid);
1301  if (device) {
1302  current_audio.impl.LockDevice(device);
1303  }
1304 }
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:80
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150
void SDL_MixAudio ( Uint8 dst,
const Uint8 src,
Uint32  len,
int  volume 
)

This takes two audio buffers of the playing audio format and mixes them, performing addition, volume adjustment, and overflow clipping. The volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME for full audio volume. Note this does not change hardware volume. This is provided for convenience – you can mix your own audio data.

Definition at line 1440 of file SDL_audio.c.

References SDL_AudioDevice::convert, SDL_AudioSpec::format, get_audio_device(), SDL_AudioCVT::needed, NULL, SDL_MixAudioFormat, SDL_AudioDevice::spec, and SDL_AudioCVT::src_format.

1441 {
1442  /* Mix the user-level audio format */
1443  SDL_AudioDevice *device = get_audio_device(1);
1444  if (device != NULL) {
1446  if (device->convert.needed) {
1447  format = device->convert.src_format;
1448  } else {
1449  format = device->spec.format;
1450  }
1451  SDL_MixAudioFormat(dst, src, format, len, volume);
1452  }
1453 }
GLenum GLenum dst
#define SDL_MixAudioFormat
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:150
Uint16 SDL_AudioFormat
Audio format flags.
Definition: SDL_audio.h:64
GLenum GLsizei len
SDL_AudioFormat src_format
Definition: SDL_audio.h:203
#define NULL
Definition: begin_code.h:143
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
SDL_AudioFormat format
Definition: SDL_audio.h:171
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:153
GLenum src
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150
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().

1411 {
1412  if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
1413  return 0;
1414  }
1416 }
static int format_idx_sub
Definition: SDL_audio.c:1373
static int format_idx
Definition: SDL_audio.c:1372
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1374
#define NUM_FORMATS
Definition: SDL_audio.c:1371
int SDL_OpenAudio ( SDL_AudioSpec desired,
SDL_AudioSpec obtained 
)

This function opens the audio device with the desired parameters, and returns 0 if successful, placing the actual hardware parameters in the structure pointed to by obtained. If obtained is NULL, the audio data passed to the callback function will be guaranteed to be in the requested format, and will be automatically converted to the hardware audio format if necessary. This function returns -1 if it failed to open the audio device, or couldn't set up the audio thread.

When filling in the desired audio spec structure,

  • desired->freq should be the desired audio frequency in samples-per- second.
  • desired->format should be the desired audio format.
  • desired->samples is the desired size of the audio buffer, in samples. This number should be a power of two, and may be adjusted by the audio driver to a value more suitable for the hardware. Good values seem to range between 512 and 8096 inclusive, depending on the application and CPU speed. Smaller values yield faster response time, but can lead to underflow if the application is doing heavy processing and cannot fill the audio buffer in time. A stereo sample consists of both right and left channels in LR ordering. Note that the number of samples is directly related to time by the following formula:
    1 ms = (samples*1000)/freq
  • desired->size is the size in bytes of the audio buffer, and is calculated by SDL_OpenAudio().
  • desired->silence is the value used to set the buffer to silence, and is calculated by SDL_OpenAudio().
  • desired->callback should be set to a function that will be called when the audio device is ready for more data. It is passed a pointer to the audio buffer, and the length in bytes of the audio buffer. This function usually runs in a separate thread, and so you should protect data structures that it accesses by calling SDL_LockAudio() and SDL_UnlockAudio() in your code. Alternately, you may pass a NULL pointer here, and call SDL_QueueAudio() with some frequency, to queue more audio samples to be played.
  • desired->userdata is passed as the first parameter to your callback function. If you passed a NULL callback, this value is ignored.

The audio device starts out playing silence when it's opened, and should be enabled for playing by calling SDL_PauseAudio(0) when you are ready for your audio callback function to be called. Since the audio driver may modify the requested size of the audio buffer, you should allocate any local mixing buffers after you open the audio device.

Definition at line 1219 of file SDL_audio.c.

References NULL, open_audio_device(), SDL_assert, SDL_AUDIO_ALLOW_ANY_CHANGE, SDL_INIT_AUDIO, SDL_InitSubSystem, SDL_SetError, and SDL_WasInit.

1220 {
1221  SDL_AudioDeviceID id = 0;
1222 
1223  /* Start up the audio driver, if necessary. This is legacy behaviour! */
1224  if (!SDL_WasInit(SDL_INIT_AUDIO)) {
1225  if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
1226  return -1;
1227  }
1228  }
1229 
1230  /* SDL_OpenAudio() is legacy and can only act on Device ID #1. */
1231  if (open_devices[0] != NULL) {
1232  SDL_SetError("Audio device is already opened");
1233  return -1;
1234  }
1235 
1236  if (obtained) {
1237  id = open_audio_device(NULL, 0, desired, obtained,
1239  } else {
1240  id = open_audio_device(NULL, 0, desired, NULL, 0, 1);
1241  }
1242 
1243  SDL_assert((id == 0) || (id == 1));
1244  return (id == 0) ? -1 : 0;
1245 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
#define SDL_InitSubSystem
#define SDL_AUDIO_ALLOW_ANY_CHANGE
Definition: SDL_audio.h:143
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
static SDL_AudioDeviceID open_audio_device(const char *devname, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes, int min_id)
Definition: SDL_audio.c:962
#define SDL_INIT_AUDIO
Definition: SDL.h:76
Uint32 SDL_AudioDeviceID
Definition: SDL_audio.h:303
#define SDL_WasInit
SDL_AudioDeviceID SDL_OpenAudioDevice ( const char *  device,
int  iscapture,
const SDL_AudioSpec desired,
SDL_AudioSpec obtained,
int  allowed_changes 
)

Open a specific audio device. Passing in a device name of NULL requests the most reasonable default (and is equivalent to calling SDL_OpenAudio()).

The device name is a UTF-8 string reported by SDL_GetAudioDeviceName(), but some drivers allow arbitrary and driver-specific strings, such as a hostname/IP address for a remote audio server, or a filename in the diskaudio driver.

Returns
0 on error, a valid device ID that is >= 2 on success.

SDL_OpenAudio(), unlike this function, always acts on device ID 1.

Definition at line 1248 of file SDL_audio.c.

References open_audio_device().

1251 {
1252  return open_audio_device(device, iscapture, desired, obtained,
1253  allowed_changes, 2);
1254 }
static SDL_AudioDeviceID open_audio_device(const char *devname, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes, int min_id)
Definition: SDL_audio.c:962
void SDL_OpenedAudioDeviceDisconnected ( SDL_AudioDevice device)

Definition at line 364 of file SDL_audio.c.

References SDL_AudioDevice::enabled, get_audio_device(), SDL_AudioDevice::id, SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioDriverImpl::LockDevice, SDL_assert, SDL_AUDIODEVICEREMOVED, SDL_ENABLE, SDL_GetEventState, SDL_PushEvent, SDL_zero, and SDL_AudioDriverImpl::UnlockDevice.

365 {
366  SDL_assert(get_audio_device(device->id) == device);
367 
368  if (!device->enabled) {
369  return;
370  }
371 
372  /* Ends the audio callback and mark the device as STOPPED, but the
373  app still needs to close the device to free resources. */
374  current_audio.impl.LockDevice(device);
375  device->enabled = 0;
377 
378  /* Post the event, if desired */
381  SDL_zero(event);
382  event.adevice.type = SDL_AUDIODEVICEREMOVED;
383  event.adevice.which = device->id;
384  event.adevice.iscapture = device->iscapture ? 1 : 0;
385  SDL_PushEvent(&event);
386  }
387 }
SDL_AudioDeviceID id
Definition: SDL_sysaudio.h:147
#define SDL_ENABLE
Definition: SDL_events.h:718
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:81
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
struct _cl_event * event
#define SDL_PushEvent
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:80
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
General event structure.
Definition: SDL_events.h:521
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150
static SDL_AudioFormat SDL_ParseAudioFormat ( const char *  string)
static

Definition at line 670 of file SDL_audio.c.

References CHECK_FMT_STRING, and S32.

Referenced by prepare_audiospec().

671 {
672 #define CHECK_FMT_STRING(x) if (SDL_strcmp(string, #x) == 0) return AUDIO_##x
673  CHECK_FMT_STRING(U8);
674  CHECK_FMT_STRING(S8);
675  CHECK_FMT_STRING(U16LSB);
676  CHECK_FMT_STRING(S16LSB);
677  CHECK_FMT_STRING(U16MSB);
678  CHECK_FMT_STRING(S16MSB);
679  CHECK_FMT_STRING(U16SYS);
680  CHECK_FMT_STRING(S16SYS);
681  CHECK_FMT_STRING(U16);
682  CHECK_FMT_STRING(S16);
683  CHECK_FMT_STRING(S32LSB);
684  CHECK_FMT_STRING(S32MSB);
685  CHECK_FMT_STRING(S32SYS);
687  CHECK_FMT_STRING(F32LSB);
688  CHECK_FMT_STRING(F32MSB);
689  CHECK_FMT_STRING(F32SYS);
690  CHECK_FMT_STRING(F32);
691 #undef CHECK_FMT_STRING
692  return 0;
693 }
#define S32
#define CHECK_FMT_STRING(x)
void SDL_PauseAudio ( int  pause_on)

Definition at line 1290 of file SDL_audio.c.

References SDL_PauseAudioDevice().

1291 {
1292  SDL_PauseAudioDevice(1, pause_on);
1293 }
void SDL_PauseAudioDevice(SDL_AudioDeviceID devid, int pause_on)
Definition: SDL_audio.c:1279
void SDL_PauseAudioDevice ( SDL_AudioDeviceID  devid,
int  pause_on 
)

Definition at line 1279 of file SDL_audio.c.

References get_audio_device(), SDL_AudioDriver::impl, SDL_AudioDriverImpl::LockDevice, SDL_AudioDevice::paused, and SDL_AudioDriverImpl::UnlockDevice.

Referenced by SDL_PauseAudio().

1280 {
1281  SDL_AudioDevice *device = get_audio_device(devid);
1282  if (device) {
1283  current_audio.impl.LockDevice(device);
1284  device->paused = pause_on;
1286  }
1287 }
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:81
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:80
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150
int SDL_QueueAudio ( SDL_AudioDeviceID  dev,
const void data,
Uint32  len 
)

Queue more audio on non-callback devices.

SDL offers two ways to feed audio to the device: you can either supply a callback that SDL triggers with some frequency to obtain more audio (pull method), or you can supply no callback, and then SDL will expect you to supply data at regular intervals (push method) with this function.

There are no limits on the amount of data you can queue, short of exhaustion of address space. Queued data will drain to the device as necessary without further intervention from you. If the device needs audio but there is not enough queued, it will play silence to make up the difference. This means you will have skips in your audio playback if you aren't routinely queueing sufficient data.

This function copies the supplied data, so you are safe to free it when the function returns. This function is thread-safe, but queueing to the same device from two threads at once does not promise which buffer will be queued first.

You may not queue audio on a device that is using an application-supplied callback; doing so returns an error. You have to use the audio callback or queue audio with this function, but not both.

You should not call SDL_LockAudio() on the device before queueing; SDL handles locking internally for this function.

Parameters
devThe device ID to which we will queue audio.
dataThe data to queue to the device for later playback.
lenThe number of bytes (not samples!) to which (data) points.
Returns
zero on success, -1 on error.
See also
SDL_GetQueuedAudioSize
SDL_ClearQueuedAudio

Definition at line 475 of file SDL_audio.c.

References SDL_AudioDevice::buffer_queue_head, SDL_AudioDevice::buffer_queue_pool, SDL_AudioDevice::buffer_queue_tail, SDL_AudioSpec::callback, SDL_AudioBufferQueue::data, SDL_AudioBufferQueue::datalen, free_audio_queue(), get_audio_device(), SDL_AudioDriver::impl, SDL_AudioDriverImpl::LockDevice, SDL_AudioBufferQueue::next, NULL, SDL_AudioDevice::queued_bytes, SDL_assert, SDL_AUDIOBUFFERQUEUE_PACKETLEN, SDL_BufferQueueDrainCallback(), SDL_malloc, SDL_memcpy, SDL_min, SDL_OutOfMemory, SDL_SetError, SDL_AudioDevice::spec, SDL_AudioBufferQueue::startpos, and SDL_AudioDriverImpl::UnlockDevice.

476 {
477  SDL_AudioDevice *device = get_audio_device(devid);
478  const Uint8 *data = (const Uint8 *) _data;
479  SDL_AudioBufferQueue *orighead;
480  SDL_AudioBufferQueue *origtail;
481  Uint32 origlen;
482  Uint32 datalen;
483 
484  if (!device) {
485  return -1; /* get_audio_device() will have set the error state */
486  }
487 
488  if (device->spec.callback != SDL_BufferQueueDrainCallback) {
489  return SDL_SetError("Audio device has a callback, queueing not allowed");
490  }
491 
492  current_audio.impl.LockDevice(device);
493 
494  orighead = device->buffer_queue_head;
495  origtail = device->buffer_queue_tail;
496  origlen = origtail ? origtail->datalen : 0;
497 
498  while (len > 0) {
499  SDL_AudioBufferQueue *packet = device->buffer_queue_tail;
500  SDL_assert(!packet || (packet->datalen <= SDL_AUDIOBUFFERQUEUE_PACKETLEN));
501  if (!packet || (packet->datalen >= SDL_AUDIOBUFFERQUEUE_PACKETLEN)) {
502  /* tail packet missing or completely full; we need a new packet. */
503  packet = device->buffer_queue_pool;
504  if (packet != NULL) {
505  /* we have one available in the pool. */
506  device->buffer_queue_pool = packet->next;
507  } else {
508  /* Have to allocate a new one! */
510  if (packet == NULL) {
511  /* uhoh, reset so we've queued nothing new, free what we can. */
512  if (!origtail) {
513  packet = device->buffer_queue_head; /* whole queue. */
514  } else {
515  packet = origtail->next; /* what we added to existing queue. */
516  origtail->next = NULL;
517  origtail->datalen = origlen;
518  }
519  device->buffer_queue_head = orighead;
520  device->buffer_queue_tail = origtail;
521  device->buffer_queue_pool = NULL;
522 
524 
525  free_audio_queue(packet); /* give back what we can. */
526 
527  return SDL_OutOfMemory();
528  }
529  }
530  packet->datalen = 0;
531  packet->startpos = 0;
532  packet->next = NULL;
533 
534  SDL_assert((device->buffer_queue_head != NULL) == (device->queued_bytes != 0));
535  if (device->buffer_queue_tail == NULL) {
536  device->buffer_queue_head = packet;
537  } else {
538  device->buffer_queue_tail->next = packet;
539  }
540  device->buffer_queue_tail = packet;
541  }
542 
543  datalen = SDL_min(len, SDL_AUDIOBUFFERQUEUE_PACKETLEN - packet->datalen);
544  SDL_memcpy(packet->data + packet->datalen, data, datalen);
545  data += datalen;
546  len -= datalen;
547  packet->datalen += datalen;
548  device->queued_bytes += datalen;
549  }
550 
552 
553  return 0;
554 }
#define SDL_min(x, y)
Definition: SDL_stdinc.h:345
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_AudioBufferQueue * buffer_queue_pool
Definition: SDL_sysaudio.h:180
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:150
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:81
GLenum GLsizei len
SDL_AudioBufferQueue * buffer_queue_head
Definition: SDL_sysaudio.h:178
SDL_AudioBufferQueue * buffer_queue_tail
Definition: SDL_sysaudio.h:179
#define SDL_memcpy
struct SDL_AudioBufferQueue * next
Definition: SDL_sysaudio.h:66
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_AudioCallback callback
Definition: SDL_audio.h:177
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:80
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
static void free_audio_queue(SDL_AudioBufferQueue *buffer)
Definition: SDL_audio.c:423
#define SDL_SetError
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
Uint8 data[SDL_AUDIOBUFFERQUEUE_PACKETLEN]
Definition: SDL_sysaudio.h:63
#define SDL_malloc
#define SDL_AUDIOBUFFERQUEUE_PACKETLEN
Definition: SDL_sysaudio.h:58
static void SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int _len)
Definition: SDL_audio.c:433
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150
void SDL_RemoveAudioDevice ( const int  iscapture,
void handle 
)

Definition at line 405 of file SDL_audio.c.

References SDL_AudioDriver::captureDevicesRemoved, SDL_AudioDriver::detectionLock, SDL_AudioDriverImpl::FreeDeviceHandle, SDL_AudioDriver::impl, SDL_AudioDriver::inputDevices, mark_device_removed(), SDL_AudioDriver::outputDevices, SDL_AudioDriver::outputDevicesRemoved, SDL_LockMutex, and SDL_UnlockMutex.

406 {
408  if (iscapture) {
410  } else {
412  }
415 }
#define SDL_LockMutex
SDL_bool captureDevicesRemoved
Definition: SDL_sysaudio.h:124
static void mark_device_removed(void *handle, SDL_AudioDeviceItem *devices, SDL_bool *removedFlag)
Definition: SDL_audio.c:390
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:123
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:128
SDL_bool outputDevicesRemoved
Definition: SDL_sysaudio.h:125
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
void(* FreeDeviceHandle)(void *handle)
Definition: SDL_sysaudio.h:82
#define SDL_UnlockMutex
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:129
int SDL_RunAudio ( void devicep)

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().

596 {
597  SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
598  const int silence = (int) device->spec.silence;
599  const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq);
600  const int stream_len = (device->convert.needed) ? device->convert.len : device->spec.size;
601  Uint8 *stream;
602  void *udata = device->spec.userdata;
603  void (SDLCALL *fill) (void *, Uint8 *, int) = device->spec.callback;
604 
605  /* The audio mixing is always a high priority thread */
607 
608  /* Perform any thread setup */
609  device->threadid = SDL_ThreadID();
610  current_audio.impl.ThreadInit(device);
611 
612  /* Loop, filling the audio buffers */
613  while (!device->shutdown) {
614  /* Fill the current buffer with sound */
615  if (device->convert.needed) {
616  stream = device->convert.buf;
617  } else if (device->enabled) {
619  } else {
620  /* if the device isn't enabled, we still write to the
621  fake_stream, so the app's callback will fire with
622  a regular frequency, in case they depend on that
623  for timing or progress. They can use hotplug
624  now to know if the device failed. */
625  stream = NULL;
626  }
627 
628  if (stream == NULL) {
629  stream = device->fake_stream;
630  }
631 
632  /* !!! FIXME: this should be LockDevice. */
633  SDL_LockMutex(device->mixer_lock);
634  if (device->paused) {
635  SDL_memset(stream, silence, stream_len);
636  } else {
637  (*fill) (udata, stream, stream_len);
638  }
639  SDL_UnlockMutex(device->mixer_lock);
640 
641  /* Convert the audio if necessary */
642  if (device->enabled && device->convert.needed) {
643  SDL_ConvertAudio(&device->convert);
645  if (stream == NULL) {
646  stream = device->fake_stream;
647  } else {
648  SDL_memcpy(stream, device->convert.buf,
649  device->convert.len_cvt);
650  }
651  }
652 
653  /* Ready current buffer for play and change current buffer */
654  if (stream == device->fake_stream) {
655  SDL_Delay(delay);
656  } else {
657  current_audio.impl.PlayDevice(device);
658  current_audio.impl.WaitDevice(device);
659  }
660  }
661 
662  /* Wait for the audio to drain. */
663  current_audio.impl.WaitDone(device);
664 
665  return 0;
666 }
#define SDL_ThreadID
#define SDL_LockMutex
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:171
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
Uint8 silence
Definition: SDL_audio.h:173
Uint8 * buf
Definition: SDL_audio.h:206
GLuint GLuint stream
SDL_threadID threadid
Definition: SDL_sysaudio.h:175
void(* PlayDevice)(_THIS)
Definition: SDL_sysaudio.h:75
Uint16 samples
Definition: SDL_audio.h:174
void(* WaitDevice)(_THIS)
Definition: SDL_sysaudio.h:74
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:150
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
#define SDL_memcpy
void(* ThreadInit)(_THIS)
Definition: SDL_sysaudio.h:73
#define SDL_ConvertAudio
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_AudioCallback callback
Definition: SDL_audio.h:177
Uint8 * fake_stream
Definition: SDL_sysaudio.h:168
#define SDL_Delay
Uint32 size
Definition: SDL_audio.h:176
#define NULL
Definition: begin_code.h:143
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
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
Uint8 *(* GetDeviceBuf)(_THIS)
Definition: SDL_sysaudio.h:77
void * userdata
Definition: SDL_audio.h:178
#define SDL_UnlockMutex
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:153
#define SDLCALL
Definition: SDL_internal.h:31
#define SDL_SetThreadPriority
#define SDL_memset
void(* WaitDone)(_THIS)
Definition: SDL_sysaudio.h:78
void SDL_UnlockAudio ( void  )

Definition at line 1323 of file SDL_audio.c.

References SDL_UnlockAudioDevice().

1324 {
1326 }
void SDL_UnlockAudioDevice(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1313
void SDL_UnlockAudioDevice ( SDL_AudioDeviceID  devid)

Definition at line 1313 of file SDL_audio.c.

References get_audio_device(), SDL_AudioDriver::impl, and SDL_AudioDriverImpl::UnlockDevice.

Referenced by SDL_UnlockAudio().

1314 {
1315  /* Obtain a lock on the mixing buffers */
1316  SDL_AudioDevice *device = get_audio_device(devid);
1317  if (device) {
1319  }
1320 }
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:81
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:120
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:150

Variable Documentation

AudioBootStrap ALSA_bootstrap
AudioBootStrap ANDROIDAUD_bootstrap
AudioBootStrap ARTS_bootstrap
const AudioBootStrap* const bootstrap[]
static

Definition at line 76 of file SDL_audio.c.

AudioBootStrap BSD_AUDIO_bootstrap
AudioBootStrap COREAUDIO_bootstrap
SDL_AudioDriver current_audio
static

Definition at line 33 of file SDL_audio.c.

AudioBootStrap DART_bootstrap
AudioBootStrap DCAUD_bootstrap
AudioBootStrap DISKAUD_bootstrap
AudioBootStrap DSOUND_bootstrap
AudioBootStrap DSP_bootstrap
AudioBootStrap DUMMYAUD_bootstrap

Definition at line 44 of file SDL_dummyaudio.c.

AudioBootStrap EmscriptenAudio_bootstrap
AudioBootStrap ESD_bootstrap
int format_idx
static

Definition at line 1372 of file SDL_audio.c.

Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().

int format_idx_sub
static

Definition at line 1373 of file SDL_audio.c.

Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().

SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
static
Initial value:
= {
}
#define AUDIO_S32MSB
Definition: SDL_audio.h:104
#define AUDIO_U16LSB
Definition: SDL_audio.h:91
#define AUDIO_F32MSB
Definition: SDL_audio.h:113
#define AUDIO_U8
Definition: SDL_audio.h:89
#define AUDIO_F32LSB
Definition: SDL_audio.h:112
#define AUDIO_S32LSB
Definition: SDL_audio.h:103
#define AUDIO_S16MSB
Definition: SDL_audio.h:94
#define AUDIO_S16LSB
Definition: SDL_audio.h:92
#define AUDIO_S8
Definition: SDL_audio.h:90
#define AUDIO_U16MSB
Definition: SDL_audio.h:93

Definition at line 1374 of file SDL_audio.c.

Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().

AudioBootStrap FUSIONSOUND_bootstrap
AudioBootStrap HAIKUAUDIO_bootstrap
AudioBootStrap NACLAUD_bootstrap
AudioBootStrap NAS_bootstrap
AudioBootStrap NDSAUD_bootstrap
SDL_AudioDevice* open_devices[16]
static

Definition at line 34 of file SDL_audio.c.

AudioBootStrap PAUDIO_bootstrap
AudioBootStrap PSPAUD_bootstrap
AudioBootStrap PULSEAUDIO_bootstrap
AudioBootStrap QSAAUDIO_bootstrap
AudioBootStrap SNDIO_bootstrap
AudioBootStrap SNDMGR_bootstrap
AudioBootStrap SUNAUDIO_bootstrap
AudioBootStrap WINMM_bootstrap
AudioBootStrap XAUDIO2_bootstrap