From 9dac3cbd6089b95b1ad17b29c39440d597f163a0 Mon Sep 17 00:00:00 2001 From: cvde <4895293+cvde@users.noreply.github.com> Date: Sun, 29 Oct 2023 13:07:50 +0100 Subject: [PATCH] Adjusted the gain compensation to not lose gain due to applied pan stages (Issue #1086) --- src/sfizz/Voice.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 1a0823fa..3315fb69 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -980,6 +980,10 @@ void Voice::Impl::panStageMono(AudioSpan buffer) noexcept (*modulationSpan)[i] += mod[i]; } pan(*modulationSpan, leftBuffer, rightBuffer); + + // add +3dB (10^(3/20)) to compensate for the pan stage (-3dB per stage) + applyGain1(1.4125375446227544f, leftBuffer); + applyGain1(1.4125375446227544f, rightBuffer); } void Voice::Impl::panStageStereo(AudioSpan buffer) noexcept @@ -1020,9 +1024,9 @@ void Voice::Impl::panStageStereo(AudioSpan buffer) noexcept } pan(*modulationSpan, leftBuffer, rightBuffer); - // add +3dB to compensate for the 2 pan stages (-3dB each stage) - applyGain1(1.4125375446227544f, leftBuffer); - applyGain1(1.4125375446227544f, rightBuffer); + // add +6dB (10^(6/20)) to compensate for the 2 pan stages (-3dB per stage) + applyGain1(1.9952623149688797f, leftBuffer); + applyGain1(1.9952623149688797f, rightBuffer); } void Voice::Impl::filterStageMono(AudioSpan buffer) noexcept