]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/alac.c
Hardcode register to prevent aparent miscompilation.
[ffmpeg] / libavcodec / alac.c
index 354c92303febf5070c9e5ce9e14a804a7b79bfe9..0689a46ef5c07d173af06d7ba4cd468750f329a4 100644 (file)
@@ -55,6 +55,7 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "bytestream.h"
+#include "unary.h"
 
 #define ALAC_EXTRADATA_SIZE 36
 #define MAX_CHANNELS 2
@@ -106,7 +107,7 @@ static void allocate_buffers(ALACContext *alac)
 
 static int alac_set_info(ALACContext *alac)
 {
-    unsigned char *ptr = alac->avctx->extradata;
+    const unsigned char *ptr = alac->avctx->extradata;
 
     ptr += 4; /* size */
     ptr += 4; /* alac */
@@ -159,15 +160,12 @@ static void bastardized_rice_decompress(ALACContext *alac,
     int sign_modifier = 0;
 
     for (output_count = 0; output_count < output_size; output_count++) {
-        int32_t x = 0;
+        int32_t x;
         int32_t x_modified;
         int32_t final_val;
 
         /* read x - number of 1s before 0 represent the rice */
-        while (x <= 8 && get_bits1(&alac->gb)) {
-            x++;
-        }
-
+        x = get_unary_0_9(&alac->gb);
 
         if (x > 8) { /* RICE THRESHOLD */
             /* use alternative encoding */
@@ -228,10 +226,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
             sign_modifier = 1;
 
-            x = 0;
-            while (x <= 8 && get_bits1(&alac->gb)) {
-                x++;
-            }
+            x = get_unary_0_9(&alac->gb);
 
             if (x > 8) {
                 block_size = get_bits(&alac->gb, 16);
@@ -269,7 +264,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
     }
 }
 
-static inline int32_t sign_extended32(int32_t val, int bits)
+static inline int32_t extend_sign32(int32_t val, int bits)
 {
     return (val << (32 - bits)) >> (32 - bits);
 }
@@ -313,7 +308,7 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
             prev_value = buffer_out[i];
             error_value = error_buffer[i+1];
             buffer_out[i+1] =
-                sign_extended32((prev_value + error_value), readsamplesize);
+                extend_sign32((prev_value + error_value), readsamplesize);
         }
         return;
     }
@@ -324,21 +319,21 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
             int32_t val;
 
             val = buffer_out[i] + error_buffer[i+1];
-            val = sign_extended32(val, readsamplesize);
+            val = extend_sign32(val, readsamplesize);
             buffer_out[i+1] = val;
         }
 
 #if 0
     /* 4 and 8 are very common cases (the only ones i've seen). these
-     * should be unrolled and optimised
+     * should be unrolled and optimized
      */
     if (predictor_coef_num == 4) {
-        /* FIXME: optimised general case */
+        /* FIXME: optimized general case */
         return;
     }
 
     if (predictor_coef_table == 8) {
-        /* FIXME: optimised general case */
+        /* FIXME: optimized general case */
         return;
     }
 #endif
@@ -359,7 +354,7 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
             outval = (1 << (predictor_quantitization-1)) + sum;
             outval = outval >> predictor_quantitization;
             outval = outval + buffer_out[0] + error_val;
-            outval = sign_extended32(outval, readsamplesize);
+            outval = extend_sign32(outval, readsamplesize);
 
             buffer_out[predictor_coef_num+1] = outval;
 
@@ -444,7 +439,7 @@ static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS],
 
 static int alac_decode_frame(AVCodecContext *avctx,
                              void *outbuffer, int *outputsize,
-                             uint8_t *inbuffer, int input_buffer_size)
+                             const uint8_t *inbuffer, int input_buffer_size)
 {
     ALACContext *alac = avctx->priv_data;
 
@@ -573,7 +568,7 @@ static int alac_decode_frame(AVCodecContext *avctx,
                     int32_t audiobits;
 
                     audiobits = get_bits(&alac->gb, alac->setinfo_sample_size);
-                    audiobits = sign_extended32(audiobits, readsamplesize);
+                    audiobits = extend_sign32(audiobits, readsamplesize);
 
                     alac->outputsamples_buffer[chan][i] = audiobits;
                 }
@@ -617,6 +612,8 @@ static int alac_decode_frame(AVCodecContext *avctx,
         break;
     case 20:
     case 24:
+        // It is not clear if there exist any encoder that creates 24 bit ALAC
+        // files. iTunes convert 24 bit raw files to 16 bit before encoding.
     case 32:
         av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size);
         break;