comparison alac.c @ 9097:b2f29d9da737 libavcodec

ALAC: use sign_extend() from mathops.h
author mru
date Tue, 03 Mar 2009 01:53:54 +0000
parents e9d9d946f213
children 42a7dfa5b3e4
comparison
equal deleted inserted replaced
9096:005cf8ba225f 9097:b2f29d9da737
54 54
55 #include "avcodec.h" 55 #include "avcodec.h"
56 #include "bitstream.h" 56 #include "bitstream.h"
57 #include "bytestream.h" 57 #include "bytestream.h"
58 #include "unary.h" 58 #include "unary.h"
59 #include "mathops.h"
59 60
60 #define ALAC_EXTRADATA_SIZE 36 61 #define ALAC_EXTRADATA_SIZE 36
61 #define MAX_CHANNELS 2 62 #define MAX_CHANNELS 2
62 63
63 typedef struct { 64 typedef struct {
227 history = 0; 228 history = 0;
228 } 229 }
229 } 230 }
230 } 231 }
231 232
232 static inline int32_t extend_sign32(int32_t val, int bits)
233 {
234 return (val << (32 - bits)) >> (32 - bits);
235 }
236
237 static inline int sign_only(int v) 233 static inline int sign_only(int v)
238 { 234 {
239 return v ? FFSIGN(v) : 0; 235 return v ? FFSIGN(v) : 0;
240 } 236 }
241 237
271 int32_t error_value; 267 int32_t error_value;
272 268
273 prev_value = buffer_out[i]; 269 prev_value = buffer_out[i];
274 error_value = error_buffer[i+1]; 270 error_value = error_buffer[i+1];
275 buffer_out[i+1] = 271 buffer_out[i+1] =
276 extend_sign32((prev_value + error_value), readsamplesize); 272 sign_extend((prev_value + error_value), readsamplesize);
277 } 273 }
278 return; 274 return;
279 } 275 }
280 276
281 /* read warm-up samples */ 277 /* read warm-up samples */
282 if (predictor_coef_num > 0) 278 if (predictor_coef_num > 0)
283 for (i = 0; i < predictor_coef_num; i++) { 279 for (i = 0; i < predictor_coef_num; i++) {
284 int32_t val; 280 int32_t val;
285 281
286 val = buffer_out[i] + error_buffer[i+1]; 282 val = buffer_out[i] + error_buffer[i+1];
287 val = extend_sign32(val, readsamplesize); 283 val = sign_extend(val, readsamplesize);
288 buffer_out[i+1] = val; 284 buffer_out[i+1] = val;
289 } 285 }
290 286
291 #if 0 287 #if 0
292 /* 4 and 8 are very common cases (the only ones i've seen). these 288 /* 4 and 8 are very common cases (the only ones i've seen). these
317 } 313 }
318 314
319 outval = (1 << (predictor_quantitization-1)) + sum; 315 outval = (1 << (predictor_quantitization-1)) + sum;
320 outval = outval >> predictor_quantitization; 316 outval = outval >> predictor_quantitization;
321 outval = outval + buffer_out[0] + error_val; 317 outval = outval + buffer_out[0] + error_val;
322 outval = extend_sign32(outval, readsamplesize); 318 outval = sign_extend(outval, readsamplesize);
323 319
324 buffer_out[predictor_coef_num+1] = outval; 320 buffer_out[predictor_coef_num+1] = outval;
325 321
326 if (error_val > 0) { 322 if (error_val > 0) {
327 int predictor_num = predictor_coef_num - 1; 323 int predictor_num = predictor_coef_num - 1;
543 for (i = 0; i < outputsamples; i++) 539 for (i = 0; i < outputsamples; i++)
544 for (chan = 0; chan < channels; chan++) { 540 for (chan = 0; chan < channels; chan++) {
545 int32_t audiobits; 541 int32_t audiobits;
546 542
547 audiobits = get_bits_long(&alac->gb, alac->setinfo_sample_size); 543 audiobits = get_bits_long(&alac->gb, alac->setinfo_sample_size);
548 audiobits = extend_sign32(audiobits, alac->setinfo_sample_size); 544 audiobits = sign_extend(audiobits, alac->setinfo_sample_size);
549 545
550 alac->outputsamples_buffer[chan][i] = audiobits; 546 alac->outputsamples_buffer[chan][i] = audiobits;
551 } 547 }
552 /* wasted_bytes = 0; */ 548 /* wasted_bytes = 0; */
553 interlacing_shift = 0; 549 interlacing_shift = 0;