diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2010-01-09 13:28:04 +0000 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2010-01-09 13:28:04 +0000 |
commit | 14b8607065ff7204cff29b108e42fd930a52a5ed (patch) | |
tree | eb04acb8a0efea46d50055f7af472d9597ab37c8 | |
parent | b090930d432957a06f78701212b3024f93958f17 (diff) | |
download | ffmpeg-14b8607065ff7204cff29b108e42fd930a52a5ed.tar.gz |
Add support for hard-coded MDCT-related ff_sine_windows tables.
Originally committed as revision 21108 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/Makefile | 1 | ||||
-rw-r--r-- | libavcodec/aac.c | 4 | ||||
-rw-r--r-- | libavcodec/aacenc.c | 4 | ||||
-rw-r--r-- | libavcodec/atrac1.c | 2 | ||||
-rw-r--r-- | libavcodec/dsputil.h | 26 | ||||
-rw-r--r-- | libavcodec/mdct.c | 21 | ||||
-rw-r--r-- | libavcodec/mdct_tablegen.c | 61 | ||||
-rw-r--r-- | libavcodec/mdct_tablegen.h | 59 | ||||
-rw-r--r-- | libavcodec/nellymoserdec.c | 2 | ||||
-rw-r--r-- | libavcodec/tableprint.c | 1 | ||||
-rw-r--r-- | libavcodec/tableprint.h | 1 | ||||
-rw-r--r-- | libavcodec/twinvq.c | 6 | ||||
-rw-r--r-- | libavcodec/wma.c | 4 | ||||
-rw-r--r-- | libavcodec/wmaprodec.c | 3 |
14 files changed, 152 insertions, 43 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 7ff5c45d86..a08c75fa1b 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -697,6 +697,7 @@ $(SUBDIR)%_tables.h: $(SUBDIR)%_tablegen$(HOSTEXESUF) ./$< > $@ ifdef CONFIG_HARDCODED_TABLES +$(SUBDIR)mdct.o: $(SUBDIR)mdct_tables.h $(SUBDIR)mpegaudiodec.o: $(SUBDIR)mpegaudio_tables.h $(SUBDIR)motionpixels.o: $(SUBDIR)motionpixels_tables.h endif diff --git a/libavcodec/aac.c b/libavcodec/aac.c index 19b3153f23..2bb05b85a2 100644 --- a/libavcodec/aac.c +++ b/libavcodec/aac.c @@ -552,8 +552,8 @@ static av_cold int aac_decode_init(AVCodecContext *avccontext) // window initialization ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); - ff_sine_window_init(ff_sine_1024, 1024); - ff_sine_window_init(ff_sine_128, 128); + ff_init_ff_sine_windows(10); + ff_init_ff_sine_windows( 7); return 0; } diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index ce102b6e3b..d32ae5e286 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -178,8 +178,8 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) // window init ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); - ff_sine_window_init(ff_sine_1024, 1024); - ff_sine_window_init(ff_sine_128, 128); + ff_init_ff_sine_windows(10); + ff_init_ff_sine_windows(7); s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]); diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c index 2009bba753..6477cff4e8 100644 --- a/libavcodec/atrac1.c +++ b/libavcodec/atrac1.c @@ -339,7 +339,7 @@ static av_cold int atrac1_decode_init(AVCodecContext *avctx) ff_mdct_init(&q->mdct_ctx[1], 8, 1, -1.0/ (1 << 15)); ff_mdct_init(&q->mdct_ctx[2], 9, 1, -1.0/ (1 << 15)); - ff_sine_window_init(ff_sine_32, 32); + ff_init_ff_sine_windows(5); atrac_generate_tables(); diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h index e483276070..7b218acaf1 100644 --- a/libavcodec/dsputil.h +++ b/libavcodec/dsputil.h @@ -741,15 +741,19 @@ typedef struct FFTContext { #if CONFIG_HARDCODED_TABLES #define COSTABLE_CONST const #define SINTABLE_CONST const +#define SINETABLE_CONST const #else #define COSTABLE_CONST #define SINTABLE_CONST +#define SINETABLE_CONST #endif #define COSTABLE(size) \ COSTABLE_CONST DECLARE_ALIGNED_16(FFTSample, ff_cos_##size[size/2]) #define SINTABLE(size) \ SINTABLE_CONST DECLARE_ALIGNED_16(FFTSample, ff_sin_##size[size/2]) +#define SINETABLE(size) \ + SINETABLE_CONST DECLARE_ALIGNED_16(float, ff_sine_##size[size]) extern COSTABLE(16); extern COSTABLE(32); extern COSTABLE(64); @@ -846,15 +850,19 @@ void ff_kbd_window_init(float *window, float alpha, int n); * @param n size of half window */ void ff_sine_window_init(float *window, int n); -extern float ff_sine_32 [ 32]; -extern float ff_sine_64 [ 64]; -extern float ff_sine_128 [ 128]; -extern float ff_sine_256 [ 256]; -extern float ff_sine_512 [ 512]; -extern float ff_sine_1024[1024]; -extern float ff_sine_2048[2048]; -extern float ff_sine_4096[4096]; -extern float * const ff_sine_windows[13]; +/** + * initialize the specified entry of ff_sine_windows + */ +void ff_init_ff_sine_windows(int index); +extern SINETABLE( 32); +extern SINETABLE( 64); +extern SINETABLE( 128); +extern SINETABLE( 256); +extern SINETABLE( 512); +extern SINETABLE(1024); +extern SINETABLE(2048); +extern SINETABLE(4096); +extern SINETABLE_CONST float * const ff_sine_windows[13]; int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale); void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); diff --git a/libavcodec/mdct.c b/libavcodec/mdct.c index a2b9e8b423..8734bdc56f 100644 --- a/libavcodec/mdct.c +++ b/libavcodec/mdct.c @@ -48,26 +48,7 @@ av_cold void ff_kbd_window_init(float *window, float alpha, int n) window[i] = sqrt(local_window[i] / sum); } -DECLARE_ALIGNED(16, float, ff_sine_32 [ 32]); -DECLARE_ALIGNED(16, float, ff_sine_64 [ 64]); -DECLARE_ALIGNED(16, float, ff_sine_128 [ 128]); -DECLARE_ALIGNED(16, float, ff_sine_256 [ 256]); -DECLARE_ALIGNED(16, float, ff_sine_512 [ 512]); -DECLARE_ALIGNED(16, float, ff_sine_1024[1024]); -DECLARE_ALIGNED(16, float, ff_sine_2048[2048]); -DECLARE_ALIGNED(16, float, ff_sine_4096[4096]); -float * const ff_sine_windows[] = { - NULL, NULL, NULL, NULL, NULL, // unused - ff_sine_32 , ff_sine_64 , - ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096 -}; - -// Generate a sine window. -av_cold void ff_sine_window_init(float *window, int n) { - int i; - for(i = 0; i < n; i++) - window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); -} +#include "mdct_tablegen.h" /** * init MDCT or IMDCT computation. diff --git a/libavcodec/mdct_tablegen.c b/libavcodec/mdct_tablegen.c new file mode 100644 index 0000000000..f04502f181 --- /dev/null +++ b/libavcodec/mdct_tablegen.c @@ -0,0 +1,61 @@ +/* + * Generate a header file for hardcoded MDCT tables + * + * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de> + * + * 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 <stdlib.h> +#define CONFIG_HARDCODED_TABLES 0 +#define av_cold +#define SINETABLE_CONST +#define SINETABLE(size) \ + float ff_sine_##size[size] +#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#include "mdct_tablegen.h" +#include "tableprint.h" + +void tableinit(void) +{ + int i; + for (i = 5; i <= 12; i++) + ff_init_ff_sine_windows(i); +} + +#define SINE_TABLE_DEF(size) \ + { \ + "SINETABLE("#size")", \ + write_float_array, \ + ff_sine_##size, \ + size \ + }, + +const struct tabledef tables[] = { + SINE_TABLE_DEF( 32) + SINE_TABLE_DEF( 64) + SINE_TABLE_DEF( 128) + SINE_TABLE_DEF( 256) + SINE_TABLE_DEF( 512) + SINE_TABLE_DEF(1024) + SINE_TABLE_DEF(2048) + SINE_TABLE_DEF(4096) + { NULL } +}; diff --git a/libavcodec/mdct_tablegen.h b/libavcodec/mdct_tablegen.h new file mode 100644 index 0000000000..30a517c2e5 --- /dev/null +++ b/libavcodec/mdct_tablegen.h @@ -0,0 +1,59 @@ +/* + * Header file for hardcoded MDCT tables + * + * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de> + * + * 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 <assert.h> +// do not use libavutil/mathematics.h since this is compiled both +// for the host and the target and config.h is only valid for the target +#include <math.h> + +#if !CONFIG_HARDCODED_TABLES +SINETABLE( 32); +SINETABLE( 64); +SINETABLE( 128); +SINETABLE( 256); +SINETABLE( 512); +SINETABLE(1024); +SINETABLE(2048); +SINETABLE(4096); +#else +#include "mdct_tables.h" +#endif + +SINETABLE_CONST float * const ff_sine_windows[] = { + NULL, NULL, NULL, NULL, NULL, // unused + ff_sine_32 , ff_sine_64 , + ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096 +}; + +// Generate a sine window. +av_cold void ff_sine_window_init(float *window, int n) { + int i; + for(i = 0; i < n; i++) + window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); +} + +av_cold void ff_init_ff_sine_windows(int index) { + assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows)); +#if !CONFIG_HARDCODED_TABLES + ff_sine_window_init(ff_sine_windows[index], 1 << index); +#endif +} diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c index 8ed4298fc2..9c36141786 100644 --- a/libavcodec/nellymoserdec.c +++ b/libavcodec/nellymoserdec.c @@ -144,7 +144,7 @@ static av_cold int decode_init(AVCodecContext * avctx) { /* Generate overlap window */ if (!ff_sine_128[127]) - ff_sine_window_init(ff_sine_128, 128); + ff_init_ff_sine_windows(7); avctx->sample_fmt = SAMPLE_FMT_S16; avctx->channel_layout = CH_LAYOUT_MONO; diff --git a/libavcodec/tableprint.c b/libavcodec/tableprint.c index 4f94c6a53f..d715fd777b 100644 --- a/libavcodec/tableprint.c +++ b/libavcodec/tableprint.c @@ -39,6 +39,7 @@ void write_##name##_array(const void *arg, int len, int dummy)\ WRITE_1D_FUNC(int8, int8_t, "%3"PRIi8, 15) WRITE_1D_FUNC(uint32, uint32_t, "0x%08"PRIx32, 7) +WRITE_1D_FUNC(float, float, "%.18e", 3) #define WRITE_2D_FUNC(name, type)\ void write_##name##_2d_array(const void *arg, int len, int len2)\ diff --git a/libavcodec/tableprint.h b/libavcodec/tableprint.h index e73a9e20b3..706e296533 100644 --- a/libavcodec/tableprint.h +++ b/libavcodec/tableprint.h @@ -32,6 +32,7 @@ */ void write_int8_array (const void *, int, int); void write_uint32_array (const void *, int, int); +void write_float_array (const void *, int, int); void write_int8_2d_array (const void *, int, int); void write_uint32_2d_array(const void *, int, int); /** \} */ // end of printfuncs group diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c index 7131584232..f1073722d8 100644 --- a/libavcodec/twinvq.c +++ b/libavcodec/twinvq.c @@ -893,9 +893,9 @@ static av_cold void init_mdct_win(TwinContext *tctx) } - ff_sine_window_init(ff_sine_windows[av_log2(size_m) ], size_m ); - ff_sine_window_init(ff_sine_windows[av_log2(size_s/2) ], size_s/2); - ff_sine_window_init(ff_sine_windows[av_log2(mtab->size)], mtab->size); + ff_init_ff_sine_windows(av_log2(size_m)); + ff_init_ff_sine_windows(av_log2(size_s/2)); + ff_init_ff_sine_windows(av_log2(mtab->size)); } /** diff --git a/libavcodec/wma.c b/libavcodec/wma.c index 9b2588f530..3322d0ed6a 100644 --- a/libavcodec/wma.c +++ b/libavcodec/wma.c @@ -343,9 +343,7 @@ int ff_wma_init(AVCodecContext *avctx, int flags2) /* init MDCT windows : simple sinus window */ for (i = 0; i < s->nb_block_sizes; i++) { - int n; - n = 1 << (s->frame_len_bits - i); - ff_sine_window_init(ff_sine_windows[s->frame_len_bits - i], n); + ff_init_ff_sine_windows(s->frame_len_bits - i); s->windows[i] = ff_sine_windows[s->frame_len_bits - i]; } diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c index cbc97d9c82..dee47e0e2a 100644 --- a/libavcodec/wmaprodec.c +++ b/libavcodec/wmaprodec.c @@ -425,9 +425,8 @@ static av_cold int decode_init(AVCodecContext *avctx) /** init MDCT windows: simple sinus window */ for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) { - const int n = 1 << (WMAPRO_BLOCK_MAX_BITS - i); const int win_idx = WMAPRO_BLOCK_MAX_BITS - i; - ff_sine_window_init(ff_sine_windows[win_idx], n); + ff_init_ff_sine_windows(win_idx); s->windows[WMAPRO_BLOCK_SIZES - i - 1] = ff_sine_windows[win_idx]; } |