summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-05-05 01:21:57 +0200
committerwm4 <wm4@nowhere>2017-05-05 01:22:06 +0200
commit698416ee9767c104b53f816c3596192515ded2b5 (patch)
tree21ef1ce7944abbe3b30e832a19d732746516c88d /player
parent5757db844a449ed6a1e0fadb2bd62bae6852c78a (diff)
downloadmpv-698416ee9767c104b53f816c3596192515ded2b5.tar.bz2
mpv-698416ee9767c104b53f816c3596192515ded2b5.tar.xz
audio: replace from_dB function
The author of the old code disagreed with LGPL. The new code is a clean room reimplementation by Niklas Haas. It lacks the clamping, but we decided it doesn't matter. Untested, bugs can be fixed later anyway.
Diffstat (limited to 'player')
-rw-r--r--player/audio.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/player/audio.c b/player/audio.c
index 0922db804c..51c84afb7a 100644
--- a/player/audio.c
+++ b/player/audio.c
@@ -119,13 +119,9 @@ fail:
mp_notify(mpctx, MP_EVENT_CHANGE_ALL, NULL);
}
-// Convert to gain value from dB. input <= -200dB will become 0 gain.
-// Copyright (C)2002 Anders Johansson
-static float from_dB(float in, float k, float mi, float ma)
+static double db_gain(double db)
{
- if (in <= -200)
- return 0.0;
- return pow(10.0, MPCLAMP(in, mi, ma) / k);
+ return pow(10.0, db/20.0);
}
static float compute_replaygain(struct MPContext *mpctx)
@@ -151,7 +147,7 @@ static float compute_replaygain(struct MPContext *mpctx)
}
gain += opts->rgain_preamp;
- rgain = from_dB(gain, 20.0, -200.0, 60.0);
+ rgain = db_gain(gain);
MP_VERBOSE(mpctx, "Applying replay-gain: %f\n", rgain);
@@ -160,7 +156,7 @@ static float compute_replaygain(struct MPContext *mpctx)
MP_VERBOSE(mpctx, "...with clipping prevention: %f\n", rgain);
}
} else if (opts->rgain_fallback) {
- rgain = from_dB(opts->rgain_fallback, 20.0, -200.0, 60.0);
+ rgain = db_gain(opts->rgain_fallback);
MP_VERBOSE(mpctx, "Applying fallback gain: %f\n", rgain);
}