[FFmpeg-cvslog] avfilter/avf_showspectrum: use ff_generate_window_func

Paul B Mahol git at videolan.org
Mon Dec 28 19:04:50 CET 2015


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Dec 28 18:51:56 2015 +0100| [f88546b426af6d38f76a8d1b7dc05109a12c7bb9] | committer: Paul B Mahol

avfilter/avf_showspectrum: use ff_generate_window_func

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

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

 doc/filters.texi               |   17 ++++++++++-----
 libavfilter/Makefile           |    2 +-
 libavfilter/avf_showspectrum.c |   45 +++++++++++++++++-----------------------
 3 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 316eaa4..1d14bc9 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -14647,14 +14647,21 @@ Set window function.
 
 It accepts the following values:
 @table @samp
- at item none
-No samples pre-processing (do not expect this to be faster)
+ at item rect
+ at item bartlett
 @item hann
-Hann window
+ at item hanning
 @item hamming
-Hamming window
 @item blackman
-Blackman window
+ at item welch
+ at item flattop
+ at item bharris
+ at item bnuttall
+ at item bhann
+ at item sine
+ at item nuttall
+ at item lanczos
+ at item gauss
 @end table
 
 Default value is @code{hann}.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 37b3a70..e334016 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -285,7 +285,7 @@ OBJS-$(CONFIG_AVECTORSCOPE_FILTER)           += avf_avectorscope.o
 OBJS-$(CONFIG_CONCAT_FILTER)                 += avf_concat.o
 OBJS-$(CONFIG_SHOWCQT_FILTER)                += avf_showcqt.o lswsutils.o lavfutils.o
 OBJS-$(CONFIG_SHOWFREQS_FILTER)              += avf_showfreqs.o window_func.o
-OBJS-$(CONFIG_SHOWSPECTRUM_FILTER)           += avf_showspectrum.o
+OBJS-$(CONFIG_SHOWSPECTRUM_FILTER)           += avf_showspectrum.o window_func.o
 OBJS-$(CONFIG_SHOWVOLUME_FILTER)             += avf_showvolume.o
 OBJS-$(CONFIG_SHOWWAVES_FILTER)              += avf_showwaves.o
 OBJS-$(CONFIG_SHOWWAVESPIC_FILTER)           += avf_showwaves.o
diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 384bad5..433400d 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -33,11 +33,11 @@
 #include "libavutil/opt.h"
 #include "avfilter.h"
 #include "internal.h"
+#include "window_func.h"
 
 enum DisplayMode  { COMBINED, SEPARATE, NB_MODES };
 enum DisplayScale { LINEAR, SQRT, CBRT, LOG, NB_SCALES };
 enum ColorMode    { CHANNEL, INTENSITY, NB_CLMODES };
-enum WindowFunc   { WFUNC_NONE, WFUNC_HANN, WFUNC_HAMMING, WFUNC_BLACKMAN, NB_WFUNC };
 enum SlideMode    { REPLACE, SCROLL, FULLFRAME, RSCROLL, NB_SLIDES };
 
 typedef struct {
@@ -57,6 +57,7 @@ typedef struct {
     FFTSample **rdft_data;      ///< bins holder for each (displayed) channels
     float *window_func_lut;     ///< Window function LUT
     int win_func;
+    float overlap;
     float *combine_buffer;      ///< color combining buffer (3 * h items)
 } ShowSpectrumContext;
 
@@ -83,10 +84,22 @@ static const AVOption showspectrum_options[] = {
         { "log",  "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=LOG},    0, 0, FLAGS, "scale" },
         { "lin",  "linear",      0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, "scale" },
     { "saturation", "color saturation multiplier", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl = 1}, -10, 10, FLAGS },
-    { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = WFUNC_HANN}, 0, NB_WFUNC-1, FLAGS, "win_func" },
-        { "hann",     "Hann window",     0, AV_OPT_TYPE_CONST, {.i64 = WFUNC_HANN},     0, 0, FLAGS, "win_func" },
-        { "hamming",  "Hamming window",  0, AV_OPT_TYPE_CONST, {.i64 = WFUNC_HAMMING},  0, 0, FLAGS, "win_func" },
-        { "blackman", "Blackman window", 0, AV_OPT_TYPE_CONST, {.i64 = WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
+    { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = WFUNC_HANNING}, 0, NB_WFUNC-1, FLAGS, "win_func" },
+        { "rect",     "Rectangular",      0, AV_OPT_TYPE_CONST, {.i64=WFUNC_RECT},     0, 0, FLAGS, "win_func" },
+        { "bartlett", "Bartlett",         0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BARTLETT}, 0, 0, FLAGS, "win_func" },
+        { "hann",     "Hann",             0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING},  0, 0, FLAGS, "win_func" },
+        { "hanning",  "Hanning",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING},  0, 0, FLAGS, "win_func" },
+        { "hamming",  "Hamming",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HAMMING},  0, 0, FLAGS, "win_func" },
+        { "blackman", "Blackman",         0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
+        { "welch",    "Welch",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_WELCH},    0, 0, FLAGS, "win_func" },
+        { "flattop",  "Flat-top",         0, AV_OPT_TYPE_CONST, {.i64=WFUNC_FLATTOP},  0, 0, FLAGS, "win_func" },
+        { "bharris",  "Blackman-Harris",  0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHARRIS},  0, 0, FLAGS, "win_func" },
+        { "bnuttall", "Blackman-Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BNUTTALL}, 0, 0, FLAGS, "win_func" },
+        { "bhann",    "Bartlett-Hann",    0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHANN},    0, 0, FLAGS, "win_func" },
+        { "sine",     "Sine",             0, AV_OPT_TYPE_CONST, {.i64=WFUNC_SINE},     0, 0, FLAGS, "win_func" },
+        { "nuttall",  "Nuttall",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL},  0, 0, FLAGS, "win_func" },
+        { "lanczos",  "Lanczos",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS},  0, 0, FLAGS, "win_func" },
+        { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
     { NULL }
 };
 
@@ -203,27 +216,7 @@ static int config_output(AVFilterLink *outlink)
                          sizeof(*s->window_func_lut));
         if (!s->window_func_lut)
             return AVERROR(ENOMEM);
-        switch (s->win_func) {
-        case WFUNC_NONE:
-            for (i = 0; i < win_size; i++)
-                s->window_func_lut[i] = 1.;
-            break;
-        case WFUNC_HANN:
-            for (i = 0; i < win_size; i++)
-                s->window_func_lut[i] = .5f * (1 - cos(2*M_PI*i / (win_size-1)));
-            break;
-        case WFUNC_HAMMING:
-            for (i = 0; i < win_size; i++)
-                s->window_func_lut[i] = .54f - .46f * cos(2*M_PI*i / (win_size-1));
-            break;
-        case WFUNC_BLACKMAN: {
-            for (i = 0; i < win_size; i++)
-                s->window_func_lut[i] = .42f - .5f*cos(2*M_PI*i / (win_size-1)) + .08f*cos(4*M_PI*i / (win_size-1));
-            break;
-        }
-        default:
-            av_assert0(0);
-        }
+        ff_generate_window_func(s->window_func_lut, win_size, s->win_func, &s->overlap);
 
         /* prepare the initial picref buffer (black frame) */
         av_frame_free(&s->outpicref);



More information about the ffmpeg-cvslog mailing list