From a5175e5ed04eb4b4ad1e40dd55be51d7f684af30 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 27 Sep 2023 11:48:46 -0400
Subject: [PATCH] audio: Fixed bug when setting up mixing formats.
Reference Issue #8226.
---
src/audio/SDL_audio.c | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index cfd169ad6170..585f2d052257 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -173,14 +173,29 @@ void OnAudioStreamDestroy(SDL_AudioStream *stream)
}
+// device should be locked when calling this.
+static SDL_bool AudioDeviceCanUseSimpleCopy(SDL_AudioDevice *device)
+{
+ SDL_assert(device != NULL);
+ return (
+ device->logical_devices && // there's a logical device
+ !device->logical_devices->next && // there's only _ONE_ logical device
+ !device->logical_devices->postmix && // there isn't a postmix callback
+ !SDL_AtomicGet(&device->logical_devices->paused) && // it isn't paused
+ device->logical_devices->bound_streams && // there's a bound stream
+ !device->logical_devices->bound_streams->next_binding // there's only _ONE_ bound stream.
+ ) ? SDL_TRUE : SDL_FALSE;
+}
+
// should hold logdev's physical device's lock before calling.
static void UpdateAudioStreamFormatsLogical(SDL_LogicalAudioDevice *logdev)
{
- const SDL_bool iscapture = logdev->physical_device->iscapture;
+ SDL_AudioDevice *device = logdev->physical_device;
+ const SDL_bool iscapture = device->iscapture;
SDL_AudioSpec spec;
- SDL_copyp(&spec, &logdev->physical_device->spec);
- if (logdev->postmix != NULL) {
- spec.format = SDL_AUDIO_F32;
+ SDL_copyp(&spec, &device->spec);
+ if (!AudioDeviceCanUseSimpleCopy(device)) {
+ spec.format = SDL_AUDIO_F32; // mixing and postbuf operates in float32 format.
}
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) {
@@ -201,20 +216,6 @@ static void UpdateAudioStreamFormatsPhysical(SDL_AudioDevice *device)
}
-// device should be locked when calling this.
-static SDL_bool AudioDeviceCanUseSimpleCopy(SDL_AudioDevice *device)
-{
- SDL_assert(device != NULL);
- return (
- device->logical_devices && // there's a logical device
- !device->logical_devices->next && // there's only _ONE_ logical device
- !device->logical_devices->postmix && // there isn't a postmix callback
- !SDL_AtomicGet(&device->logical_devices->paused) && // it isn't paused
- device->logical_devices->bound_streams && // there's a bound stream
- !device->logical_devices->bound_streams->next_binding // there's only _ONE_ bound stream.
- ) ? SDL_TRUE : SDL_FALSE;
-}
-
// device management and hotplug...