Browse code

avfilter/window_func: add cauchy, parzen and poisson window function

Paul B Mahol authored on 2016/08/17 01:03:56
Showing 5 changed files
... ...
@@ -16519,6 +16519,9 @@ It accepts the following values:
16519 16519
 @item gauss
16520 16520
 @item tukey
16521 16521
 @item dolph
16522
+@item cauchy
16523
+@item parzen
16524
+@item poisson
16522 16525
 @end table
16523 16526
 Default is @code{hanning}.
16524 16527
 
... ...
@@ -16667,6 +16670,9 @@ It accepts the following values:
16667 16667
 @item gauss
16668 16668
 @item tukey
16669 16669
 @item dolph
16670
+@item cauchy
16671
+@item parzen
16672
+@item poisson
16670 16673
 @end table
16671 16674
 
16672 16675
 Default value is @code{hann}.
... ...
@@ -16811,6 +16817,9 @@ It accepts the following values:
16811 16811
 @item gauss
16812 16812
 @item tukey
16813 16813
 @item dolph
16814
+@item cauchy
16815
+@item parzen
16816
+@item poisson
16814 16817
 @end table
16815 16818
 Default value is @code{hann}.
16816 16819
 
... ...
@@ -113,6 +113,9 @@ static const AVOption showfreqs_options[] = {
113 113
         { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
114 114
         { "tukey",    "Tukey",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY},    0, 0, FLAGS, "win_func" },
115 115
         { "dolph",    "Dolph-Chebyshev",  0, AV_OPT_TYPE_CONST, {.i64=WFUNC_DOLPH},    0, 0, FLAGS, "win_func" },
116
+        { "cauchy",   "Cauchy",           0, AV_OPT_TYPE_CONST, {.i64=WFUNC_CAUCHY},   0, 0, FLAGS, "win_func" },
117
+        { "parzen",   "Parzen",           0, AV_OPT_TYPE_CONST, {.i64=WFUNC_PARZEN},   0, 0, FLAGS, "win_func" },
118
+        { "poisson",  "Poisson",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_POISSON},  0, 0, FLAGS, "win_func" },
116 119
     { "overlap",  "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1.}, 0., 1., FLAGS },
117 120
     { "averaging", "set time averaging", OFFSET(avg), AV_OPT_TYPE_INT, {.i64=1}, 0, INT32_MAX, FLAGS },
118 121
     { "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
... ...
@@ -135,6 +135,9 @@ static const AVOption showspectrum_options[] = {
135 135
         { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
136 136
         { "tukey",    "Tukey",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY},    0, 0, FLAGS, "win_func" },
137 137
         { "dolph",    "Dolph-Chebyshev",  0, AV_OPT_TYPE_CONST, {.i64=WFUNC_DOLPH},    0, 0, FLAGS, "win_func" },
138
+        { "cauchy",   "Cauchy",           0, AV_OPT_TYPE_CONST, {.i64=WFUNC_CAUCHY},   0, 0, FLAGS, "win_func" },
139
+        { "parzen",   "Parzen",           0, AV_OPT_TYPE_CONST, {.i64=WFUNC_PARZEN},   0, 0, FLAGS, "win_func" },
140
+        { "poisson",  "Poisson",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_POISSON},  0, 0, FLAGS, "win_func" },
138 141
     { "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS, "orientation" },
139 142
         { "vertical",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL},   0, 0, FLAGS, "orientation" },
140 143
         { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
... ...
@@ -967,6 +970,9 @@ static const AVOption showspectrumpic_options[] = {
967 967
         { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
968 968
         { "tukey",    "Tukey",            0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY},    0, 0, FLAGS, "win_func" },
969 969
         { "dolph",    "Dolph-Chebyshev",  0, AV_OPT_TYPE_CONST, {.i64=WFUNC_DOLPH},    0, 0, FLAGS, "win_func" },
970
+        { "cauchy",   "Cauchy",           0, AV_OPT_TYPE_CONST, {.i64=WFUNC_CAUCHY},   0, 0, FLAGS, "win_func" },
971
+        { "parzen",   "Parzen",           0, AV_OPT_TYPE_CONST, {.i64=WFUNC_PARZEN},   0, 0, FLAGS, "win_func" },
972
+        { "poisson",  "Poisson",          0, AV_OPT_TYPE_CONST, {.i64=WFUNC_POISSON},  0, 0, FLAGS, "win_func" },
970 973
     { "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS, "orientation" },
971 974
         { "vertical",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL},   0, 0, FLAGS, "orientation" },
972 975
         { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
... ...
@@ -128,6 +128,50 @@ void ff_generate_window_func(float *lut, int N, int win_func, float *overlap)
128 128
         }
129 129
         *overlap = 0.5;}
130 130
         break;
131
+    case WFUNC_CAUCHY:
132
+        for (n = 0; n < N; n++) {
133
+            double x = 2 * ((n / (double)(N - 1)) - .5);
134
+
135
+            if (x <= -.5 || x >= .5) {
136
+                lut[n] = 0;
137
+            } else {
138
+                lut[n] = FFMIN(1, fabs(1/(1+4*16*x*x)));
139
+            }
140
+        }
141
+        *overlap = 0.75;
142
+        break;
143
+    case WFUNC_PARZEN:
144
+        for (n = 0; n < N; n++) {
145
+            double x = 2 * ((n / (double)(N - 1)) - .5);
146
+
147
+            if (x > 0.25 && x <= 0.5) {
148
+                lut[n] = -2 * powf(-1 + 2 * x, 3);
149
+            } else if (x >= -.5 && x < -.25) {
150
+                lut[n] = 2 * powf(1 + 2 * x, 3);
151
+            } else if (x >= -.25 && x < 0) {
152
+                lut[n] = 1 - 24 * x * x - 48 * x * x * x;
153
+            } else if (x >= 0 && x <= .25) {
154
+                lut[n] = 1 - 24 * x * x + 48 * x * x * x;
155
+            } else {
156
+                lut[n] = 0;
157
+            }
158
+        }
159
+        *overlap = 0.75;
160
+        break;
161
+    case WFUNC_POISSON:
162
+        for (n = 0; n < N; n++) {
163
+            double x = 2 * ((n / (double)(N - 1)) - .5);
164
+
165
+            if (x >= 0 && x <= .5) {
166
+                lut[n] = exp(-6*x);
167
+            } else if (x < 0 && x >= -.5) {
168
+                lut[n] = exp(6*x);
169
+            } else {
170
+                lut[n] = 0;
171
+            }
172
+        }
173
+        *overlap = 0.75;
174
+        break;
131 175
     default:
132 176
         av_assert0(0);
133 177
     }
... ...
@@ -26,7 +26,8 @@ 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 28
                       WFUNC_BHANN, WFUNC_LANCZOS, WFUNC_GAUSS, WFUNC_TUKEY,
29
-                      WFUNC_DOLPH, NB_WFUNC };
29
+                      WFUNC_DOLPH, WFUNC_CAUCHY, WFUNC_PARZEN, WFUNC_POISSON,
30
+                      NB_WFUNC };
30 31
 
31 32
 void ff_generate_window_func(float *lut, int N, int win_func, float *overlap);
32 33