diff --git a/audio/drivers/openal.c b/audio/drivers/openal.c index 9e89b94165..756cc42925 100644 --- a/audio/drivers/openal.c +++ b/audio/drivers/openal.c @@ -32,6 +32,7 @@ #include #include +#include #include "../audio_driver.h" #include "../../verbosity.h" @@ -252,6 +253,42 @@ static bool al_use_float(void *data) return true; } +static void *al_list_new(void *u) +{ + union string_list_elem_attr attr; + const char *audio_out_device_list; + struct string_list *sl = string_list_new(); + + if (!sl) + return NULL; + + attr.i = 0; + + if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT")) + audio_out_device_list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); + else + audio_out_device_list = alcGetString(NULL, ALC_DEVICE_SPECIFIER); + + if (audio_out_device_list) + { + while (*audio_out_device_list) + { + string_list_append(sl, audio_out_device_list, attr); + audio_out_device_list += strlen(audio_out_device_list) + 1; + } + } + + return sl; +} + +static void al_device_list_free(void *u, void *slp) +{ + struct string_list *sl = (struct string_list*)slp; + + if (sl) + string_list_free(sl); +} + audio_driver_t audio_openal = { al_init, al_write, @@ -262,8 +299,8 @@ audio_driver_t audio_openal = { al_free, al_use_float, "openal", - NULL, - NULL, + al_list_new, + al_device_list_free, al_write_avail, al_buffer_size, }; diff --git a/audio/drivers/xaudio.c b/audio/drivers/xaudio.c index fce40cc5f7..ac494d0ff4 100644 --- a/audio/drivers/xaudio.c +++ b/audio/drivers/xaudio.c @@ -73,9 +73,6 @@ typedef struct uint8_t flags; } xa_t; -/* Forward declarations */ -static void *xa_list_new(void *u); - #if defined(__cplusplus) && !defined(CINTERFACE) struct xaudio2 : public IXAudio2VoiceCallback #else @@ -239,6 +236,51 @@ static size_t xa_device_get_samplerate(int id) #endif } +static void *xa_list_new(void *u) +{ +#if defined(_XBOX) || !defined(HAVE_MMDEVICE) + unsigned i; + union string_list_elem_attr attr; + uint32_t dev_count = 0; + IXAudio2 *ixa2 = NULL; + struct string_list *sl = string_list_new(); + + if (!sl) + return NULL; + + attr.i = 0; + + if (FAILED(XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR))) + return NULL; + + IXAudio2_GetDeviceCount(ixa2, &dev_count); + + for (i = 0; i < dev_count; i++) + { + XAUDIO2_DEVICE_DETAILS dev_detail; + if (IXAudio2_GetDeviceDetails(ixa2, i, &dev_detail) == S_OK) + { + char *str = utf16_to_utf8_string_alloc(dev_detail.DisplayName); + + if (str) + { + string_list_append(sl, str, attr); + free(str); + } + } + } + + IXAudio2_Release(ixa2); + + return sl; +#elif defined(__WINRT__) + return NULL; +#else + return mmdevice_list_new(u, 0 /* eRender */); +#endif +} + + static xaudio2_t *xaudio2_new(unsigned *rate, unsigned channels, unsigned latency, size_t len, const char *dev_id) { @@ -546,50 +588,6 @@ static void xa_device_list_free(void *u, void *slp) string_list_free(sl); } -static void *xa_list_new(void *u) -{ -#if defined(_XBOX) || !defined(HAVE_MMDEVICE) - unsigned i; - union string_list_elem_attr attr; - uint32_t dev_count = 0; - IXAudio2 *ixa2 = NULL; - struct string_list *sl = string_list_new(); - - if (!sl) - return NULL; - - attr.i = 0; - - if (FAILED(XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR))) - return NULL; - - IXAudio2_GetDeviceCount(ixa2, &dev_count); - - for (i = 0; i < dev_count; i++) - { - XAUDIO2_DEVICE_DETAILS dev_detail; - if (IXAudio2_GetDeviceDetails(ixa2, i, &dev_detail) == S_OK) - { - char *str = utf16_to_utf8_string_alloc(dev_detail.DisplayName); - - if (str) - { - string_list_append(sl, str, attr); - free(str); - } - } - } - - IXAudio2_Release(ixa2); - - return sl; -#elif defined(__WINRT__) - return NULL; -#else - return mmdevice_list_new(u, 0 /* eRender */); -#endif -} - audio_driver_t audio_xa = { xa_init, xa_write,