]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/alac.c
snow altivec is broken
[ffmpeg] / libavcodec / alac.c
index 5655ea3c6fc61eaaf8175e4dbd2dc91dd349bcb6..b9edf596a9cdae858366a3c241c2c2805262cd51 100644 (file)
@@ -170,7 +170,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
 
         if (x > 8) { /* RICE THRESHOLD */
-          /* use alternative encoding */
+            /* use alternative encoding */
             int32_t value;
 
             value = get_bits(&alac->gb, readsamplesize);
@@ -181,7 +181,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
             x = value;
         } else {
-          /* standard rice encoding */
+            /* standard rice encoding */
             int extrabits;
             int k; /* size of extra bits */
 
@@ -201,10 +201,9 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
                 if (extrabits > 1) {
                     x += extrabits - 1;
-                    get_bits(&alac->gb, k);
-                } else {
-                    get_bits(&alac->gb, k - 1);
-                }
+                    skip_bits(&alac->gb, k);
+                } else
+                    skip_bits(&alac->gb, k - 1);
             }
         }
 
@@ -217,8 +216,8 @@ static void bastardized_rice_decompress(ALACContext *alac,
         sign_modifier = 0;
 
         /* now update the history */
-        history += (x_modified * rice_historymult)
-                 - ((history * rice_historymult) >> 9);
+        history += x_modified * rice_historymult
+                   - ((history * rice_historymult) >> 9);
 
         if (x_modified > 0xffff)
             history = 0xffff;
@@ -251,16 +250,15 @@ static void bastardized_rice_decompress(ALACContext *alac,
                 if (extrabits < 2) {
                     x = 1 - extrabits;
                     block_size += x;
-                    get_bits(&alac->gb, k - 1);
+                    skip_bits(&alac->gb, k - 1);
                 } else {
-                    get_bits(&alac->gb, k);
+                    skip_bits(&alac->gb, k);
                 }
             }
 
             if (block_size > 0) {
                 memset(&output_buffer[output_count+1], 0, block_size * 4);
                 output_count += block_size;
-
             }
 
             if (block_size > 0xffff)
@@ -292,7 +290,9 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
     *buffer_out = *error_buffer;
 
     if (!predictor_coef_num) {
-        if (output_size <= 1) return;
+        if (output_size <= 1)
+            return;
+
         memcpy(buffer_out+1, error_buffer+1, (output_size-1) * 4);
         return;
     }
@@ -301,31 +301,29 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
       /* second-best case scenario for fir decompression,
        * error describes a small difference from the previous sample only
        */
-        if (output_size <= 1) return;
+        if (output_size <= 1)
+            return;
         for (i = 0; i < output_size - 1; i++) {
             int32_t prev_value;
             int32_t error_value;
 
             prev_value = buffer_out[i];
             error_value = error_buffer[i+1];
-            buffer_out[i+1] = SIGN_EXTENDED32((prev_value + error_value), readsamplesize);
+            buffer_out[i+1] =
+                SIGN_EXTENDED32((prev_value + error_value), readsamplesize);
         }
         return;
     }
 
     /* read warm-up samples */
-    if (predictor_coef_num > 0) {
-        int i;
+    if (predictor_coef_num > 0)
         for (i = 0; i < predictor_coef_num; i++) {
             int32_t val;
 
             val = buffer_out[i] + error_buffer[i+1];
-
             val = SIGN_EXTENDED32(val, readsamplesize);
-
             buffer_out[i+1] = val;
         }
-    }
 
 #if 0
     /* 4 and 8 are very common cases (the only ones i've seen). these
@@ -342,12 +340,9 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
     }
 #endif
 
-
     /* general case */
     if (predictor_coef_num > 0) {
-        for (i = predictor_coef_num + 1;
-             i < output_size;
-             i++) {
+        for (i = predictor_coef_num + 1; i < output_size; i++) {
             int j;
             int sum = 0;
             int outval;
@@ -404,32 +399,29 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
     }
 }
 
-static void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b,
-                    int16_t *buffer_out,
-                    int numchannels, int numsamples,
-                    uint8_t interlacing_shift,
-                    uint8_t interlacing_leftweight)
+static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS],
+                                  int16_t *buffer_out,
+                                  int numchannels, int numsamples,
+                                  uint8_t interlacing_shift,
+                                  uint8_t interlacing_leftweight)
 {
     int i;
-    if (numsamples <= 0) return;
+    if (numsamples <= 0)
+        return;
 
     /* weighted interlacing */
     if (interlacing_leftweight) {
         for (i = 0; i < numsamples; i++) {
-            int32_t difference, midright;
-            int16_t left;
-            int16_t right;
+            int32_t a, b;
 
-            midright = buffer_a[i];
-            difference = buffer_b[i];
+            a = buffer[0][i];
+            b = buffer[1][i];
 
+            a -= (b * interlacing_leftweight) >> interlacing_shift;
+            b += a;
 
-            right = midright - ((difference * interlacing_leftweight) >> interlacing_shift);
-            left = (midright - ((difference * interlacing_leftweight) >> interlacing_shift))
-                 + difference;
-
-            buffer_out[i*numchannels] = left;
-            buffer_out[i*numchannels + 1] = right;
+            buffer_out[i*numchannels] = b;
+            buffer_out[i*numchannels + 1] = a;
         }
 
         return;
@@ -439,8 +431,8 @@ static void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b,
     for (i = 0; i < numsamples; i++) {
         int16_t left, right;
 
-        left = buffer_a[i];
-        right = buffer_b[i];
+        left = buffer[0][i];
+        right = buffer[1][i];
 
         buffer_out[i*numchannels] = left;
         buffer_out[i*numchannels + 1] = right;
@@ -492,17 +484,17 @@ static int alac_decode_frame(AVCodecContext *avctx,
     /* 2^result = something to do with output waiting.
      * perhaps matters if we read > 1 frame in a pass?
      */
-    get_bits(&alac->gb, 4);
+    skip_bits(&alac->gb, 4);
 
-    get_bits(&alac->gb, 12); /* unknown, skip 12 bits */
+    skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */
 
     /* the output sample size is stored soon */
-    hassize = get_bits(&alac->gb, 1);
+    hassize = get_bits1(&alac->gb);
 
     wasted_bytes = get_bits(&alac->gb, 2); /* unknown ? */
 
     /* whether the frame is compressed */
-    isnotcompressed = get_bits(&alac->gb, 1);
+    isnotcompressed = get_bits1(&alac->gb);
 
     if (hassize) {
         /* now read the number of samples as a 32bit integer */
@@ -533,14 +525,12 @@ static int alac_decode_frame(AVCodecContext *avctx,
             predictor_coef_num[chan] = get_bits(&alac->gb, 5);
 
             /* read the predictor table */
-            for (i = 0; i < predictor_coef_num[chan]; i++) {
+            for (i = 0; i < predictor_coef_num[chan]; i++)
                 predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16);
-            }
         }
 
-        if (wasted_bytes) {
+        if (wasted_bytes)
             av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n");
-        }
 
         for (chan = 0; chan < channels; chan++) {
             bastardized_rice_decompress(alac,
@@ -563,8 +553,8 @@ static int alac_decode_frame(AVCodecContext *avctx,
                                                prediction_quantitization[chan]);
             } else {
                 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]);
-                /* i think the only other prediction type (or perhaps this is just a
-                 * boolean?) runs adaptive fir twice.. like:
+                /* I think the only other prediction type (or perhaps this is
+                 * just a boolean?) runs adaptive fir twice.. like:
                  * predictor_decompress_fir_adapt(predictor_error, tempout, ...)
                  * predictor_decompress_fir_adapt(predictor_error, outputsamples ...)
                  * little strange..
@@ -575,7 +565,7 @@ static int alac_decode_frame(AVCodecContext *avctx,
         /* not compressed, easy case */
         if (alac->setinfo_sample_size <= 16) {
             int i, chan;
-            for (chan = 0; chan < channels; chan++) {
+            for (chan = 0; chan < channels; chan++)
                 for (i = 0; i < outputsamples; i++) {
                     int32_t audiobits;
 
@@ -584,10 +574,9 @@ static int alac_decode_frame(AVCodecContext *avctx,
 
                     alac->outputsamples_buffer[chan][i] = audiobits;
                 }
-            }
         } else {
             int i, chan;
-            for (chan = 0; chan < channels; chan++) {
+            for (chan = 0; chan < channels; chan++)
                 for (i = 0; i < outputsamples; i++) {
                     int32_t audiobits;
 
@@ -600,7 +589,6 @@ static int alac_decode_frame(AVCodecContext *avctx,
 
                     alac->outputsamples_buffer[chan][i] = audiobits;
                 }
-            }
         }
         /* wasted_bytes = 0; */
         interlacing_shift = 0;
@@ -608,15 +596,14 @@ static int alac_decode_frame(AVCodecContext *avctx,
     }
 
     switch(alac->setinfo_sample_size) {
-    case 16: {
+    case 16:
         if (channels == 2) {
-            deinterlace_16(alac->outputsamples_buffer[0],
-                           alac->outputsamples_buffer[1],
-                           (int16_t*)outbuffer,
-                           alac->numchannels,
-                           outputsamples,
-                           interlacing_shift,
-                           interlacing_leftweight);
+            reconstruct_stereo_16(alac->outputsamples_buffer,
+                                  (int16_t*)outbuffer,
+                                  alac->numchannels,
+                                  outputsamples,
+                                  interlacing_shift,
+                                  interlacing_leftweight);
         } else {
             int i;
             for (i = 0; i < outputsamples; i++) {
@@ -625,7 +612,6 @@ static int alac_decode_frame(AVCodecContext *avctx,
             }
         }
         break;
-    }
     case 20:
     case 24:
     case 32: