summaryrefslogtreecommitdiffstats
path: root/audio/filter/af_volume.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-06-23 15:11:23 +0200
committerwm4 <wm4@nowhere>2015-06-23 15:11:23 +0200
commit62269871aa7b52fa08ca08ea91b76ecfd61166e4 (patch)
tree0ddcd42c29167b71c14dda0c082f00fad304dd33 /audio/filter/af_volume.c
parent4c6a600943cf0bc7ef5c51816b471cb688d7cd61 (diff)
downloadmpv-62269871aa7b52fa08ca08ea91b76ecfd61166e4.tar.bz2
mpv-62269871aa7b52fa08ca08ea91b76ecfd61166e4.tar.xz
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).
Diffstat (limited to 'audio/filter/af_volume.c')
-rw-r--r--audio/filter/af_volume.c14
1 files changed, 11 insertions, 3 deletions
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;
}