diff options
author | Rostislav Pehlivanov <atomnuker@gmail.com> | 2017-09-23 14:21:22 +0100 |
---|---|---|
committer | Rostislav Pehlivanov <atomnuker@gmail.com> | 2017-09-23 14:35:06 +0100 |
commit | 039ebaa5f39ef45444f3cc42ab2ff71b0e9a1161 (patch) | |
tree | ccb6a83013d5daea6e259509b86cc2b5d347063e | |
parent | 2ad1768c7b48b6c77bbe9c42a4c2744f7b029182 (diff) | |
download | ffmpeg-039ebaa5f39ef45444f3cc42ab2ff71b0e9a1161.tar.gz |
lavfi: make window_func an inline function
Eliminate lavc->lavfi dependency. The function isn't big and doesn't
deserve its own file.
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
-rw-r--r-- | libavcodec/opusenc_psy.c | 2 | ||||
-rw-r--r-- | libavfilter/Makefile | 10 | ||||
-rw-r--r-- | libavfilter/af_afftfilt.c | 2 | ||||
-rw-r--r-- | libavfilter/avf_showfreqs.c | 2 | ||||
-rw-r--r-- | libavfilter/avf_showspectrum.c | 2 | ||||
-rw-r--r-- | libavfilter/vaf_spectrumsynth.c | 2 | ||||
-rw-r--r-- | libavfilter/window_func.c | 178 | ||||
-rw-r--r-- | libavfilter/window_func.h | 158 |
8 files changed, 167 insertions, 189 deletions
diff --git a/libavcodec/opusenc_psy.c b/libavcodec/opusenc_psy.c index 7c356fc568..e6858f1856 100644 --- a/libavcodec/opusenc_psy.c +++ b/libavcodec/opusenc_psy.c @@ -507,7 +507,7 @@ av_cold int ff_opus_psy_init(OpusPsyContext *s, AVCodecContext *avctx, ret = AVERROR(ENOMEM); goto fail; } - ff_generate_window_func(s->window[i], 2*len, WFUNC_SINE, &tmp); + generate_window_func(s->window[i], 2*len, WFUNC_SINE, &tmp); if ((ret = ff_mdct15_init(&s->mdct[i], 0, i + 3, 68 << (CELT_BLOCK_NB - 1 - i)))) goto fail; } diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 98acb51bcb..9eeb7d218f 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -37,7 +37,7 @@ OBJS-$(CONFIG_AECHO_FILTER) += af_aecho.o OBJS-$(CONFIG_AEMPHASIS_FILTER) += af_aemphasis.o OBJS-$(CONFIG_AEVAL_FILTER) += aeval.o OBJS-$(CONFIG_AFADE_FILTER) += af_afade.o -OBJS-$(CONFIG_AFFTFILT_FILTER) += af_afftfilt.o window_func.o +OBJS-$(CONFIG_AFFTFILT_FILTER) += af_afftfilt.o OBJS-$(CONFIG_AFIR_FILTER) += af_afir.o OBJS-$(CONFIG_AFORMAT_FILTER) += af_aformat.o OBJS-$(CONFIG_AGATE_FILTER) += af_agate.o @@ -369,13 +369,13 @@ OBJS-$(CONFIG_APHASEMETER_FILTER) += avf_aphasemeter.o 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 window_func.o -OBJS-$(CONFIG_SHOWSPECTRUMPIC_FILTER) += avf_showspectrum.o window_func.o +OBJS-$(CONFIG_SHOWFREQS_FILTER) += avf_showfreqs.o +OBJS-$(CONFIG_SHOWSPECTRUM_FILTER) += avf_showspectrum.o +OBJS-$(CONFIG_SHOWSPECTRUMPIC_FILTER) += avf_showspectrum.o OBJS-$(CONFIG_SHOWVOLUME_FILTER) += avf_showvolume.o OBJS-$(CONFIG_SHOWWAVES_FILTER) += avf_showwaves.o OBJS-$(CONFIG_SHOWWAVESPIC_FILTER) += avf_showwaves.o -OBJS-$(CONFIG_SPECTRUMSYNTH_FILTER) += vaf_spectrumsynth.o window_func.o +OBJS-$(CONFIG_SPECTRUMSYNTH_FILTER) += vaf_spectrumsynth.o # multimedia sources OBJS-$(CONFIG_AMOVIE_FILTER) += src_movie.o diff --git a/libavfilter/af_afftfilt.c b/libavfilter/af_afftfilt.c index d166fa4190..52755a1fb4 100644 --- a/libavfilter/af_afftfilt.c +++ b/libavfilter/af_afftfilt.c @@ -166,7 +166,7 @@ static int config_input(AVFilterLink *inlink) sizeof(*s->window_func_lut)); if (!s->window_func_lut) return AVERROR(ENOMEM); - ff_generate_window_func(s->window_func_lut, s->window_size, s->win_func, &overlap); + generate_window_func(s->window_func_lut, s->window_size, s->win_func, &overlap); if (s->overlap == 1) s->overlap = overlap; diff --git a/libavfilter/avf_showfreqs.c b/libavfilter/avf_showfreqs.c index 068ff1fb88..22f28ec387 100644 --- a/libavfilter/avf_showfreqs.c +++ b/libavfilter/avf_showfreqs.c @@ -218,7 +218,7 @@ static int config_output(AVFilterLink *outlink) sizeof(*s->window_func_lut)); if (!s->window_func_lut) return AVERROR(ENOMEM); - ff_generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap); + generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap); if (s->overlap == 1.) s->overlap = overlap; s->hop_size = (1. - s->overlap) * s->win_size; diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c index 4317161d79..956f62f3ad 100644 --- a/libavfilter/avf_showspectrum.c +++ b/libavfilter/avf_showspectrum.c @@ -403,7 +403,7 @@ static int config_output(AVFilterLink *outlink) sizeof(*s->window_func_lut)); if (!s->window_func_lut) return AVERROR(ENOMEM); - ff_generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap); + generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap); if (s->overlap == 1) s->overlap = overlap; s->hop_size = (1. - s->overlap) * s->win_size; diff --git a/libavfilter/vaf_spectrumsynth.c b/libavfilter/vaf_spectrumsynth.c index ed191a3e34..fed2cbba03 100644 --- a/libavfilter/vaf_spectrumsynth.c +++ b/libavfilter/vaf_spectrumsynth.c @@ -210,7 +210,7 @@ static int config_output(AVFilterLink *outlink) sizeof(*s->window_func_lut)); if (!s->window_func_lut) return AVERROR(ENOMEM); - ff_generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap); + generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap); if (s->overlap == 1) s->overlap = overlap; s->hop_size = (1 - s->overlap) * s->win_size; diff --git a/libavfilter/window_func.c b/libavfilter/window_func.c deleted file mode 100644 index acf1b20847..0000000000 --- a/libavfilter/window_func.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2015 Paul B Mahol - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <math.h> - -#include "libavutil/avassert.h" -#include "window_func.h" - -void ff_generate_window_func(float *lut, int N, int win_func, float *overlap) -{ - int n; - - switch (win_func) { - case WFUNC_RECT: - for (n = 0; n < N; n++) - lut[n] = 1.; - *overlap = 0.; - break; - case WFUNC_BARTLETT: - for (n = 0; n < N; n++) - lut[n] = 1.-fabs((n-(N-1)/2.)/((N-1)/2.)); - *overlap = 0.5; - break; - case WFUNC_HANNING: - for (n = 0; n < N; n++) - lut[n] = .5*(1-cos(2*M_PI*n/(N-1))); - *overlap = 0.5; - break; - case WFUNC_HAMMING: - for (n = 0; n < N; n++) - lut[n] = .54-.46*cos(2*M_PI*n/(N-1)); - *overlap = 0.5; - break; - case WFUNC_BLACKMAN: - for (n = 0; n < N; n++) - lut[n] = .42659-.49656*cos(2*M_PI*n/(N-1))+.076849*cos(4*M_PI*n/(N-1)); - *overlap = 0.661; - break; - case WFUNC_WELCH: - for (n = 0; n < N; n++) - lut[n] = 1.-(n-(N-1)/2.)/((N-1)/2.)*(n-(N-1)/2.)/((N-1)/2.); - *overlap = 0.293; - break; - case WFUNC_FLATTOP: - for (n = 0; n < N; n++) - lut[n] = 1.-1.985844164102*cos( 2*M_PI*n/(N-1))+1.791176438506*cos( 4*M_PI*n/(N-1))- - 1.282075284005*cos( 6*M_PI*n/(N-1))+0.667777530266*cos( 8*M_PI*n/(N-1))- - 0.240160796576*cos(10*M_PI*n/(N-1))+0.056656381764*cos(12*M_PI*n/(N-1))- - 0.008134974479*cos(14*M_PI*n/(N-1))+0.000624544650*cos(16*M_PI*n/(N-1))- - 0.000019808998*cos(18*M_PI*n/(N-1))+0.000000132974*cos(20*M_PI*n/(N-1)); - *overlap = 0.841; - break; - case WFUNC_BHARRIS: - for (n = 0; n < N; n++) - lut[n] = 0.35875-0.48829*cos(2*M_PI*n/(N-1))+0.14128*cos(4*M_PI*n/(N-1))-0.01168*cos(6*M_PI*n/(N-1)); - *overlap = 0.661; - break; - case WFUNC_BNUTTALL: - for (n = 0; n < N; n++) - lut[n] = 0.3635819-0.4891775*cos(2*M_PI*n/(N-1))+0.1365995*cos(4*M_PI*n/(N-1))-0.0106411*cos(6*M_PI*n/(N-1)); - *overlap = 0.661; - break; - case WFUNC_BHANN: - for (n = 0; n < N; n++) - lut[n] = 0.62-0.48*fabs(n/(double)(N-1)-.5)-0.38*cos(2*M_PI*n/(N-1)); - *overlap = 0.5; - break; - case WFUNC_SINE: - for (n = 0; n < N; n++) - lut[n] = sin(M_PI*n/(N-1)); - *overlap = 0.75; - break; - case WFUNC_NUTTALL: - for (n = 0; n < N; n++) - 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: -#define SQR(x) ((x)*(x)) - for (n = 0; n < N; n++) - lut[n] = exp(-0.5 * SQR((n-(N-1)/2)/(0.4*(N-1)/2.f))); - *overlap = 0.75; - break; - case WFUNC_TUKEY: - for (n = 0; n < N; n++) { - float M = (N-1)/2.; - - if (FFABS(n - M) >= 0.3 * M) { - lut[n] = 0.5 * (1 + cos((M_PI*(FFABS(n - M) - 0.3 * M))/((1 - 0.3) * M))); - } else { - lut[n] = 1; - } - } - *overlap = 0.33; - break; - case WFUNC_DOLPH: { - double b = cosh(7.6009022095419887 / (N-1)), sum, t, c, norm = 0; - int j; - for (c = 1 - 1 / (b*b), n = (N-1) / 2; n >= 0; --n) { - for (sum = !n, b = t = j = 1; j <= n && sum != t; b *= (n-j) * (1./j), ++j) - t = sum, sum += (b *= c * (N - n - j) * (1./j)); - sum /= (N - 1 - n), sum /= (norm = norm ? norm : sum); - lut[n] = sum; - lut[N - 1 - n] = sum; - } - *overlap = 0.5;} - break; - case WFUNC_CAUCHY: - for (n = 0; n < N; n++) { - double x = 2 * ((n / (double)(N - 1)) - .5); - - if (x <= -.5 || x >= .5) { - lut[n] = 0; - } else { - lut[n] = FFMIN(1, fabs(1/(1+4*16*x*x))); - } - } - *overlap = 0.75; - break; - case WFUNC_PARZEN: - for (n = 0; n < N; n++) { - double x = 2 * ((n / (double)(N - 1)) - .5); - - if (x > 0.25 && x <= 0.5) { - lut[n] = -2 * powf(-1 + 2 * x, 3); - } else if (x >= -.5 && x < -.25) { - lut[n] = 2 * powf(1 + 2 * x, 3); - } else if (x >= -.25 && x < 0) { - lut[n] = 1 - 24 * x * x - 48 * x * x * x; - } else if (x >= 0 && x <= .25) { - lut[n] = 1 - 24 * x * x + 48 * x * x * x; - } else { - lut[n] = 0; - } - } - *overlap = 0.75; - break; - case WFUNC_POISSON: - for (n = 0; n < N; n++) { - double x = 2 * ((n / (double)(N - 1)) - .5); - - if (x >= 0 && x <= .5) { - lut[n] = exp(-6*x); - } else if (x < 0 && x >= -.5) { - lut[n] = exp(6*x); - } else { - lut[n] = 0; - } - } - *overlap = 0.75; - break; - default: - av_assert0(0); - } -} diff --git a/libavfilter/window_func.h b/libavfilter/window_func.h index 4611498d47..a94482c937 100644 --- a/libavfilter/window_func.h +++ b/libavfilter/window_func.h @@ -22,6 +22,9 @@ #ifndef AVFILTER_WINDOW_FUNC_H #define AVFILTER_WINDOW_FUNC_H +#include <math.h> +#include "libavutil/avassert.h" + enum WindowFunc { WFUNC_RECT, WFUNC_HANNING, WFUNC_HAMMING, WFUNC_BLACKMAN, WFUNC_BARTLETT, WFUNC_WELCH, WFUNC_FLATTOP, WFUNC_BHARRIS, WFUNC_BNUTTALL, WFUNC_SINE, WFUNC_NUTTALL, @@ -29,6 +32,159 @@ enum WindowFunc { WFUNC_RECT, WFUNC_HANNING, WFUNC_HAMMING, WFUNC_BLACKMAN, WFUNC_DOLPH, WFUNC_CAUCHY, WFUNC_PARZEN, WFUNC_POISSON, NB_WFUNC }; -void ff_generate_window_func(float *lut, int N, int win_func, float *overlap); +static inline void generate_window_func(float *lut, int N, int win_func, + float *overlap) +{ + int n; + + switch (win_func) { + case WFUNC_RECT: + for (n = 0; n < N; n++) + lut[n] = 1.; + *overlap = 0.; + break; + case WFUNC_BARTLETT: + for (n = 0; n < N; n++) + lut[n] = 1.-fabs((n-(N-1)/2.)/((N-1)/2.)); + *overlap = 0.5; + break; + case WFUNC_HANNING: + for (n = 0; n < N; n++) + lut[n] = .5*(1-cos(2*M_PI*n/(N-1))); + *overlap = 0.5; + break; + case WFUNC_HAMMING: + for (n = 0; n < N; n++) + lut[n] = .54-.46*cos(2*M_PI*n/(N-1)); + *overlap = 0.5; + break; + case WFUNC_BLACKMAN: + for (n = 0; n < N; n++) + lut[n] = .42659-.49656*cos(2*M_PI*n/(N-1))+.076849*cos(4*M_PI*n/(N-1)); + *overlap = 0.661; + break; + case WFUNC_WELCH: + for (n = 0; n < N; n++) + lut[n] = 1.-(n-(N-1)/2.)/((N-1)/2.)*(n-(N-1)/2.)/((N-1)/2.); + *overlap = 0.293; + break; + case WFUNC_FLATTOP: + for (n = 0; n < N; n++) + lut[n] = 1.-1.985844164102*cos( 2*M_PI*n/(N-1))+1.791176438506*cos( 4*M_PI*n/(N-1))- + 1.282075284005*cos( 6*M_PI*n/(N-1))+0.667777530266*cos( 8*M_PI*n/(N-1))- + 0.240160796576*cos(10*M_PI*n/(N-1))+0.056656381764*cos(12*M_PI*n/(N-1))- + 0.008134974479*cos(14*M_PI*n/(N-1))+0.000624544650*cos(16*M_PI*n/(N-1))- + 0.000019808998*cos(18*M_PI*n/(N-1))+0.000000132974*cos(20*M_PI*n/(N-1)); + *overlap = 0.841; + break; + case WFUNC_BHARRIS: + for (n = 0; n < N; n++) + lut[n] = 0.35875-0.48829*cos(2*M_PI*n/(N-1))+0.14128*cos(4*M_PI*n/(N-1))-0.01168*cos(6*M_PI*n/(N-1)); + *overlap = 0.661; + break; + case WFUNC_BNUTTALL: + for (n = 0; n < N; n++) + lut[n] = 0.3635819-0.4891775*cos(2*M_PI*n/(N-1))+0.1365995*cos(4*M_PI*n/(N-1))-0.0106411*cos(6*M_PI*n/(N-1)); + *overlap = 0.661; + break; + case WFUNC_BHANN: + for (n = 0; n < N; n++) + lut[n] = 0.62-0.48*fabs(n/(double)(N-1)-.5)-0.38*cos(2*M_PI*n/(N-1)); + *overlap = 0.5; + break; + case WFUNC_SINE: + for (n = 0; n < N; n++) + lut[n] = sin(M_PI*n/(N-1)); + *overlap = 0.75; + break; + case WFUNC_NUTTALL: + for (n = 0; n < N; n++) + 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: + #define SQR(x) ((x)*(x)) + for (n = 0; n < N; n++) + lut[n] = exp(-0.5 * SQR((n-(N-1)/2)/(0.4*(N-1)/2.f))); + *overlap = 0.75; + break; + case WFUNC_TUKEY: + for (n = 0; n < N; n++) { + float M = (N-1)/2.; + + if (FFABS(n - M) >= 0.3 * M) { + lut[n] = 0.5 * (1 + cos((M_PI*(FFABS(n - M) - 0.3 * M))/((1 - 0.3) * M))); + } else { + lut[n] = 1; + } + } + *overlap = 0.33; + break; + case WFUNC_DOLPH: { + double b = cosh(7.6009022095419887 / (N-1)), sum, t, c, norm = 0; + int j; + for (c = 1 - 1 / (b*b), n = (N-1) / 2; n >= 0; --n) { + for (sum = !n, b = t = j = 1; j <= n && sum != t; b *= (n-j) * (1./j), ++j) + t = sum, sum += (b *= c * (N - n - j) * (1./j)); + sum /= (N - 1 - n), sum /= (norm = norm ? norm : sum); + lut[n] = sum; + lut[N - 1 - n] = sum; + } + *overlap = 0.5;} + break; + case WFUNC_CAUCHY: + for (n = 0; n < N; n++) { + double x = 2 * ((n / (double)(N - 1)) - .5); + + if (x <= -.5 || x >= .5) { + lut[n] = 0; + } else { + lut[n] = FFMIN(1, fabs(1/(1+4*16*x*x))); + } + } + *overlap = 0.75; + break; + case WFUNC_PARZEN: + for (n = 0; n < N; n++) { + double x = 2 * ((n / (double)(N - 1)) - .5); + + if (x > 0.25 && x <= 0.5) { + lut[n] = -2 * powf(-1 + 2 * x, 3); + } else if (x >= -.5 && x < -.25) { + lut[n] = 2 * powf(1 + 2 * x, 3); + } else if (x >= -.25 && x < 0) { + lut[n] = 1 - 24 * x * x - 48 * x * x * x; + } else if (x >= 0 && x <= .25) { + lut[n] = 1 - 24 * x * x + 48 * x * x * x; + } else { + lut[n] = 0; + } + } + *overlap = 0.75; + break; + case WFUNC_POISSON: + for (n = 0; n < N; n++) { + double x = 2 * ((n / (double)(N - 1)) - .5); + + if (x >= 0 && x <= .5) { + lut[n] = exp(-6*x); + } else if (x < 0 && x >= -.5) { + lut[n] = exp(6*x); + } else { + lut[n] = 0; + } + } + *overlap = 0.75; + break; + default: + av_assert0(0); + } +} #endif /* AVFILTER_WINDOW_FUNC_H */ |