From 8b06fc86f38e62d2dfed58eeb03d5dad597047e1 Mon Sep 17 00:00:00 2001 From: Mohammad Alsaleh Date: Sat, 28 Jun 2014 02:58:57 +0300 Subject: af_volume: fix calculations including replay-gain rgain is not an additive value. It's a multiplier/gain. Previous behaviour produced negative level values in some cases (when rgain < 1.0) which caused volume to be louder when its value was lowered. CC: @mpv-player/stable Signed-off-by: Mohammad Alsaleh Signed-off-by: wm4 --- audio/filter/af_volume.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/audio/filter/af_volume.c b/audio/filter/af_volume.c index f07914313b..f9f4a4ac40 100644 --- a/audio/filter/af_volume.c +++ b/audio/filter/af_volume.c @@ -79,7 +79,7 @@ static int control(struct af_instance *af, int cmd, void *arg) if (!s->rgain_clip) // clipping prevention s->rgain = MPMIN(s->rgain, 1.0 / peak); } - if (s->detach && fabs(s->level + s->rgain - 2.0) < 0.00001) + if (s->detach && fabs(s->level * s->rgain - 1.0) < 0.00001) return AF_DETACH; return af_test_output(af, in); } @@ -97,7 +97,7 @@ static void filter_plane(struct af_instance *af, void *ptr, int num_samples) { struct priv *s = af->priv; - float level = s->level + s->rgain - 1.0; + float level = s->level * s->rgain; if (af_fmt_from_planar(af->data->format) == AF_FORMAT_S16) { int16_t *a = ptr; -- cgit v1.2.3