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_sysaudio.h"
#include "../thread/SDL_systhread.h"
+ Include dependency graph for SDL_audio.c:

Go to the source code of this file.

Macros

#define _THIS   SDL_AudioDevice *_this
 
#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 int SDL_AudioCaptureFromDevice_Default (_THIS, void *buffer, int buflen)
 
static void SDL_AudioFlushCapture_Default (_THIS)
 
static void SDL_AudioPrepareToClose_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 SDL_AudioLockOrUnlockDeviceWithNoMixerLock (SDL_AudioDevice *device)
 
static void finish_audio_entry_points_init (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 *packet)
 
static int queue_audio_to_device (SDL_AudioDevice *device, const Uint8 *data, Uint32 len)
 
static Uint32 dequeue_audio_from_device (SDL_AudioDevice *device, Uint8 *stream, Uint32 len)
 
static void SDL_BufferQueueDrainCallback (void *userdata, Uint8 *stream, int len)
 
static void SDL_BufferQueueFillCallback (void *userdata, Uint8 *stream, int len)
 
int SDL_QueueAudio (SDL_AudioDeviceID devid, const void *data, Uint32 len)
 
Uint32 SDL_DequeueAudio (SDL_AudioDeviceID devid, void *data, Uint32 len)
 
Uint32 SDL_GetQueuedAudioSize (SDL_AudioDeviceID devid)
 
void SDL_ClearQueuedAudio (SDL_AudioDeviceID devid)
 
static int SDL_RunAudio (void *devicep)
 
static int SDL_CaptureAudio (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 PULSEAUDIO_bootstrap
 
AudioBootStrap ALSA_bootstrap
 
AudioBootStrap SNDIO_bootstrap
 
AudioBootStrap BSD_AUDIO_bootstrap
 
AudioBootStrap DSP_bootstrap
 
AudioBootStrap QSAAUDIO_bootstrap
 
AudioBootStrap SUNAUDIO_bootstrap
 
AudioBootStrap ARTS_bootstrap
 
AudioBootStrap ESD_bootstrap
 
AudioBootStrap NACLAUDIO_bootstrap
 
AudioBootStrap NAS_bootstrap
 
AudioBootStrap XAUDIO2_bootstrap
 
AudioBootStrap DSOUND_bootstrap
 
AudioBootStrap WINMM_bootstrap
 
AudioBootStrap PAUDIO_bootstrap
 
AudioBootStrap HAIKUAUDIO_bootstrap
 
AudioBootStrap COREAUDIO_bootstrap
 
AudioBootStrap DISKAUDIO_bootstrap
 
AudioBootStrap DUMMYAUDIO_bootstrap
 
AudioBootStrap FUSIONSOUND_bootstrap
 
AudioBootStrap ANDROIDAUDIO_bootstrap
 
AudioBootStrap PSPAUDIO_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

◆ _THIS

#define _THIS   SDL_AudioDevice *_this

Definition at line 31 of file SDL_audio.c.

◆ CHECK_FMT_STRING

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

Referenced by SDL_ParseAudioFormat().

◆ FILL_STUB

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

Referenced by finish_audio_entry_points_init().

◆ NUM_FORMATS

#define NUM_FORMATS   10

Definition at line 1584 of file SDL_audio.c.

Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().

Function Documentation

◆ add_audio_device()

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

Definition at line 310 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().

311 {
312  int retval = -1;
313  const size_t size = sizeof (SDL_AudioDeviceItem) + SDL_strlen(name) + 1;
315  if (item == NULL) {
316  return -1;
317  }
318 
319  SDL_assert(handle != NULL); /* we reserve NULL, audio backends can't use it. */
320 
321  item->handle = handle;
322  SDL_strlcpy(item->name, name, size - sizeof (SDL_AudioDeviceItem));
323 
325  item->next = *devices;
326  *devices = item;
327  retval = (*devCount)++;
329 
330  return retval;
331 }
#define SDL_strlcpy
#define SDL_LockMutex
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:107
GLuint const GLchar * name
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
GLsizeiptr size
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:129
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

◆ add_capture_device()

static SDL_INLINE int add_capture_device ( const char *  name,
void handle 
)
static

Definition at line 334 of file SDL_audio.c.

References add_audio_device(), SDL_AudioDriverImpl::HasCaptureSupport, SDL_AudioDriver::impl, SDL_AudioDriver::inputDeviceCount, SDL_AudioDriver::inputDevices, SDL_assert, and SDL_INLINE.

Referenced by SDL_AddAudioDevice().

335 {
338 }
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:310
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:135

◆ add_output_device()

static SDL_INLINE int add_output_device ( const char *  name,
void handle 
)
static

Definition at line 341 of file SDL_audio.c.

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

Referenced by SDL_AddAudioDevice().

342 {
344 }
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:310
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:134

◆ clean_out_device_list()

static void clean_out_device_list ( SDL_AudioDeviceItem **  devices,
int *  devCount,
SDL_bool removedFlag 
)
static

Definition at line 985 of file SDL_audio.c.

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

Referenced by SDL_GetNumAudioDevices().

986 {
987  SDL_AudioDeviceItem *item = *devices;
988  SDL_AudioDeviceItem *prev = NULL;
989  int total = 0;
990 
991  while (item) {
992  SDL_AudioDeviceItem *next = item->next;
993  if (item->handle != NULL) {
994  total++;
995  prev = item;
996  } else {
997  if (prev) {
998  prev->next = next;
999  } else {
1000  *devices = next;
1001  }
1002  SDL_free(item);
1003  }
1004  item = next;
1005  }
1006 
1007  *devCount = total;
1008  *removedFlag = SDL_FALSE;
1009 }
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:107
void SDL_free(void *mem)
#define NULL
Definition: begin_code.h:143

◆ close_audio_device()

static void close_audio_device ( SDL_AudioDevice device)
static

Definition at line 1079 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_AudioDevice::hidden, SDL_AudioDevice::id, SDL_AudioDriver::impl, SDL_AudioDevice::mixer_lock, SDL_AudioCVT::needed, NULL, SDL_assert, SDL_AtomicSet, SDL_DestroyMutex, SDL_free(), SDL_WaitThread, SDL_AudioDevice::shutdown, and SDL_AudioDevice::thread.

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

1080 {
1081  if (!device) {
1082  return;
1083  }
1084 
1085  if (device->id > 0) {
1086  SDL_AudioDevice *opendev = open_devices[device->id - 1];
1087  SDL_assert((opendev == device) || (opendev == NULL));
1088  if (opendev == device) {
1089  open_devices[device->id - 1] = NULL;
1090  }
1091  }
1092 
1093  SDL_AtomicSet(&device->shutdown, 1);
1094  SDL_AtomicSet(&device->enabled, 0);
1095  if (device->thread != NULL) {
1096  SDL_WaitThread(device->thread, NULL);
1097  }
1098  if (device->mixer_lock != NULL) {
1099  SDL_DestroyMutex(device->mixer_lock);
1100  }
1101  SDL_free(device->fake_stream);
1102  if (device->convert.needed) {
1103  SDL_free(device->convert.buf);
1104  }
1105  if (device->hidden != NULL) {
1106  current_audio.impl.CloseDevice(device);
1107  }
1108 
1111 
1112  SDL_free(device);
1113 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
struct SDL_PrivateAudioData * hidden
Definition: SDL_sysaudio.h:189
SDL_AudioDeviceID id
Definition: SDL_sysaudio.h:153
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:175
SDL_atomic_t enabled
Definition: SDL_sysaudio.h:167
Uint8 * buf
Definition: SDL_audio.h:206
SDL_atomic_t shutdown
Definition: SDL_sysaudio.h:166
SDL_AudioBufferQueue * buffer_queue_pool
Definition: SDL_sysaudio.h:184
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_AudioBufferQueue * buffer_queue_head
Definition: SDL_sysaudio.h:182
void SDL_free(void *mem)
Uint8 * fake_stream
Definition: SDL_sysaudio.h:172
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
void(* CloseDevice)(_THIS)
Definition: SDL_sysaudio.h:85
#define SDL_DestroyMutex
static void free_audio_queue(SDL_AudioBufferQueue *packet)
Definition: SDL_audio.c:453
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
#define SDL_AtomicSet
SDL_Thread * thread
Definition: SDL_sysaudio.h:178
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:159
#define SDL_WaitThread

◆ dequeue_audio_from_device()

static Uint32 dequeue_audio_from_device ( SDL_AudioDevice device,
Uint8 stream,
Uint32  len 
)
static

Definition at line 531 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_min, SDLCALL, and SDL_AudioBufferQueue::startpos.

Referenced by SDL_BufferQueueDrainCallback(), and SDL_DequeueAudio().

532 {
533  SDL_AudioBufferQueue *packet;
534  Uint8 *ptr = stream;
535 
536  while ((len > 0) && ((packet = device->buffer_queue_head) != NULL)) {
537  const Uint32 avail = packet->datalen - packet->startpos;
538  const Uint32 cpy = SDL_min(len, avail);
539  SDL_assert(device->queued_bytes >= avail);
540 
541  SDL_memcpy(ptr, packet->data + packet->startpos, cpy);
542  packet->startpos += cpy;
543  ptr += cpy;
544  device->queued_bytes -= cpy;
545  len -= cpy;
546 
547  if (packet->startpos == packet->datalen) { /* packet is done, put it in the pool. */
548  device->buffer_queue_head = packet->next;
549  SDL_assert((packet->next != NULL) || (packet == device->buffer_queue_tail));
550  packet->next = device->buffer_queue_pool;
551  device->buffer_queue_pool = packet;
552  }
553  }
554 
555  SDL_assert((device->buffer_queue_head != NULL) == (device->queued_bytes != 0));
556 
557  if (device->buffer_queue_head == NULL) {
558  device->buffer_queue_tail = NULL; /* in case we drained the queue entirely. */
559  }
560 
561  return (Uint32) (ptr - stream);
562 }
#define SDL_min(x, y)
Definition: SDL_stdinc.h:349
GLuint GLuint stream
SDL_AudioBufferQueue * buffer_queue_pool
Definition: SDL_sysaudio.h:184
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
GLenum GLsizei len
SDL_AudioBufferQueue * buffer_queue_head
Definition: SDL_sysaudio.h:182
SDL_AudioBufferQueue * buffer_queue_tail
Definition: SDL_sysaudio.h:183
#define SDL_memcpy
struct SDL_AudioBufferQueue * next
Definition: SDL_sysaudio.h:70
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
Uint8 data[SDL_AUDIOBUFFERQUEUE_PACKETLEN]
Definition: SDL_sysaudio.h:67

◆ finish_audio_entry_points_init()

static void finish_audio_entry_points_init ( void  )
static

Definition at line 268 of file SDL_audio.c.

References FILL_STUB, SDL_AudioDriver::impl, SDL_AudioDriverImpl::LockDevice, NULL, SDL_AudioLockOrUnlockDeviceWithNoMixerLock(), SDL_AudioDriverImpl::SkipMixerLock, and SDL_AudioDriverImpl::UnlockDevice.

Referenced by SDL_AudioInit().

269 {
270  /*
271  * Fill in stub functions for unused driver entry points. This lets us
272  * blindly call them without having to check for validity first.
273  */
274 
278  }
281  }
282  }
283 
284 #define FILL_STUB(x) \
285  if (current_audio.impl.x == NULL) { \
286  current_audio.impl.x = SDL_Audio##x##_Default; \
287  }
288  FILL_STUB(DetectDevices);
289  FILL_STUB(OpenDevice);
290  FILL_STUB(ThreadInit);
291  FILL_STUB(WaitDevice);
292  FILL_STUB(PlayDevice);
293  FILL_STUB(GetPendingBytes);
294  FILL_STUB(GetDeviceBuf);
295  FILL_STUB(CaptureFromDevice);
296  FILL_STUB(FlushCapture);
297  FILL_STUB(PrepareToClose);
298  FILL_STUB(CloseDevice);
299  FILL_STUB(LockDevice);
300  FILL_STUB(UnlockDevice);
301  FILL_STUB(FreeDeviceHandle);
302  FILL_STUB(Deinitialize);
303 #undef FILL_STUB
304 }
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:87
#define FILL_STUB(x)
static void SDL_AudioLockOrUnlockDeviceWithNoMixerLock(SDL_AudioDevice *device)
Definition: SDL_audio.c:263
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:86
#define NULL
Definition: begin_code.h:143
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126

◆ free_audio_queue()

static void free_audio_queue ( SDL_AudioBufferQueue packet)
static

Definition at line 453 of file SDL_audio.c.

References SDL_AudioBufferQueue::next, and SDL_free().

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

454 {
455  while (packet) {
456  SDL_AudioBufferQueue *next = packet->next;
457  SDL_free(packet);
458  packet = next;
459  }
460 }
struct SDL_AudioBufferQueue * next
Definition: SDL_sysaudio.h:70
void SDL_free(void *mem)

◆ free_device_list()

static void free_device_list ( SDL_AudioDeviceItem **  devices,
int *  devCount 
)
static

Definition at line 347 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().

348 {
349  SDL_AudioDeviceItem *item, *next;
350  for (item = *devices; item != NULL; item = next) {
351  next = item->next;
352  if (item->handle != NULL) {
354  }
355  SDL_free(item);
356  }
357  *devices = NULL;
358  *devCount = 0;
359 }
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:107
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:126
void(* FreeDeviceHandle)(void *handle)
Definition: SDL_sysaudio.h:88

◆ get_audio_device()

static SDL_AudioDevice* get_audio_device ( SDL_AudioDeviceID  id)
static

Definition at line 141 of file SDL_audio.c.

References NULL, SDL_arraysize, and SDL_SetError.

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

142 {
143  id--;
144  if ((id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL)) {
145  SDL_SetError("Invalid audio device ID");
146  return NULL;
147  }
148 
149  return open_devices[id];
150 }
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:90

◆ is_in_audio_device_thread()

static SDL_INLINE SDL_bool is_in_audio_device_thread ( SDL_AudioDevice device)
static

Definition at line 233 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().

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

◆ mark_device_removed()

static void mark_device_removed ( void handle,
SDL_AudioDeviceItem devices,
SDL_bool removedFlag 
)
static

Definition at line 407 of file SDL_audio.c.

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

Referenced by SDL_RemoveAudioDevice().

408 {
409  SDL_AudioDeviceItem *item;
410  SDL_assert(handle != NULL);
411  for (item = devices; item != NULL; item = item->next) {
412  if (item->handle == handle) {
413  item->handle = NULL;
414  *removedFlag = SDL_TRUE;
415  return;
416  }
417  }
418 }
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:107
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143

◆ open_audio_device()

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 1179 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_AudioDevice::handle, SDL_AudioDriverImpl::HasCaptureSupport, SDL_AudioDevice::hidden, 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::OnlyHasDefaultCaptureDevice, SDL_AudioDriverImpl::OnlyHasDefaultOutputDevice, SDL_AudioDriverImpl::OpenDevice, SDL_AudioDriver::outputDevices, SDL_AudioDevice::paused, prepare_audiospec(), SDL_AudioDriverImpl::ProvidesOwnCallbackThread, SDL_AudioSpec::samples, SDL_arraysize, SDL_assert, SDL_AtomicSet, SDL_AUDIO_ALLOW_CHANNELS_CHANGE, SDL_AUDIO_ALLOW_FORMAT_CHANGE, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE, SDL_AUDIOBUFFERQUEUE_PACKETLEN, SDL_BufferQueueDrainCallback(), SDL_BufferQueueFillCallback(), SDL_BuildAudioCVT, SDL_CalculateAudioSpec(), SDL_calloc(), SDL_CaptureAudio(), SDL_CreateMutex, SDL_CreateThreadInternal(), 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_AudioDevice::shutdown, 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().

1182 {
1183  const SDL_bool is_internal_thread = (desired->callback != NULL);
1184  SDL_AudioDeviceID id = 0;
1185  SDL_AudioSpec _obtained;
1186  SDL_AudioDevice *device;
1187  SDL_bool build_cvt;
1188  void *handle = NULL;
1189  int i = 0;
1190 
1191  if (!SDL_WasInit(SDL_INIT_AUDIO)) {
1192  SDL_SetError("Audio subsystem is not initialized");
1193  return 0;
1194  }
1195 
1196  if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
1197  SDL_SetError("No capture support");
1198  return 0;
1199  }
1200 
1201  /* !!! FIXME: there is a race condition here if two devices open from two threads at once. */
1202  /* Find an available device ID... */
1203  for (id = min_id - 1; id < SDL_arraysize(open_devices); id++) {
1204  if (open_devices[id] == NULL) {
1205  break;
1206  }
1207  }
1208 
1209  if (id == SDL_arraysize(open_devices)) {
1210  SDL_SetError("Too many open audio devices");
1211  return 0;
1212  }
1213 
1214  if (!obtained) {
1215  obtained = &_obtained;
1216  }
1217  if (!prepare_audiospec(desired, obtained)) {
1218  return 0;
1219  }
1220 
1221  /* If app doesn't care about a specific device, let the user override. */
1222  if (devname == NULL) {
1223  devname = SDL_getenv("SDL_AUDIO_DEVICE_NAME");
1224  }
1225 
1226  /*
1227  * Catch device names at the high level for the simple case...
1228  * This lets us have a basic "device enumeration" for systems that
1229  * don't have multiple devices, but makes sure the device name is
1230  * always NULL when it hits the low level.
1231  *
1232  * Also make sure that the simple case prevents multiple simultaneous
1233  * opens of the default system device.
1234  */
1235 
1236  if ((iscapture) && (current_audio.impl.OnlyHasDefaultCaptureDevice)) {
1237  if ((devname) && (SDL_strcmp(devname, DEFAULT_INPUT_DEVNAME) != 0)) {
1238  SDL_SetError("No such device");
1239  return 0;
1240  }
1241  devname = NULL;
1242 
1243  for (i = 0; i < SDL_arraysize(open_devices); i++) {
1244  if ((open_devices[i]) && (open_devices[i]->iscapture)) {
1245  SDL_SetError("Audio device already open");
1246  return 0;
1247  }
1248  }
1249  } else if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
1250  if ((devname) && (SDL_strcmp(devname, DEFAULT_OUTPUT_DEVNAME) != 0)) {
1251  SDL_SetError("No such device");
1252  return 0;
1253  }
1254  devname = NULL;
1255 
1256  for (i = 0; i < SDL_arraysize(open_devices); i++) {
1257  if ((open_devices[i]) && (!open_devices[i]->iscapture)) {
1258  SDL_SetError("Audio device already open");
1259  return 0;
1260  }
1261  }
1262  } else if (devname != NULL) {
1263  /* if the app specifies an exact string, we can pass the backend
1264  an actual device handle thingey, which saves them the effort of
1265  figuring out what device this was (such as, reenumerating
1266  everything again to find the matching human-readable name).
1267  It might still need to open a device based on the string for,
1268  say, a network audio server, but this optimizes some cases. */
1269  SDL_AudioDeviceItem *item;
1271  for (item = iscapture ? current_audio.inputDevices : current_audio.outputDevices; item; item = item->next) {
1272  if ((item->handle != NULL) && (SDL_strcmp(item->name, devname) == 0)) {
1273  handle = item->handle;
1274  break;
1275  }
1276  }
1278  }
1279 
1281  /* has to be in our device list, or the default device. */
1282  if ((handle == NULL) && (devname != NULL)) {
1283  SDL_SetError("No such device.");
1284  return 0;
1285  }
1286  }
1287 
1288  device = (SDL_AudioDevice *) SDL_calloc(1, sizeof (SDL_AudioDevice));
1289  if (device == NULL) {
1290  SDL_OutOfMemory();
1291  return 0;
1292  }
1293  device->id = id + 1;
1294  device->spec = *obtained;
1295  device->iscapture = iscapture ? SDL_TRUE : SDL_FALSE;
1296  device->handle = handle;
1297 
1298  SDL_AtomicSet(&device->shutdown, 0); /* just in case. */
1299  SDL_AtomicSet(&device->paused, 1);
1300  SDL_AtomicSet(&device->enabled, 1);
1301 
1302  /* Create a mutex for locking the sound buffers */
1304  device->mixer_lock = SDL_CreateMutex();
1305  if (device->mixer_lock == NULL) {
1306  close_audio_device(device);
1307  SDL_SetError("Couldn't create mixer lock");
1308  return 0;
1309  }
1310  }
1311 
1312  if (current_audio.impl.OpenDevice(device, handle, devname, iscapture) < 0) {
1313  close_audio_device(device);
1314  return 0;
1315  }
1316 
1317  /* if your target really doesn't need it, set it to 0x1 or something. */
1318  /* otherwise, close_audio_device() won't call impl.CloseDevice(). */
1319  SDL_assert(device->hidden != NULL);
1320 
1321  /* See if we need to do any conversion */
1322  build_cvt = SDL_FALSE;
1323  if (obtained->freq != device->spec.freq) {
1324  if (allowed_changes & SDL_AUDIO_ALLOW_FREQUENCY_CHANGE) {
1325  obtained->freq = device->spec.freq;
1326  } else {
1327  build_cvt = SDL_TRUE;
1328  }
1329  }
1330  if (obtained->format != device->spec.format) {
1331  if (allowed_changes & SDL_AUDIO_ALLOW_FORMAT_CHANGE) {
1332  obtained->format = device->spec.format;
1333  } else {
1334  build_cvt = SDL_TRUE;
1335  }
1336  }
1337  if (obtained->channels != device->spec.channels) {
1338  if (allowed_changes & SDL_AUDIO_ALLOW_CHANNELS_CHANGE) {
1339  obtained->channels = device->spec.channels;
1340  } else {
1341  build_cvt = SDL_TRUE;
1342  }
1343  }
1344 
1345  /* If the audio driver changes the buffer size, accept it.
1346  This needs to be done after the format is modified above,
1347  otherwise it might not have the correct buffer size.
1348  */
1349  if (device->spec.samples != obtained->samples) {
1350  obtained->samples = device->spec.samples;
1351  SDL_CalculateAudioSpec(obtained);
1352  }
1353 
1354  if (build_cvt) {
1355  /* Build an audio conversion block */
1356  if (SDL_BuildAudioCVT(&device->convert,
1357  obtained->format, obtained->channels,
1358  obtained->freq,
1359  device->spec.format, device->spec.channels,
1360  device->spec.freq) < 0) {
1361  close_audio_device(device);
1362  return 0;
1363  }
1364  if (device->convert.needed) {
1365  device->convert.len = (int) (((double) device->spec.size) /
1366  device->convert.len_ratio);
1367 
1368  device->convert.buf =
1369  (Uint8 *) SDL_malloc(device->convert.len *
1370  device->convert.len_mult);
1371  if (device->convert.buf == NULL) {
1372  close_audio_device(device);
1373  SDL_OutOfMemory();
1374  return 0;
1375  }
1376  }
1377  }
1378 
1379  if (device->spec.callback == NULL) { /* use buffer queueing? */
1380  /* pool a few packets to start. Enough for two callbacks. */
1381  const int packetlen = SDL_AUDIOBUFFERQUEUE_PACKETLEN;
1382  const int wantbytes = ((device->convert.needed) ? device->convert.len : device->spec.size) * 2;
1383  const int wantpackets = (wantbytes / packetlen) + ((wantbytes % packetlen) ? packetlen : 0);
1384  for (i = 0; i < wantpackets; i++) {
1386  if (packet) { /* don't care if this fails, we'll deal later. */
1387  packet->datalen = 0;
1388  packet->startpos = 0;
1389  packet->next = device->buffer_queue_pool;
1390  device->buffer_queue_pool = packet;
1391  }
1392  }
1393 
1395  device->spec.userdata = device;
1396  }
1397 
1398  /* add it to our list of open devices. */
1399  open_devices[id] = device;
1400 
1401  /* Start the audio thread if necessary */
1403  /* Start the audio thread */
1404  /* !!! FIXME: we don't force the audio thread stack size here if it calls into user code, but maybe we should? */
1405  /* buffer queueing callback only needs a few bytes, so make the stack tiny. */
1406  const size_t stacksize = is_internal_thread ? 64 * 1024 : 0;
1407  char threadname[64];
1408 
1409  /* Allocate a fake audio buffer; only used by our internal threads. */
1410  Uint32 stream_len = (device->convert.needed) ? device->convert.len_cvt : 0;
1411  if (device->spec.size > stream_len) {
1412  stream_len = device->spec.size;
1413  }
1414  SDL_assert(stream_len > 0);
1415 
1416  device->fake_stream = (Uint8 *) SDL_malloc(stream_len);
1417  if (device->fake_stream == NULL) {
1418  close_audio_device(device);
1419  SDL_OutOfMemory();
1420  return 0;
1421  }
1422 
1423  SDL_snprintf(threadname, sizeof (threadname), "SDLAudioDev%d", (int) device->id);
1424  device->thread = SDL_CreateThreadInternal(iscapture ? SDL_CaptureAudio : SDL_RunAudio, threadname, stacksize, device);
1425 
1426  if (device->thread == NULL) {
1427  close_audio_device(device);
1428  SDL_SetError("Couldn't create audio thread");
1429  return 0;
1430  }
1431  }
1432 
1433  return device->id;
1434 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
struct SDL_PrivateAudioData * hidden
Definition: SDL_sysaudio.h:189
SDL_AudioDeviceID id
Definition: SDL_sysaudio.h:153
#define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE
Definition: SDL_audio.h:140
#define SDL_LockMutex
GLuint id
static int SDL_CaptureAudio(void *devicep)
Definition: SDL_audio.c:795
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:175
SDL_atomic_t enabled
Definition: SDL_sysaudio.h:167
Uint8 * buf
Definition: SDL_audio.h:206
#define SDL_BuildAudioCVT
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:107
SDL_atomic_t paused
Definition: SDL_sysaudio.h:168
#define SDL_CreateMutex
SDL_atomic_t shutdown
Definition: SDL_sysaudio.h:166
double len_ratio
Definition: SDL_audio.h:210
SDL_AudioBufferQueue * buffer_queue_pool
Definition: SDL_sysaudio.h:184
Uint16 samples
Definition: SDL_audio.h:174
static int SDL_RunAudio(void *devicep)
Definition: SDL_audio.c:714
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:156
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
#define SDL_AUDIO_ALLOW_CHANNELS_CHANGE
Definition: SDL_audio.h:142
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:129
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
Definition: SDL_thread.c:427
void * SDL_calloc(size_t nmemb, size_t size)
struct SDL_AudioBufferQueue * next
Definition: SDL_sysaudio.h:70
Uint8 channels
Definition: SDL_audio.h:172
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
SDL_bool iscapture
Definition: SDL_sysaudio.h:169
static int prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
Definition: SDL_audio.c:1122
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
Definition: SDL_audio.c:1632
SDL_AudioCallback callback
Definition: SDL_audio.h:177
Uint8 * fake_stream
Definition: SDL_sysaudio.h:172
static void SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int len)
Definition: SDL_audio.c:565
#define SDL_getenv
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:134
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:50
Uint32 size
Definition: SDL_audio.h:176
#define SDL_assert(condition)
Definition: SDL_assert.h:167
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
Definition: SDL_sysaudio.h:76
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_bool
Definition: SDL_stdinc.h:130
static void SDL_BufferQueueFillCallback(void *userdata, Uint8 *stream, int len)
Definition: SDL_audio.c:586
#define SDL_SetError
#define SDL_INIT_AUDIO
Definition: SDL.h:76
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
Uint32 SDL_AudioDeviceID
Definition: SDL_audio.h:304
SDL_AudioFormat format
Definition: SDL_audio.h:171
#define SDL_AtomicSet
void * userdata
Definition: SDL_audio.h:178
#define DEFAULT_OUTPUT_DEVNAME
Definition: SDL_sysaudio.h:30
#define SDL_AUDIO_ALLOW_FORMAT_CHANGE
Definition: SDL_audio.h:141
#define SDL_snprintf
#define DEFAULT_INPUT_DEVNAME
Definition: SDL_sysaudio.h:31
#define SDL_UnlockMutex
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:90
#define SDL_malloc
#define SDL_strcmp
SDL_Thread * thread
Definition: SDL_sysaudio.h:178
#define SDL_WasInit
#define SDL_AUDIOBUFFERQUEUE_PACKETLEN
Definition: SDL_sysaudio.h:62
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:159
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:135
static void close_audio_device(SDL_AudioDevice *device)
Definition: SDL_audio.c:1079

◆ prepare_audiospec()

static int prepare_audiospec ( const SDL_AudioSpec orig,
SDL_AudioSpec prepared 
)
static

Definition at line 1122 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().

1123 {
1124  SDL_memcpy(prepared, orig, sizeof(SDL_AudioSpec));
1125 
1126  if (orig->freq == 0) {
1127  const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY");
1128  if ((!env) || ((prepared->freq = SDL_atoi(env)) == 0)) {
1129  prepared->freq = 22050; /* a reasonable default */
1130  }
1131  }
1132 
1133  if (orig->format == 0) {
1134  const char *env = SDL_getenv("SDL_AUDIO_FORMAT");
1135  if ((!env) || ((prepared->format = SDL_ParseAudioFormat(env)) == 0)) {
1136  prepared->format = AUDIO_S16; /* a reasonable default */
1137  }
1138  }
1139 
1140  switch (orig->channels) {
1141  case 0:{
1142  const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
1143  if ((!env) || ((prepared->channels = (Uint8) SDL_atoi(env)) == 0)) {
1144  prepared->channels = 2; /* a reasonable default */
1145  }
1146  break;
1147  }
1148  case 1: /* Mono */
1149  case 2: /* Stereo */
1150  case 4: /* surround */
1151  case 6: /* surround with center and lfe */
1152  break;
1153  default:
1154  SDL_SetError("Unsupported number of audio channels.");
1155  return 0;
1156  }
1157 
1158  if (orig->samples == 0) {
1159  const char *env = SDL_getenv("SDL_AUDIO_SAMPLES");
1160  if ((!env) || ((prepared->samples = (Uint16) SDL_atoi(env)) == 0)) {
1161  /* Pick a default of ~46 ms at desired frequency */
1162  /* !!! FIXME: remove this when the non-Po2 resampling is in. */
1163  const int samples = (prepared->freq / 1000) * 46;
1164  int power2 = 1;
1165  while (power2 < samples) {
1166  power2 *= 2;
1167  }
1168  prepared->samples = power2;
1169  }
1170  }
1171 
1172  /* Calculate the silence and size of the audio specification */
1173  SDL_CalculateAudioSpec(prepared);
1174 
1175  return 1;
1176 }
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:143
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
Definition: SDL_audio.c:1632
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:151
static SDL_AudioFormat SDL_ParseAudioFormat(const char *string)
Definition: SDL_audio.c:876

◆ queue_audio_to_device()

static int queue_audio_to_device ( SDL_AudioDevice device,
const Uint8 data,
Uint32  len 
)
static

Definition at line 464 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, free_audio_queue(), SDL_AudioBufferQueue::next, NULL, SDL_AudioDevice::queued_bytes, SDL_assert, SDL_AUDIOBUFFERQUEUE_PACKETLEN, SDL_malloc, SDL_memcpy, SDL_min, SDL_OutOfMemory, and SDL_AudioBufferQueue::startpos.

Referenced by SDL_BufferQueueFillCallback(), and SDL_QueueAudio().

465 {
466  SDL_AudioBufferQueue *orighead;
467  SDL_AudioBufferQueue *origtail;
468  Uint32 origlen;
469  Uint32 datalen;
470 
471  orighead = device->buffer_queue_head;
472  origtail = device->buffer_queue_tail;
473  origlen = origtail ? origtail->datalen : 0;
474 
475  while (len > 0) {
476  SDL_AudioBufferQueue *packet = device->buffer_queue_tail;
477  SDL_assert(!packet || (packet->datalen <= SDL_AUDIOBUFFERQUEUE_PACKETLEN));
478  if (!packet || (packet->datalen >= SDL_AUDIOBUFFERQUEUE_PACKETLEN)) {
479  /* tail packet missing or completely full; we need a new packet. */
480  packet = device->buffer_queue_pool;
481  if (packet != NULL) {
482  /* we have one available in the pool. */
483  device->buffer_queue_pool = packet->next;
484  } else {
485  /* Have to allocate a new one! */
487  if (packet == NULL) {
488  /* uhoh, reset so we've queued nothing new, free what we can. */
489  if (!origtail) {
490  packet = device->buffer_queue_head; /* whole queue. */
491  } else {
492  packet = origtail->next; /* what we added to existing queue. */
493  origtail->next = NULL;
494  origtail->datalen = origlen;
495  }
496  device->buffer_queue_head = orighead;
497  device->buffer_queue_tail = origtail;
498  device->buffer_queue_pool = NULL;
499 
500  free_audio_queue(packet); /* give back what we can. */
501 
502  return SDL_OutOfMemory();
503  }
504  }
505  packet->datalen = 0;
506  packet->startpos = 0;
507  packet->next = NULL;
508 
509  SDL_assert((device->buffer_queue_head != NULL) == (device->queued_bytes != 0));
510  if (device->buffer_queue_tail == NULL) {
511  device->buffer_queue_head = packet;
512  } else {
513  device->buffer_queue_tail->next = packet;
514  }
515  device->buffer_queue_tail = packet;
516  }
517 
518  datalen = SDL_min(len, SDL_AUDIOBUFFERQUEUE_PACKETLEN - packet->datalen);
519  SDL_memcpy(packet->data + packet->datalen, data, datalen);
520  data += datalen;
521  len -= datalen;
522  packet->datalen += datalen;
523  device->queued_bytes += datalen;
524  }
525 
526  return 0;
527 }
#define SDL_min(x, y)
Definition: SDL_stdinc.h:349
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_AudioBufferQueue * buffer_queue_pool
Definition: SDL_sysaudio.h:184
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
GLenum GLsizei len
SDL_AudioBufferQueue * buffer_queue_head
Definition: SDL_sysaudio.h:182
SDL_AudioBufferQueue * buffer_queue_tail
Definition: SDL_sysaudio.h:183
#define SDL_memcpy
struct SDL_AudioBufferQueue * next
Definition: SDL_sysaudio.h:70
#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 *packet)
Definition: SDL_audio.c:453
Uint8 data[SDL_AUDIOBUFFERQUEUE_PACKETLEN]
Definition: SDL_sysaudio.h:67
#define SDL_malloc
#define SDL_AUDIOBUFFERQUEUE_PACKETLEN
Definition: SDL_sysaudio.h:62

◆ SDL_AddAudioDevice()

void SDL_AddAudioDevice ( const int  iscapture,
const char *  name,
void handle 
)

Definition at line 364 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().

365 {
366  const int device_index = iscapture ? add_capture_device(name, handle) : add_output_device(name, handle);
367  if (device_index != -1) {
368  /* Post the event, if desired */
371  SDL_zero(event);
372  event.adevice.type = SDL_AUDIODEVICEADDED;
373  event.adevice.which = device_index;
374  event.adevice.iscapture = iscapture;
375  SDL_PushEvent(&event);
376  }
377  }
378 }
static SDL_INLINE int add_output_device(const char *name, void *handle)
Definition: SDL_audio.c:341
#define SDL_ENABLE
Definition: SDL_events.h:722
GLuint const GLchar * name
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
#define SDL_zero(x)
Definition: SDL_stdinc.h:359
static SDL_INLINE int add_capture_device(const char *name, void *handle)
Definition: SDL_audio.c:334
General event structure.
Definition: SDL_events.h:525

◆ SDL_AudioCaptureFromDevice_Default()

static int SDL_AudioCaptureFromDevice_Default ( _THIS  ,
void buffer,
int  buflen 
)
static

Definition at line 195 of file SDL_audio.c.

196 {
197  return -1; /* just fail immediately. */
198 }

◆ SDL_AudioCloseDevice_Default()

static void SDL_AudioCloseDevice_Default ( _THIS  )
static

Definition at line 211 of file SDL_audio.c.

212 { /* no-op. */
213 }

◆ SDL_AudioDeinitialize_Default()

static void SDL_AudioDeinitialize_Default ( void  )
static

Definition at line 216 of file SDL_audio.c.

217 { /* no-op. */
218 }

◆ SDL_AudioDetectDevices_Default()

static void SDL_AudioDetectDevices_Default ( void  )
static

Definition at line 155 of file SDL_audio.c.

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

156 {
157  /* you have to write your own implementation if these assertions fail. */
160 
161  SDL_AddAudioDevice(SDL_FALSE, DEFAULT_OUTPUT_DEVNAME, (void *) ((size_t) 0x1));
163  SDL_AddAudioDevice(SDL_TRUE, DEFAULT_INPUT_DEVNAME, (void *) ((size_t) 0x2));
164  }
165 }
GLuint GLfloat GLfloat GLfloat x1
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
GLfixed GLfixed x2
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
#define DEFAULT_OUTPUT_DEVNAME
Definition: SDL_sysaudio.h:30
#define DEFAULT_INPUT_DEVNAME
Definition: SDL_sysaudio.h:31
void SDL_AddAudioDevice(const int iscapture, const char *name, void *handle)
Definition: SDL_audio.c:364

◆ SDL_AudioFlushCapture_Default()

static void SDL_AudioFlushCapture_Default ( _THIS  )
static

Definition at line 201 of file SDL_audio.c.

202 { /* no-op. */
203 }

◆ SDL_AudioFreeDeviceHandle_Default()

static void SDL_AudioFreeDeviceHandle_Default ( void handle)
static

Definition at line 221 of file SDL_audio.c.

222 { /* no-op. */
223 }

◆ SDL_AudioGetDeviceBuf_Default()

static Uint8* SDL_AudioGetDeviceBuf_Default ( _THIS  )
static

Definition at line 189 of file SDL_audio.c.

References NULL.

190 {
191  return NULL;
192 }
#define NULL
Definition: begin_code.h:143

◆ SDL_AudioGetPendingBytes_Default()

static int SDL_AudioGetPendingBytes_Default ( _THIS  )
static

Definition at line 183 of file SDL_audio.c.

184 {
185  return 0;
186 }

◆ SDL_AudioInit()

int SDL_AudioInit ( const char *  driver_name)

Definition at line 917 of file SDL_audio.c.

References AudioBootStrap::demand_only, SDL_AudioDriver::desc, AudioBootStrap::desc, SDL_AudioDriverImpl::DetectDevices, SDL_AudioDriver::detectionLock, finish_audio_entry_points_init(), 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.

918 {
919  int i = 0;
920  int initialized = 0;
921  int tried_to_init = 0;
922 
924  SDL_AudioQuit(); /* shutdown driver if already running. */
925  }
926 
929 
930  /* Select the proper audio driver */
931  if (driver_name == NULL) {
932  driver_name = SDL_getenv("SDL_AUDIODRIVER");
933  }
934 
935  for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
936  /* make sure we should even try this driver before doing so... */
937  const AudioBootStrap *backend = bootstrap[i];
938  if ((driver_name && (SDL_strncasecmp(backend->name, driver_name, SDL_strlen(driver_name)) != 0)) ||
939  (!driver_name && backend->demand_only)) {
940  continue;
941  }
942 
943  tried_to_init = 1;
945  current_audio.name = backend->name;
946  current_audio.desc = backend->desc;
947  initialized = backend->init(&current_audio.impl);
948  }
949 
950  if (!initialized) {
951  /* specific drivers will set the error message if they fail... */
952  if (!tried_to_init) {
953  if (driver_name) {
954  SDL_SetError("Audio target '%s' not available", driver_name);
955  } else {
956  SDL_SetError("No available audio device");
957  }
958  }
959 
961  return -1; /* No driver was available, so fail. */
962  }
963 
965 
967 
968  /* Make sure we have a list of devices available at startup. */
970 
971  return 0;
972 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
const char * name
Definition: SDL_sysaudio.h:120
void(* DetectDevices)(void)
Definition: SDL_sysaudio.h:75
const char * name
Definition: SDL_sysaudio.h:197
#define SDL_CreateMutex
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
#define SDL_strncasecmp
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:129
const char * desc
Definition: SDL_sysaudio.h:124
void SDL_AudioQuit(void)
Definition: SDL_audio.c:1560
#define SDL_zero(x)
Definition: SDL_stdinc.h:359
#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:50
static const AudioBootStrap *const bootstrap[]
Definition: SDL_audio.c:67
#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:126
#define SDL_strlen
int(* init)(SDL_AudioDriverImpl *impl)
Definition: SDL_sysaudio.h:199
const char * desc
Definition: SDL_sysaudio.h:198
#define SDL_WasInit
static void finish_audio_entry_points_init(void)
Definition: SDL_audio.c:268

◆ SDL_AudioLockDevice_Default()

static void SDL_AudioLockDevice_Default ( SDL_AudioDevice device)
static

Definition at line 247 of file SDL_audio.c.

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

248 {
249  if (!is_in_audio_device_thread(device)) {
250  SDL_LockMutex(device->mixer_lock);
251  }
252 }
#define SDL_LockMutex
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:175
static SDL_INLINE SDL_bool is_in_audio_device_thread(SDL_AudioDevice *device)
Definition: SDL_audio.c:233

◆ SDL_AudioLockOrUnlockDeviceWithNoMixerLock()

static void SDL_AudioLockOrUnlockDeviceWithNoMixerLock ( SDL_AudioDevice device)
static

Definition at line 263 of file SDL_audio.c.

Referenced by finish_audio_entry_points_init().

264 {
265 }

◆ SDL_AudioOpenDevice_Default()

static int SDL_AudioOpenDevice_Default ( _THIS  ,
void handle,
const char *  devname,
int  iscapture 
)
static

Definition at line 227 of file SDL_audio.c.

References SDL_INLINE, and SDL_Unsupported.

228 {
229  return SDL_Unsupported();
230 }
#define SDL_Unsupported()
Definition: SDL_error.h:53

◆ SDL_AudioPlayDevice_Default()

static void SDL_AudioPlayDevice_Default ( _THIS  )
static

Definition at line 178 of file SDL_audio.c.

179 { /* no-op. */
180 }

◆ SDL_AudioPrepareToClose_Default()

static void SDL_AudioPrepareToClose_Default ( _THIS  )
static

Definition at line 206 of file SDL_audio.c.

207 { /* no-op. */
208 }

◆ SDL_AudioQuit()

void SDL_AudioQuit ( void  )

Definition at line 1560 of file SDL_audio.c.

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

Referenced by SDL_AudioInit().

1561 {
1563 
1564  if (!current_audio.name) { /* not initialized?! */
1565  return;
1566  }
1567 
1568  for (i = 0; i < SDL_arraysize(open_devices); i++) {
1570  }
1571 
1574 
1575  /* Free the driver data */
1577 
1579 
1582 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
const char * name
Definition: SDL_sysaudio.h:120
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:129
void(* Deinitialize)(void)
Definition: SDL_sysaudio.h:89
#define SDL_zero(x)
Definition: SDL_stdinc.h:359
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:134
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:50
static void free_device_list(SDL_AudioDeviceItem **devices, int *devCount)
Definition: SDL_audio.c:347
#define SDL_DestroyMutex
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
Uint32 SDL_AudioDeviceID
Definition: SDL_audio.h:304
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:90
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:135
static void close_audio_device(SDL_AudioDevice *device)
Definition: SDL_audio.c:1079

◆ SDL_AudioThreadInit_Default()

static void SDL_AudioThreadInit_Default ( _THIS  )
static

Definition at line 168 of file SDL_audio.c.

169 { /* no-op. */
170 }

◆ SDL_AudioUnlockDevice_Default()

static void SDL_AudioUnlockDevice_Default ( SDL_AudioDevice device)
static

Definition at line 255 of file SDL_audio.c.

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

256 {
257  if (!is_in_audio_device_thread(device)) {
258  SDL_UnlockMutex(device->mixer_lock);
259  }
260 }
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:175
#define SDL_UnlockMutex
static SDL_INLINE SDL_bool is_in_audio_device_thread(SDL_AudioDevice *device)
Definition: SDL_audio.c:233

◆ SDL_AudioWaitDevice_Default()

static void SDL_AudioWaitDevice_Default ( _THIS  )
static

Definition at line 173 of file SDL_audio.c.

174 { /* no-op. */
175 }

◆ SDL_BufferQueueDrainCallback()

static void SDL_BufferQueueDrainCallback ( void userdata,
Uint8 stream,
int  len 
)
static

Definition at line 565 of file SDL_audio.c.

References SDL_AudioDevice::buffer_queue_head, dequeue_audio_from_device(), SDL_AudioDevice::iscapture, NULL, SDL_assert, SDL_memset, SDLCALL, SDL_AudioSpec::silence, and SDL_AudioDevice::spec.

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

566 {
567  /* this function always holds the mixer lock before being called. */
568  SDL_AudioDevice *device = (SDL_AudioDevice *) userdata;
569  Uint32 written;
570 
571  SDL_assert(device != NULL); /* this shouldn't ever happen, right?! */
572  SDL_assert(!device->iscapture); /* this shouldn't ever happen, right?! */
573  SDL_assert(len >= 0); /* this shouldn't ever happen, right?! */
574 
575  written = dequeue_audio_from_device(device, stream, (Uint32) len);
576  stream += written;
577  len -= (int) written;
578 
579  if (len > 0) { /* fill any remaining space in the stream with silence. */
580  SDL_assert(device->buffer_queue_head == NULL);
581  SDL_memset(stream, device->spec.silence, len);
582  }
583 }
Uint8 silence
Definition: SDL_audio.h:173
GLuint GLuint stream
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:156
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
GLenum GLsizei len
SDL_AudioBufferQueue * buffer_queue_head
Definition: SDL_sysaudio.h:182
SDL_bool iscapture
Definition: SDL_sysaudio.h:169
static Uint32 dequeue_audio_from_device(SDL_AudioDevice *device, Uint8 *stream, Uint32 len)
Definition: SDL_audio.c:531
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
#define SDL_memset

◆ SDL_BufferQueueFillCallback()

static void SDL_BufferQueueFillCallback ( void userdata,
Uint8 stream,
int  len 
)
static

Definition at line 586 of file SDL_audio.c.

References SDL_AudioDevice::iscapture, NULL, queue_audio_to_device(), and SDL_assert.

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

587 {
588  /* this function always holds the mixer lock before being called. */
589  SDL_AudioDevice *device = (SDL_AudioDevice *) userdata;
590 
591  SDL_assert(device != NULL); /* this shouldn't ever happen, right?! */
592  SDL_assert(device->iscapture); /* this shouldn't ever happen, right?! */
593  SDL_assert(len >= 0); /* this shouldn't ever happen, right?! */
594 
595  /* note that if this needs to allocate more space and run out of memory,
596  we have no choice but to quietly drop the data and hope it works out
597  later, but you probably have bigger problems in this case anyhow. */
599 }
static int queue_audio_to_device(SDL_AudioDevice *device, const Uint8 *data, Uint32 len)
Definition: SDL_audio.c:464
GLuint GLuint stream
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
GLenum GLsizei len
SDL_bool iscapture
Definition: SDL_sysaudio.h:169
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143

◆ SDL_CalculateAudioSpec()

void SDL_CalculateAudioSpec ( SDL_AudioSpec spec)

Definition at line 1632 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().

1633 {
1634  switch (spec->format) {
1635  case AUDIO_U8:
1636  spec->silence = 0x80;
1637  break;
1638  default:
1639  spec->silence = 0x00;
1640  break;
1641  }
1642  spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
1643  spec->size *= spec->channels;
1644  spec->size *= spec->samples;
1645 }
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

◆ SDL_CaptureAudio()

static int SDL_CaptureAudio ( void devicep)
static

Definition at line 795 of file SDL_audio.c.

References SDL_AudioCVT::buf, callback(), SDL_AudioSpec::callback, SDL_AudioDriverImpl::CaptureFromDevice, SDL_AudioDevice::convert, SDL_AudioDevice::enabled, SDL_AudioDevice::fake_stream, SDL_AudioDriverImpl::FlushCapture, SDL_AudioSpec::freq, SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioCVT::len, SDL_AudioDevice::mixer_lock, SDL_AudioCVT::needed, SDL_AudioDevice::paused, SDL_AudioSpec::samples, SDL_assert, SDL_AtomicGet, SDL_ConvertAudio, SDL_Delay, SDL_LockMutex, SDL_memset, SDL_OpenedAudioDeviceDisconnected(), 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, and void.

Referenced by open_audio_device().

796 {
797  SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
798  const int silence = (int) device->spec.silence;
799  const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq);
800  const int stream_len = (device->convert.needed) ? device->convert.len : device->spec.size;
801  Uint8 *stream;
802  void *udata = device->spec.userdata;
803  void (SDLCALL *callback) (void *, Uint8 *, int) = device->spec.callback;
804 
805  SDL_assert(device->iscapture);
806 
807  /* The audio mixing is always a high priority thread */
809 
810  /* Perform any thread setup */
811  device->threadid = SDL_ThreadID();
812  current_audio.impl.ThreadInit(device);
813 
814  /* Loop, filling the audio buffers */
815  while (!SDL_AtomicGet(&device->shutdown)) {
816  int still_need;
817  Uint8 *ptr;
818 
819  if (!SDL_AtomicGet(&device->enabled) || SDL_AtomicGet(&device->paused)) {
820  SDL_Delay(delay); /* just so we don't cook the CPU. */
821  current_audio.impl.FlushCapture(device); /* dump anything pending. */
822  continue;
823  }
824 
825  /* Fill the current buffer with sound */
826  still_need = stream_len;
827  if (device->convert.needed) {
828  ptr = stream = device->convert.buf;
829  } else {
830  /* just use the "fake" stream to hold data read from the device. */
831  ptr = stream = device->fake_stream;
832  }
833 
834  /* We still read from the device when "paused" to keep the state sane,
835  and block when there isn't data so this thread isn't eating CPU.
836  But we don't process it further or call the app's callback. */
837 
838  while (still_need > 0) {
839  const int rc = current_audio.impl.CaptureFromDevice(device, ptr, still_need);
840  SDL_assert(rc <= still_need); /* device should not overflow buffer. :) */
841  if (rc > 0) {
842  still_need -= rc;
843  ptr += rc;
844  } else { /* uhoh, device failed for some reason! */
846  break;
847  }
848  }
849 
850  if (still_need > 0) {
851  /* Keep any data we already read, silence the rest. */
852  SDL_memset(ptr, silence, still_need);
853  }
854 
855  if (device->convert.needed) {
856  SDL_ConvertAudio(&device->convert);
857  }
858 
859  /* !!! FIXME: this should be LockDevice. */
860  SDL_LockMutex(device->mixer_lock);
861  if (SDL_AtomicGet(&device->paused)) {
862  current_audio.impl.FlushCapture(device); /* one snuck in! */
863  } else {
864  (*callback)(udata, stream, stream_len);
865  }
866  SDL_UnlockMutex(device->mixer_lock);
867  }
868 
870 
871  return 0;
872 }
#define SDL_ThreadID
#define SDL_LockMutex
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:175
SDL_atomic_t enabled
Definition: SDL_sysaudio.h:167
Uint8 silence
Definition: SDL_audio.h:173
Uint8 * buf
Definition: SDL_audio.h:206
GLuint GLuint stream
SDL_atomic_t paused
Definition: SDL_sysaudio.h:168
SDL_atomic_t shutdown
Definition: SDL_sysaudio.h:166
SDL_threadID threadid
Definition: SDL_sysaudio.h:179
Uint16 samples
Definition: SDL_audio.h:174
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
Definition: SDL_audio.c:381
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:156
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* ThreadInit)(_THIS)
Definition: SDL_sysaudio.h:77
#define SDL_ConvertAudio
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
SDL_bool iscapture
Definition: SDL_sysaudio.h:169
static Uint32 callback(Uint32 interval, void *param)
Definition: testtimer.c:34
SDL_AudioCallback callback
Definition: SDL_audio.h:177
Uint8 * fake_stream
Definition: SDL_sysaudio.h:172
#define SDL_Delay
Uint32 size
Definition: SDL_audio.h:176
#define SDL_assert(condition)
Definition: SDL_assert.h:167
int(* CaptureFromDevice)(_THIS, void *buffer, int buflen)
Definition: SDL_sysaudio.h:82
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:126
void(* FlushCapture)(_THIS)
Definition: SDL_sysaudio.h:83
#define SDL_AtomicGet
void * userdata
Definition: SDL_audio.h:178
#define SDL_UnlockMutex
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:159
#define SDLCALL
Definition: SDL_internal.h:31
#define SDL_SetThreadPriority
#define SDL_memset

◆ SDL_ClearQueuedAudio()

void SDL_ClearQueuedAudio ( SDL_AudioDeviceID  dev)

Drop any queued audio data. For playback devices, this is any queued data still waiting to be submitted to the hardware. For capture devices, this is any data that was queued by the device that hasn't yet been dequeued by the application.

Immediately after this call, SDL_GetQueuedAudioSize() will return 0. For playback devices, the hardware will start playing silence if more audio isn't queued. Unpaused capture devices will start filling the queue again as soon as they have more data available (which, depending on the state of the hardware and the thread, could be before this function call returns!).

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 queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use the audio callback, 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 668 of file SDL_audio.c.

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

669 {
670  SDL_AudioDevice *device = get_audio_device(devid);
671  SDL_AudioBufferQueue *packet;
672 
673  if (!device) {
674  return; /* nothing to do. */
675  }
676 
677  /* Blank out the device and release the mutex. Free it afterwards. */
678  current_audio.impl.LockDevice(device);
679 
680  /* merge the available pool and the current queue into one list. */
681  packet = device->buffer_queue_head;
682  if (packet) {
683  device->buffer_queue_tail->next = device->buffer_queue_pool;
684  } else {
685  packet = device->buffer_queue_pool;
686  }
687 
688  /* Remove the queued packets from the device. */
689  device->buffer_queue_tail = NULL;
690  device->buffer_queue_head = NULL;
691  device->queued_bytes = 0;
692  device->buffer_queue_pool = packet;
693 
694  /* Keep up to two packets in the pool to reduce future malloc pressure. */
695  if (packet) {
696  if (!packet->next) {
697  packet = NULL; /* one packet (the only one) for the pool. */
698  } else {
699  SDL_AudioBufferQueue *next = packet->next->next;
700  packet->next->next = NULL; /* two packets for the pool. */
701  packet = next; /* rest will be freed. */
702  }
703  }
704 
706 
707  /* free any extra packets we didn't keep in the pool. */
708  free_audio_queue(packet);
709 }
SDL_AudioBufferQueue * buffer_queue_pool
Definition: SDL_sysaudio.h:184
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:87
SDL_AudioBufferQueue * buffer_queue_head
Definition: SDL_sysaudio.h:182
SDL_AudioBufferQueue * buffer_queue_tail
Definition: SDL_sysaudio.h:183
struct SDL_AudioBufferQueue * next
Definition: SDL_sysaudio.h:70
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:86
#define NULL
Definition: begin_code.h:143
static void free_audio_queue(SDL_AudioBufferQueue *packet)
Definition: SDL_audio.c:453
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

◆ SDL_CloseAudio()

void SDL_CloseAudio ( void  )

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

Definition at line 1554 of file SDL_audio.c.

References SDL_CloseAudioDevice().

1555 {
1557 }
void SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1548

◆ SDL_CloseAudioDevice()

void SDL_CloseAudioDevice ( SDL_AudioDeviceID  devid)

Definition at line 1548 of file SDL_audio.c.

References close_audio_device(), and get_audio_device().

Referenced by SDL_CloseAudio().

1549 {
1551 }
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141
static void close_audio_device(SDL_AudioDevice *device)
Definition: SDL_audio.c:1079

◆ SDL_DequeueAudio()

Uint32 SDL_DequeueAudio ( SDL_AudioDeviceID  dev,
void data,
Uint32  len 
)

Dequeue more audio on non-callback devices.

(If you are looking to queue audio for output on a non-callback playback device, you want SDL_QueueAudio() instead. This will always return 0 if you use it with playback devices.)

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

There are no limits on the amount of data you can queue, short of exhaustion of address space. Data from the device will keep queuing as necessary without further intervention from you. This means you will eventually run out of memory if you aren't routinely dequeueing data.

Capture devices will not queue data when paused; if you are expecting to not need captured audio for some length of time, use SDL_PauseAudioDevice() to stop the capture device from queueing more data. This can be useful during, say, level loading times. When unpaused, capture devices will start queueing data from that point, having flushed any capturable data available while paused.

This function is thread-safe, but dequeueing from the same device from two threads at once does not promise which thread will dequeued data first.

You may not dequeue audio from a device that is using an application-supplied callback; doing so returns an error. You have to use the audio callback, or dequeue 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 from which we will dequeue audio.
dataA pointer into where audio data should be copied.
lenThe number of bytes (not samples!) to which (data) points.
Returns
number of bytes dequeued, which could be less than requested.
See also
SDL_GetQueuedAudioSize
SDL_ClearQueuedAudio

Definition at line 625 of file SDL_audio.c.

References SDL_AudioSpec::callback, dequeue_audio_from_device(), get_audio_device(), SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioDriverImpl::LockDevice, SDL_BufferQueueFillCallback(), SDL_AudioDevice::spec, and SDL_AudioDriverImpl::UnlockDevice.

626 {
627  SDL_AudioDevice *device = get_audio_device(devid);
628  Uint32 rc;
629 
630  if ( (len == 0) || /* nothing to do? */
631  (!device) || /* called with bogus device id */
632  (!device->iscapture) || /* playback devices can't dequeue */
633  (device->spec.callback != SDL_BufferQueueFillCallback) ) { /* not set for queueing */
634  return 0; /* just report zero bytes dequeued. */
635  }
636 
637  current_audio.impl.LockDevice(device);
638  rc = dequeue_audio_from_device(device, data, len);
640  return rc;
641 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:156
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:87
GLenum GLsizei len
SDL_bool iscapture
Definition: SDL_sysaudio.h:169
static Uint32 dequeue_audio_from_device(SDL_AudioDevice *device, Uint8 *stream, Uint32 len)
Definition: SDL_audio.c:531
SDL_AudioCallback callback
Definition: SDL_audio.h:177
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:86
static void SDL_BufferQueueFillCallback(void *userdata, Uint8 *stream, int len)
Definition: SDL_audio.c:586
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

◆ SDL_FirstAudioFormat()

SDL_AudioFormat SDL_FirstAudioFormat ( SDL_AudioFormat  format)

Definition at line 1611 of file SDL_audio.c.

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

1612 {
1613  for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
1614  if (format_list[format_idx][0] == format) {
1615  break;
1616  }
1617  }
1618  format_idx_sub = 0;
1619  return SDL_NextAudioFormat();
1620 }
static int format_idx_sub
Definition: SDL_audio.c:1586
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
static int format_idx
Definition: SDL_audio.c:1585
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1587
SDL_AudioFormat SDL_NextAudioFormat(void)
Definition: SDL_audio.c:1623
#define NUM_FORMATS
Definition: SDL_audio.c:1584

◆ SDL_GetAudioDeviceName()

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 1039 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.

1040 {
1041  const char *retval = NULL;
1042 
1043  if (!SDL_WasInit(SDL_INIT_AUDIO)) {
1044  SDL_SetError("Audio subsystem is not initialized");
1045  return NULL;
1046  }
1047 
1048  if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
1049  SDL_SetError("No capture support");
1050  return NULL;
1051  }
1052 
1053  if (index >= 0) {
1054  SDL_AudioDeviceItem *item;
1055  int i;
1056 
1060  if (index < i) {
1061  for (i--; i > index; i--, item = item->next) {
1062  SDL_assert(item != NULL);
1063  }
1064  SDL_assert(item != NULL);
1065  retval = item->name;
1066  }
1068  }
1069 
1070  if (retval == NULL) {
1071  SDL_SetError("No such device");
1072  }
1073 
1074  return retval;
1075 }
#define SDL_LockMutex
struct SDL_AudioDeviceItem * next
Definition: SDL_sysaudio.h:107
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:129
SDL_bool retval
GLuint index
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:134
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:50
#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:126
#define SDL_UnlockMutex
#define SDL_WasInit
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:135

◆ SDL_GetAudioDeviceStatus()

SDL_AudioStatus SDL_GetAudioDeviceStatus ( SDL_AudioDeviceID  devid)

Definition at line 1476 of file SDL_audio.c.

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

Referenced by SDL_GetAudioStatus().

1477 {
1478  SDL_AudioDevice *device = get_audio_device(devid);
1480  if (device && SDL_AtomicGet(&device->enabled)) {
1481  if (SDL_AtomicGet(&device->paused)) {
1482  status = SDL_AUDIO_PAUSED;
1483  } else {
1484  status = SDL_AUDIO_PLAYING;
1485  }
1486  }
1487  return status;
1488 }
SDL_atomic_t enabled
Definition: SDL_sysaudio.h:167
SDL_atomic_t paused
Definition: SDL_sysaudio.h:168
SDL_AudioStatus
Definition: SDL_audio.h:369
#define SDL_AtomicGet
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

◆ SDL_GetAudioDriver()

const char* SDL_GetAudioDriver ( int  index)

Definition at line 908 of file SDL_audio.c.

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

909 {
910  if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
911  return bootstrap[index]->name;
912  }
913  return NULL;
914 }
int SDL_GetNumAudioDrivers(void)
Definition: SDL_audio.c:902
const char * name
Definition: SDL_sysaudio.h:197
GLuint index
static const AudioBootStrap *const bootstrap[]
Definition: SDL_audio.c:67
#define NULL
Definition: begin_code.h:143

◆ SDL_GetAudioStatus()

SDL_AudioStatus SDL_GetAudioStatus ( void  )

Definition at line 1492 of file SDL_audio.c.

References SDL_GetAudioDeviceStatus().

1493 {
1494  return SDL_GetAudioDeviceStatus(1);
1495 }
SDL_AudioStatus SDL_GetAudioDeviceStatus(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1476

◆ SDL_GetCurrentAudioDriver()

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 978 of file SDL_audio.c.

References SDL_AudioDriver::name.

979 {
980  return current_audio.name;
981 }
const char * name
Definition: SDL_sysaudio.h:120
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33

◆ SDL_GetNumAudioDevices()

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 1013 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.

1014 {
1015  int retval = 0;
1016 
1017  if (!SDL_WasInit(SDL_INIT_AUDIO)) {
1018  return -1;
1019  }
1020 
1022  if (iscapture && current_audio.captureDevicesRemoved) {
1024  }
1025 
1026  if (!iscapture && current_audio.outputDevicesRemoved) {
1029  }
1030 
1033 
1034  return retval;
1035 }
#define SDL_LockMutex
SDL_bool captureDevicesRemoved
Definition: SDL_sysaudio.h:130
static void clean_out_device_list(SDL_AudioDeviceItem **devices, int *devCount, SDL_bool *removedFlag)
Definition: SDL_audio.c:985
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:129
SDL_bool retval
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:134
SDL_bool outputDevicesRemoved
Definition: SDL_sysaudio.h:131
#define SDL_INIT_AUDIO
Definition: SDL.h:76
#define SDL_UnlockMutex
#define SDL_WasInit
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:135

◆ SDL_GetNumAudioDrivers()

int SDL_GetNumAudioDrivers ( void  )

Definition at line 902 of file SDL_audio.c.

References SDL_arraysize.

Referenced by SDL_GetAudioDriver().

903 {
904  return SDL_arraysize(bootstrap) - 1;
905 }
static const AudioBootStrap *const bootstrap[]
Definition: SDL_audio.c:67
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:90

◆ SDL_GetQueuedAudioSize()

Uint32 SDL_GetQueuedAudioSize ( SDL_AudioDeviceID  dev)

Get the number of bytes of still-queued audio.

For playback device:

This is the number of bytes that have been queued for playback with SDL_QueueAudio(), but have not yet been sent to the hardware. This number may shrink at any time, so this only informs of pending data.

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.

For capture devices:

This is the number of bytes that have been captured by the device and are waiting for you to dequeue. This number may grow at any time, so this only informs of the lower-bound of available data.

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 queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use the audio callback, 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 644 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_BufferQueueFillCallback(), SDL_AudioDevice::spec, and SDL_AudioDriverImpl::UnlockDevice.

645 {
646  Uint32 retval = 0;
647  SDL_AudioDevice *device = get_audio_device(devid);
648 
649  if (!device) {
650  return 0;
651  }
652 
653  /* Nothing to do unless we're set up for queueing. */
654  if (device->spec.callback == SDL_BufferQueueDrainCallback) {
655  current_audio.impl.LockDevice(device);
656  retval = device->queued_bytes + current_audio.impl.GetPendingBytes(device);
658  } else if (device->spec.callback == SDL_BufferQueueFillCallback) {
659  current_audio.impl.LockDevice(device);
660  retval = device->queued_bytes;
662  }
663 
664  return retval;
665 }
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:156
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:87
SDL_bool retval
SDL_AudioCallback callback
Definition: SDL_audio.h:177
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:86
static void SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int len)
Definition: SDL_audio.c:565
static void SDL_BufferQueueFillCallback(void *userdata, Uint8 *stream, int len)
Definition: SDL_audio.c:586
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
int(* GetPendingBytes)(_THIS)
Definition: SDL_sysaudio.h:80
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

◆ SDL_LockAudio()

void SDL_LockAudio ( void  )

Definition at line 1526 of file SDL_audio.c.

References SDL_LockAudioDevice().

1527 {
1529 }
void SDL_LockAudioDevice(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1516

◆ SDL_LockAudioDevice()

void SDL_LockAudioDevice ( SDL_AudioDeviceID  devid)

Definition at line 1516 of file SDL_audio.c.

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

Referenced by SDL_LockAudio().

1517 {
1518  /* Obtain a lock on the mixing buffers */
1519  SDL_AudioDevice *device = get_audio_device(devid);
1520  if (device) {
1521  current_audio.impl.LockDevice(device);
1522  }
1523 }
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:86
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

◆ SDL_MixAudio()

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 1653 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.

1654 {
1655  /* Mix the user-level audio format */
1656  SDL_AudioDevice *device = get_audio_device(1);
1657  if (device != NULL) {
1659  if (device->convert.needed) {
1660  format = device->convert.src_format;
1661  } else {
1662  format = device->spec.format;
1663  }
1664  SDL_MixAudioFormat(dst, src, format, len, volume);
1665  }
1666 }
GLenum GLenum dst
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
#define SDL_MixAudioFormat
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:156
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
SDL_AudioFormat format
Definition: SDL_audio.h:171
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:159
GLenum src
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

◆ SDL_NextAudioFormat()

SDL_AudioFormat SDL_NextAudioFormat ( void  )

Definition at line 1623 of file SDL_audio.c.

References format_idx, format_idx_sub, format_list, and NUM_FORMATS.

Referenced by SDL_FirstAudioFormat().

1624 {
1625  if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
1626  return 0;
1627  }
1629 }
static int format_idx_sub
Definition: SDL_audio.c:1586
static int format_idx
Definition: SDL_audio.c:1585
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1587
#define NUM_FORMATS
Definition: SDL_audio.c:1584

◆ SDL_OpenAudio()

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:
    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 (or for capture devices, call SDL_DequeueAudio() with some frequency, to obtain audio samples).
  • 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 1438 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.

1439 {
1440  SDL_AudioDeviceID id = 0;
1441 
1442  /* Start up the audio driver, if necessary. This is legacy behaviour! */
1443  if (!SDL_WasInit(SDL_INIT_AUDIO)) {
1444  if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
1445  return -1;
1446  }
1447  }
1448 
1449  /* SDL_OpenAudio() is legacy and can only act on Device ID #1. */
1450  if (open_devices[0] != NULL) {
1451  SDL_SetError("Audio device is already opened");
1452  return -1;
1453  }
1454 
1455  if (obtained) {
1456  id = open_audio_device(NULL, 0, desired, obtained,
1458  } else {
1459  id = open_audio_device(NULL, 0, desired, NULL, 0, 1);
1460  }
1461 
1462  SDL_assert((id == 0) || (id == 1));
1463  return (id == 0) ? -1 : 0;
1464 }
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:1179
#define SDL_INIT_AUDIO
Definition: SDL.h:76
Uint32 SDL_AudioDeviceID
Definition: SDL_audio.h:304
#define SDL_WasInit

◆ SDL_OpenAudioDevice()

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 1467 of file SDL_audio.c.

References open_audio_device().

1470 {
1471  return open_audio_device(device, iscapture, desired, obtained,
1472  allowed_changes, 2);
1473 }
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:1179

◆ SDL_OpenedAudioDeviceDisconnected()

void SDL_OpenedAudioDeviceDisconnected ( SDL_AudioDevice device)

Definition at line 381 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_AtomicGet, SDL_AtomicSet, SDL_AUDIODEVICEREMOVED, SDL_ENABLE, SDL_GetEventState, SDL_PushEvent, SDL_zero, and SDL_AudioDriverImpl::UnlockDevice.

Referenced by SDL_CaptureAudio(), and SDL_RemoveAudioDevice().

382 {
383  SDL_assert(get_audio_device(device->id) == device);
384 
385  if (!SDL_AtomicGet(&device->enabled)) {
386  return;
387  }
388 
389  /* Ends the audio callback and mark the device as STOPPED, but the
390  app still needs to close the device to free resources. */
391  current_audio.impl.LockDevice(device);
392  SDL_AtomicSet(&device->enabled, 0);
394 
395  /* Post the event, if desired */
398  SDL_zero(event);
399  event.adevice.type = SDL_AUDIODEVICEREMOVED;
400  event.adevice.which = device->id;
401  event.adevice.iscapture = device->iscapture ? 1 : 0;
402  SDL_PushEvent(&event);
403  }
404 }
SDL_AudioDeviceID id
Definition: SDL_sysaudio.h:153
SDL_atomic_t enabled
Definition: SDL_sysaudio.h:167
#define SDL_ENABLE
Definition: SDL_events.h:722
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:87
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
SDL_bool iscapture
Definition: SDL_sysaudio.h:169
#define SDL_PushEvent
#define SDL_zero(x)
Definition: SDL_stdinc.h:359
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:86
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
#define SDL_AtomicSet
#define SDL_AtomicGet
General event structure.
Definition: SDL_events.h:525
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

◆ SDL_ParseAudioFormat()

static SDL_AudioFormat SDL_ParseAudioFormat ( const char *  string)
static

Definition at line 876 of file SDL_audio.c.

References CHECK_FMT_STRING, and S32.

Referenced by prepare_audiospec().

877 {
878 #define CHECK_FMT_STRING(x) if (SDL_strcmp(string, #x) == 0) return AUDIO_##x
879  CHECK_FMT_STRING(U8);
880  CHECK_FMT_STRING(S8);
881  CHECK_FMT_STRING(U16LSB);
882  CHECK_FMT_STRING(S16LSB);
883  CHECK_FMT_STRING(U16MSB);
884  CHECK_FMT_STRING(S16MSB);
885  CHECK_FMT_STRING(U16SYS);
886  CHECK_FMT_STRING(S16SYS);
887  CHECK_FMT_STRING(U16);
888  CHECK_FMT_STRING(S16);
889  CHECK_FMT_STRING(S32LSB);
890  CHECK_FMT_STRING(S32MSB);
891  CHECK_FMT_STRING(S32SYS);
893  CHECK_FMT_STRING(F32LSB);
894  CHECK_FMT_STRING(F32MSB);
895  CHECK_FMT_STRING(F32SYS);
896  CHECK_FMT_STRING(F32);
897 #undef CHECK_FMT_STRING
898  return 0;
899 }
#define S32
#define CHECK_FMT_STRING(x)

◆ SDL_PauseAudio()

void SDL_PauseAudio ( int  pause_on)

Definition at line 1509 of file SDL_audio.c.

References SDL_PauseAudioDevice().

1510 {
1511  SDL_PauseAudioDevice(1, pause_on);
1512 }
void SDL_PauseAudioDevice(SDL_AudioDeviceID devid, int pause_on)
Definition: SDL_audio.c:1498

◆ SDL_PauseAudioDevice()

void SDL_PauseAudioDevice ( SDL_AudioDeviceID  devid,
int  pause_on 
)

Definition at line 1498 of file SDL_audio.c.

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

Referenced by SDL_PauseAudio().

1499 {
1500  SDL_AudioDevice *device = get_audio_device(devid);
1501  if (device) {
1502  current_audio.impl.LockDevice(device);
1503  SDL_AtomicSet(&device->paused, pause_on ? 1 : 0);
1505  }
1506 }
SDL_atomic_t paused
Definition: SDL_sysaudio.h:168
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:87
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:86
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
#define SDL_AtomicSet
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

◆ SDL_QueueAudio()

int SDL_QueueAudio ( SDL_AudioDeviceID  dev,
const void data,
Uint32  len 
)

Queue more audio on non-callback devices.

(If you are looking to retrieve queued audio from a non-callback capture device, you want SDL_DequeueAudio() instead. This will return -1 to signify an error if you use it with capture 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 602 of file SDL_audio.c.

References SDL_AudioSpec::callback, get_audio_device(), SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioDriverImpl::LockDevice, queue_audio_to_device(), SDL_BufferQueueDrainCallback(), SDL_SetError, SDL_AudioDevice::spec, and SDL_AudioDriverImpl::UnlockDevice.

603 {
604  SDL_AudioDevice *device = get_audio_device(devid);
605  int rc = 0;
606 
607  if (!device) {
608  return -1; /* get_audio_device() will have set the error state */
609  } else if (device->iscapture) {
610  return SDL_SetError("This is a capture device, queueing not allowed");
611  } else if (device->spec.callback != SDL_BufferQueueDrainCallback) {
612  return SDL_SetError("Audio device has a callback, queueing not allowed");
613  }
614 
615  if (len > 0) {
616  current_audio.impl.LockDevice(device);
617  rc = queue_audio_to_device(device, data, len);
619  }
620 
621  return rc;
622 }
static int queue_audio_to_device(SDL_AudioDevice *device, const Uint8 *data, Uint32 len)
Definition: SDL_audio.c:464
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:156
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:87
GLenum GLsizei len
SDL_bool iscapture
Definition: SDL_sysaudio.h:169
SDL_AudioCallback callback
Definition: SDL_audio.h:177
void(* LockDevice)(_THIS)
Definition: SDL_sysaudio.h:86
static void SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int len)
Definition: SDL_audio.c:565
#define SDL_SetError
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

◆ SDL_RemoveAudioDevice()

void SDL_RemoveAudioDevice ( const int  iscapture,
void handle 
)

Definition at line 422 of file SDL_audio.c.

References SDL_AudioDriver::captureDevicesRemoved, SDL_AudioDriver::detectionLock, SDL_AudioDriverImpl::FreeDeviceHandle, SDL_AudioDevice::handle, SDL_AudioDriver::impl, SDL_AudioDriver::inputDevices, mark_device_removed(), NULL, SDL_AudioDriver::outputDevices, SDL_AudioDriver::outputDevicesRemoved, SDL_arraysize, SDL_LockMutex, SDL_OpenedAudioDeviceDisconnected(), and SDL_UnlockMutex.

423 {
424  int device_index;
425  SDL_AudioDevice *device = NULL;
426 
428  if (iscapture) {
430  } else {
432  }
433  for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++)
434  {
435  device = open_devices[device_index];
436  if (device != NULL && device->handle == handle)
437  {
439  break;
440  }
441  }
443 
445 }
static SDL_AudioDevice * open_devices[16]
Definition: SDL_audio.c:34
#define SDL_LockMutex
SDL_bool captureDevicesRemoved
Definition: SDL_sysaudio.h:130
static void mark_device_removed(void *handle, SDL_AudioDeviceItem *devices, SDL_bool *removedFlag)
Definition: SDL_audio.c:407
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
Definition: SDL_audio.c:381
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
SDL_mutex * detectionLock
Definition: SDL_sysaudio.h:129
SDL_AudioDeviceItem * outputDevices
Definition: SDL_sysaudio.h:134
#define NULL
Definition: begin_code.h:143
SDL_bool outputDevicesRemoved
Definition: SDL_sysaudio.h:131
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
void(* FreeDeviceHandle)(void *handle)
Definition: SDL_sysaudio.h:88
#define SDL_UnlockMutex
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:90
SDL_AudioDeviceItem * inputDevices
Definition: SDL_sysaudio.h:135

◆ SDL_RunAudio()

static int SDL_RunAudio ( void devicep)
static

Definition at line 714 of file SDL_audio.c.

References SDL_AudioCVT::buf, callback(), SDL_AudioSpec::callback, SDL_AudioDevice::convert, SDL_AudioDevice::enabled, SDL_AudioDevice::fake_stream, SDL_AudioSpec::freq, SDL_AudioDriverImpl::GetDeviceBuf, SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioCVT::len, SDL_AudioCVT::len_cvt, SDL_AudioDevice::mixer_lock, SDL_AudioCVT::needed, NULL, SDL_AudioDevice::paused, SDL_AudioDriverImpl::PlayDevice, SDL_AudioDriverImpl::PrepareToClose, SDL_AudioSpec::samples, SDL_assert, SDL_AtomicGet, 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, and SDL_AudioDriverImpl::WaitDevice.

Referenced by open_audio_device().

715 {
716  SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
717  const int silence = (int) device->spec.silence;
718  const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq);
719  const int stream_len = (device->convert.needed) ? device->convert.len : device->spec.size;
720  Uint8 *stream;
721  void *udata = device->spec.userdata;
722  void (SDLCALL *callback) (void *, Uint8 *, int) = device->spec.callback;
723 
724  SDL_assert(!device->iscapture);
725 
726  /* The audio mixing is always a high priority thread */
728 
729  /* Perform any thread setup */
730  device->threadid = SDL_ThreadID();
731  current_audio.impl.ThreadInit(device);
732 
733  /* Loop, filling the audio buffers */
734  while (!SDL_AtomicGet(&device->shutdown)) {
735  /* Fill the current buffer with sound */
736  if (device->convert.needed) {
737  stream = device->convert.buf;
738  } else if (SDL_AtomicGet(&device->enabled)) {
740  } else {
741  /* if the device isn't enabled, we still write to the
742  fake_stream, so the app's callback will fire with
743  a regular frequency, in case they depend on that
744  for timing or progress. They can use hotplug
745  now to know if the device failed. */
746  stream = NULL;
747  }
748 
749  if (stream == NULL) {
750  stream = device->fake_stream;
751  }
752 
753  /* !!! FIXME: this should be LockDevice. */
754  if ( SDL_AtomicGet(&device->enabled) ) {
755  SDL_LockMutex(device->mixer_lock);
756  if (SDL_AtomicGet(&device->paused)) {
757  SDL_memset(stream, silence, stream_len);
758  } else {
759  (*callback) (udata, stream, stream_len);
760  }
761  SDL_UnlockMutex(device->mixer_lock);
762  }
763 
764  /* Convert the audio if necessary */
765  if (device->convert.needed && SDL_AtomicGet(&device->enabled)) {
766  SDL_ConvertAudio(&device->convert);
768  if (stream == NULL) {
769  stream = device->fake_stream;
770  } else {
771  SDL_memcpy(stream, device->convert.buf,
772  device->convert.len_cvt);
773  }
774  }
775 
776  /* Ready current buffer for play and change current buffer */
777  if (stream == device->fake_stream) {
778  SDL_Delay(delay);
779  } else {
780  current_audio.impl.PlayDevice(device);
781  current_audio.impl.WaitDevice(device);
782  }
783  }
784 
786 
787  /* Wait for the audio to drain. */
788  SDL_Delay(((device->spec.samples * 1000) / device->spec.freq) * 2);
789 
790  return 0;
791 }
#define SDL_ThreadID
#define SDL_LockMutex
SDL_mutex * mixer_lock
Definition: SDL_sysaudio.h:175
SDL_atomic_t enabled
Definition: SDL_sysaudio.h:167
Uint8 silence
Definition: SDL_audio.h:173
Uint8 * buf
Definition: SDL_audio.h:206
GLuint GLuint stream
SDL_atomic_t paused
Definition: SDL_sysaudio.h:168
SDL_atomic_t shutdown
Definition: SDL_sysaudio.h:166
SDL_threadID threadid
Definition: SDL_sysaudio.h:179
void(* PlayDevice)(_THIS)
Definition: SDL_sysaudio.h:79
Uint16 samples
Definition: SDL_audio.h:174
void(* WaitDevice)(_THIS)
Definition: SDL_sysaudio.h:78
SDL_AudioSpec spec
Definition: SDL_sysaudio.h:156
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
#define SDL_memcpy
void(* ThreadInit)(_THIS)
Definition: SDL_sysaudio.h:77
#define SDL_ConvertAudio
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
void(* PrepareToClose)(_THIS)
Definition: SDL_sysaudio.h:84
SDL_bool iscapture
Definition: SDL_sysaudio.h:169
static Uint32 callback(Uint32 interval, void *param)
Definition: testtimer.c:34
SDL_AudioCallback callback
Definition: SDL_audio.h:177
Uint8 * fake_stream
Definition: SDL_sysaudio.h:172
#define SDL_Delay
Uint32 size
Definition: SDL_audio.h:176
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#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:126
Uint8 *(* GetDeviceBuf)(_THIS)
Definition: SDL_sysaudio.h:81
#define SDL_AtomicGet
void * userdata
Definition: SDL_audio.h:178
#define SDL_UnlockMutex
SDL_AudioCVT convert
Definition: SDL_sysaudio.h:159
#define SDLCALL
Definition: SDL_internal.h:31
#define SDL_SetThreadPriority
#define SDL_memset

◆ SDL_UnlockAudio()

void SDL_UnlockAudio ( void  )

Definition at line 1542 of file SDL_audio.c.

References SDL_UnlockAudioDevice().

1543 {
1545 }
void SDL_UnlockAudioDevice(SDL_AudioDeviceID devid)
Definition: SDL_audio.c:1532

◆ SDL_UnlockAudioDevice()

void SDL_UnlockAudioDevice ( SDL_AudioDeviceID  devid)

Definition at line 1532 of file SDL_audio.c.

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

Referenced by SDL_UnlockAudio().

1533 {
1534  /* Obtain a lock on the mixing buffers */
1535  SDL_AudioDevice *device = get_audio_device(devid);
1536  if (device) {
1538  }
1539 }
static SDL_AudioDriver current_audio
Definition: SDL_audio.c:33
void(* UnlockDevice)(_THIS)
Definition: SDL_sysaudio.h:87
SDL_AudioDriverImpl impl
Definition: SDL_sysaudio.h:126
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
Definition: SDL_audio.c:141

Variable Documentation

◆ ALSA_bootstrap

AudioBootStrap ALSA_bootstrap

◆ ANDROIDAUDIO_bootstrap

AudioBootStrap ANDROIDAUDIO_bootstrap

◆ ARTS_bootstrap

AudioBootStrap ARTS_bootstrap

◆ bootstrap

const AudioBootStrap* const bootstrap[]
static

Definition at line 67 of file SDL_audio.c.

◆ BSD_AUDIO_bootstrap

AudioBootStrap BSD_AUDIO_bootstrap

◆ COREAUDIO_bootstrap

AudioBootStrap COREAUDIO_bootstrap

◆ current_audio

SDL_AudioDriver current_audio
static

Definition at line 33 of file SDL_audio.c.

◆ DISKAUDIO_bootstrap

AudioBootStrap DISKAUDIO_bootstrap

◆ DSOUND_bootstrap

AudioBootStrap DSOUND_bootstrap

◆ DSP_bootstrap

AudioBootStrap DSP_bootstrap

◆ DUMMYAUDIO_bootstrap

AudioBootStrap DUMMYAUDIO_bootstrap

Definition at line 61 of file SDL_dummyaudio.c.

◆ EMSCRIPTENAUDIO_bootstrap

AudioBootStrap EMSCRIPTENAUDIO_bootstrap

◆ ESD_bootstrap

AudioBootStrap ESD_bootstrap

◆ format_idx

int format_idx
static

Definition at line 1585 of file SDL_audio.c.

Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().

◆ format_idx_sub

int format_idx_sub
static

Definition at line 1586 of file SDL_audio.c.

Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().

◆ format_list

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 1587 of file SDL_audio.c.

Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().

◆ FUSIONSOUND_bootstrap

AudioBootStrap FUSIONSOUND_bootstrap

◆ HAIKUAUDIO_bootstrap

AudioBootStrap HAIKUAUDIO_bootstrap

◆ NACLAUDIO_bootstrap

AudioBootStrap NACLAUDIO_bootstrap

◆ NAS_bootstrap

AudioBootStrap NAS_bootstrap

◆ open_devices

SDL_AudioDevice* open_devices[16]
static

Definition at line 34 of file SDL_audio.c.

◆ PAUDIO_bootstrap

AudioBootStrap PAUDIO_bootstrap

◆ PSPAUDIO_bootstrap

AudioBootStrap PSPAUDIO_bootstrap

◆ PULSEAUDIO_bootstrap

AudioBootStrap PULSEAUDIO_bootstrap

◆ QSAAUDIO_bootstrap

AudioBootStrap QSAAUDIO_bootstrap

◆ SNDIO_bootstrap

AudioBootStrap SNDIO_bootstrap

Definition at line 63 of file SDL_audio.c.

◆ SUNAUDIO_bootstrap

AudioBootStrap SUNAUDIO_bootstrap

◆ WINMM_bootstrap

AudioBootStrap WINMM_bootstrap

◆ XAUDIO2_bootstrap

AudioBootStrap XAUDIO2_bootstrap