[FFmpeg-devel] [PATCH] WMA: use a table instead of pow() in decode_exp_vlc

Mans Rullgard mans
Tue Sep 29 02:05:39 CEST 2009


---
 libavcodec/wmadec.c |   77 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index a4d5ad6..ce2940d 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -240,6 +240,74 @@ static void decode_exp_lsp(WMACodecContext *s, int ch)
                      s->block_len, lsp_coefs);
 }
 
+/** pow(10, i / 16.0) for i in -60..67 */
+static const float pow_tab[128] = {
+    1.7782794100389e-04, 2.0535250264571e-04,
+    2.3713737056617e-04, 2.7384196342644e-04,
+    3.1622776601684e-04, 3.6517412725484e-04,
+    4.2169650342858e-04, 4.8696752516586e-04,
+    5.6234132519035e-04, 6.4938163157621e-04,
+    7.4989420933246e-04, 8.6596432336006e-04,
+    1.0000000000000e-03, 1.1547819846895e-03,
+    1.3335214321633e-03, 1.5399265260595e-03,
+    1.7782794100389e-03, 2.0535250264571e-03,
+    2.3713737056617e-03, 2.7384196342644e-03,
+    3.1622776601684e-03, 3.6517412725484e-03,
+    4.2169650342858e-03, 4.8696752516586e-03,
+    5.6234132519035e-03, 6.4938163157621e-03,
+    7.4989420933246e-03, 8.6596432336006e-03,
+    1.0000000000000e-02, 1.1547819846895e-02,
+    1.3335214321633e-02, 1.5399265260595e-02,
+    1.7782794100389e-02, 2.0535250264571e-02,
+    2.3713737056617e-02, 2.7384196342644e-02,
+    3.1622776601684e-02, 3.6517412725484e-02,
+    4.2169650342858e-02, 4.8696752516586e-02,
+    5.6234132519035e-02, 6.4938163157621e-02,
+    7.4989420933246e-02, 8.6596432336007e-02,
+    1.0000000000000e-01, 1.1547819846895e-01,
+    1.3335214321633e-01, 1.5399265260595e-01,
+    1.7782794100389e-01, 2.0535250264571e-01,
+    2.3713737056617e-01, 2.7384196342644e-01,
+    3.1622776601684e-01, 3.6517412725484e-01,
+    4.2169650342858e-01, 4.8696752516586e-01,
+    5.6234132519035e-01, 6.4938163157621e-01,
+    7.4989420933246e-01, 8.6596432336007e-01,
+    1.0000000000000e+00, 1.1547819846895e+00,
+    1.3335214321633e+00, 1.5399265260595e+00,
+    1.7782794100389e+00, 2.0535250264571e+00,
+    2.3713737056617e+00, 2.7384196342644e+00,
+    3.1622776601684e+00, 3.6517412725484e+00,
+    4.2169650342858e+00, 4.8696752516586e+00,
+    5.6234132519035e+00, 6.4938163157621e+00,
+    7.4989420933246e+00, 8.6596432336007e+00,
+    1.0000000000000e+01, 1.1547819846895e+01,
+    1.3335214321633e+01, 1.5399265260595e+01,
+    1.7782794100389e+01, 2.0535250264571e+01,
+    2.3713737056617e+01, 2.7384196342644e+01,
+    3.1622776601684e+01, 3.6517412725484e+01,
+    4.2169650342858e+01, 4.8696752516586e+01,
+    5.6234132519035e+01, 6.4938163157621e+01,
+    7.4989420933246e+01, 8.6596432336007e+01,
+    1.0000000000000e+02, 1.1547819846895e+02,
+    1.3335214321633e+02, 1.5399265260595e+02,
+    1.7782794100389e+02, 2.0535250264571e+02,
+    2.3713737056617e+02, 2.7384196342644e+02,
+    3.1622776601684e+02, 3.6517412725484e+02,
+    4.2169650342858e+02, 4.8696752516586e+02,
+    5.6234132519035e+02, 6.4938163157621e+02,
+    7.4989420933246e+02, 8.6596432336007e+02,
+    1.0000000000000e+03, 1.1547819846895e+03,
+    1.3335214321633e+03, 1.5399265260595e+03,
+    1.7782794100389e+03, 2.0535250264571e+03,
+    2.3713737056617e+03, 2.7384196342644e+03,
+    3.1622776601684e+03, 3.6517412725484e+03,
+    4.2169650342858e+03, 4.8696752516586e+03,
+    5.6234132519035e+03, 6.4938163157621e+03,
+    7.4989420933246e+03, 8.6596432336007e+03,
+    1.0000000000000e+04, 1.1547819846895e+04,
+    1.3335214321633e+04, 1.5399265260595e+04,
+};
+
 /**
  * decode exponents coded with VLC codes
  */
@@ -248,6 +316,7 @@ static int decode_exp_vlc(WMACodecContext *s, int ch)
     int last_exp, n, code;
     const uint16_t *ptr;
     float v, *q, max_scale, *q_end;
+    const float *ptab = pow_tab + 60;
 
     ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
     q = s->exponents[ch];
@@ -255,8 +324,7 @@ static int decode_exp_vlc(WMACodecContext *s, int ch)
     max_scale = 0;
     if (s->version == 1) {
         last_exp = get_bits(&s->gb, 5) + 10;
-        /* XXX: use a table */
-        v = pow(10, last_exp * (1.0 / 16.0));
+        v = ptab[last_exp];
         max_scale = v;
         n = *ptr++;
         do {
@@ -271,8 +339,9 @@ static int decode_exp_vlc(WMACodecContext *s, int ch)
             return -1;
         /* NOTE: this offset is the same as MPEG4 AAC ! */
         last_exp += code - 60;
-        /* XXX: use a table */
-        v = pow(10, last_exp * (1.0 / 16.0));
+        if ((unsigned)last_exp + 60 > FF_ARRAY_ELEMS(pow_tab))
+            return -1;
+        v = ptab[last_exp];
         if (v > max_scale)
             max_scale = v;
         n = *ptr++;
-- 
1.6.4.4




More information about the ffmpeg-devel mailing list