[FFmpeg-cvslog] AAC encoder: simplify and speed up find_min_book

Claudio Freire git at videolan.org
Wed Sep 23 07:32:48 CEST 2015


ffmpeg | branch: master | Claudio Freire <klaussfreire at gmail.com> | Mon Sep 21 03:41:26 2015 -0300| [b01f3ddad31aba45254dfd553447c7952f86fd31] | committer: Claudio Freire

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b01f3ddad31aba45254dfd553447c7952f86fd31
---

 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 0ab15a3..dbc9554 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 9e7595a..381b4a4 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 8c5fe27..18d3f88 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;
 }
 



More information about the ffmpeg-cvslog mailing list