alac: reverse lpc coeff order, simplify filter

Reversing the lpc coefficient order simplifies indexing in the filter.
This commit is contained in:
Justin Ruggles 2012-07-19 14:08:22 -04:00
parent 2f096bb10e
commit fb57e913e1
1 changed files with 12 additions and 13 deletions

View File

@ -194,6 +194,7 @@ static void lpc_prediction(int32_t *error_buffer, int32_t *buffer_out,
int lpc_order, int lpc_quant)
{
int i;
int32_t *pred = buffer_out;
/* first sample always copies */
*buffer_out = *error_buffer;
@ -217,37 +218,35 @@ static void lpc_prediction(int32_t *error_buffer, int32_t *buffer_out,
}
/* read warm-up samples */
for (i = 0; i < lpc_order; i++) {
buffer_out[i + 1] = sign_extend(buffer_out[i] + error_buffer[i + 1],
bps);
}
for (i = 1; i <= lpc_order; i++)
buffer_out[i] = sign_extend(buffer_out[i - 1] + error_buffer[i], bps);
/* NOTE: 4 and 8 are very common cases that could be optimized. */
for (i = lpc_order; i < nb_samples - 1; i++) {
for (; i < nb_samples; i++) {
int j;
int val = 0;
int error_val = error_buffer[i + 1];
int error_val = error_buffer[i];
int error_sign;
int d = buffer_out[i - lpc_order];
int d = *pred++;
/* LPC prediction */
for (j = 0; j < lpc_order; j++)
val += (buffer_out[i - j] - d) * lpc_coefs[j];
val += (pred[j] - d) * lpc_coefs[j];
val = (val + (1 << (lpc_quant - 1))) >> lpc_quant;
val += d + error_val;
buffer_out[i + 1] = sign_extend(val, bps);
buffer_out[i] = sign_extend(val, bps);
/* adapt LPC coefficients */
error_sign = sign_only(error_val);
if (error_sign) {
for (j = lpc_order - 1; j >= 0 && error_val * error_sign > 0; j--) {
for (j = 0; j < lpc_order && error_val * error_sign > 0; j++) {
int sign;
val = d - buffer_out[i - j];
val = d - pred[j];
sign = sign_only(val) * error_sign;
lpc_coefs[j] -= sign;
val *= sign;
error_val -= (val >> lpc_quant) * (lpc_order - j);
error_val -= (val >> lpc_quant) * (j + 1);
}
}
}
@ -350,7 +349,7 @@ static int decode_element(AVCodecContext *avctx, void *data, int ch_index,
lpc_order[ch] = get_bits(&alac->gb, 5);
/* read the predictor table */
for (i = 0; i < lpc_order[ch]; i++)
for (i = lpc_order[ch] - 1; i >= 0; i--)
lpc_coefs[ch][i] = get_sbits(&alac->gb, 16);
}