diff --git a/audio/common/mmdevice_common.c b/audio/common/mmdevice_common.c index 8f23471c3c..c30e0f5222 100644 --- a/audio/common/mmdevice_common.c +++ b/audio/common/mmdevice_common.c @@ -108,6 +108,45 @@ const char *mmdevice_hresult_name(int hr) return ""; } +size_t mmdevice_samplerate(void *data) +{ + HRESULT hr; + PWAVEFORMATEX devfmt_props; + PROPVARIANT prop_var; + IMMDevice *device = (IMMDevice*)data; + IPropertyStore *prop_store = NULL; + DWORD result = 0; + + if (!device) + return 0; + + hr = _IMMDevice_OpenPropertyStore(device, + STGM_READ, &prop_store); + + if (FAILED(hr)) + return 0; + + PropVariantInit(&prop_var); + hr = _IPropertyStore_GetValue(prop_store, + PKEY_AudioEngine_DeviceFormat, &prop_var); + if (SUCCEEDED(hr)) + { + devfmt_props = (PWAVEFORMATEX)prop_var.blob.pBlobData; + result = devfmt_props->nSamplesPerSec; + } + + PropVariantClear(&prop_var); + if (prop_store) + { +#ifdef __cplusplus + prop_store->Release(); +#else + prop_store->lpVtbl->Release(prop_store); +#endif + prop_store = NULL; + } + return (size_t)result; +} char *mmdevice_name(void *data) { diff --git a/audio/common/mmdevice_common.h b/audio/common/mmdevice_common.h index 6c57f85da2..1d911dc4e2 100644 --- a/audio/common/mmdevice_common.h +++ b/audio/common/mmdevice_common.h @@ -30,8 +30,14 @@ void *mmdevice_list_new(const void *u, unsigned data_flow); */ char* mmdevice_name(void *data); +/** + * Gets the samplerate of the provided IMMDevice. + */ +size_t mmdevice_samplerate(void *data); + const char *mmdevice_hresult_name(int hr); + void *mmdevice_init_device(const char *id, unsigned data_flow); RETRO_END_DECLS diff --git a/audio/common/mmdevice_common_inline.h b/audio/common/mmdevice_common_inline.h index 14859fe384..73500eefa3 100644 --- a/audio/common/mmdevice_common_inline.h +++ b/audio/common/mmdevice_common_inline.h @@ -18,7 +18,7 @@ #include -/* Fix for MSYS2 increasing _WIN32_WINNT to 0x0603*/ +/* Fix for MSYS2 increasing _WIN32_WINNT to 0x0603 */ #if defined(__MINGW32__) || defined(__MINGW64__) #define WIN32_LEAN_AND_MEAN #endif diff --git a/audio/drivers/xaudio.c b/audio/drivers/xaudio.c index 74e3ac2a48..43565d19c3 100644 --- a/audio/drivers/xaudio.c +++ b/audio/drivers/xaudio.c @@ -38,7 +38,13 @@ #include "xaudio.h" -#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) +#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600 /*_WIN32_WINNT_VISTA */) +#ifndef HAVE_MMDEVICE +#define HAVE_MMDEVICE +#endif +#endif + +#ifdef HAVE_MMDEVICE #include "../common/mmdevice_common.h" #endif @@ -265,29 +271,27 @@ static xaudio2_t *xaudio2_new(unsigned *rate, unsigned channels, /* Search for device name first */ if (list && list->elems) { - if (list->elems) + /* If any devices were found... */ + size_t i; + for (i = 0; i < list->size; i++) { - /* If any devices were found... */ - size_t i; - for (i = 0; i < list->size; i++) + if (string_is_equal(dev_id, list->elems[i].data)) { - if (string_is_equal(dev_id, list->elems[i].data)) - { - RARCH_DBG("[XAudio2] Found device #%d: \"%s\".\n", i, list->elems[i].data); - idx_found = i; - break; - } + RARCH_DBG("[XAudio2] Found device #%d: \"%s\".\n", i, + list->elems[i].data); + idx_found = i; + break; } + } - /* Index was not found yet based on name string, - * just assume id is a one-character number index. */ - if (idx_found == -1) + /* Index was not found yet based on name string, + * just assume id is a one-character number index. */ + if (idx_found == -1) + { + if (isdigit(dev_id[0])) { - if (isdigit(dev_id[0])) - { - idx_found = strtoul(dev_id, NULL, 0); - RARCH_LOG("[XAudio2] Fallback, device index is a single number index instead: %d.\n", idx_found); - } + idx_found = strtoul(dev_id, NULL, 0); + RARCH_LOG("[XAudio2] Fallback, device index is a single number index instead: %d.\n", idx_found); } } } @@ -521,7 +525,7 @@ static void xa_device_list_free(void *u, void *slp) static void *xa_list_new(void *u) { -#if defined(_XBOX) || !(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) +#if defined(_XBOX) || !defined(HAVE_MMDEVICE) unsigned i; union string_list_elem_attr attr; uint32_t dev_count = 0;