[FFmpeg-cvslog] avfilter/af_anlmdn: use lut table to calculate weights

Paul B Mahol git at videolan.org
Thu Jan 10 22:53:55 EET 2019


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Thu Jan 10 12:00:56 2019 +0100| [395e8a53fa0266f26581f3e9752b0dbc93998a90] | committer: Paul B Mahol

avfilter/af_anlmdn: use lut table to calculate weights

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

 libavfilter/af_anlmdn.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/libavfilter/af_anlmdn.c b/libavfilter/af_anlmdn.c
index 79c5ce0f4f..6d9e89f44c 100644
--- a/libavfilter/af_anlmdn.c
+++ b/libavfilter/af_anlmdn.c
@@ -29,6 +29,10 @@
 
 #include "af_anlmdndsp.h"
 
+#define MAX_DIFF         11.f
+#define WEIGHT_LUT_NBITS 20
+#define WEIGHT_LUT_SIZE  (1<<WEIGHT_LUT_NBITS)
+
 #define SQR(x) ((x) * (x))
 
 typedef struct AudioNLMeansContext {
@@ -38,6 +42,9 @@ typedef struct AudioNLMeansContext {
     int64_t pd;
     int64_t rd;
 
+    float pdiff_lut_scale;
+    float weight_lut[WEIGHT_LUT_SIZE];
+
     int K;
     int S;
     int N;
@@ -150,6 +157,13 @@ static int config_output(AVFilterLink *outlink)
     if (!s->fifo)
         return AVERROR(ENOMEM);
 
+    s->pdiff_lut_scale = 1.f / MAX_DIFF * WEIGHT_LUT_SIZE;
+    for (int i = 0; i < WEIGHT_LUT_SIZE; i++) {
+        float w = -i / s->pdiff_lut_scale;
+
+        s->weight_lut[i] = expf(w);
+    }
+
     ff_anlmdn_init(&s->dsp);
 
     return 0;
@@ -183,13 +197,16 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
 
         for (int j = 0; j < 2 * S; j++) {
             const float distance = cache[j];
+            unsigned weight_lut_idx;
             float w;
 
-            av_assert0(distance >= 0.f);
-            w = -distance * sw;
-            if (w < -11.f)
+            av_assert2(distance >= 0.f);
+            w = distance * sw;
+            if (w >= MAX_DIFF)
                 continue;
-            w = expf(w);
+            weight_lut_idx = w * s->pdiff_lut_scale;
+            av_assert2(weight_lut_idx < WEIGHT_LUT_SIZE);
+            w = s->weight_lut[weight_lut_idx];
             P += w * f[i - S + j + (j >= S)];
             Q += w;
         }



More information about the ffmpeg-cvslog mailing list