From 62269871aa7b52fa08ca08ea91b76ecfd61166e4 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 23 Jun 2015 15:11:23 +0200 Subject: af: move af_from_dB() function to af_volume.c And also simplify it (it certainly had the most awkward API you could think of for such a simple function). --- audio/filter/af.h | 1 - audio/filter/af_volume.c | 14 +++++++++++--- audio/filter/tools.c | 18 ------------------ 3 files changed, 11 insertions(+), 22 deletions(-) (limited to 'audio') diff --git a/audio/filter/af.h b/audio/filter/af.h index e8beac9631..88cbbc0119 100644 --- a/audio/filter/af.h +++ b/audio/filter/af.h @@ -157,7 +157,6 @@ double af_calc_delay(struct af_stream *s); int af_test_output(struct af_instance *af, struct mp_audio *out); -int af_from_dB(int n, float *in, float *out, float k, float mi, float ma); int af_from_ms(int n, float *in, int *out, int rate, float mi, float ma); float af_softclip(float a); diff --git a/audio/filter/af_volume.c b/audio/filter/af_volume.c index 8de9d8dfa9..d66e38c0e1 100644 --- a/audio/filter/af_volume.c +++ b/audio/filter/af_volume.c @@ -44,6 +44,14 @@ struct priv { float cfg_volume; }; +// Convert to gain value from dB. input <= -200dB will become 0 gain. +static float from_dB(float in, float k, float mi, float ma) +{ + if (in <= -200) + return 0.0; + return pow(10.0, MPCLAMP(in, mi, ma) / k); +} + static int control(struct af_instance *af, int cmd, void *arg) { struct priv *s = af->priv; @@ -75,7 +83,7 @@ static int control(struct af_instance *af, int cmd, void *arg) } gain += s->rgain_preamp; - af_from_dB(1, &gain, &s->rgain, 20.0, -200.0, 60.0); + s->rgain = from_dB(gain, 20.0, -200.0, 60.0); MP_VERBOSE(af, "Applying replay-gain: %f\n", s->rgain); @@ -84,7 +92,7 @@ static int control(struct af_instance *af, int cmd, void *arg) MP_VERBOSE(af, "...with clipping prevention: %f\n", s->rgain); } } else if (s->replaygain_fallback) { - af_from_dB(1, &s->replaygain_fallback, &s->rgain, 20.0, -200.0, 60.0); + s->rgain = from_dB(s->replaygain_fallback, 20.0, -200.0, 60.0); MP_VERBOSE(af, "Applying fallback gain: %f\n", s->rgain); } if (s->detach && fabs(s->level * s->rgain - 1.0) < 0.00001) @@ -150,7 +158,7 @@ static int af_open(struct af_instance *af) struct priv *s = af->priv; af->control = control; af->filter_frame = filter; - af_from_dB(1, &s->cfg_volume, &s->level, 20.0, -200.0, 60.0); + s->level = from_dB(s->cfg_volume, 20.0, -200.0, 60.0); return AF_OK; } diff --git a/audio/filter/tools.c b/audio/filter/tools.c index a465e7ec2a..4ebea64d4a 100644 --- a/audio/filter/tools.c +++ b/audio/filter/tools.c @@ -21,24 +21,6 @@ #include "common/common.h" #include "af.h" -/* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if - * fail. input <= -200dB will become 0 gain. */ -int af_from_dB(int n, float* in, float* out, float k, float mi, float ma) -{ - int i = 0; - // Sanity check - if(!in || !out) - return AF_ERROR; - - for(i=0;i