From 698416ee9767c104b53f816c3596192515ded2b5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 5 May 2017 01:21:57 +0200 Subject: 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. --- player/audio.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'player/audio.c') 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); } -- cgit v1.2.3