From b01f3ddad31aba45254dfd553447c7952f86fd31 Mon Sep 17 00:00:00 2001 From: Claudio Freire Date: Mon, 21 Sep 2015 03:41:26 -0300 Subject: [PATCH] AAC encoder: simplify and speed up find_min_book Trivial change to simplify the small but hot find_min_book function. The new form is easier to understand and faster. --- libavcodec/aacenc_utils.h | 11 ++++------- libavcodec/aacenctab.h | 4 ++++ libavcodec/mips/aaccoder_mips.c | 12 ++++-------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/libavcodec/aacenc_utils.h b/libavcodec/aacenc_utils.h index 0ab15a3e5e..dbc9554379 100644 --- a/libavcodec/aacenc_utils.h +++ b/libavcodec/aacenc_utils.h @@ -89,13 +89,10 @@ static inline int find_min_book(float maxval, int sf) float Q34 = sqrtf(Q * sqrtf(Q)); int qmaxval, cb; qmaxval = maxval * Q34 + C_QUANT; - if (qmaxval == 0) cb = 0; - else if (qmaxval == 1) cb = 1; - else if (qmaxval == 2) cb = 3; - else if (qmaxval <= 4) cb = 5; - else if (qmaxval <= 7) cb = 7; - else if (qmaxval <= 12) cb = 9; - else cb = 11; + if (qmaxval >= (FF_ARRAY_ELEMS(aac_maxval_cb))) + cb = 11; + else + cb = aac_maxval_cb[qmaxval]; return cb; } diff --git a/libavcodec/aacenctab.h b/libavcodec/aacenctab.h index 9e7595a755..381b4a4e16 100644 --- a/libavcodec/aacenctab.h +++ b/libavcodec/aacenctab.h @@ -110,4 +110,8 @@ static const uint8_t aac_cb_in_map[CB_TOT_ALL+1] = {0,1,2,3,4,5,6,7,8,9,10,11,0, static const uint8_t aac_cb_range [12] = {0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17}; static const uint8_t aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16}; +static unsigned char aac_maxval_cb[] = { + 0, 1, 3, 5, 5, 7, 7, 7, 9, 9, 9, 9, 9, 11 +}; + #endif /* AVCODEC_AACENCTAB_H */ diff --git a/libavcodec/mips/aaccoder_mips.c b/libavcodec/mips/aaccoder_mips.c index 8c5fe271be..18d3f88743 100644 --- a/libavcodec/mips/aaccoder_mips.c +++ b/libavcodec/mips/aaccoder_mips.c @@ -178,14 +178,10 @@ static int find_min_book(float maxval, int sf) { float Q = ff_aac_pow2sf_tab[POW_SF2_ZERO - sf + SCALE_ONE_POS - SCALE_DIV_512]; float Q34 = sqrtf(Q * sqrtf(Q)); int qmaxval, cb; - qmaxval = maxval * Q34 + 0.4054f; - if (qmaxval == 0) cb = 0; - else if (qmaxval == 1) cb = 1; - else if (qmaxval == 2) cb = 3; - else if (qmaxval <= 4) cb = 5; - else if (qmaxval <= 7) cb = 7; - else if (qmaxval <= 12) cb = 9; - else cb = 11; + if (qmaxval >= (FF_ARRAY_ELEMS(aac_maxval_cb))) + cb = 11; + else + cb = aac_maxval_cb[qmaxval]; return cb; }