From 5b0e838a7433daf0d44aff10574791cced63113e Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 28 Oct 2024 13:42:23 -0400
Subject: [PATCH] wasapi: Deal with device buffer sizes changing.
Otherwise, it would fill the previous size's worth of data into the current
size's buffer.
Fixes #11122.
---
src/audio/wasapi/SDL_wasapi.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index cf90efc0f9d85..ecb1c14b3e473 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -111,6 +111,12 @@ static int UpdateAudioStream(_THIS, const SDL_AudioSpec *oldspec)
}
}
+ /* if the device sample size changed, make sure we're asking for enough data. */
+ if (this->callbackspec.samples != this->spec.samples) {
+ this->callbackspec.samples = this->spec.samples;
+ SDL_CalculateAudioSpec(&this->callbackspec);
+ }
+
/* make sure our scratch buffer can cover the new device spec. */
if (this->spec.size > this->work_buffer_len) {
Uint8 *ptr = (Uint8 *)SDL_realloc(this->work_buffer, this->spec.size);