From 40aef0a1f927b5882a8bad4c353d4bcef9a561e8 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Wed, 15 Jan 2025 21:31:19 +0300 Subject: [PATCH] scale in mixing to prevent excessive gain --- src/twn_audio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/twn_audio.c b/src/twn_audio.c index 61b20f1..c39ebc9 100644 --- a/src/twn_audio.c +++ b/src/twn_audio.c @@ -366,9 +366,11 @@ static void audio_mixin_streams(const AudioChannel *channel, for (size_t s = 0; s < frames; ++s) { /* left channel */ sa[s * 2 + 0] += (float)(sb[s * 2 + 0] * channel->volume * left_panning); + sa[s * 2 + 0] *= 1 / (float)M_2_SQRTPI; /* right channel */ sa[s * 2 + 1] += (float)(sb[s * 2 + 1] * channel->volume * right_panning); + sa[s * 2 + 1] *= 1 / (float)M_2_SQRTPI; } }