mirror of
https://github.com/mpv-player/mpv
synced 2024-12-19 05:15:12 +00:00
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).
This commit is contained in:
parent
4c6a600943
commit
62269871aa
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user