Commit fc9cf0b2 authored by Justin Ruggles's avatar Justin Ruggles

alacenc: pretty-printing and other cosmetics

parent 51c24838
......@@ -167,8 +167,8 @@ static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
/* calculate sum of 2nd order residual for each channel */
sum[0] = sum[1] = sum[2] = sum[3] = 0;
for (i = 2; i < n; i++) {
lt = left_ch[i] - 2*left_ch[i-1] + left_ch[i-2];
rt = right_ch[i] - 2*right_ch[i-1] + right_ch[i-2];
lt = left_ch[i] - 2 * left_ch[i - 1] + left_ch[i - 2];
rt = right_ch[i] - 2 * right_ch[i - 1] + right_ch[i - 2];
sum[2] += FFABS((lt + rt) >> 1);
sum[3] += FFABS(lt - rt);
sum[0] += FFABS(lt);
......@@ -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;
}
......@@ -276,21 +272,20 @@ static void alac_linear_predictor(AlacEncodeContext *s, int ch)
s->write_sample_size);
res_val = residual[i];
if(res_val) {
if (res_val) {
int index = lpc.lpc_order - 1;
int neg = (res_val < 0);
while(index >= 0 && (neg ? (res_val < 0):(res_val > 0))) {
while (index >= 0 && (neg ? (res_val < 0) : (res_val > 0))) {
int val = samples[0] - samples[lpc.lpc_order - index];
int sign = (val ? FFSIGN(val) : 0);
if(neg)
sign*=-1;
if (neg)
sign *= -1;
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--;
}
}
......@@ -310,16 +305,16 @@ static void alac_entropy_coder(AlacEncodeContext *s)
k = av_log2((history >> 9) + 3);
x = -2*(*samples)-1;
x ^= (x>>31);
x = -2 * (*samples) -1;
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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment