21 #include "../SDL_internal.h" 31 #define _THIS SDL_AudioDevice *_this 37 #define DEFAULT_OUTPUT_DEVNAME "System audio output device" 38 #define DEFAULT_INPUT_DEVNAME "System audio capture device" 77 #if SDL_AUDIO_DRIVER_PULSEAUDIO 80 #if SDL_AUDIO_DRIVER_ALSA 83 #if SDL_AUDIO_DRIVER_SNDIO 86 #if SDL_AUDIO_DRIVER_BSD 89 #if SDL_AUDIO_DRIVER_OSS 92 #if SDL_AUDIO_DRIVER_QSA 95 #if SDL_AUDIO_DRIVER_SUNAUDIO 98 #if SDL_AUDIO_DRIVER_ARTS 101 #if SDL_AUDIO_DRIVER_ESD 104 #if SDL_AUDIO_DRIVER_NACL 107 #if SDL_AUDIO_DRIVER_NAS 110 #if SDL_AUDIO_DRIVER_XAUDIO2 113 #if SDL_AUDIO_DRIVER_DSOUND 116 #if SDL_AUDIO_DRIVER_WINMM 119 #if SDL_AUDIO_DRIVER_PAUDIO 122 #if SDL_AUDIO_DRIVER_HAIKU 125 #if SDL_AUDIO_DRIVER_COREAUDIO 128 #if SDL_AUDIO_DRIVER_DISK 131 #if SDL_AUDIO_DRIVER_DUMMY 134 #if SDL_AUDIO_DRIVER_FUSIONSOUND 137 #if SDL_AUDIO_DRIVER_ANDROID 140 #if SDL_AUDIO_DRIVER_PSP 143 #if SDL_AUDIO_DRIVER_EMSCRIPTEN 158 return open_devices[
id];
269 #define FILL_STUB(x) \ 270 if (current_audio.impl.x == NULL) { \ 271 current_audio.impl.x = SDL_Audio##x##_Default; \ 308 item->
next = *devices;
310 retval = (*devCount)++;
333 for (item = *devices; item !=
NULL; item = next) {
350 if (device_index != -1) {
356 event.adevice.which = device_index;
357 event.adevice.iscapture = iscapture;
383 event.adevice.which = device->
id;
384 event.adevice.iscapture = device->
iscapture ? 1 : 0;
394 for (item = devices; item !=
NULL; item = item->
next) {
395 if (item->
handle == handle) {
489 return SDL_SetError(
"Audio device has a callback, queueing not allowed");
496 origlen = origtail ? origtail->
datalen : 0;
504 if (packet !=
NULL) {
510 if (packet ==
NULL) {
515 packet = origtail->
next;
637 (*fill) (udata,
stream, stream_len);
672 #define CHECK_FMT_STRING(x) if (SDL_strcmp(string, #x) == 0) return AUDIO_##x 691 #undef CHECK_FMT_STRING 715 int tried_to_init = 0;
725 if (driver_name ==
NULL) {
729 for (i = 0; (!initialized) && (bootstrap[i]); ++
i) {
741 initialized = backend->
init(¤t_audio.
impl);
746 if (!tried_to_init) {
748 SDL_SetError(
"Audio target '%s' not available", driver_name);
774 return current_audio.
name;
855 for (i--; i >
index; i--, item = item->
next) {
864 if (retval ==
NULL) {
909 if (orig->
freq == 0) {
910 const char *env =
SDL_getenv(
"SDL_AUDIO_FREQUENCY");
911 if ((!env) || ((prepared->
freq =
SDL_atoi(env)) == 0)) {
912 prepared->
freq = 22050;
917 const char *env =
SDL_getenv(
"SDL_AUDIO_FORMAT");
925 const char *env =
SDL_getenv(
"SDL_AUDIO_CHANNELS");
942 const char *env =
SDL_getenv(
"SDL_AUDIO_SAMPLES");
948 while (power2 < samples) {
964 int allowed_changes,
int min_id)
985 for (
id = min_id - 1;
id <
SDL_arraysize(open_devices);
id++) {
986 if (open_devices[
id] ==
NULL) {
997 obtained = &_obtained;
1004 if (devname ==
NULL) {
1005 devname =
SDL_getenv(
"SDL_AUDIO_DEVICE_NAME");
1026 if ((open_devices[i]) && (open_devices[
i]->
iscapture)) {
1039 if ((open_devices[i]) && (!open_devices[
i]->
iscapture)) {
1044 }
else if (devname !=
NULL) {
1064 if ((handle ==
NULL) && (devname !=
NULL)) {
1071 if (device ==
NULL) {
1076 device->
id =
id + 1;
1077 device->
spec = *obtained;
1092 if (current_audio.
impl.
OpenDevice(device, handle, devname, iscapture) < 0) {
1158 if (device->
spec.
size > stream_len) {
1173 const int wantpackets = (wantbytes / packetlen) + ((wantbytes % packetlen) ? packetlen : 0);
1174 for (i = 0; i < wantpackets; i++) {
1189 open_devices[
id] = device;
1195 SDL_snprintf(name,
sizeof (name),
"SDLAudioDev%d", (
int) device->
id);
1197 #if defined(__WIN32__) && !defined(HAVE_LIBC) 1198 #undef SDL_CreateThread 1231 if (open_devices[0] !=
NULL) {
1244 return (
id == 0) ? -1 : 0;
1250 int allowed_changes)
1253 allowed_changes, 2);
1261 if (device && device->
enabled) {
1284 device->
paused = pause_on;
1334 open_devices[devid - 1] =
NULL;
1349 if (!current_audio.
name) {
1354 if (open_devices[i] !=
NULL) {
1371 #define NUM_FORMATS 10 1444 if (device !=
NULL) {
static SDL_AudioDevice * open_devices[16]
static int format_idx_sub
AudioBootStrap DISKAUD_bootstrap
void SDL_LockAudioDevice(SDL_AudioDeviceID devid)
#define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE
void SDL_UnlockAudio(void)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
AudioBootStrap SUNAUDIO_bootstrap
GLuint GLfloat GLfloat GLfloat x1
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
SDL_bool captureDevicesRemoved
AudioBootStrap PULSEAUDIO_bootstrap
void(* DetectDevices)(void)
int SDL_GetNumAudioDrivers(void)
uint32_t Uint32
An unsigned 32-bit integer type.
int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
AudioBootStrap DUMMYAUD_bootstrap
const char * SDL_GetCurrentAudioDriver()
static void mark_device_removed(void *handle, SDL_AudioDeviceItem *devices, SDL_bool *removedFlag)
const char * SDL_GetAudioDriver(int index)
#define SDL_BuildAudioCVT
AudioBootStrap NDSAUD_bootstrap
struct SDL_AudioDeviceItem * next
static void clean_out_device_list(SDL_AudioDeviceItem **devices, int *devCount, SDL_bool *removedFlag)
AudioBootStrap QSAAUDIO_bootstrap
static SDL_INLINE int add_output_device(const char *name, void *handle)
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define DEFAULT_INPUT_DEVNAME
int ProvidesOwnCallbackThread
AudioBootStrap DCAUD_bootstrap
SDL_AudioDeviceID SDL_OpenAudioDevice(const char *device, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes)
void(* PlayDevice)(_THIS)
SDL_AudioBufferQueue * buffer_queue_pool
void(* WaitDevice)(_THIS)
void SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
#define SDL_InitSubSystem
#define SDL_MixAudioFormat
Uint16 SDL_AudioFormat
Audio format flags.
Uint32 SDL_GetQueuedAudioSize(SDL_AudioDeviceID devid)
static Uint8 * SDL_AudioGetDeviceBuf_Default(_THIS)
GLuint const GLchar * name
AudioBootStrap DSOUND_bootstrap
static void SDL_AudioUnlockDevice_Default(SDL_AudioDevice *device)
static SDL_AudioDriver current_audio
void(* UnlockDevice)(_THIS)
AudioBootStrap ARTS_bootstrap
int SDL_RunAudio(void *devicep)
static void finalize_audio_entry_points(void)
AudioBootStrap WINMM_bootstrap
AudioBootStrap BSD_AUDIO_bootstrap
SDL_AudioFormat SDL_NextAudioFormat(void)
#define SDL_AUDIO_ALLOW_CHANNELS_CHANGE
AudioBootStrap DART_bootstrap
SDL_mutex * detectionLock
SDL_AudioBufferQueue * buffer_queue_head
#define DEFAULT_OUTPUT_DEVNAME
SDL_AudioBufferQueue * buffer_queue_tail
static void SDL_AudioDeinitialize_Default(void)
struct SDL_AudioBufferQueue * next
void(* ThreadInit)(_THIS)
int OnlyHasDefaultOutputDevice
SDL_AudioStatus SDL_GetAudioDeviceStatus(SDL_AudioDeviceID devid)
#define SDL_GetEventState(type)
AudioBootStrap NACLAUD_bootstrap
void SDL_RemoveAudioDevice(const int iscapture, void *handle)
uint8_t Uint8
An unsigned 8-bit integer type.
static void SDL_AudioWaitDevice_Default(_THIS)
#define SDL_AUDIO_BITSIZE(x)
AudioBootStrap PAUDIO_bootstrap
#define SDL_AUDIO_ALLOW_ANY_CHANGE
void(* Deinitialize)(void)
static int prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
void SDL_UnlockAudioDevice(SDL_AudioDeviceID devid)
static int SDL_AudioOpenDevice_Default(_THIS, void *handle, const char *devname, int iscapture)
AudioBootStrap COREAUDIO_bootstrap
void SDL_PauseAudio(int pause_on)
AudioBootStrap ALSA_bootstrap
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
#define SDL_AllocAudioMem
SDL_AudioStatus SDL_GetAudioStatus(void)
SDL_AudioCallback callback
SDL_AudioFormat src_format
static void SDL_AudioThreadInit_Default(_THIS)
static void SDL_AudioDetectDevices_Default(void)
static int add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices, int *devCount)
AudioBootStrap NAS_bootstrap
void(* LockDevice)(_THIS)
const char * SDL_GetAudioDeviceName(int index, int iscapture)
SDL_AudioDeviceItem * outputDevices
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)
static int SDL_AudioGetPendingBytes_Default(_THIS)
#define SDL_assert(condition)
static const AudioBootStrap *const bootstrap[]
AudioBootStrap SNDMGR_bootstrap
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
static void SDL_AudioPlayDevice_Default(_THIS)
#define SDL_OutOfMemory()
SDL_bool outputDevicesRemoved
static void free_device_list(SDL_AudioDeviceItem **devices, int *devCount)
static void free_audio_queue(SDL_AudioBufferQueue *buffer)
AudioBootStrap DSP_bootstrap
static SDL_AudioDeviceID open_audio_device(const char *devname, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes, int min_id)
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
void(* CloseDevice)(_THIS)
int AllowsArbitraryDeviceNames
static SDL_INLINE int add_capture_device(const char *name, void *handle)
static void SDL_AudioLockDevice_Default(SDL_AudioDevice *device)
void(* FreeDeviceHandle)(void *handle)
AudioBootStrap XAUDIO2_bootstrap
AudioBootStrap HAIKUAUDIO_bootstrap
void SDL_CloseAudio(void)
Uint8 *(* GetDeviceBuf)(_THIS)
int SDL_GetNumAudioDevices(int iscapture)
uint16_t Uint16
An unsigned 16-bit integer type.
#define SDL_AUDIO_ALLOW_FORMAT_CHANGE
static SDL_AudioFormat SDL_ParseAudioFormat(const char *string)
#define SDL_arraysize(array)
Uint8 data[SDL_AUDIOBUFFERQUEUE_PACKETLEN]
int(* init)(SDL_AudioDriverImpl *impl)
static void SDL_AudioCloseDevice_Default(_THIS)
int(* GetPendingBytes)(_THIS)
AudioBootStrap ESD_bootstrap
int OnlyHasDefaultInputDevice
void SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
static void SDL_AudioWaitDone_Default(_THIS)
#define SDL_AUDIOBUFFERQUEUE_PACKETLEN
AudioBootStrap ANDROIDAUD_bootstrap
static void SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int _len)
void SDL_MixAudio(Uint8 *dst, const Uint8 *src, Uint32 len, int volume)
#define CHECK_FMT_STRING(x)
void SDL_PauseAudioDevice(SDL_AudioDeviceID devid, int pause_on)
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
#define SDL_Unsupported()
AudioBootStrap PSPAUD_bootstrap
static SDL_INLINE SDL_bool is_in_audio_device_thread(SDL_AudioDevice *device)
#define SDL_SetThreadPriority
AudioBootStrap EmscriptenAudio_bootstrap
SDL_AudioDeviceItem * inputDevices
static void SDL_AudioFreeDeviceHandle_Default(void *handle)
AudioBootStrap SNDIO_bootstrap
int SDL_AudioInit(const char *driver_name)
void SDL_AddAudioDevice(const int iscapture, const char *name, void *handle)
static void close_audio_device(SDL_AudioDevice *device)
AudioBootStrap FUSIONSOUND_bootstrap
int SDL_QueueAudio(SDL_AudioDeviceID devid, const void *_data, Uint32 len)