From fafbea1ced33d891e71cc5cc9f71626b2c1fd7a6 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 7 Sep 2023 10:48:04 -0400
Subject: [PATCH] audio: Move internal float32 mixing to a simplified function
---
src/audio/SDL_audio.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index c5f32a3c2abb..11dd3e312655 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -677,6 +677,13 @@ void SDL_AudioThreadFinalize(SDL_AudioDevice *device)
SDL_AtomicSet(&device->thread_alive, 0);
}
+static void MixFloat32Audio(float *dst, const float *src, const int buffer_size)
+{
+ if (SDL_MixAudioFormat((Uint8 *) dst, (const Uint8 *) src, SDL_AUDIO_F32, buffer_size, SDL_MIX_MAXVOLUME) < 0) {
+ SDL_assert(!"This shouldn't happen.");
+ }
+}
+
// Output device thread. This is split into chunks, so backends that need to control this directly can use the pieces they need without duplicating effort.
@@ -754,11 +761,7 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
retval = SDL_FALSE;
break;
} else if (br > 0) { // it's okay if we get less than requested, we mix what we have.
- if (SDL_MixAudioFormat((Uint8 *) mix_buffer, device->work_buffer, SDL_AUDIO_F32, br, SDL_MIX_MAXVOLUME) < 0) { // !!! FIXME: allow streams to specify gain?
- SDL_assert(!"This shouldn't happen.");
- retval = SDL_FALSE; // uh...?
- break;
- }
+ MixFloat32Audio(mix_buffer, (float *) device->work_buffer, br);
}
}
}