SDL: testaudiocapture: Make sure we convert captured audio to output format.

From f290c85b223c8d0f956b90eb093712fc65297fed Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 11 Aug 2023 16:52:23 -0400
Subject: [PATCH] testaudiocapture: Make sure we convert captured audio to
 output format.

Fixes #8114.
---
 test/testaudiocapture.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/test/testaudiocapture.c b/test/testaudiocapture.c
index 8755079b4783..fd83d29f8784 100644
--- a/test/testaudiocapture.c
+++ b/test/testaudiocapture.c
@@ -98,7 +98,8 @@ int main(int argc, char **argv)
 {
     SDL_AudioDeviceID *devices;
     SDLTest_CommonState *state;
-    SDL_AudioSpec spec;
+    SDL_AudioSpec outspec;
+    SDL_AudioSpec inspec;
     SDL_AudioDeviceID device;
     SDL_AudioDeviceID want_device = SDL_AUDIO_DEVICE_DEFAULT_CAPTURE;
     const char *devname = NULL;
@@ -178,8 +179,8 @@ int main(int argc, char **argv)
         exit(1);
     }
     SDL_PauseAudioDevice(device);
-    SDL_GetAudioDeviceFormat(device, &spec);
-    stream_out = SDL_CreateAndBindAudioStream(device, &spec);
+    SDL_GetAudioDeviceFormat(device, &outspec);
+    stream_out = SDL_CreateAndBindAudioStream(device, &outspec);
     if (!stream_out) {
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError());
         SDL_Quit();
@@ -198,14 +199,16 @@ int main(int argc, char **argv)
         exit(1);
     }
     SDL_PauseAudioDevice(device);
-    SDL_GetAudioDeviceFormat(device, &spec);
-    stream_in = SDL_CreateAndBindAudioStream(device, &spec);
+    SDL_GetAudioDeviceFormat(device, &inspec);
+    stream_in = SDL_CreateAndBindAudioStream(device, &inspec);
     if (!stream_in) {
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for capture: %s!\n", SDL_GetError());
         SDL_Quit();
         exit(1);
     }
 
+    SDL_SetAudioStreamFormat(stream_in, NULL, &outspec);  /* make sure we output at the playback format. */
+
     SDL_Log("Ready! Hold down mouse or finger to record!\n");
 
 #ifdef __EMSCRIPTEN__