From 30deaba97ba0a25b794b2099c742deae40a9cdda Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Sun, 24 Sep 2023 22:40:13 +0200 Subject: [PATCH] avcodec/aacdec_template: Don't init unused table for fixed-point decoder The fixed-point decoder actually does not use the floating-point tables initialized by ff_aac_tableinit() at all. So don't initialize them for it; instead merge initializing these tables into ff_aac_float_common_init() which is already the function for the common static initializations of the floating-point AAC decoder and the (also floating-point) AAC encoder. Doing so saves also one AVOnce. Signed-off-by: Andreas Rheinhardt --- libavcodec/aacdec_template.c | 1 - libavcodec/aacenc.c | 7 ++- libavcodec/aactab.c | 102 +++++++++++++++++------------------ libavcodec/aactab.h | 2 - 4 files changed, 52 insertions(+), 60 deletions(-) diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 308fa08f5c..65dd8b4bf9 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -1128,7 +1128,6 @@ static av_cold void aac_static_table_init(void) AAC_RENAME(ff_aac_sbr_init)(); ff_aacdec_common_init_once(); - ff_aac_tableinit(); // window initialization AAC_RENAME(avpriv_kbd_window_init)(AAC_RENAME(aac_kbd_long_960), 4.0, 960); diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index 2a34685aec..5e6a255a8f 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -1210,9 +1210,6 @@ static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s) if (!s->fdsp) return AVERROR(ENOMEM); - // window init - ff_aac_float_common_init(); - if ((ret = av_tx_init(&s->mdct1024, &s->mdct1024_fn, AV_TX_FLOAT_MDCT, 0, 1024, &scale, 0)) < 0) return ret; @@ -1359,6 +1356,9 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) if (s->channels > 3) s->options.mid_side = 0; + // Initialize static tables + ff_aac_float_common_init(); + if ((ret = dsp_init(avctx, s)) < 0) return ret; @@ -1393,7 +1393,6 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) #endif ff_af_queue_init(avctx, &s->afq); - ff_aac_tableinit(); return 0; } diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c index d0006eac35..edb51d8810 100644 --- a/libavcodec/aactab.c +++ b/libavcodec/aactab.c @@ -36,18 +36,64 @@ #include -float ff_aac_pow2sf_tab[428]; -float ff_aac_pow34sf_tab[428]; - #if CONFIG_AAC_ENCODER || CONFIG_AAC_DECODER #include "kbdwin.h" #include "sinewin.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]; +static av_cold void aac_tableinit(void) +{ + /* 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 (int 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; + } +} + static av_cold void aac_float_common_init(void) { + aac_tableinit(); + avpriv_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); avpriv_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); ff_init_ff_sine_windows(10); @@ -3299,53 +3345,3 @@ const DECLARE_ALIGNED(32, int, ff_aac_eld_window_480_fixed)[1800] = { 0xffecff1c, 0xffed391e, 0xffed740c, 0xffedafb1, 0xffedebe1, 0xffee287d, 0xffee654e, 0xffeea23f, }; - -static void aac_tableinit(void) -{ - /* 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 (int 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; - } -} - -void ff_aac_tableinit(void) -{ - static AVOnce init_static_once = AV_ONCE_INIT; - ff_thread_once(&init_static_once, aac_tableinit); -} diff --git a/libavcodec/aactab.h b/libavcodec/aactab.h index 9b1450c2eb..7693876c34 100644 --- a/libavcodec/aactab.h +++ b/libavcodec/aactab.h @@ -42,8 +42,6 @@ extern float ff_aac_pow2sf_tab[428]; extern float ff_aac_pow34sf_tab[428]; -void ff_aac_tableinit(void); - /* @name ltp_coef * Table of the LTP coefficients */