alacenc: pretty-printing and other cosmetics

This commit is contained in:
Justin Ruggles 2012-02-01 21:21:24 -05:00
parent 51c2483862
commit fc9cf0b2a6

View File

@ -184,10 +184,9 @@ static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
/* return mode with lowest score */
best = 0;
for (i = 1; i < 4; i++) {
if (score[i] < score[best]) {
if (score[i] < score[best])
best = i;
}
}
return best;
}
@ -199,21 +198,17 @@ static void alac_stereo_decorrelation(AlacEncodeContext *s)
mode = estimate_stereo_mode(left, right, n);
switch(mode)
{
switch (mode) {
case ALAC_CHMODE_LEFT_RIGHT:
s->interlacing_leftweight = 0;
s->interlacing_shift = 0;
break;
case ALAC_CHMODE_LEFT_SIDE:
for (i = 0; i < n; i++) {
for (i = 0; i < n; i++)
right[i] = left[i] - right[i];
}
s->interlacing_leftweight = 1;
s->interlacing_shift = 0;
break;
case ALAC_CHMODE_RIGHT_SIDE:
for (i = 0; i < n; i++) {
tmp = right[i];
@ -223,7 +218,6 @@ static void alac_stereo_decorrelation(AlacEncodeContext *s)
s->interlacing_leftweight = 1;
s->interlacing_shift = 31;
break;
default:
for (i = 0; i < n; i++) {
tmp = left[i];
@ -244,8 +238,10 @@ static void alac_linear_predictor(AlacEncodeContext *s, int ch)
if (lpc.lpc_order == 31) {
s->predictor_buf[0] = s->sample_buf[ch][0];
for (i = 1; i < s->avctx->frame_size; i++)
s->predictor_buf[i] = s->sample_buf[ch][i] - s->sample_buf[ch][i-1];
for (i = 1; i < s->avctx->frame_size; i++) {
s->predictor_buf[i] = s->sample_buf[ch][i ] -
s->sample_buf[ch][i - 1];
}
return;
}
@ -289,8 +285,7 @@ static void alac_linear_predictor(AlacEncodeContext *s, int ch)
lpc.lpc_coeff[index] -= sign;
val *= sign;
res_val -= ((val >> lpc.lpc_quant) *
(lpc.lpc_order - index));
res_val -= (val >> lpc.lpc_quant) * (lpc.lpc_order - index);
index--;
}
}
@ -311,15 +306,15 @@ static void alac_entropy_coder(AlacEncodeContext *s)
k = av_log2((history >> 9) + 3);
x = -2 * (*samples) -1;
x ^= (x>>31);
x ^= x >> 31;
samples++;
i++;
encode_scalar(s, x - sign_modifier, k, s->write_sample_size);
history += x * s->rc.history_mult
- ((history * s->rc.history_mult) >> 9);
history += x * s->rc.history_mult -
((history * s->rc.history_mult) >> 9);
sign_modifier = 0;
if (x > 0xFFFF)
@ -336,9 +331,7 @@ static void alac_entropy_coder(AlacEncodeContext *s)
block_size++;
}
encode_scalar(s, block_size, k, 16);
sign_modifier = (block_size <= 0xFFFF);
history = 0;
}
@ -356,7 +349,6 @@ static void write_compressed_frame(AlacEncodeContext *s)
put_bits(&s->pbctx, 8, s->interlacing_leftweight);
for (i = 0; i < s->avctx->channels; i++) {
calc_predictor_params(s, i);
put_bits(&s->pbctx, 4, prediction_type);
@ -365,10 +357,9 @@ static void write_compressed_frame(AlacEncodeContext *s)
put_bits(&s->pbctx, 3, s->rc.rice_modifier);
put_bits(&s->pbctx, 5, s->lpc[i].lpc_order);
// predictor coeff. table
for (j = 0; j < s->lpc[i].lpc_order; j++) {
for (j = 0; j < s->lpc[i].lpc_order; j++)
put_sbits(&s->pbctx, 16, s->lpc[i].lpc_coeff[j]);
}
}
// apply lpc and entropy coding to audio samples
@ -429,9 +420,11 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
s->rc.k_modifier = 14;
s->rc.rice_modifier = 4;
s->max_coded_frame_size = 8 + (avctx->frame_size * avctx->channels * DEFAULT_SAMPLE_SIZE >> 3);
s->max_coded_frame_size = 8 + (avctx->frame_size * avctx->channels *
DEFAULT_SAMPLE_SIZE >> 3);
s->write_sample_size = DEFAULT_SAMPLE_SIZE + avctx->channels - 1; // FIXME: consider wasted_bytes
// FIXME: consider wasted_bytes
s->write_sample_size = DEFAULT_SAMPLE_SIZE + avctx->channels - 1;
avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata) {