avfilter/avf_showfreqs: add lanczos and gauss windowing functions

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2015-09-15 09:13:53 +00:00
parent 1c853d5727
commit f2b1df735e
1 changed files with 14 additions and 1 deletions

View 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);
}