From a45fbda994df54600101e845e29f0af60e456e95 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 19 Mar 2011 17:19:04 +0000 Subject: Move ff_kbd_window_init() to a separate file This function is not tightly coupled to mdct, and it's in the way of making a fixed-point mdct implementation. Signed-off-by: Mans Rullgard --- libavcodec/Makefile | 6 +++--- libavcodec/aacdec.c | 1 + libavcodec/aacenc.c | 1 + libavcodec/ac3dec.c | 1 + libavcodec/ac3enc_float.c | 1 + libavcodec/fft.h | 13 ------------- libavcodec/kbdwin.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/kbdwin.h | 35 ++++++++++++++++++++++++++++++++++ libavcodec/mdct.c | 25 ------------------------ 9 files changed, 90 insertions(+), 41 deletions(-) create mode 100644 libavcodec/kbdwin.c create mode 100644 libavcodec/kbdwin.h (limited to 'libavcodec') diff --git a/libavcodec/Makefile b/libavcodec/Makefile index d72a34062e..b21921b74c 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -49,14 +49,14 @@ OBJS-$(CONFIG_VDPAU) += vdpau.o OBJS-$(CONFIG_A64MULTI_ENCODER) += a64multienc.o elbg.o OBJS-$(CONFIG_A64MULTI5_ENCODER) += a64multienc.o elbg.o OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o aacps.o \ - aacadtsdec.o mpeg4audio.o + aacadtsdec.o mpeg4audio.o kbdwin.o OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o \ aacpsy.o aactab.o \ psymodel.o iirfilter.o \ - mpeg4audio.o + mpeg4audio.o kbdwin.o OBJS-$(CONFIG_AASC_DECODER) += aasc.o msrledec.o OBJS-$(CONFIG_AC3_DECODER) += ac3dec.o ac3dec_data.o ac3.o -OBJS-$(CONFIG_AC3_ENCODER) += ac3enc_float.o ac3tab.o ac3.o +OBJS-$(CONFIG_AC3_ENCODER) += ac3enc_float.o ac3tab.o ac3.o kbdwin.o OBJS-$(CONFIG_AC3_FIXED_ENCODER) += ac3enc_fixed.o ac3tab.o ac3.o OBJS-$(CONFIG_ALAC_DECODER) += alac.o OBJS-$(CONFIG_ALAC_ENCODER) += alacenc.o diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index a981fbeb7f..0a1ac93bae 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -87,6 +87,7 @@ #include "fft.h" #include "fmtconvert.h" #include "lpc.h" +#include "kbdwin.h" #include "aac.h" #include "aactab.h" diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index f74e28526d..9b53001dfe 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -34,6 +34,7 @@ #include "put_bits.h" #include "dsputil.h" #include "mpeg4audio.h" +#include "kbdwin.h" #include "aac.h" #include "aactab.h" diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index fbc8dd1c54..b089adcb21 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -35,6 +35,7 @@ #include "ac3_parser.h" #include "ac3dec.h" #include "ac3dec_data.h" +#include "kbdwin.h" /** Large enough for maximum possible frame size when the specification limit is ignored */ #define AC3_FRAME_BUFFER_SIZE 32768 diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c index e46ec6a85d..91f73e5b44 100644 --- a/libavcodec/ac3enc_float.c +++ b/libavcodec/ac3enc_float.c @@ -28,6 +28,7 @@ #define CONFIG_AC3ENC_FLOAT 1 #include "ac3enc.c" +#include "kbdwin.h" /** diff --git a/libavcodec/fft.h b/libavcodec/fft.h index 610a9a9f44..88fd325dfa 100644 --- a/libavcodec/fft.h +++ b/libavcodec/fft.h @@ -124,19 +124,6 @@ void ff_dct_init_mmx(DCTContext *s); void ff_fft_end(FFTContext *s); -/** - * Maximum window size for ff_kbd_window_init. - */ -#define FF_KBD_WINDOW_MAX 1024 - -/** - * Generate a Kaiser-Bessel Derived Window. - * @param window pointer to half window - * @param alpha determines window shape - * @param n size of half window, max FF_KBD_WINDOW_MAX - */ -void ff_kbd_window_init(float *window, float alpha, int n); - /** * Generate a sine window. * @param window pointer to half window diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c new file mode 100644 index 0000000000..c2c1c59040 --- /dev/null +++ b/libavcodec/kbdwin.c @@ -0,0 +1,48 @@ +/* + * This file is part of Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include "libavutil/attributes.h" +#include "kbdwin.h" + +#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation + +av_cold void ff_kbd_window_init(float *window, float alpha, int n) +{ + int i, j; + double sum = 0.0, bessel, tmp; + double local_window[FF_KBD_WINDOW_MAX]; + double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); + + assert(n <= FF_KBD_WINDOW_MAX); + + for (i = 0; i < n; i++) { + tmp = i * (n - i) * alpha2; + bessel = 1.0; + for (j = BESSEL_I0_ITER; j > 0; j--) + bessel = bessel * tmp / (j * j) + 1; + sum += bessel; + local_window[i] = sum; + } + + sum++; + for (i = 0; i < n; i++) + window[i] = sqrt(local_window[i] / sum); +} + diff --git a/libavcodec/kbdwin.h b/libavcodec/kbdwin.h new file mode 100644 index 0000000000..5ac2b8ca5a --- /dev/null +++ b/libavcodec/kbdwin.h @@ -0,0 +1,35 @@ +/* + * This file is part of Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_KBDWIN_H +#define AVCODEC_KBDWIN_H + +/** + * Maximum window size for ff_kbd_window_init. + */ +#define FF_KBD_WINDOW_MAX 1024 + +/** + * Generate a Kaiser-Bessel Derived Window. + * @param window pointer to half window + * @param alpha determines window shape + * @param n size of half window, max FF_KBD_WINDOW_MAX + */ +void ff_kbd_window_init(float *window, float alpha, int n); + +#endif diff --git a/libavcodec/mdct.c b/libavcodec/mdct.c index c99a6cfee2..f2f34f9eda 100644 --- a/libavcodec/mdct.c +++ b/libavcodec/mdct.c @@ -30,31 +30,6 @@ * MDCT/IMDCT transforms. */ -// Generate a Kaiser-Bessel Derived Window. -#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation -av_cold void ff_kbd_window_init(float *window, float alpha, int n) -{ - int i, j; - double sum = 0.0, bessel, tmp; - double local_window[FF_KBD_WINDOW_MAX]; - double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); - - assert(n <= FF_KBD_WINDOW_MAX); - - for (i = 0; i < n; i++) { - tmp = i * (n - i) * alpha2; - bessel = 1.0; - for (j = BESSEL_I0_ITER; j > 0; j--) - bessel = bessel * tmp / (j * j) + 1; - sum += bessel; - local_window[i] = sum; - } - - sum++; - for (i = 0; i < n; i++) - window[i] = sqrt(local_window[i] / sum); -} - #include "mdct_tablegen.h" /** -- cgit v1.2.3