wasapi_select_device_format - cleanup

This commit is contained in:
libretroadmin 2024-04-06 19:01:12 +02:00
parent a0dc153508
commit f0cc87189c

View File

@ -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;