summaryrefslogtreecommitdiff
path: root/libavfilter/af_afir.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2017-12-31 19:09:07 +0100
committerPaul B Mahol <onemda@gmail.com>2017-12-31 19:16:22 +0100
commitf3552c3b9d517e278ec45d5e2bd53bf3e7dc754b (patch)
tree7565bd5cc1b0f80c49e773a7c433a8fa15ef76c3 /libavfilter/af_afir.c
parent0e1f771d2200d14d298df09c91e14f51e418fd3a (diff)
avfilter/af_afir: rework FIR gain measurement
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/af_afir.c')
-rw-r--r--libavfilter/af_afir.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
index c81a1e22cf..6687242631 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -105,7 +105,7 @@ static int fir_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
if (out) {
float *ptr = (float *)out->extended_data[ch];
- s->fdsp->vector_fmul_scalar(ptr, dst, s->gain * s->wet_gain, FFALIGN(out->nb_samples, 4));
+ s->fdsp->vector_fmul_scalar(ptr, dst, s->wet_gain, FFALIGN(out->nb_samples, 4));
emms_c();
}
@@ -166,7 +166,6 @@ static int convert_coeffs(AVFilterContext *ctx)
{
AudioFIRContext *s = ctx->priv;
int i, ch, n, N;
- float power = 0;
s->nb_taps = av_audio_fifo_size(s->fifo[1]);
if (s->nb_taps <= 0)
@@ -217,13 +216,29 @@ static int convert_coeffs(AVFilterContext *ctx)
av_audio_fifo_read(s->fifo[1], (void **)s->in[1]->extended_data, s->nb_taps);
+ if (s->again) {
+ float power = 0;
+
+ for (ch = 0; ch < ctx->inputs[1]->channels; ch++) {
+ float *time = (float *)s->in[1]->extended_data[!s->one2many * ch];
+
+ for (i = 0; i < s->nb_taps; i++)
+ power += FFABS(time[i]);
+ }
+
+ s->gain = sqrtf(1.f / (ctx->inputs[1]->channels * power)) / (sqrtf(ctx->inputs[1]->channels));
+ for (ch = 0; ch < ctx->inputs[1]->channels; ch++) {
+ float *time = (float *)s->in[1]->extended_data[!s->one2many * ch];
+
+ s->fdsp->vector_fmul_scalar(time, time, s->gain, FFALIGN(s->nb_taps, 4));
+ }
+ }
+
for (ch = 0; ch < ctx->inputs[1]->channels; ch++) {
float *time = (float *)s->in[1]->extended_data[!s->one2many * ch];
float *block = s->block[ch];
FFTComplex *coeff = s->coeff[ch];
- power += s->fdsp->scalarproduct_float(time, time, s->nb_taps);
-
for (i = FFMAX(1, s->length * s->nb_taps); i < s->nb_taps; i++)
time[i] = 0;
@@ -252,7 +267,6 @@ static int convert_coeffs(AVFilterContext *ctx)
}
av_frame_free(&s->in[1]);
- s->gain = s->again ? 1.f / sqrtf(power / ctx->inputs[1]->channels) : 1.f;
av_log(ctx, AV_LOG_DEBUG, "nb_taps: %d\n", s->nb_taps);
av_log(ctx, AV_LOG_DEBUG, "nb_partitions: %d\n", s->nb_partitions);
av_log(ctx, AV_LOG_DEBUG, "partition size: %d\n", s->part_size);