aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/alac.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-07-09 11:33:31 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2012-07-19 13:26:47 -0400
commitf2515cd629d64484be5747639b485ddad9b6bf85 (patch)
tree8fdb8c396abf2bcdace0752f1608e91c975c68af /libavcodec/alac.c
parentabc4376b31b672f8f38c30851cbe1acd016b6e18 (diff)
downloadffmpeg-f2515cd629d64484be5747639b485ddad9b6bf85.tar.gz
alac: simplify lpc coefficient adaptation
Diffstat (limited to 'libavcodec/alac.c')
-rw-r--r--libavcodec/alac.c41
1 files changed, 10 insertions, 31 deletions
diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 7306e57405..110d2cbcb1 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -206,6 +206,7 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
int j;
int val = 0;
int error_val = error_buffer[i];
+ int error_sign;
for (j = 0; j < predictor_coef_num; j++) {
val += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
@@ -218,39 +219,17 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
buffer_out[predictor_coef_num + 1] = sign_extend(val, readsamplesize);
- if (error_val > 0) {
- int predictor_num = predictor_coef_num - 1;
-
- while (predictor_num >= 0 && error_val > 0) {
+ /* adapt LPC coefficients */
+ error_sign = sign_only(error_val);
+ if (error_sign) {
+ for (j = predictor_coef_num - 1; j >= 0 && error_val * error_sign > 0; j--) {
int sign;
- val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num];
- sign = sign_only(val);
-
- predictor_coef_table[predictor_num] -= sign;
-
- val *= sign; /* absolute value */
-
+ val = buffer_out[0] - buffer_out[predictor_coef_num - j];
+ sign = sign_only(val) * error_sign;
+ predictor_coef_table[j] -= sign;
+ val *= sign;
error_val -= ((val >> predictor_quantitization) *
- (predictor_coef_num - predictor_num));
-
- predictor_num--;
- }
- } else if (error_val < 0) {
- int predictor_num = predictor_coef_num - 1;
-
- while (predictor_num >= 0 && error_val < 0) {
- int sign;
- val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num];
- sign = -sign_only(val);
-
- predictor_coef_table[predictor_num] -= sign;
-
- val *= sign; /* neg value */
-
- error_val -= ((val >> predictor_quantitization) *
- (predictor_coef_num - predictor_num));
-
- predictor_num--;
+ (predictor_coef_num - j));
}
}