[FFmpeg-cvslog] avfilter/af_afftdn: refactor set_noise_profile()

Paul B Mahol git at videolan.org
Fri Mar 18 12:23:21 EET 2022


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Mar 18 10:38:15 2022 +0100| [28447a4290e2a0c653f985e5d66181bffc372b06] | committer: Paul B Mahol

avfilter/af_afftdn: refactor set_noise_profile()

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

 libavfilter/af_afftdn.c | 65 +++++++++++++++++--------------------------------
 1 file changed, 23 insertions(+), 42 deletions(-)

diff --git a/libavfilter/af_afftdn.c b/libavfilter/af_afftdn.c
index d6154f3fbd..75895fa3d9 100644
--- a/libavfilter/af_afftdn.c
+++ b/libavfilter/af_afftdn.c
@@ -912,58 +912,39 @@ static void finish_sample_noise(AudioFFTDeNoiseContext *s,
 
 static void set_noise_profile(AudioFFTDeNoiseContext *s,
                               DeNoiseChannel *dnch,
-                              double *sample_noise,
-                              int new_profile)
+                              double *sample_noise)
 {
     double new_band_noise[NB_PROFILE_BANDS];
     double temp[NB_PROFILE_BANDS];
-    double sum = 0.0, d1;
-    float new_noise_floor;
-    int i = 0, n;
+    double sum = 0.0;
 
     for (int m = 0; m < NB_PROFILE_BANDS; m++)
         temp[m] = sample_noise[m];
 
-    if (new_profile) {
-        for (int m = 0; m < SOLVE_SIZE; m++) {
-            sum = 0.0;
-            for (n = 0; n < NB_PROFILE_BANDS; n++)
-                sum += s->matrix_b[i++] * temp[n];
-            s->vector_b[m] = sum;
-        }
-        solve(s->matrix_a, s->vector_b, SOLVE_SIZE);
-        i = 0;
-        for (int m = 0; m < NB_PROFILE_BANDS; m++) {
-            sum = 0.0;
-            for (n = 0; n < SOLVE_SIZE; n++)
-                sum += s->matrix_c[i++] * s->vector_b[n];
-            temp[m] = sum;
-        }
+    for (int m = 0, i = 0; m < SOLVE_SIZE; m++) {
+        sum = 0.0;
+        for (int n = 0; n < NB_PROFILE_BANDS; n++)
+            sum += s->matrix_b[i++] * temp[n];
+        s->vector_b[m] = sum;
+    }
+    solve(s->matrix_a, s->vector_b, SOLVE_SIZE);
+    for (int m = 0, i = 0; m < NB_PROFILE_BANDS; m++) {
+        sum = 0.0;
+        for (int n = 0; n < SOLVE_SIZE; n++)
+            sum += s->matrix_c[i++] * s->vector_b[n];
+        temp[m] = sum;
     }
 
-    sum = 0.0;
-    for (int m = 0; m < NB_PROFILE_BANDS; m++)
-        sum += temp[m];
-
-    d1 = sum / NB_PROFILE_BANDS;
-    for (int m = 0; m < NB_PROFILE_BANDS; m++)
-        temp[m] -= d1;
-
-    new_noise_floor = d1;
+    reduce_mean(temp);
 
-    if (new_profile) {
-        av_log(s, AV_LOG_INFO, "bn=");
-        for (int m = 0; m < NB_PROFILE_BANDS; m++) {
-            new_band_noise[m] = temp[m];
-            new_band_noise[m] = av_clipd(new_band_noise[m], -24.0, 24.0);
-            av_log(s, AV_LOG_INFO, "%f ", new_band_noise[m]);
-        }
-        av_log(s, AV_LOG_INFO, "\n");
-        memcpy(dnch->band_noise, new_band_noise, sizeof(new_band_noise));
+    av_log(s, AV_LOG_INFO, "bn=");
+    for (int m = 0; m < NB_PROFILE_BANDS; m++) {
+        new_band_noise[m] = temp[m];
+        new_band_noise[m] = av_clipd(new_band_noise[m], -24.0, 24.0);
+        av_log(s, AV_LOG_INFO, "%f ", new_band_noise[m]);
     }
-
-    if (s->track_noise)
-        dnch->noise_floor = new_noise_floor;
+    av_log(s, AV_LOG_INFO, "\n");
+    memcpy(dnch->band_noise, new_band_noise, sizeof(new_band_noise));
 }
 
 static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@@ -1074,7 +1055,7 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in)
             double sample_noise[NB_PROFILE_BANDS];
 
             finish_sample_noise(s, dnch, sample_noise);
-            set_noise_profile(s, dnch, sample_noise, 1);
+            set_noise_profile(s, dnch, sample_noise);
             set_parameters(s, dnch, 1, 1);
         }
         s->sample_noise = 0;



More information about the ffmpeg-cvslog mailing list