Browse code

avfilter/window_func: add tukey window function

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

Paul B Mahol authored on 2016/01/05 19:37:11
Showing 5 changed files
... ...
@@ -14535,6 +14535,7 @@ It accepts the following values:
14535 14535
 @item nuttall
14536 14536
 @item lanczos
14537 14537
 @item gauss
14538
+@item tukey
14538 14539
 @end table
14539 14540
 Default is @code{hanning}.
14540 14541
 
... ...
@@ -14678,6 +14679,7 @@ It accepts the following values:
14678 14678
 @item nuttall
14679 14679
 @item lanczos
14680 14680
 @item gauss
14681
+@item tukey
14681 14682
 @end table
14682 14683
 
14683 14684
 Default value is @code{hann}.
... ...
@@ -111,6 +111,7 @@ static const AVOption showfreqs_options[] = {
111 111
         { "nuttall",  "Nuttall",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL},  0, 0, FLAGS, "win_func" },
112 112
         { "lanczos",  "Lanczos",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS},  0, 0, FLAGS, "win_func" },
113 113
         { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
114
+        { "tukey",    "Tukey",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY},    0, 0, FLAGS, "win_func" },
114 115
     { "overlap",  "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1.}, 0., 1., FLAGS },
115 116
     { "averaging", "set time averaging", OFFSET(avg), AV_OPT_TYPE_INT, {.i64=1}, 0, INT32_MAX, FLAGS },
116 117
     { "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
... ...
@@ -123,6 +123,7 @@ static const AVOption showspectrum_options[] = {
123 123
         { "nuttall",  "Nuttall",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL},  0, 0, FLAGS, "win_func" },
124 124
         { "lanczos",  "Lanczos",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS},  0, 0, FLAGS, "win_func" },
125 125
         { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
126
+        { "tukey",    "Tukey",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY},    0, 0, FLAGS, "win_func" },
126 127
     { "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS, "orientation" },
127 128
         { "vertical",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL},   0, 0, FLAGS, "orientation" },
128 129
         { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
... ...
@@ -826,6 +827,7 @@ static const AVOption showspectrumpic_options[] = {
826 826
         { "nuttall",  "Nuttall",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL},  0, 0, FLAGS, "win_func" },
827 827
         { "lanczos",  "Lanczos",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS},  0, 0, FLAGS, "win_func" },
828 828
         { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
829
+        { "tukey",    "Tukey",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY},    0, 0, FLAGS, "win_func" },
829 830
     { "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS, "orientation" },
830 831
         { "vertical",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL},   0, 0, FLAGS, "orientation" },
831 832
         { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
... ...
@@ -104,6 +104,18 @@ void ff_generate_window_func(float *lut, int N, int win_func, float *overlap)
104 104
             lut[n] = exp(-0.5 * SQR((n-(N-1)/2)/(0.4*(N-1)/2.f)));
105 105
         *overlap = 0.75;
106 106
         break;
107
+    case WFUNC_TUKEY:
108
+        for (n = 0; n < N; n++) {
109
+            float M = (N-1)/2.;
110
+
111
+            if (FFABS(n - M) >= 0.3 * M) {
112
+                lut[n] = 0.5 * (1 + cos((M_PI*(FFABS(n - M) - 0.3 * M))/((1 - 0.3) * M)));
113
+            } else {
114
+                lut[n] = 1;
115
+            }
116
+        }
117
+        *overlap = 0.33;
118
+        break;
107 119
     default:
108 120
         av_assert0(0);
109 121
     }
... ...
@@ -25,7 +25,7 @@
25 25
 enum WindowFunc     { WFUNC_RECT, WFUNC_HANNING, WFUNC_HAMMING, WFUNC_BLACKMAN,
26 26
                       WFUNC_BARTLETT, WFUNC_WELCH, WFUNC_FLATTOP,
27 27
                       WFUNC_BHARRIS, WFUNC_BNUTTALL, WFUNC_SINE, WFUNC_NUTTALL,
28
-                      WFUNC_BHANN, WFUNC_LANCZOS, WFUNC_GAUSS, NB_WFUNC };
28
+                      WFUNC_BHANN, WFUNC_LANCZOS, WFUNC_GAUSS, WFUNC_TUKEY, NB_WFUNC };
29 29
 
30 30
 void ff_generate_window_func(float *lut, int N, int win_func, float *overlap);
31 31