Commit 08be74ac authored by Jovan Zelincevic's avatar Jovan Zelincevic Committed by Michael Niedermayer

libavcodec: Implementation of AAC_fixed_decoder (LC-module) [2/4]

Add fixed point implementation of functions for generating tables
Signed-off-by: 's avatarNedeljko Babic <nedeljko.babic@imgtec.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent f497a9e8
...@@ -30,6 +30,29 @@ ...@@ -30,6 +30,29 @@
#ifndef AVCODEC_AAC_H #ifndef AVCODEC_AAC_H
#define AVCODEC_AAC_H #define AVCODEC_AAC_H
#ifndef USE_FIXED
#define USE_FIXED 0
#endif
#if USE_FIXED
#include "libavutil/softfloat.h"
#define FFT_FLOAT 0
#define FFT_FIXED_32 1
#define Q30(x) (int)((x)*1073741824.0 + 0.5)
#define Q31(x) (int)((x)*2147483648.0 + 0.5)
#else
#define FFT_FLOAT 1
#define FFT_FIXED_32 0
#define Q30(x) x
#define Q31(x) x
#endif /* USE_FIXED */
#include "libavutil/float_dsp.h" #include "libavutil/float_dsp.h"
#include "avcodec.h" #include "avcodec.h"
#include "imdct15.h" #include "imdct15.h"
......
...@@ -38,9 +38,9 @@ ...@@ -38,9 +38,9 @@
/* @name ltp_coef /* @name ltp_coef
* Table of the LTP coefficients * Table of the LTP coefficients
*/ */
static const float ltp_coef[8] = { static const INTFLOAT ltp_coef[8] = {
0.570829, 0.696616, 0.813004, 0.911304, Q30(0.570829f), Q30(0.696616f), Q30(0.813004f), Q30(0.911304f),
0.984900, 1.067894, 1.194601, 1.369533, Q30(0.984900f), Q30(1.067894f), Q30(1.194601f), Q30(1.369533f),
}; };
/* @name tns_tmp2_map /* @name tns_tmp2_map
...@@ -49,28 +49,28 @@ static const float ltp_coef[8] = { ...@@ -49,28 +49,28 @@ static const float ltp_coef[8] = {
* respectively. * respectively.
* @{ * @{
*/ */
static const float tns_tmp2_map_1_3[4] = { static const INTFLOAT tns_tmp2_map_1_3[4] = {
0.00000000, -0.43388373, 0.64278758, 0.34202015, Q31(0.00000000f), Q31(-0.43388373f), Q31(0.64278758f), Q31(0.34202015f),
}; };
static const float tns_tmp2_map_0_3[8] = { static const INTFLOAT tns_tmp2_map_0_3[8] = {
0.00000000, -0.43388373, -0.78183150, -0.97492790, Q31(0.00000000f), Q31(-0.43388373f), Q31(-0.78183150f), Q31(-0.97492790f),
0.98480773, 0.86602539, 0.64278758, 0.34202015, Q31(0.98480773f), Q31( 0.86602539f), Q31( 0.64278758f), Q31( 0.34202015f),
}; };
static const float tns_tmp2_map_1_4[8] = { static const INTFLOAT tns_tmp2_map_1_4[8] = {
0.00000000, -0.20791170, -0.40673664, -0.58778524, Q31(0.00000000f), Q31(-0.20791170f), Q31(-0.40673664f), Q31(-0.58778524f),
0.67369562, 0.52643216, 0.36124167, 0.18374951, Q31(0.67369562f), Q31( 0.52643216f), Q31( 0.36124167f), Q31( 0.18374951f),
}; };
static const float tns_tmp2_map_0_4[16] = { static const INTFLOAT tns_tmp2_map_0_4[16] = {
0.00000000, -0.20791170, -0.40673664, -0.58778524, Q31( 0.00000000f), Q31(-0.20791170f), Q31(-0.40673664f), Q31(-0.58778524f),
-0.74314481, -0.86602539, -0.95105654, -0.99452192, Q31(-0.74314481f), Q31(-0.86602539f), Q31(-0.95105654f), Q31(-0.99452192f),
0.99573416, 0.96182561, 0.89516330, 0.79801720, Q31( 0.99573416f), Q31( 0.96182561f), Q31( 0.89516330f), Q31( 0.79801720f),
0.67369562, 0.52643216, 0.36124167, 0.18374951, Q31( 0.67369562f), Q31( 0.52643216f), Q31( 0.36124167f), Q31( 0.18374951f),
}; };
static const float * const tns_tmp2_map[4] = { static const INTFLOAT * const tns_tmp2_map[4] = {
tns_tmp2_map_0_3, tns_tmp2_map_0_3,
tns_tmp2_map_0_4, tns_tmp2_map_0_4,
tns_tmp2_map_1_3, tns_tmp2_map_1_3,
......
This diff is collapsed.
...@@ -46,7 +46,11 @@ ...@@ -46,7 +46,11 @@
*/ */
DECLARE_ALIGNED(32, extern float, ff_aac_kbd_long_1024)[1024]; DECLARE_ALIGNED(32, extern float, ff_aac_kbd_long_1024)[1024];
DECLARE_ALIGNED(32, extern float, ff_aac_kbd_short_128)[128]; DECLARE_ALIGNED(32, extern float, ff_aac_kbd_short_128)[128];
DECLARE_ALIGNED(32, extern int, ff_aac_kbd_long_1024_fixed)[1024];
DECLARE_ALIGNED(32, extern int, ff_aac_kbd_long_512_fixed)[512];
DECLARE_ALIGNED(32, extern int, ff_aac_kbd_short_128_fixed)[128];
const DECLARE_ALIGNED(32, extern float, ff_aac_eld_window_512)[1920]; const DECLARE_ALIGNED(32, extern float, ff_aac_eld_window_512)[1920];
const DECLARE_ALIGNED(32, extern int, ff_aac_eld_window_512_fixed)[1920];
const DECLARE_ALIGNED(32, extern float, ff_aac_eld_window_480)[1800]; const DECLARE_ALIGNED(32, extern float, ff_aac_eld_window_480)[1800];
// @} // @}
......
/*
* Generate a header file for hardcoded AAC cube-root table
*
* Copyright (c) 2010 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
*/
#define USE_FIXED 1
#include "cbrt_tablegen_template.c"
...@@ -19,3 +19,6 @@ ...@@ -19,3 +19,6 @@
* License along with FFmpeg; if not, write to the Free Software * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define USE_FIXED 0
#include "cbrt_tablegen_template.c"
...@@ -27,13 +27,26 @@ ...@@ -27,13 +27,26 @@
#include <math.h> #include <math.h>
#include "libavutil/attributes.h" #include "libavutil/attributes.h"
#if USE_FIXED
#define CBRT_RENAME(a) a ## _fixed
#define CBRT(x) (int)floor((x).f * 8192 + 0.5)
#else
#define CBRT_RENAME(a) a
#define CBRT(x) x.i
#endif
#if CONFIG_HARDCODED_TABLES #if CONFIG_HARDCODED_TABLES
#if USE_FIXED
#define cbrt_tableinit_fixed()
#include "libavcodec/cbrt_fixed_tables.h"
#else
#define cbrt_tableinit() #define cbrt_tableinit()
#include "libavcodec/cbrt_tables.h" #include "libavcodec/cbrt_tables.h"
#endif
#else #else
static uint32_t cbrt_tab[1 << 13]; static uint32_t cbrt_tab[1 << 13];
static av_cold void cbrt_tableinit(void) static av_cold void CBRT_RENAME(cbrt_tableinit)(void)
{ {
if (!cbrt_tab[(1<<13) - 1]) { if (!cbrt_tab[(1<<13) - 1]) {
int i; int i;
...@@ -44,7 +57,7 @@ static av_cold void cbrt_tableinit(void) ...@@ -44,7 +57,7 @@ static av_cold void cbrt_tableinit(void)
uint32_t i; uint32_t i;
} f; } f;
f.f = pow(i, 1.0 / 3.0) * i; f.f = pow(i, 1.0 / 3.0) * i;
cbrt_tab[i] = f.i; cbrt_tab[i] = CBRT(f);
} }
} }
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
int main(void) int main(void)
{ {
cbrt_tableinit(); CBRT_RENAME(cbrt_tableinit)();
write_fileheader(); write_fileheader();
......
...@@ -16,5 +16,6 @@ ...@@ -16,5 +16,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define USE_FIXED 0
#include "sinewin.h" #include "sinewin.h"
#include "sinewin_tablegen.h" #include "sinewin_tablegen.h"
...@@ -30,20 +30,32 @@ ...@@ -30,20 +30,32 @@
# define SINETABLE_CONST # define SINETABLE_CONST
#endif #endif
#ifndef USE_FIXED
#define USE_FIXED 0
#endif
#if USE_FIXED
#define SINEWIN_SUFFIX(a) a ## _fixed
#define INTFLOAT int
#else
#define SINEWIN_SUFFIX(a) a
#define INTFLOAT float
#endif
#define SINETABLE(size) \ #define SINETABLE(size) \
SINETABLE_CONST DECLARE_ALIGNED(32, float, ff_sine_##size)[size] SINETABLE_CONST DECLARE_ALIGNED(32, INTFLOAT, SINEWIN_SUFFIX(ff_sine_##size))[size]
/** /**
* Generate a sine window. * Generate a sine window.
* @param window pointer to half window * @param window pointer to half window
* @param n size of half window * @param n size of half window
*/ */
void ff_sine_window_init(float *window, int n); void SINEWIN_SUFFIX(ff_sine_window_init)(INTFLOAT *window, int n);
/** /**
* initialize the specified entry of ff_sine_windows * initialize the specified entry of ff_sine_windows
*/ */
void ff_init_ff_sine_windows(int index); void SINEWIN_SUFFIX(ff_init_ff_sine_windows)(int index);
extern SINETABLE( 32); extern SINETABLE( 32);
extern SINETABLE( 64); extern SINETABLE( 64);
...@@ -55,6 +67,6 @@ extern SINETABLE(2048); ...@@ -55,6 +67,6 @@ extern SINETABLE(2048);
extern SINETABLE(4096); extern SINETABLE(4096);
extern SINETABLE(8192); extern SINETABLE(8192);
extern SINETABLE_CONST float * const ff_sine_windows[14]; extern SINETABLE_CONST INTFLOAT * const SINEWIN_SUFFIX(ff_sine_windows)[14];
#endif /* AVCODEC_SINEWIN_H */ #endif /* AVCODEC_SINEWIN_H */
/*
* 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
*/
#define USE_FIXED 1
#include "sinewin.h"
#include "sinewin_tablegen.h"
/*
* Generate a header file for hardcoded sine windows
*
* 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
*/
#define USE_FIXED 1
#include "sinewin_tablegen_template.c"
...@@ -19,3 +19,6 @@ ...@@ -19,3 +19,6 @@
* License along with FFmpeg; if not, write to the Free Software * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define USE_FIXED 0
#include "sinewin_tablegen_template.c"
...@@ -41,26 +41,41 @@ SINETABLE(2048); ...@@ -41,26 +41,41 @@ SINETABLE(2048);
SINETABLE(4096); SINETABLE(4096);
SINETABLE(8192); SINETABLE(8192);
#else #else
#if USE_FIXED
#include "libavcodec/sinewin_fixed_tables.h"
#else
#include "libavcodec/sinewin_tables.h" #include "libavcodec/sinewin_tables.h"
#endif #endif
#endif
#if USE_FIXED
#define SINEWIN_SUFFIX(a) a ## _fixed
#define INTFLOAT int
#define SIN_FIX(a) (int)floor((a) * 0x80000000 + 0.5)
#else
#define SINEWIN_SUFFIX(a) a
#define INTFLOAT float
#define SIN_FIX(a) a
#endif
SINETABLE_CONST float * const ff_sine_windows[] = { SINETABLE_CONST INTFLOAT * const SINEWIN_SUFFIX(ff_sine_windows)[] = {
NULL, NULL, NULL, NULL, NULL, // unused NULL, NULL, NULL, NULL, NULL, // unused
ff_sine_32 , ff_sine_64 , SINEWIN_SUFFIX(ff_sine_32) , SINEWIN_SUFFIX(ff_sine_64), SINEWIN_SUFFIX(ff_sine_128),
ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096, ff_sine_8192 SINEWIN_SUFFIX(ff_sine_256), SINEWIN_SUFFIX(ff_sine_512), SINEWIN_SUFFIX(ff_sine_1024),
SINEWIN_SUFFIX(ff_sine_2048), SINEWIN_SUFFIX(ff_sine_4096), SINEWIN_SUFFIX(ff_sine_8192)
}; };
// Generate a sine window. // Generate a sine window.
av_cold void ff_sine_window_init(float *window, int n) { av_cold void SINEWIN_SUFFIX(ff_sine_window_init)(INTFLOAT *window, int n) {
int i; int i;
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); window[i] = SIN_FIX(sinf((i + 0.5) * (M_PI / (2.0 * n))));
} }
av_cold void ff_init_ff_sine_windows(int index) { av_cold void SINEWIN_SUFFIX(ff_init_ff_sine_windows)(int index) {
assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows)); assert(index >= 0 && index < FF_ARRAY_ELEMS(SINEWIN_SUFFIX(ff_sine_windows)));
#if !CONFIG_HARDCODED_TABLES #if !CONFIG_HARDCODED_TABLES
ff_sine_window_init(ff_sine_windows[index], 1 << index); SINEWIN_SUFFIX(ff_sine_window_init)(SINEWIN_SUFFIX(ff_sine_windows)[index], 1 << index);
#endif #endif
} }
......
...@@ -22,9 +22,23 @@ ...@@ -22,9 +22,23 @@
#include <stdlib.h> #include <stdlib.h>
#define CONFIG_HARDCODED_TABLES 0 #define CONFIG_HARDCODED_TABLES 0
#if USE_FIXED
#define ADD_SUFFIX(a) a ## _fixed
#define INTFLOAT int
#define WRITE_FUNC write_int32_t_array
#else
#define ADD_SUFFIX(a) a
#define INTFLOAT float
#define WRITE_FUNC write_float_array
#endif
#define SINETABLE_CONST #define SINETABLE_CONST
#define SINETABLE(size) \ #define SINETABLE(size) \
float ff_sine_##size[size] INTFLOAT ADD_SUFFIX(ff_sine_##size)[size]
#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
#include "sinewin_tablegen.h" #include "sinewin_tablegen.h"
#include "tableprint.h" #include "tableprint.h"
...@@ -36,9 +50,9 @@ int main(void) ...@@ -36,9 +50,9 @@ int main(void)
write_fileheader(); write_fileheader();
for (i = 5; i <= 13; i++) { for (i = 5; i <= 13; i++) {
ff_init_ff_sine_windows(i); ADD_SUFFIX(ff_init_ff_sine_windows)(i);
printf("SINETABLE(%4i) = {\n", 1 << i); printf("SINETABLE(%4i) = {\n", 1 << i);
write_float_array(ff_sine_windows[i], 1 << i); WRITE_FUNC(ADD_SUFFIX(ff_sine_windows)[i], 1 << i);
printf("};\n"); printf("};\n");
} }
......
...@@ -64,6 +64,7 @@ void write_int8_t_array (const int8_t *, int); ...@@ -64,6 +64,7 @@ void write_int8_t_array (const int8_t *, int);
void write_uint8_t_array (const uint8_t *, int); void write_uint8_t_array (const uint8_t *, int);
void write_uint16_t_array (const uint16_t *, int); void write_uint16_t_array (const uint16_t *, int);
void write_uint32_t_array (const uint32_t *, int); void write_uint32_t_array (const uint32_t *, int);
void write_int32_t_array (const int32_t *, int);
void write_float_array (const float *, int); void write_float_array (const float *, int);
void write_int8_t_2d_array (const void *, int, int); void write_int8_t_2d_array (const void *, int, int);
void write_uint8_t_2d_array (const void *, int, int); void write_uint8_t_2d_array (const void *, int, int);
...@@ -116,6 +117,7 @@ WRITE_1D_FUNC(uint8_t, "0x%02"PRIx8, 15) ...@@ -116,6 +117,7 @@ WRITE_1D_FUNC(uint8_t, "0x%02"PRIx8, 15)
WRITE_1D_FUNC(uint16_t, "0x%08"PRIx16, 7) WRITE_1D_FUNC(uint16_t, "0x%08"PRIx16, 7)
WRITE_1D_FUNC(int16_t, "%5"PRIi16, 7) WRITE_1D_FUNC(int16_t, "%5"PRIi16, 7)
WRITE_1D_FUNC(uint32_t, "0x%08"PRIx32, 7) WRITE_1D_FUNC(uint32_t, "0x%08"PRIx32, 7)
WRITE_1D_FUNC(int32_t, "0x%08"PRIx32, 7)
WRITE_1D_FUNC(float, "%.18e", 3) WRITE_1D_FUNC(float, "%.18e", 3)
WRITE_2D_FUNC(int8_t) WRITE_2D_FUNC(int8_t)
......
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