Commit 14b86070 authored by Reimar Döffinger's avatar Reimar Döffinger
Browse files

Add support for hard-coded MDCT-related ff_sine_windows tables.

Originally committed as revision 21108 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent b090930d
......@@ -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
......@@ -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;
}
......
......@@ -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]);
......
......@@ -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();
......
......@@ -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);
......
......@@ -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.
......
/*
* 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 }
};
/*
* 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
}
......@@ -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;
......
......@@ -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)\
......
......@@ -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
......
......@@ -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));
}
/**
......
......@@ -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];
}
......
......@@ -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];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment