[FFmpeg-cvslog] avfilter/af_asubboost: add boost option

Paul B Mahol git at videolan.org
Fri May 13 16:17:13 EEST 2022


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri May 13 14:19:43 2022 +0200| [075c2308e3eb0421c4f708633ff1b1c5d5062105] | committer: Paul B Mahol

avfilter/af_asubboost: add boost option

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=075c2308e3eb0421c4f708633ff1b1c5d5062105
---

 doc/filters.texi           |  9 ++++++---
 libavfilter/af_asubboost.c | 20 ++++++++++++++------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 8e7cb6beef..e7623b7967 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -3131,15 +3131,18 @@ The filter accepts the following options:
 @table @option
 @item dry
 Set dry gain, how much of original signal is kept. Allowed range is from 0 to 1.
-Default value is 0.7.
+Default value is 1.0.
 
 @item wet
 Set wet gain, how much of filtered signal is kept. Allowed range is from 0 to 1.
-Default value is 0.7.
+Default value is 1.0.
+
+ at item boost
+Set max boost factor. Allowed range is from 1 to 12. Default value is 2.
 
 @item decay
 Set delay line decay gain value. Allowed range is from 0 to 1.
-Default value is 0.7.
+Default value is 0.0.
 
 @item feedback
 Set delay line feedback gain value. Allowed range is from 0 to 1.
diff --git a/libavfilter/af_asubboost.c b/libavfilter/af_asubboost.c
index 11b0825f97..1eb079e3b6 100644
--- a/libavfilter/af_asubboost.c
+++ b/libavfilter/af_asubboost.c
@@ -29,6 +29,7 @@ typedef struct ASubBoostContext {
     double dry_gain;
     double wet_gain;
     double feedback;
+    double max_boost;
     double decay;
     double delay;
     double cutoff;
@@ -75,7 +76,7 @@ static int config_input(AVFilterLink *inlink)
     ASubBoostContext *s = ctx->priv;
 
     s->buffer = ff_get_audio_buffer(inlink, inlink->sample_rate / 10);
-    s->w = ff_get_audio_buffer(inlink, 2);
+    s->w = ff_get_audio_buffer(inlink, 3);
     s->write_pos = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->write_pos));
     if (!s->buffer || !s->w || !s->write_pos)
         return AVERROR(ENOMEM);
@@ -97,6 +98,7 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
     const double wet = ctx->is_disabled ? 1. : s->wet_gain;
     const double dry = ctx->is_disabled ? 1. : s->dry_gain;
     const double feedback = s->feedback, decay = s->decay;
+    const double max_boost = s->max_boost;
     const double b0 = s->b0;
     const double b1 = s->b1;
     const double b2 = s->b2;
@@ -112,16 +114,21 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
         double *buffer = (double *)s->buffer->extended_data[ch];
         double *w = (double *)s->w->extended_data[ch];
         int write_pos = s->write_pos[ch];
+        const double a = 0.00001;
+        const double b = 1. - a;
 
         for (int n = 0; n < in->nb_samples; n++) {
-            double out_sample;
+            double out_sample, boost;
 
             out_sample = src[n] * b0 + w[0];
             w[0] = b1 * src[n] + w[1] + a1 * out_sample;
             w[1] = b2 * src[n] + a2 * out_sample;
 
             buffer[write_pos] = buffer[write_pos] * decay + out_sample * feedback;
-            dst[n] = (src[n] * dry + buffer[write_pos] * mix) * wet;
+            boost = av_clipd((1. -  (fabs(src[n] * dry))) / fabs(buffer[write_pos]), 0., max_boost);
+            w[2] = boost > w[2] ? w[2] * b + a * boost : w[2] * a + b * boost;
+            w[2] = av_clipd(w[2], 0., max_boost);
+            dst[n] = (src[n] * dry + w[2] * buffer[write_pos] * mix) * wet;
 
             if (++write_pos >= buffer_samples)
                 write_pos = 0;
@@ -185,9 +192,10 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar
 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 
 static const AVOption asubboost_options[] = {
-    { "dry",      "set dry gain", OFFSET(dry_gain), AV_OPT_TYPE_DOUBLE, {.dbl=0.7},      0,   1, FLAGS },
-    { "wet",      "set wet gain", OFFSET(wet_gain), AV_OPT_TYPE_DOUBLE, {.dbl=0.7},      0,   1, FLAGS },
-    { "decay",    "set decay",    OFFSET(decay),    AV_OPT_TYPE_DOUBLE, {.dbl=0.7},      0,   1, FLAGS },
+    { "dry",      "set dry gain", OFFSET(dry_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1.0},      0,   1, FLAGS },
+    { "wet",      "set wet gain", OFFSET(wet_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1.0},      0,   1, FLAGS },
+    { "boost",    "set max boost",OFFSET(max_boost),AV_OPT_TYPE_DOUBLE, {.dbl=2.0},      1,  12, FLAGS },
+    { "decay",    "set decay",    OFFSET(decay),    AV_OPT_TYPE_DOUBLE, {.dbl=0.0},      0,   1, FLAGS },
     { "feedback", "set feedback", OFFSET(feedback), AV_OPT_TYPE_DOUBLE, {.dbl=0.9},      0,   1, FLAGS },
     { "cutoff",   "set cutoff",   OFFSET(cutoff),   AV_OPT_TYPE_DOUBLE, {.dbl=100},     50, 900, FLAGS },
     { "slope",    "set slope",    OFFSET(slope),    AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0.0001,   1, FLAGS },



More information about the ffmpeg-cvslog mailing list