From ffe6a4f4b6f56296165cea8651f35563d168ac89 Mon Sep 17 00:00:00 2001 From: Quinten Kock Date: Wed, 21 Jun 2023 20:51:11 +0200 Subject: [PATCH] Make setGenericVolume keep balance between channels Previously setGenericVolume would apply the same amount of difference on all channels, making e.g. 100%/50% -> 80%/30%. This commit changes it to keep the ratios equal instead, so that the resulting volume would be 80%/40%, keeping the balance the same. BUG: 435840 FIXED-IN: 5.27.7 (cherry picked from commit cfe4a360f2640d7bd4e2d936804b100a299b268a) --- src/context.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/context.h b/src/context.h index 3d1f7525..969fa13b 100644 --- a/src/context.h +++ b/src/context.h @@ -123,9 +123,12 @@ public: newVolume = qBound(0, newVolume, PA_VOLUME_MAX); pa_cvolume newCVolume = cVolume; if (channel == -1) { // -1 all channels - const qint64 diff = newVolume - pa_cvolume_max(&cVolume); + const qint64 orig = pa_cvolume_max(&cVolume); + const qint64 diff = newVolume - orig; for (int i = 0; i < newCVolume.channels; ++i) { - newCVolume.values[i] = qBound(0, newCVolume.values[i] + diff, PA_VOLUME_MAX); + const qint64 channel = newCVolume.values[i]; + const qint64 channelDiff = orig == 0 ? diff : diff * channel / orig; + newCVolume.values[i] = qBound(0, newCVolume.values[i] + channelDiff, PA_VOLUME_MAX); } } else { Q_ASSERT(newCVolume.channels > channel); -- GitLab