avcodec/aac_tablegen: get rid of hardcoded tables entirely
Commit 96786a12f6df26990bbe7c0ca4592b3731724469 makes runtime initialization cheap. Tested with FATE, with/without --enable-hardcoded-tables. Reviewed-by: Rostislav Pehlivanov <atomnuker@gmail.com> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
This commit is contained in:
parent
861f2b2a53
commit
79abf2d0de
@ -920,7 +920,6 @@ SLIBOBJS-$(HAVE_GNU_WINDRES) += avcodecres.o
|
||||
|
||||
SKIPHEADERS += %_tablegen.h \
|
||||
%_tables.h \
|
||||
aac_tablegen_decl.h \
|
||||
fft-internal.h \
|
||||
tableprint.h \
|
||||
tableprint_vlc.h \
|
||||
@ -964,8 +963,7 @@ TESTOBJS = dctref.o
|
||||
|
||||
TOOLS = fourcc2pixfmt
|
||||
|
||||
HOSTPROGS = aac_tablegen \
|
||||
aacps_tablegen \
|
||||
HOSTPROGS = aacps_tablegen \
|
||||
aacps_fixed_tablegen \
|
||||
aacsbr_tablegen \
|
||||
aacsbr_fixed_tablegen \
|
||||
@ -999,7 +997,7 @@ $(SUBDIR)%_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DCONFIG_SMALL=0
|
||||
endif
|
||||
|
||||
GEN_HEADERS = cbrt_tables.h cbrt_fixed_tables.h aacps_tables.h aacps_fixed_tables.h aacsbr_tables.h \
|
||||
aacsbr_fixed_tables.h aac_tables.h dsd_tables.h dv_tables.h \
|
||||
aacsbr_fixed_tables.h dsd_tables.h dv_tables.h \
|
||||
sinewin_tables.h sinewin_fixed_tables.h mpegaudio_tables.h motionpixels_tables.h \
|
||||
pcm_tables.h qdm2_tables.h
|
||||
GEN_HEADERS := $(addprefix $(SUBDIR), $(GEN_HEADERS))
|
||||
@ -1014,7 +1012,6 @@ $(SUBDIR)aacps_float.o: $(SUBDIR)aacps_tables.h
|
||||
$(SUBDIR)aacps_fixed.o: $(SUBDIR)aacps_fixed_tables.h
|
||||
$(SUBDIR)aacsbr.o: $(SUBDIR)aacsbr_tables.h
|
||||
$(SUBDIR)aacsbr_fixed.o: $(SUBDIR)aacsbr_fixed_tables.h
|
||||
$(SUBDIR)aactab.o: $(SUBDIR)aac_tables.h
|
||||
$(SUBDIR)aactab_fixed.o: $(SUBDIR)aac_fixed_tables.h
|
||||
$(SUBDIR)dsddec.o: $(SUBDIR)dsd_tables.h
|
||||
$(SUBDIR)dvenc.o: $(SUBDIR)dv_tables.h
|
||||
|
@ -151,6 +151,8 @@ typedef struct PredictorState {
|
||||
#define SCALE_MAX_DIFF 60 ///< maximum scalefactor difference allowed by standard
|
||||
#define SCALE_DIFF_ZERO 60 ///< codebook index corresponding to zero scalefactor indices difference
|
||||
|
||||
#define POW_SF2_ZERO 200 ///< ff_aac_pow2sf_tab index corresponding to pow(2, 0);
|
||||
|
||||
#define NOISE_PRE 256 ///< preamble for NOISE_BT, put in bitstream with the first noise band
|
||||
#define NOISE_PRE_BITS 9 ///< length of preamble
|
||||
#define NOISE_OFFSET 90 ///< subtracted from global gain, used as offset for the preamble
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Generate a header file for hardcoded AAC tables
|
||||
*
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* 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
|
||||
#include "aac_tablegen.h"
|
||||
#include "tableprint.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ff_aac_tableinit();
|
||||
|
||||
write_fileheader();
|
||||
|
||||
WRITE_ARRAY("const", float, ff_aac_pow2sf_tab);
|
||||
|
||||
WRITE_ARRAY("const", float, ff_aac_pow34sf_tab);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Header file for hardcoded AAC tables
|
||||
*
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AAC_TABLEGEN_H
|
||||
#define AVCODEC_AAC_TABLEGEN_H
|
||||
|
||||
#include "aac_tablegen_decl.h"
|
||||
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
#include "libavcodec/aac_tables.h"
|
||||
#else
|
||||
#include "libavutil/mathematics.h"
|
||||
float ff_aac_pow2sf_tab[428];
|
||||
float ff_aac_pow34sf_tab[428];
|
||||
|
||||
av_cold void ff_aac_tableinit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* 2^(i/16) for 0 <= i <= 15 */
|
||||
static const float exp2_lut[] = {
|
||||
1.00000000000000000000,
|
||||
1.04427378242741384032,
|
||||
1.09050773266525765921,
|
||||
1.13878863475669165370,
|
||||
1.18920711500272106672,
|
||||
1.24185781207348404859,
|
||||
1.29683955465100966593,
|
||||
1.35425554693689272830,
|
||||
1.41421356237309504880,
|
||||
1.47682614593949931139,
|
||||
1.54221082540794082361,
|
||||
1.61049033194925430818,
|
||||
1.68179283050742908606,
|
||||
1.75625216037329948311,
|
||||
1.83400808640934246349,
|
||||
1.91520656139714729387,
|
||||
};
|
||||
float t1 = 8.8817841970012523233890533447265625e-16; // 2^(-50)
|
||||
float t2 = 3.63797880709171295166015625e-12; // 2^(-38)
|
||||
int t1_inc_cur, t2_inc_cur;
|
||||
int t1_inc_prev = 0;
|
||||
int t2_inc_prev = 8;
|
||||
|
||||
for (i = 0; i < 428; i++) {
|
||||
t1_inc_cur = 4 * (i % 4);
|
||||
t2_inc_cur = (8 + 3*i) % 16;
|
||||
if (t1_inc_cur < t1_inc_prev)
|
||||
t1 *= 2;
|
||||
if (t2_inc_cur < t2_inc_prev)
|
||||
t2 *= 2;
|
||||
// A much more efficient and accurate way of doing:
|
||||
// ff_aac_pow2sf_tab[i] = pow(2, (i - POW_SF2_ZERO) / 4.0);
|
||||
// ff_aac_pow34sf_tab[i] = pow(ff_aac_pow2sf_tab[i], 3.0/4.0);
|
||||
ff_aac_pow2sf_tab[i] = t1 * exp2_lut[t1_inc_cur];
|
||||
ff_aac_pow34sf_tab[i] = t2 * exp2_lut[t2_inc_cur];
|
||||
t1_inc_prev = t1_inc_cur;
|
||||
t2_inc_prev = t2_inc_cur;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_HARDCODED_TABLES */
|
||||
|
||||
#endif /* AVCODEC_AAC_TABLEGEN_H */
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Header file for hardcoded AAC tables
|
||||
*
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AAC_TABLEGEN_DECL_H
|
||||
#define AVCODEC_AAC_TABLEGEN_DECL_H
|
||||
|
||||
#define POW_SF2_ZERO 200 ///< ff_aac_pow2sf_tab index corresponding to pow(2, 0);
|
||||
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
#define ff_aac_tableinit()
|
||||
extern const float ff_aac_pow2sf_tab[428];
|
||||
extern const float ff_aac_pow34sf_tab[428];
|
||||
#else
|
||||
void ff_aac_tableinit(void);
|
||||
extern float ff_aac_pow2sf_tab[428];
|
||||
extern float ff_aac_pow34sf_tab[428];
|
||||
#endif /* CONFIG_HARDCODED_TABLES */
|
||||
|
||||
#endif /* AVCODEC_AAC_TABLEGEN_DECL_H */
|
@ -44,7 +44,6 @@
|
||||
#include "aacenctab.h"
|
||||
#include "aacenc_utils.h"
|
||||
#include "aacenc_quantization.h"
|
||||
#include "aac_tablegen_decl.h"
|
||||
|
||||
#include "aacenc_is.h"
|
||||
#include "aacenc_tns.h"
|
||||
|
@ -45,8 +45,6 @@
|
||||
#include "aacenc.h"
|
||||
#include "aactab.h"
|
||||
#include "aacenctab.h"
|
||||
#include "aac_tablegen_decl.h"
|
||||
|
||||
|
||||
/**
|
||||
* structure used in optimal codebook search
|
||||
|
@ -49,7 +49,6 @@
|
||||
#include "aacenc.h"
|
||||
#include "aactab.h"
|
||||
#include "aacenctab.h"
|
||||
#include "aac_tablegen_decl.h"
|
||||
|
||||
/** Frequency in Hz for lower limit of noise substitution **/
|
||||
#define NOISE_LOW_LIMIT 4000
|
||||
|
@ -29,8 +29,8 @@
|
||||
#define AVCODEC_AACENC_UTILS_H
|
||||
|
||||
#include "aac.h"
|
||||
#include "aac_tablegen_decl.h"
|
||||
#include "aacenctab.h"
|
||||
#include "aactab.h"
|
||||
|
||||
#define ROUND_STANDARD 0.4054f
|
||||
#define ROUND_TO_ZERO 0.1054f
|
||||
|
@ -29,10 +29,12 @@
|
||||
|
||||
#include "libavutil/mem.h"
|
||||
#include "aac.h"
|
||||
#include "aac_tablegen.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
float ff_aac_pow2sf_tab[428];
|
||||
float ff_aac_pow34sf_tab[428];
|
||||
|
||||
DECLARE_ALIGNED(32, float, ff_aac_kbd_long_1024)[1024];
|
||||
DECLARE_ALIGNED(32, float, ff_aac_kbd_short_128)[128];
|
||||
DECLARE_ALIGNED(32, int, ff_aac_kbd_long_1024_fixed)[1024];
|
||||
|
@ -32,7 +32,6 @@
|
||||
|
||||
#include "libavutil/mem.h"
|
||||
#include "aac.h"
|
||||
#include "aac_tablegen_decl.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -40,6 +39,55 @@
|
||||
* Tables in this file are shared by the AAC decoders and encoder
|
||||
*/
|
||||
|
||||
extern float ff_aac_pow2sf_tab[428];
|
||||
extern float ff_aac_pow34sf_tab[428];
|
||||
|
||||
static inline void ff_aac_tableinit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* 2^(i/16) for 0 <= i <= 15 */
|
||||
static const float exp2_lut[] = {
|
||||
1.00000000000000000000,
|
||||
1.04427378242741384032,
|
||||
1.09050773266525765921,
|
||||
1.13878863475669165370,
|
||||
1.18920711500272106672,
|
||||
1.24185781207348404859,
|
||||
1.29683955465100966593,
|
||||
1.35425554693689272830,
|
||||
1.41421356237309504880,
|
||||
1.47682614593949931139,
|
||||
1.54221082540794082361,
|
||||
1.61049033194925430818,
|
||||
1.68179283050742908606,
|
||||
1.75625216037329948311,
|
||||
1.83400808640934246349,
|
||||
1.91520656139714729387,
|
||||
};
|
||||
float t1 = 8.8817841970012523233890533447265625e-16; // 2^(-50)
|
||||
float t2 = 3.63797880709171295166015625e-12; // 2^(-38)
|
||||
int t1_inc_cur, t2_inc_cur;
|
||||
int t1_inc_prev = 0;
|
||||
int t2_inc_prev = 8;
|
||||
|
||||
for (i = 0; i < 428; i++) {
|
||||
t1_inc_cur = 4 * (i % 4);
|
||||
t2_inc_cur = (8 + 3*i) % 16;
|
||||
if (t1_inc_cur < t1_inc_prev)
|
||||
t1 *= 2;
|
||||
if (t2_inc_cur < t2_inc_prev)
|
||||
t2 *= 2;
|
||||
// A much more efficient and accurate way of doing:
|
||||
// ff_aac_pow2sf_tab[i] = pow(2, (i - POW_SF2_ZERO) / 4.0);
|
||||
// ff_aac_pow34sf_tab[i] = pow(ff_aac_pow2sf_tab[i], 3.0/4.0);
|
||||
ff_aac_pow2sf_tab[i] = t1 * exp2_lut[t1_inc_cur];
|
||||
ff_aac_pow34sf_tab[i] = t2 * exp2_lut[t2_inc_cur];
|
||||
t1_inc_prev = t1_inc_cur;
|
||||
t2_inc_prev = t2_inc_cur;
|
||||
}
|
||||
}
|
||||
|
||||
/* @name ltp_coef
|
||||
* Table of the LTP coefficients
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user