From f0cc87189cb7461d26cd6f843ab676e0f2c34556 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Sat, 6 Apr 2024 19:01:12 +0200 Subject: [PATCH] wasapi_select_device_format - cleanup --- audio/common/wasapi.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/audio/common/wasapi.c b/audio/common/wasapi.c index 20a92cedd2..b94a3ed20e 100644 --- a/audio/common/wasapi.c +++ b/audio/common/wasapi.c @@ -228,7 +228,6 @@ static bool wasapi_is_format_suitable(const WAVEFORMATEXTENSIBLE *format) */ static bool wasapi_select_device_format(WAVEFORMATEXTENSIBLE *format, IAudioClient *client, AUDCLNT_SHAREMODE mode, unsigned channels) { - static const unsigned preferred_rates[] = { 48000, 44100, 96000, 192000, 32000 }; /* Try the requested sample format first, then try the other one. */ WAVEFORMATEXTENSIBLE *suggested_format = NULL; bool result = false; @@ -255,7 +254,6 @@ static bool wasapi_select_device_format(WAVEFORMATEXTENSIBLE *format, IAudioClie } else { - result = false; RARCH_ERR("[WASAPI]: Windows suggested a format, but RetroArch can't use it.\n"); } break; @@ -267,15 +265,16 @@ static bool wasapi_select_device_format(WAVEFORMATEXTENSIBLE *format, IAudioClie * RetroArch will try selecting a format. */ size_t i, j; bool preferred_formats[2]; - WAVEFORMATEXTENSIBLE possible_format; - HRESULT format_check_hr; preferred_formats[0] = (format->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE); preferred_formats[1] = (format->Format.wFormatTag != WAVE_FORMAT_EXTENSIBLE); RARCH_WARN("[WASAPI]: Requested format not supported, and Windows could not suggest one. RetroArch will do so.\n"); for (i = 0; i < ARRAY_SIZE(preferred_formats); ++i) { + static const unsigned preferred_rates[] = { 48000, 44100, 96000, 192000, 32000 }; for (j = 0; j < ARRAY_SIZE(preferred_rates); ++j) { + HRESULT format_check_hr; + WAVEFORMATEXTENSIBLE possible_format; wasapi_set_format(&possible_format, preferred_formats[i], preferred_rates[j], channels); format_check_hr = _IAudioClient_IsFormatSupported(client, mode, (const WAVEFORMATEX *) &possible_format, NULL); if (SUCCEEDED(format_check_hr)) @@ -289,13 +288,11 @@ static bool wasapi_select_device_format(WAVEFORMATEXTENSIBLE *format, IAudioClie } } RARCH_ERR("[WASAPI]: Failed to select client format: No suitable format available.\n"); - result = false; break; } default: /* Something else went wrong. */ RARCH_ERR("[WASAPI]: Failed to select client format: %s.\n", hresult_name(hr)); - result = false; break; } done: @@ -443,8 +440,8 @@ static IAudioClient *wasapi_init_client_sh(IMMDevice *device, } /* Use audio latency setting for buffer size if allowed */ - if ( sh_buffer_length < WASAPI_SH_BUFFER_DEVICE_PERIOD - || sh_buffer_length > WASAPI_SH_BUFFER_CLIENT_BUFFER) + if ( (sh_buffer_length < WASAPI_SH_BUFFER_DEVICE_PERIOD) + || (sh_buffer_length > WASAPI_SH_BUFFER_CLIENT_BUFFER)) { /* Buffer_duration is in 100ns units. */ buffer_duration = latency * 10000.0;