From ac32c522ada13ba39b166f84cad13e0b74738388 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 10 Aug 2021 18:11:09 -0700
Subject: [PATCH] Try using the built-in WASAPI audio rate conversion
Fixes https://github.com/libsdl-org/SDL/issues/4608
---
src/audio/wasapi/SDL_wasapi.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index 277921e11..f0c1ac033 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -556,21 +556,12 @@ WASAPI_PrepDevice(_THIS, const SDL_bool updatestream)
return WIN_SetErrorFromHRESULT("WASAPI can't determine minimum device period", ret);
}
-#if 1 /* we're getting reports that WASAPI's resampler introduces distortions, so it's disabled for now. --ryan. */
- this->spec.freq = waveformat->nSamplesPerSec; /* force sampling rate so our resampler kicks in, if necessary. */
-#else
- /* favor WASAPI's resampler over our own, in Win7+. */
+ /* favor WASAPI's resampler over our own */
if (this->spec.freq != waveformat->nSamplesPerSec) {
- /* RATEADJUST only works with output devices in share mode, and is available in Win7 and later.*/
- if (WIN_IsWindows7OrGreater() && !this->iscapture && (sharemode == AUDCLNT_SHAREMODE_SHARED)) {
- streamflags |= AUDCLNT_STREAMFLAGS_RATEADJUST;
- waveformat->nSamplesPerSec = this->spec.freq;
- waveformat->nAvgBytesPerSec = waveformat->nSamplesPerSec * waveformat->nChannels * (waveformat->wBitsPerSample / 8);
- } else {
- this->spec.freq = waveformat->nSamplesPerSec; /* force sampling rate so our resampler kicks in. */
- }
+ streamflags |= (AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY);
+ waveformat->nSamplesPerSec = this->spec.freq;
+ waveformat->nAvgBytesPerSec = waveformat->nSamplesPerSec * waveformat->nChannels * (waveformat->wBitsPerSample / 8);
}
-#endif
streamflags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
ret = IAudioClient_Initialize(client, sharemode, streamflags, 0, 0, waveformat, NULL);