Browse Source

avfilter: add anlmf filter

Paul B Mahol 3 years ago
parent
commit
209488ccb0
6 changed files with 27 additions and 4 deletions
  1. 1 0
      Changelog
  2. 2 2
      doc/filters.texi
  3. 1 0
      libavfilter/Makefile
  4. 21 1
      libavfilter/af_anlms.c
  5. 1 0
      libavfilter/allfilters.c
  6. 1 1
      libavfilter/version.h

+ 1 - 0
Changelog

@@ -43,6 +43,7 @@ version <next>:
 - adynamicequalizer audio filter
 - adynamicequalizer audio filter
 - yadif_videotoolbox filter
 - yadif_videotoolbox filter
 - VideoToolbox ProRes encoder
 - VideoToolbox ProRes encoder
+- anlmf audio filter
 
 
 
 
 version 4.4:
 version 4.4:

+ 2 - 2
doc/filters.texi

@@ -2301,8 +2301,8 @@ Set smooth factor. Default value is @var{11}. Allowed range is from @var{1} to @
 
 
 This filter supports the all above options as @ref{commands}.
 This filter supports the all above options as @ref{commands}.
 
 
-@section anlms
-Apply Normalized Least-Mean-Squares algorithm to the first audio stream using the second audio stream.
+@section anlmf, anlms
+Apply Normalized Least-Mean-(Squares|Fourth) algorithm to the first audio stream using the second audio stream.
 
 
 This adaptive filter is used to mimic a desired filter by finding the filter coefficients that
 This adaptive filter is used to mimic a desired filter by finding the filter coefficients that
 relate to producing the least mean square of the error signal (difference between the desired,
 relate to producing the least mean square of the error signal (difference between the desired,

+ 1 - 0
libavfilter/Makefile

@@ -71,6 +71,7 @@ OBJS-$(CONFIG_AMIX_FILTER)                   += af_amix.o
 OBJS-$(CONFIG_AMULTIPLY_FILTER)              += af_amultiply.o
 OBJS-$(CONFIG_AMULTIPLY_FILTER)              += af_amultiply.o
 OBJS-$(CONFIG_ANEQUALIZER_FILTER)            += af_anequalizer.o
 OBJS-$(CONFIG_ANEQUALIZER_FILTER)            += af_anequalizer.o
 OBJS-$(CONFIG_ANLMDN_FILTER)                 += af_anlmdn.o
 OBJS-$(CONFIG_ANLMDN_FILTER)                 += af_anlmdn.o
+OBJS-$(CONFIG_ANLMF_FILTER)                  += af_anlms.o
 OBJS-$(CONFIG_ANLMS_FILTER)                  += af_anlms.o
 OBJS-$(CONFIG_ANLMS_FILTER)                  += af_anlms.o
 OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
 OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
 OBJS-$(CONFIG_APAD_FILTER)                   += af_apad.o
 OBJS-$(CONFIG_APAD_FILTER)                   += af_apad.o

+ 21 - 1
libavfilter/af_anlms.c

@@ -54,6 +54,8 @@ typedef struct AudioNLMSContext {
 
 
     AVFrame *frame[2];
     AVFrame *frame[2];
 
 
+    int anlmf;
+
     AVFloatDSPContext *fdsp;
     AVFloatDSPContext *fdsp;
 } AudioNLMSContext;
 } AudioNLMSContext;
 
 
@@ -74,7 +76,7 @@ static const AVOption anlms_options[] = {
     { NULL }
     { NULL }
 };
 };
 
 
-AVFILTER_DEFINE_CLASS(anlms);
+AVFILTER_DEFINE_CLASS_EXT(anlms, "anlm(f|s)", anlms_options);
 
 
 static int query_formats(AVFilterContext *ctx)
 static int query_formats(AVFilterContext *ctx)
 {
 {
@@ -130,6 +132,8 @@ static float process_sample(AudioNLMSContext *s, float input, float desired,
 
 
     norm = s->eps + sum;
     norm = s->eps + sum;
     b = mu * e / norm;
     b = mu * e / norm;
+    if (s->anlmf)
+        b *= 4.f * e * e;
 
 
     memcpy(tmp, delay + offset, order * sizeof(float));
     memcpy(tmp, delay + offset, order * sizeof(float));
 
 
@@ -241,6 +245,7 @@ static int config_output(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AVFilterContext *ctx = outlink->src;
     AudioNLMSContext *s = ctx->priv;
     AudioNLMSContext *s = ctx->priv;
 
 
+    s->anlmf = !strcmp(ctx->filter->name, "anlmf");
     s->kernel_size = FFALIGN(s->order, 16);
     s->kernel_size = FFALIGN(s->order, 16);
 
 
     if (!s->offset)
     if (!s->offset)
@@ -312,3 +317,18 @@ const AVFilter ff_af_anlms = {
     .flags          = AVFILTER_FLAG_SLICE_THREADS,
     .flags          = AVFILTER_FLAG_SLICE_THREADS,
     .process_command = ff_filter_process_command,
     .process_command = ff_filter_process_command,
 };
 };
+
+const AVFilter ff_af_anlmf = {
+    .name           = "anlmf",
+    .description    = NULL_IF_CONFIG_SMALL("Apply Normalized Least-Mean-Fourth algorithm to first audio stream."),
+    .priv_size      = sizeof(AudioNLMSContext),
+    .priv_class     = &anlms_class,
+    .init           = init,
+    .uninit         = uninit,
+    .activate       = activate,
+    FILTER_INPUTS(inputs),
+    FILTER_OUTPUTS(outputs),
+    FILTER_QUERY_FUNC(query_formats),
+    .flags          = AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = ff_filter_process_command,
+};

+ 1 - 0
libavfilter/allfilters.c

@@ -64,6 +64,7 @@ extern const AVFilter ff_af_amix;
 extern const AVFilter ff_af_amultiply;
 extern const AVFilter ff_af_amultiply;
 extern const AVFilter ff_af_anequalizer;
 extern const AVFilter ff_af_anequalizer;
 extern const AVFilter ff_af_anlmdn;
 extern const AVFilter ff_af_anlmdn;
+extern const AVFilter ff_af_anlmf;
 extern const AVFilter ff_af_anlms;
 extern const AVFilter ff_af_anlms;
 extern const AVFilter ff_af_anull;
 extern const AVFilter ff_af_anull;
 extern const AVFilter ff_af_apad;
 extern const AVFilter ff_af_apad;

+ 1 - 1
libavfilter/version.h

@@ -30,7 +30,7 @@
 #include "libavutil/version.h"
 #include "libavutil/version.h"
 
 
 #define LIBAVFILTER_VERSION_MAJOR   8
 #define LIBAVFILTER_VERSION_MAJOR   8
-#define LIBAVFILTER_VERSION_MINOR  20
+#define LIBAVFILTER_VERSION_MINOR  21
 #define LIBAVFILTER_VERSION_MICRO 100
 #define LIBAVFILTER_VERSION_MICRO 100