[FFmpeg-cvslog] g722: Split out computation of band->s_zero and unroll code

Peter Meerwald git at videolan.org
Mon Feb 16 02:15:20 CET 2015


ffmpeg | branch: master | Peter Meerwald <pmeerw at pmeerw.net> | Sun Feb 15 12:21:24 2015 +0100| [73ae0a9d12857852222363f9a7c14d07058ebfd3] | committer: Martin Storsjö

g722: Split out computation of band->s_zero and unroll code

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
Signed-off-by: Martin Storsjö <martin at martin.st>

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

 libavcodec/g722.c |   50 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/libavcodec/g722.c b/libavcodec/g722.c
index 74c0868..830877e 100644
--- a/libavcodec/g722.c
+++ b/libavcodec/g722.c
@@ -71,6 +71,36 @@ const int16_t ff_g722_low_inv_quant6[64] = {
      211,   170,   130,    91,    54,    17,   -54,   -17
 };
 
+static inline void s_zero(int cur_diff, struct G722Band *band)
+{
+    int s_zero = 0;
+
+    #define ACCUM(k, x, d) do { \
+            int tmp = x; \
+            band->zero_mem[k] = ((band->zero_mem[k] * 255) >> 8) + \
+               d*((band->diff_mem[k]^cur_diff) < 0 ? -128 : 128); \
+            band->diff_mem[k] = tmp; \
+            s_zero += (tmp * band->zero_mem[k]) >> 15; \
+        } while (0)
+    if (cur_diff) {
+        ACCUM(5, band->diff_mem[4], 1);
+        ACCUM(4, band->diff_mem[3], 1);
+        ACCUM(3, band->diff_mem[2], 1);
+        ACCUM(2, band->diff_mem[1], 1);
+        ACCUM(1, band->diff_mem[0], 1);
+        ACCUM(0, cur_diff << 1, 1);
+    } else {
+        ACCUM(5, band->diff_mem[4], 0);
+        ACCUM(4, band->diff_mem[3], 0);
+        ACCUM(3, band->diff_mem[2], 0);
+        ACCUM(2, band->diff_mem[1], 0);
+        ACCUM(1, band->diff_mem[0], 0);
+        ACCUM(0, cur_diff << 1, 0);
+    }
+    #undef ACCUM
+    band->s_zero = s_zero;
+}
+
 /**
  * adaptive predictor
  *
@@ -79,7 +109,7 @@ const int16_t ff_g722_low_inv_quant6[64] = {
  */
 static void do_adaptive_prediction(struct G722Band *band, const int cur_diff)
 {
-    int sg[2], limit, i, cur_qtzd_reconst;
+    int sg[2], limit, cur_qtzd_reconst;
 
     const int cur_part_reconst = band->s_zero + cur_diff < 0;
 
@@ -94,23 +124,7 @@ static void do_adaptive_prediction(struct G722Band *band, const int cur_diff)
     limit = 15360 - band->pole_mem[1];
     band->pole_mem[0] = av_clip(-192 * sg[0] + (band->pole_mem[0] * 255 >> 8), -limit, limit);
 
-
-    if (cur_diff) {
-        for (i = 0; i < 6; i++)
-            band->zero_mem[i] = ((band->zero_mem[i]*255) >> 8) +
-                                ((band->diff_mem[i]^cur_diff) < 0 ? -128 : 128);
-    } else
-        for (i = 0; i < 6; i++)
-            band->zero_mem[i] = (band->zero_mem[i]*255) >> 8;
-
-    for (i = 5; i > 0; i--)
-        band->diff_mem[i] = band->diff_mem[i-1];
-    band->diff_mem[0] = av_clip_int16(cur_diff << 1);
-
-    band->s_zero = 0;
-    for (i = 5; i >= 0; i--)
-        band->s_zero += (band->zero_mem[i]*band->diff_mem[i]) >> 15;
-
+    s_zero(cur_diff, band);
 
     cur_qtzd_reconst = av_clip_int16((band->s_predictor + cur_diff) << 1);
     band->s_predictor = av_clip_int16(band->s_zero +



More information about the ffmpeg-cvslog mailing list