[FFmpeg-cvslog] alac: reverse lpc coeff order, simplify filter

Justin Ruggles git at videolan.org
Sat Jul 28 00:10:48 CEST 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Thu Jul 19 14:08:22 2012 -0400| [fb57e913e196b26b4ee6ede90f06821e2be7e28a] | committer: Justin Ruggles

alac: reverse lpc coeff order, simplify filter

Reversing the lpc coefficient order simplifies indexing in the filter.

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

 libavcodec/alac.c |   25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index aa2e6c8..1756cdf 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -194,6 +194,7 @@ static void lpc_prediction(int32_t *error_buffer, int32_t *buffer_out,
                            int lpc_order, int lpc_quant)
 {
     int i;
+    int32_t *pred = buffer_out;
 
     /* first sample always copies */
     *buffer_out = *error_buffer;
@@ -217,37 +218,35 @@ static void lpc_prediction(int32_t *error_buffer, int32_t *buffer_out,
     }
 
     /* read warm-up samples */
-    for (i = 0; i < lpc_order; i++) {
-        buffer_out[i + 1] = sign_extend(buffer_out[i] + error_buffer[i + 1],
-                                        bps);
-    }
+    for (i = 1; i <= lpc_order; i++)
+        buffer_out[i] = sign_extend(buffer_out[i - 1] + error_buffer[i], bps);
 
     /* NOTE: 4 and 8 are very common cases that could be optimized. */
 
-    for (i = lpc_order; i < nb_samples - 1; i++) {
+    for (; i < nb_samples; i++) {
         int j;
         int val = 0;
-        int error_val = error_buffer[i + 1];
+        int error_val = error_buffer[i];
         int error_sign;
-        int d = buffer_out[i - lpc_order];
+        int d = *pred++;
 
         /* LPC prediction */
         for (j = 0; j < lpc_order; j++)
-            val += (buffer_out[i - j] - d) * lpc_coefs[j];
+            val += (pred[j] - d) * lpc_coefs[j];
         val = (val + (1 << (lpc_quant - 1))) >> lpc_quant;
         val += d + error_val;
-        buffer_out[i + 1] = sign_extend(val, bps);
+        buffer_out[i] = sign_extend(val, bps);
 
         /* adapt LPC coefficients */
         error_sign = sign_only(error_val);
         if (error_sign) {
-            for (j = lpc_order - 1; j >= 0 && error_val * error_sign > 0; j--) {
+            for (j = 0; j < lpc_order && error_val * error_sign > 0; j++) {
                 int sign;
-                val  = d - buffer_out[i - j];
+                val  = d - pred[j];
                 sign = sign_only(val) * error_sign;
                 lpc_coefs[j] -= sign;
                 val *= sign;
-                error_val -= (val >> lpc_quant) * (lpc_order - j);
+                error_val -= (val >> lpc_quant) * (j + 1);
             }
         }
     }
@@ -350,7 +349,7 @@ static int decode_element(AVCodecContext *avctx, void *data, int ch_index,
             lpc_order[ch]         = get_bits(&alac->gb, 5);
 
             /* read the predictor table */
-            for (i = 0; i < lpc_order[ch]; i++)
+            for (i = lpc_order[ch] - 1; i >= 0; i--)
                 lpc_coefs[ch][i] = get_sbits(&alac->gb, 16);
         }
 



More information about the ffmpeg-cvslog mailing list