[FFmpeg-cvslog] avfilter/avf_showspectrum: reduce number of operations

Paul B Mahol git at videolan.org
Tue Jan 12 21:26:09 CET 2016


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Jan 10 18:30:16 2016 +0100| [57df71eaf7c472e8fa3f51a01b5b75cf7c7f9b25] | committer: Paul B Mahol

avfilter/avf_showspectrum: reduce number of operations

Signed-off-by: Paul B Mahol <onemda at gmail.com>

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

 libavfilter/avf_showspectrum.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 7fd0ea9..424d1f2 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -451,13 +451,15 @@ static void run_fft(ShowSpectrumContext *s, AVFrame *fin)
 
 static void calc_magnitudes(ShowSpectrumContext *s)
 {
+    const double w = s->win_scale * (s->scale == LOG ? s->win_scale : 1);
     int ch, y, h = s->orientation == VERTICAL ? s->h : s->w;
+    const float f = s->gain * w;
 
     for (ch = 0; ch < s->nb_display_channels; ch++) {
         float *magnitudes = s->magnitudes[ch];
 
         for (y = 0; y < h; y++)
-            magnitudes[y] = MAGNITUDE(y, ch);
+            magnitudes[y] = MAGNITUDE(y, ch) * f;
     }
 }
 
@@ -475,13 +477,15 @@ static void calc_phases(ShowSpectrumContext *s)
 
 static void acalc_magnitudes(ShowSpectrumContext *s)
 {
+    const double w = s->win_scale * (s->scale == LOG ? s->win_scale : 1);
     int ch, y, h = s->orientation == VERTICAL ? s->h : s->w;
+    const float f = s->gain * w;
 
     for (ch = 0; ch < s->nb_display_channels; ch++) {
         float *magnitudes = s->magnitudes[ch];
 
         for (y = 0; y < h; y++)
-            magnitudes[y] += MAGNITUDE(y, ch);
+            magnitudes[y] += MAGNITUDE(y, ch) * f;
     }
 }
 
@@ -611,8 +615,6 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
     AVFilterLink *outlink = ctx->outputs[0];
     ShowSpectrumContext *s = ctx->priv;
     AVFrame *outpicref = s->outpicref;
-    const double w = s->data == D_PHASE ? 1 : s->win_scale;
-    const float g = s->gain;
     int h = s->orientation == VERTICAL ? s->channel_height : s->channel_width;
 
     int ch, plane, x, y;
@@ -638,7 +640,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
             switch (s->data) {
             case D_MAGNITUDE:
                 /* get magnitude */
-                a = g * w * magnitudes[y];
+                a = magnitudes[y];
                 break;
             case D_PHASE:
                 /* get phase */
@@ -666,7 +668,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
                 a = av_clipf(pow(a, 0.20), 0, 1);
                 break;
             case LOG:
-                a = 1 + log10(av_clipd(a * w, 1e-6, 1)) / 6; // zero = -120dBFS
+                a = 1 + log10(av_clipd(a, 1e-6, 1)) / 6; // zero = -120dBFS
                 break;
             default:
                 av_assert0(0);



More information about the ffmpeg-cvslog mailing list