diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-11-15 15:53:34 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-11-24 11:35:03 +0100 |
commit | 5c45f7e15603c43e04747e5385d521ab6c8720ca (patch) | |
tree | 898a6342695a0ea30943bb6b8aab121fede9be7a | |
parent | af7acbb4b87ae44560dd4223b39c031c54923b63 (diff) | |
download | ffmpeg-5c45f7e15603c43e04747e5385d521ab6c8720ca.tar.gz |
avcodec/mpegaudiodsp: Combine initializing float and int tables
This avoids code duplication in the functions used to initialize them
and allows to remove an AVOnce.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r-- | libavcodec/mpegaudiodsp.c | 54 | ||||
-rw-r--r-- | libavcodec/mpegaudiodsp.h | 3 | ||||
-rw-r--r-- | libavcodec/mpegaudiodsp_template.c | 42 |
3 files changed, 50 insertions, 49 deletions
diff --git a/libavcodec/mpegaudiodsp.c b/libavcodec/mpegaudiodsp.c index 3cafca27bf..0a14ff549e 100644 --- a/libavcodec/mpegaudiodsp.c +++ b/libavcodec/mpegaudiodsp.c @@ -21,20 +21,66 @@ #include "config.h" #include "libavutil/attributes.h" #include "libavutil/thread.h" +#include "mpegaudio.h" #include "mpegaudiodsp.h" #include "dct.h" #include "dct32.h" -static AVOnce mpadsp_float_table_init = AV_ONCE_INIT; -static AVOnce mpadsp_fixed_table_init = AV_ONCE_INIT; +static AVOnce mpadsp_table_init = AV_ONCE_INIT; + +static av_cold void mpadsp_init_tabs(void) +{ + int i, j; + /* compute mdct windows */ + for (i = 0; i < 36; i++) { + for (j = 0; j < 4; j++) { + double d; + + if (j == 2 && i % 3 != 1) + continue; + + d = sin(M_PI * (i + 0.5) / 36.0); + if (j == 1) { + if (i >= 30) d = 0; + else if (i >= 24) d = sin(M_PI * (i - 18 + 0.5) / 12.0); + else if (i >= 18) d = 1; + } else if (j == 3) { + if (i < 6) d = 0; + else if (i < 12) d = sin(M_PI * (i - 6 + 0.5) / 12.0); + else if (i < 18) d = 1; + } + //merge last stage of imdct into the window coefficients + d *= 0.5 * IMDCT_SCALAR / cos(M_PI * (2 * i + 19) / 72); + + if (j == 2) { + ff_mdct_win_float[j][i/3] = d / (1 << 5); + ff_mdct_win_fixed[j][i/3] = d / (1 << 5) * (1LL << 32) + 0.5; + } else { + int idx = i < 18 ? i : i + (MDCT_BUF_SIZE/2 - 18); + ff_mdct_win_float[j][idx] = d / (1 << 5); + ff_mdct_win_fixed[j][idx] = d / (1 << 5) * (1LL << 32) + 0.5; + } + } + } + + /* NOTE: we do frequency inversion after the MDCT by changing + the sign of the right window coefs */ + for (j = 0; j < 4; j++) { + for (i = 0; i < MDCT_BUF_SIZE; i += 2) { + ff_mdct_win_float[j + 4][i ] = ff_mdct_win_float[j][i ]; + ff_mdct_win_float[j + 4][i + 1] = -ff_mdct_win_float[j][i + 1]; + ff_mdct_win_fixed[j + 4][i ] = ff_mdct_win_fixed[j][i ]; + ff_mdct_win_fixed[j + 4][i + 1] = -ff_mdct_win_fixed[j][i + 1]; + } + } +} av_cold void ff_mpadsp_init(MPADSPContext *s) { DCTContext dct; ff_dct_init(&dct, 5, DCT_II); - ff_thread_once(&mpadsp_float_table_init, &ff_init_mpadsp_tabs_float); - ff_thread_once(&mpadsp_fixed_table_init, &ff_init_mpadsp_tabs_fixed); + ff_thread_once(&mpadsp_table_init, &mpadsp_init_tabs); s->apply_window_float = ff_mpadsp_apply_window_float; s->apply_window_fixed = ff_mpadsp_apply_window_fixed; diff --git a/libavcodec/mpegaudiodsp.h b/libavcodec/mpegaudiodsp.h index 0e4352deab..28dcec576c 100644 --- a/libavcodec/mpegaudiodsp.h +++ b/libavcodec/mpegaudiodsp.h @@ -82,9 +82,6 @@ void ff_imdct36_blocks_float(float *out, float *buf, float *in, void ff_imdct36_blocks_fixed(int *out, int *buf, int *in, int count, int switch_point, int block_type); -void ff_init_mpadsp_tabs_float(void); -void ff_init_mpadsp_tabs_fixed(void); - /** For SSE implementation, MDCT_BUF_SIZE/2 should be 128-bit aligned */ #define MDCT_BUF_SIZE FFALIGN(36, 2*4) diff --git a/libavcodec/mpegaudiodsp_template.c b/libavcodec/mpegaudiodsp_template.c index e531f8a904..f8d0870df6 100644 --- a/libavcodec/mpegaudiodsp_template.c +++ b/libavcodec/mpegaudiodsp_template.c @@ -221,48 +221,6 @@ av_cold void RENAME(ff_mpa_synth_init)(MPA_INT *window) window[512+128+16*i+j] = window[64*i+48-j]; } -av_cold void RENAME(ff_init_mpadsp_tabs)(void) -{ - int i, j; - /* compute mdct windows */ - for (i = 0; i < 36; i++) { - for (j = 0; j < 4; j++) { - double d; - - if (j == 2 && i % 3 != 1) - continue; - - d = sin(M_PI * (i + 0.5) / 36.0); - if (j == 1) { - if (i >= 30) d = 0; - else if (i >= 24) d = sin(M_PI * (i - 18 + 0.5) / 12.0); - else if (i >= 18) d = 1; - } else if (j == 3) { - if (i < 6) d = 0; - else if (i < 12) d = sin(M_PI * (i - 6 + 0.5) / 12.0); - else if (i < 18) d = 1; - } - //merge last stage of imdct into the window coefficients - d *= 0.5 * IMDCT_SCALAR / cos(M_PI * (2 * i + 19) / 72); - - if (j == 2) - RENAME(ff_mdct_win)[j][i/3] = FIXHR((d / (1<<5))); - else { - int idx = i < 18 ? i : i + (MDCT_BUF_SIZE/2 - 18); - RENAME(ff_mdct_win)[j][idx] = FIXHR((d / (1<<5))); - } - } - } - - /* NOTE: we do frequency inversion adter the MDCT by changing - the sign of the right window coefs */ - for (j = 0; j < 4; j++) { - for (i = 0; i < MDCT_BUF_SIZE; i += 2) { - RENAME(ff_mdct_win)[j + 4][i ] = RENAME(ff_mdct_win)[j][i ]; - RENAME(ff_mdct_win)[j + 4][i + 1] = -RENAME(ff_mdct_win)[j][i + 1]; - } - } -} /* cos(pi*i/18) */ #define C1 FIXHR(0.98480775301220805936/2) #define C2 FIXHR(0.93969262078590838405/2) |