summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
Diffstat (limited to 'audio')
-rw-r--r--audio/filter/af.h1
-rw-r--r--audio/filter/af_volume.c14
-rw-r--r--audio/filter/tools.c18
3 files changed, 11 insertions, 22 deletions
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<n;i++){
- if(in[i]<=-200)
- out[i]=0.0;
- else
- out[i]=pow(10.0,MPCLAMP(in[i],mi,ma)/k);
- }
- return AF_OK;
-}
-
/* Convert from ms to sample time */
int af_from_ms(int n, float* in, int* out, int rate, float mi, float ma)
{