comparison ac3dec.c @ 9672:15276eb66180 libavcodec

LGPL version of ac3_decode_transform_coeffs_ch, ~12.4% faster.
author darkshikari
date Tue, 19 May 2009 21:29:21 +0000
parents 1fe22274393a
children 3e1a08ba8481
comparison
equal deleted inserted replaced
9671:e244c40a5148 9672:15276eb66180
437 437
438 /** 438 /**
439 * Grouped mantissas for 3-level 5-level and 11-level quantization 439 * Grouped mantissas for 3-level 5-level and 11-level quantization
440 */ 440 */
441 typedef struct { 441 typedef struct {
442 int b1_mant[3]; 442 int b1_mant[2];
443 int b2_mant[3]; 443 int b2_mant[2];
444 int b4_mant[2]; 444 int b4_mant;
445 int b1ptr; 445 int b1;
446 int b2ptr; 446 int b2;
447 int b4ptr; 447 int b4;
448 } mant_groups; 448 } mant_groups;
449 449
450 /** 450 /**
451 * Decode the transform coefficients for a particular channel 451 * Decode the transform coefficients for a particular channel
452 * reference: Section 7.3 Quantization and Decoding of Mantissas 452 * reference: Section 7.3 Quantization and Decoding of Mantissas
453 */ 453 */
454 static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, mant_groups *m) 454 static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, mant_groups *m)
455 { 455 {
456 int start_freq = s->start_freq[ch_index];
457 int end_freq = s->end_freq[ch_index];
458 uint8_t *baps = s->bap[ch_index];
459 int8_t *exps = s->dexps[ch_index];
460 int *coeffs = s->fixed_coeffs[ch_index];
456 GetBitContext *gbc = &s->gbc; 461 GetBitContext *gbc = &s->gbc;
457 int i, gcode, tbap, start, end; 462 int freq;
458 uint8_t *exps; 463
459 uint8_t *bap; 464 for(freq = start_freq; freq < end_freq; freq++){
460 int *coeffs; 465 int bap = baps[freq];
461 466 int mantissa;
462 exps = s->dexps[ch_index]; 467 switch(bap){
463 bap = s->bap[ch_index];
464 coeffs = s->fixed_coeffs[ch_index];
465 start = s->start_freq[ch_index];
466 end = s->end_freq[ch_index];
467
468 for (i = start; i < end; i++) {
469 tbap = bap[i];
470 switch (tbap) {
471 case 0: 468 case 0:
472 coeffs[i] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; 469 mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
473 break; 470 break;
474
475 case 1: 471 case 1:
476 if(m->b1ptr > 2) { 472 if(m->b1){
477 gcode = get_bits(gbc, 5); 473 m->b1--;
478 m->b1_mant[0] = b1_mantissas[gcode][0]; 474 mantissa = m->b1_mant[m->b1];
479 m->b1_mant[1] = b1_mantissas[gcode][1];
480 m->b1_mant[2] = b1_mantissas[gcode][2];
481 m->b1ptr = 0;
482 } 475 }
483 coeffs[i] = m->b1_mant[m->b1ptr++]; 476 else{
477 int bits = get_bits(gbc, 5);
478 mantissa = b1_mantissas[bits][0];
479 m->b1_mant[1] = b1_mantissas[bits][1];
480 m->b1_mant[0] = b1_mantissas[bits][2];
481 m->b1 = 2;
482 }
484 break; 483 break;
485
486 case 2: 484 case 2:
487 if(m->b2ptr > 2) { 485 if(m->b2){
488 gcode = get_bits(gbc, 7); 486 m->b2--;
489 m->b2_mant[0] = b2_mantissas[gcode][0]; 487 mantissa = m->b2_mant[m->b2];
490 m->b2_mant[1] = b2_mantissas[gcode][1];
491 m->b2_mant[2] = b2_mantissas[gcode][2];
492 m->b2ptr = 0;
493 } 488 }
494 coeffs[i] = m->b2_mant[m->b2ptr++]; 489 else{
490 int bits = get_bits(gbc, 7);
491 mantissa = b2_mantissas[bits][0];
492 m->b2_mant[1] = b2_mantissas[bits][1];
493 m->b2_mant[0] = b2_mantissas[bits][2];
494 m->b2 = 2;
495 }
495 break; 496 break;
496
497 case 3: 497 case 3:
498 coeffs[i] = b3_mantissas[get_bits(gbc, 3)]; 498 mantissa = b3_mantissas[get_bits(gbc, 3)];
499 break; 499 break;
500
501 case 4: 500 case 4:
502 if(m->b4ptr > 1) { 501 if(m->b4){
503 gcode = get_bits(gbc, 7); 502 m->b4 = 0;
504 m->b4_mant[0] = b4_mantissas[gcode][0]; 503 mantissa = m->b4_mant;
505 m->b4_mant[1] = b4_mantissas[gcode][1];
506 m->b4ptr = 0;
507 } 504 }
508 coeffs[i] = m->b4_mant[m->b4ptr++]; 505 else{
506 int bits = get_bits(gbc, 7);
507 mantissa = b4_mantissas[bits][0];
508 m->b4_mant = b4_mantissas[bits][1];
509 m->b4 = 1;
510 }
509 break; 511 break;
510
511 case 5: 512 case 5:
512 coeffs[i] = b5_mantissas[get_bits(gbc, 4)]; 513 mantissa = b5_mantissas[get_bits(gbc, 4)];
513 break; 514 break;
514 515 default: /* 6 to 15 */
515 default: { 516 mantissa = get_bits(gbc, quantization_tab[bap]);
516 /* asymmetric dequantization */ 517 /* Shift mantissa and sign-extend it. */
517 int qlevel = quantization_tab[tbap]; 518 mantissa = (mantissa << (32-quantization_tab[bap]))>>8;
518 coeffs[i] = get_sbits(gbc, qlevel) << (24 - qlevel);
519 break; 519 break;
520 } 520 }
521 } 521 coeffs[freq] = mantissa >> exps[freq];
522 coeffs[i] >>= exps[i];
523 } 522 }
524 } 523 }
525 524
526 /** 525 /**
527 * Remove random dithering from coefficients with zero-bit mantissas 526 * Remove random dithering from coefficients with zero-bit mantissas
580 { 579 {
581 int ch, end; 580 int ch, end;
582 int got_cplchan = 0; 581 int got_cplchan = 0;
583 mant_groups m; 582 mant_groups m;
584 583
585 m.b1ptr = m.b2ptr = m.b4ptr = 3; 584 m.b1 = m.b2 = m.b4 = 0;
586 585
587 for (ch = 1; ch <= s->channels; ch++) { 586 for (ch = 1; ch <= s->channels; ch++) {
588 /* transform coefficients for full-bandwidth channel */ 587 /* transform coefficients for full-bandwidth channel */
589 decode_transform_coeffs_ch(s, blk, ch, &m); 588 decode_transform_coeffs_ch(s, blk, ch, &m);
590 /* tranform coefficients for coupling channel come right after the 589 /* tranform coefficients for coupling channel come right after the