#include "avcodec.h"
#include "bitstream.h"
#include "bytestream.h"
+#include "unary.h"
#define ALAC_EXTRADATA_SIZE 36
#define MAX_CHANNELS 2
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 */
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 */
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);
}
}
-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);
}
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;
}
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
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;
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;
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;
}
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;