[FFmpeg-cvslog] avfilter/af_vibrato: refactor code

Paul B Mahol git at videolan.org
Tue Aug 8 18:39:40 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Aug  8 11:27:23 2023 +0200| [c7bfc826c351534262a9ee8ab39aa1fa0efe06a7] | committer: Paul B Mahol

avfilter/af_vibrato: refactor code

Move some code out of inner loop.

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

 libavfilter/af_vibrato.c | 49 +++++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/libavfilter/af_vibrato.c b/libavfilter/af_vibrato.c
index 98ef564397..e54ae2ad4b 100644
--- a/libavfilter/af_vibrato.c
+++ b/libavfilter/af_vibrato.c
@@ -54,9 +54,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 {
     AVFilterContext *ctx = inlink->dst;
     VibratoContext *s = ctx->priv;
+    const int wave_table_size = s->wave_table_size;
+    const double *wave_table = s->wave_table;
     AVFilterLink *outlink = ctx->outputs[0];
+    const int channels = s->channels;
+    const int buf_size = s->buf_size;
+    const double depth = s->depth;
+    int wave_table_index = s->wave_table_index;
+    int buf_index = s->buf_index;
     AVFrame *out;
-    int n, c;
     const double *src;
     double *dst;
 
@@ -71,39 +77,40 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         av_frame_copy_props(out, in);
     }
 
-    for (n = 0; n < in->nb_samples; n++) {
+    for (int n = 0; n < in->nb_samples; n++) {
+        int samp1_index, samp2_index;
         double integer, decimal;
-        decimal = modf(s->depth * s->wave_table[s->wave_table_index], &integer);
+        decimal = modf(depth * wave_table[wave_table_index], &integer);
 
-        s->wave_table_index++;
-        if (s->wave_table_index >= s->wave_table_size)
-            s->wave_table_index -= s->wave_table_size;
+        wave_table_index++;
+        if (wave_table_index >= wave_table_size)
+            wave_table_index -= wave_table_size;
 
-        for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
-            int samp1_index, samp2_index;
-            double *buf;
-            double this_samp;
+        samp1_index = buf_index + integer;
+        if (samp1_index >= buf_size)
+            samp1_index -= buf_size;
+        samp2_index = samp1_index + 1;
+        if (samp2_index >= buf_size)
+            samp2_index -= buf_size;
+
+        for (int c = 0; c < channels; c++) {
+            double *buf, this_samp;
 
             src = (const double *)in->extended_data[c];
             dst = (double *)out->extended_data[c];
             buf = s->buf[c];
 
-            samp1_index = s->buf_index + integer;
-            if (samp1_index >= s->buf_size)
-                samp1_index -= s->buf_size;
-            samp2_index = samp1_index + 1;
-            if (samp2_index >= s->buf_size)
-                samp2_index -= s->buf_size;
-
             this_samp = src[n];
             dst[n] = buf[samp1_index] + (decimal * (buf[samp2_index] - buf[samp1_index]));
-            buf[s->buf_index] = this_samp;
+            buf[buf_index] = this_samp;
         }
-        s->buf_index++;
-        if (s->buf_index >= s->buf_size)
-            s->buf_index -= s->buf_size;
+        buf_index++;
+        if (buf_index >= buf_size)
+            buf_index -= buf_size;
     }
 
+    s->wave_table_index = wave_table_index;
+    s->buf_index = buf_index;
     if (in != out)
         av_frame_free(&in);
 



More information about the ffmpeg-cvslog mailing list