mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
5757db844a
commit
698416ee97
|
@ -119,13 +119,9 @@ fail:
|
||||||
mp_notify(mpctx, MP_EVENT_CHANGE_ALL, NULL);
|
mp_notify(mpctx, MP_EVENT_CHANGE_ALL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to gain value from dB. input <= -200dB will become 0 gain.
|
static double db_gain(double db)
|
||||||
// Copyright (C)2002 Anders Johansson
|
|
||||||
static float from_dB(float in, float k, float mi, float ma)
|
|
||||||
{
|
{
|
||||||
if (in <= -200)
|
return pow(10.0, db/20.0);
|
||||||
return 0.0;
|
|
||||||
return pow(10.0, MPCLAMP(in, mi, ma) / k);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static float compute_replaygain(struct MPContext *mpctx)
|
static float compute_replaygain(struct MPContext *mpctx)
|
||||||
|
@ -151,7 +147,7 @@ static float compute_replaygain(struct MPContext *mpctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
gain += opts->rgain_preamp;
|
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);
|
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);
|
MP_VERBOSE(mpctx, "...with clipping prevention: %f\n", rgain);
|
||||||
}
|
}
|
||||||
} else if (opts->rgain_fallback) {
|
} 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);
|
MP_VERBOSE(mpctx, "Applying fallback gain: %f\n", rgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue