]> git.sesse.net Git - ffmpeg/commitdiff
avfilter/avf_showfreqs: add lanczos and gauss windowing functions
authorPaul B Mahol <onemda@gmail.com>
Tue, 15 Sep 2015 09:13:53 +0000 (09:13 +0000)
committerPaul B Mahol <onemda@gmail.com>
Tue, 15 Sep 2015 09:28:40 +0000 (09:28 +0000)
Signed-off-by: Paul B Mahol <onemda@gmail.com>
libavfilter/avf_showfreqs.c

index c00e4d8633808aec3e4f054debd1b7c9aa0ea09b..5dfa2df4d5dc763443a632981c3a9219932b8f4e 100644 (file)
@@ -39,7 +39,7 @@ enum AmplitudeScale { AS_LINEAR, AS_SQRT, AS_CBRT, AS_LOG, NB_ASCALES };
 enum WindowFunc     { WFUNC_RECT, WFUNC_HANNING, WFUNC_HAMMING, WFUNC_BLACKMAN,
                       WFUNC_BARTLETT, WFUNC_WELCH, WFUNC_FLATTOP,
                       WFUNC_BHARRIS, WFUNC_BNUTTALL, WFUNC_SINE, WFUNC_NUTTALL,
-                      WFUNC_BHANN, NB_WFUNC };
+                      WFUNC_BHANN, WFUNC_LANCZOS, WFUNC_GAUSS, NB_WFUNC };
 
 typedef struct ShowFreqsContext {
     const AVClass *class;
@@ -110,6 +110,8 @@ static const AVOption showfreqs_options[] = {
         { "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" },
     { "overlap",  "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1.}, 0., 1., FLAGS },
     { "averaging", "set time averaging", OFFSET(avg), AV_OPT_TYPE_INT, {.i64=1}, 0, INT32_MAX, FLAGS },
     { "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
@@ -221,6 +223,17 @@ static void generate_window_func(float *lut, int N, int win_func, float *overlap
             lut[n] = 0.355768-0.487396*cos(2*M_PI*n/(N-1))+0.144232*cos(4*M_PI*n/(N-1))-0.012604*cos(6*M_PI*n/(N-1));
         *overlap = 0.663;
         break;
+    case WFUNC_LANCZOS:
+#define SINC(x) (!(x)) ? 1 : sin(M_PI * (x))/(M_PI * (x));
+        for (n = 0; n < N; n++)
+            lut[n] = SINC((2.*n)/(N-1)-1);
+        *overlap = 0.75;
+        break;
+    case WFUNC_GAUSS:
+        for (n = 0; n < N; n++)
+            lut[n] = pow(M_E,-0.5*pow((n-(N-1)/2)/(0.4*(N-1)/2.f),2));
+        *overlap = 0.75;
+        break;
     default:
         av_assert0(0);
     }