[FFmpeg-devel] [PATCH] avcodec/nellymoserenc: avoid wasteful pow

Ganesh Ajjanagadde gajjanagadde at gmail.com
Thu Dec 10 00:55:25 CET 2015


exp2 suffices here. Some trivial (~ 4x) speedup is done in addition here by
reusing results.

This is bit-identical to the old values.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 libavcodec/nellymoserenc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index d998dba..e6023e3 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -179,8 +179,15 @@ static av_cold int encode_init(AVCodecContext *avctx)
 
     /* Generate overlap window */
     ff_init_ff_sine_windows(7);
-    for (i = 0; i < POW_TABLE_SIZE; i++)
-        pow_table[i] = pow(2, -i / 2048.0 - 3.0 + POW_TABLE_OFFSET);
+    pow_table[0] = 1;
+    pow_table[1024] = M_SQRT1_2;
+    for (i = 1; i < 513; i++) {
+        double tmp = exp2(-i / 2048.0);
+        pow_table[i] = tmp;
+        pow_table[1024-i] = M_SQRT1_2 / tmp;
+        pow_table[1024+i] = tmp * M_SQRT1_2;
+        pow_table[2048-i] = 0.5 / tmp;
+    }
 
     if (s->avctx->trellis) {
         s->opt  = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float  ));
-- 
2.6.3



More information about the ffmpeg-devel mailing list