(XAudio2) Device index selection now works for old
pre-XAudio 2.8 codepath
This commit is contained in:
parent
453cc3dcbd
commit
b5d11db53b
|
@ -66,6 +66,9 @@ typedef struct
|
||||||
size_t bufsize;
|
size_t bufsize;
|
||||||
} xa_t;
|
} xa_t;
|
||||||
|
|
||||||
|
/* Forward declarations */
|
||||||
|
static void *xa_list_new(void *u);
|
||||||
|
|
||||||
#if defined(__cplusplus) && !defined(CINTERFACE)
|
#if defined(__cplusplus) && !defined(CINTERFACE)
|
||||||
struct xaudio2 : public IXAudio2VoiceCallback
|
struct xaudio2 : public IXAudio2VoiceCallback
|
||||||
#else
|
#else
|
||||||
|
@ -181,20 +184,22 @@ static void xaudio2_free(xaudio2_t *handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels,
|
static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels,
|
||||||
size_t size, unsigned device)
|
size_t size, const char *device)
|
||||||
{
|
{
|
||||||
xaudio2_t *handle = NULL;
|
int32_t idx_found = -1;
|
||||||
WAVEFORMATEX wfx = {0};
|
WAVEFORMATEX wfx = {0};
|
||||||
|
struct string_list *list = NULL;
|
||||||
#if defined(__cplusplus) && !defined(CINTERFACE)
|
#if defined(__cplusplus) && !defined(CINTERFACE)
|
||||||
handle = new xaudio2;
|
xaudio2_t *handle = new xaudio2;
|
||||||
#else
|
#else
|
||||||
handle = (xaudio2_t*)calloc(1, sizeof(*handle));
|
xaudio2_t *handle = (xaudio2_t*)calloc(1, sizeof(*handle));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handle)
|
if (!handle)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
list = (struct string_list*)xa_list_new(NULL);
|
||||||
|
|
||||||
#if !defined(__cplusplus) || defined(CINTERFACE)
|
#if !defined(__cplusplus) || defined(CINTERFACE)
|
||||||
handle->lpVtbl = &voice_vtable;
|
handle->lpVtbl = &voice_vtable;
|
||||||
#endif
|
#endif
|
||||||
|
@ -202,11 +207,53 @@ static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels,
|
||||||
if (FAILED(XAudio2Create(&handle->pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR)))
|
if (FAILED(XAudio2Create(&handle->pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (device)
|
||||||
|
{
|
||||||
|
/* Search for device name first */
|
||||||
|
if (list && list->elems)
|
||||||
|
{
|
||||||
|
if (list->elems)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
for (i = 0; i < list->size; i++)
|
||||||
|
{
|
||||||
|
if (string_is_equal(device, 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)
|
||||||
|
{
|
||||||
|
if (isdigit(device[0]))
|
||||||
|
{
|
||||||
|
RARCH_LOG("[XAudio2]: Fallback, device index is a single number index instead: %d.\n", idx_found);
|
||||||
|
idx_found = strtoul(device, NULL, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idx_found == -1)
|
||||||
|
idx_found = 0;
|
||||||
|
|
||||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||||
if (FAILED(IXAudio2_CreateMasteringVoice(handle->pXAudio2, &handle->pMasterVoice, channels, samplerate, 0, (LPCWSTR)(uintptr_t)device, NULL, AudioCategory_GameEffects)))
|
{
|
||||||
goto error;
|
wchar_t *temp = utf8_to_utf16_string_alloc((const char*)(char)idx_found);
|
||||||
|
if (FAILED(IXAudio2_CreateMasteringVoice(handle->pXAudio2, &handle->pMasterVoice, channels, samplerate, 0, (LPCWSTR)(uintptr_t)temp, NULL, AudioCategory_GameEffects)))
|
||||||
|
{
|
||||||
|
free(temp);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (temp)
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (FAILED(IXAudio2_CreateMasteringVoice(handle->pXAudio2, &handle->pMasterVoice, channels, samplerate, 0, device, NULL)))
|
if (FAILED(IXAudio2_CreateMasteringVoice(handle->pXAudio2, &handle->pMasterVoice, channels, samplerate, 0, idx_found, NULL)))
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -231,9 +278,13 @@ static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels,
|
||||||
XAUDIO2_COMMIT_NOW)))
|
XAUDIO2_COMMIT_NOW)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (list)
|
||||||
|
string_list_free(list);
|
||||||
return handle;
|
return handle;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
if (list)
|
||||||
|
string_list_free(list);
|
||||||
xaudio2_free(handle);
|
xaudio2_free(handle);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +294,6 @@ static void *xa_init(const char *device, unsigned rate, unsigned latency,
|
||||||
unsigned *new_rate)
|
unsigned *new_rate)
|
||||||
{
|
{
|
||||||
size_t bufsize;
|
size_t bufsize;
|
||||||
unsigned device_index = 0;
|
|
||||||
xa_t *xa = (xa_t*)calloc(1, sizeof(*xa));
|
xa_t *xa = (xa_t*)calloc(1, sizeof(*xa));
|
||||||
if (!xa)
|
if (!xa)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -258,10 +308,7 @@ static void *xa_init(const char *device, unsigned rate, unsigned latency,
|
||||||
|
|
||||||
xa->bufsize = bufsize * 2 * sizeof(float);
|
xa->bufsize = bufsize * 2 * sizeof(float);
|
||||||
|
|
||||||
if (device)
|
xa->xa = xaudio2_new(rate, 2, xa->bufsize, device);
|
||||||
device_index = strtoul(device, NULL, 0);
|
|
||||||
|
|
||||||
xa->xa = xaudio2_new(rate, 2, xa->bufsize, device_index);
|
|
||||||
if (!xa->xa)
|
if (!xa->xa)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to init XAudio2.\n");
|
RARCH_ERR("Failed to init XAudio2.\n");
|
||||||
|
|
|
@ -16489,7 +16489,6 @@ void video_context_driver_destroy(void)
|
||||||
current_video_context.check_window = NULL;
|
current_video_context.check_window = NULL;
|
||||||
current_video_context.set_resize = set_resize_null;
|
current_video_context.set_resize = set_resize_null;
|
||||||
current_video_context.suppress_screensaver = NULL;
|
current_video_context.suppress_screensaver = NULL;
|
||||||
current_video_context.has_windowed = NULL;
|
|
||||||
current_video_context.swap_buffers = swap_buffers_null;
|
current_video_context.swap_buffers = swap_buffers_null;
|
||||||
current_video_context.input_driver = NULL;
|
current_video_context.input_driver = NULL;
|
||||||
current_video_context.get_proc_address = NULL;
|
current_video_context.get_proc_address = NULL;
|
||||||
|
|
Loading…
Reference in New Issue