Mercurial > libavcodec.hg
comparison alac.c @ 5616:cb5999c836af libavcodec
Replace two #define's by inline functions
author | vitor |
---|---|
date | Thu, 30 Aug 2007 16:04:00 +0000 |
parents | d2ef80f5fd7e |
children | 4051bdeecabf |
comparison
equal
deleted
inserted
replaced
5615:7ffc96c9ab1a | 5616:cb5999c836af |
---|---|
267 history = 0; | 267 history = 0; |
268 } | 268 } |
269 } | 269 } |
270 } | 270 } |
271 | 271 |
272 #define SIGN_EXTENDED32(val, bits) ((val << (32 - bits)) >> (32 - bits)) | 272 static inline int32_t sign_extended32(int32_t val, int bits) |
273 | 273 { |
274 #define SIGN_ONLY(v) \ | 274 return (val << (32 - bits)) >> (32 - bits); |
275 ((v < 0) ? (-1) : \ | 275 } |
276 ((v > 0) ? (1) : \ | 276 |
277 (0))) | 277 static inline int sign_only(int v) |
278 { | |
279 return v ? FFSIGN(v) : 0; | |
280 } | |
278 | 281 |
279 static void predictor_decompress_fir_adapt(int32_t *error_buffer, | 282 static void predictor_decompress_fir_adapt(int32_t *error_buffer, |
280 int32_t *buffer_out, | 283 int32_t *buffer_out, |
281 int output_size, | 284 int output_size, |
282 int readsamplesize, | 285 int readsamplesize, |
308 int32_t error_value; | 311 int32_t error_value; |
309 | 312 |
310 prev_value = buffer_out[i]; | 313 prev_value = buffer_out[i]; |
311 error_value = error_buffer[i+1]; | 314 error_value = error_buffer[i+1]; |
312 buffer_out[i+1] = | 315 buffer_out[i+1] = |
313 SIGN_EXTENDED32((prev_value + error_value), readsamplesize); | 316 sign_extended32((prev_value + error_value), readsamplesize); |
314 } | 317 } |
315 return; | 318 return; |
316 } | 319 } |
317 | 320 |
318 /* read warm-up samples */ | 321 /* read warm-up samples */ |
319 if (predictor_coef_num > 0) | 322 if (predictor_coef_num > 0) |
320 for (i = 0; i < predictor_coef_num; i++) { | 323 for (i = 0; i < predictor_coef_num; i++) { |
321 int32_t val; | 324 int32_t val; |
322 | 325 |
323 val = buffer_out[i] + error_buffer[i+1]; | 326 val = buffer_out[i] + error_buffer[i+1]; |
324 val = SIGN_EXTENDED32(val, readsamplesize); | 327 val = sign_extended32(val, readsamplesize); |
325 buffer_out[i+1] = val; | 328 buffer_out[i+1] = val; |
326 } | 329 } |
327 | 330 |
328 #if 0 | 331 #if 0 |
329 /* 4 and 8 are very common cases (the only ones i've seen). these | 332 /* 4 and 8 are very common cases (the only ones i've seen). these |
354 } | 357 } |
355 | 358 |
356 outval = (1 << (predictor_quantitization-1)) + sum; | 359 outval = (1 << (predictor_quantitization-1)) + sum; |
357 outval = outval >> predictor_quantitization; | 360 outval = outval >> predictor_quantitization; |
358 outval = outval + buffer_out[0] + error_val; | 361 outval = outval + buffer_out[0] + error_val; |
359 outval = SIGN_EXTENDED32(outval, readsamplesize); | 362 outval = sign_extended32(outval, readsamplesize); |
360 | 363 |
361 buffer_out[predictor_coef_num+1] = outval; | 364 buffer_out[predictor_coef_num+1] = outval; |
362 | 365 |
363 if (error_val > 0) { | 366 if (error_val > 0) { |
364 int predictor_num = predictor_coef_num - 1; | 367 int predictor_num = predictor_coef_num - 1; |
365 | 368 |
366 while (predictor_num >= 0 && error_val > 0) { | 369 while (predictor_num >= 0 && error_val > 0) { |
367 int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; | 370 int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; |
368 int sign = SIGN_ONLY(val); | 371 int sign = sign_only(val); |
369 | 372 |
370 predictor_coef_table[predictor_num] -= sign; | 373 predictor_coef_table[predictor_num] -= sign; |
371 | 374 |
372 val *= sign; /* absolute value */ | 375 val *= sign; /* absolute value */ |
373 | 376 |
379 } else if (error_val < 0) { | 382 } else if (error_val < 0) { |
380 int predictor_num = predictor_coef_num - 1; | 383 int predictor_num = predictor_coef_num - 1; |
381 | 384 |
382 while (predictor_num >= 0 && error_val < 0) { | 385 while (predictor_num >= 0 && error_val < 0) { |
383 int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; | 386 int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; |
384 int sign = - SIGN_ONLY(val); | 387 int sign = - sign_only(val); |
385 | 388 |
386 predictor_coef_table[predictor_num] -= sign; | 389 predictor_coef_table[predictor_num] -= sign; |
387 | 390 |
388 val *= sign; /* neg value */ | 391 val *= sign; /* neg value */ |
389 | 392 |
568 for (chan = 0; chan < channels; chan++) | 571 for (chan = 0; chan < channels; chan++) |
569 for (i = 0; i < outputsamples; i++) { | 572 for (i = 0; i < outputsamples; i++) { |
570 int32_t audiobits; | 573 int32_t audiobits; |
571 | 574 |
572 audiobits = get_bits(&alac->gb, alac->setinfo_sample_size); | 575 audiobits = get_bits(&alac->gb, alac->setinfo_sample_size); |
573 audiobits = SIGN_EXTENDED32(audiobits, readsamplesize); | 576 audiobits = sign_extended32(audiobits, readsamplesize); |
574 | 577 |
575 alac->outputsamples_buffer[chan][i] = audiobits; | 578 alac->outputsamples_buffer[chan][i] = audiobits; |
576 } | 579 } |
577 } else { | 580 } else { |
578 int i, chan; | 581 int i, chan; |