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

Mans Rullgard mans
Sun Sep 27 17:30:11 CEST 2009


---
 libavcodec/wmadec.c |   76 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 71 insertions(+), 5 deletions(-)

diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 52ea7a3..fef5d03 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -243,6 +243,74 @@ static void decode_exp_lsp(WMACodecContext *s, int ch)
                      s->block_len, lsp_coefs);
 }
 
+/** pow(10, i / 16.0) for i in -60..68 */
+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
  */
@@ -251,6 +319,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];
@@ -258,8 +327,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++;
         s->dsp.fill_float(q, v, n);
@@ -273,9 +341,7 @@ 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 */
-        av_log(NULL, AV_LOG_ERROR, "exp= %d\n", last_exp);
-        v = pow(10, last_exp * (1.0 / 16.0));
+        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