comparison ac3dec.c @ 5331:b24bcdd0ae86 libavcodec

move some common values to ac3.h and utilize them
author jbr
date Sun, 15 Jul 2007 01:31:09 +0000
parents 37de2d864f03
children fc75e75e50aa
comparison
equal deleted inserted replaced
5330:37de2d864f03 5331:b24bcdd0ae86
31 #include <string.h> 31 #include <string.h>
32 32
33 #define ALT_BITSTREAM_READER 33 #define ALT_BITSTREAM_READER
34 34
35 #include "avcodec.h" 35 #include "avcodec.h"
36 #include "ac3.h"
36 #include "ac3tab.h" 37 #include "ac3tab.h"
37 #include "bitstream.h" 38 #include "bitstream.h"
38 #include "dsputil.h" 39 #include "dsputil.h"
39 #include "random.h" 40 #include "random.h"
41
42 static uint8_t bndtab[51];
43 static uint8_t masktab[253];
40 44
41 static const int nfchans_tbl[8] = { 2, 1, 2, 3, 3, 4, 4, 5 }; 45 static const int nfchans_tbl[8] = { 2, 1, 2, 3, 3, 4, 4, 5 };
42 46
43 /* table for exponent to scale_factor mapping 47 /* table for exponent to scale_factor mapping
44 * scale_factor[i] = 2 ^ -(i + 15) 48 * scale_factor[i] = 2 ^ -(i + 15)
81 85
82 static const float slevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_6DB, LEVEL_ZERO, LEVEL_MINUS_6DB }; 86 static const float slevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_6DB, LEVEL_ZERO, LEVEL_MINUS_6DB };
83 87
84 #define N 512 /* constant for IMDCT Block size */ 88 #define N 512 /* constant for IMDCT Block size */
85 89
86 #define MAX_CHANNELS 6
87 #define BLOCK_SIZE 256 90 #define BLOCK_SIZE 256
88 #define AUDIO_BLOCKS 6
89
90 /* Exponent strategies. */
91 #define AC3_EXPSTR_D15 0x01
92 #define AC3_EXPSTR_D25 0x02
93 #define AC3_EXPSTR_D45 0x03
94 #define AC3_EXPSTR_REUSE 0x00
95
96 /* Bit allocation strategies. */
97 #define AC3_DBASTR_NEW 0x01
98 #define AC3_DBASTR_NONE 0x02
99 #define AC3_DBASTR_RESERVED 0x03
100 #define AC3_DBASTR_REUSE 0x00
101 91
102 /* Output and input configurations. */ 92 /* Output and input configurations. */
103 #define AC3_OUTPUT_UNMODIFIED 0x01 93 #define AC3_OUTPUT_UNMODIFIED 0x01
104 #define AC3_OUTPUT_MONO 0x02 94 #define AC3_OUTPUT_MONO 0x02
105 #define AC3_OUTPUT_STEREO 0x04 95 #define AC3_OUTPUT_STEREO 0x04
106 #define AC3_OUTPUT_DOLBY 0x08 96 #define AC3_OUTPUT_DOLBY 0x08
107 #define AC3_OUTPUT_LFEON 0x10 97 #define AC3_OUTPUT_LFEON 0x10
108
109 #define AC3_INPUT_DUALMONO 0x00
110 #define AC3_INPUT_MONO 0x01
111 #define AC3_INPUT_STEREO 0x02
112 #define AC3_INPUT_3F 0x03
113 #define AC3_INPUT_2F_1R 0x04
114 #define AC3_INPUT_3F_1R 0x05
115 #define AC3_INPUT_2F_2R 0x06
116 #define AC3_INPUT_3F_2R 0x07
117 98
118 typedef struct { 99 typedef struct {
119 uint16_t crc1; 100 uint16_t crc1;
120 uint8_t fscod; 101 uint8_t fscod;
121 102
188 uint8_t bap[5][256]; //fbw channel bit allocation pointers 169 uint8_t bap[5][256]; //fbw channel bit allocation pointers
189 uint8_t lfebap[256]; //lfe channel bit allocation pointers 170 uint8_t lfebap[256]; //lfe channel bit allocation pointers
190 171
191 int blkoutput; //output configuration for block 172 int blkoutput; //output configuration for block
192 173
193 DECLARE_ALIGNED_16(float, transform_coeffs[MAX_CHANNELS][BLOCK_SIZE]); //transform coefficients 174 DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][BLOCK_SIZE]); //transform coefficients
194 175
195 /* For IMDCT. */ 176 /* For IMDCT. */
196 MDCTContext imdct_512; //for 512 sample imdct transform 177 MDCTContext imdct_512; //for 512 sample imdct transform
197 MDCTContext imdct_256; //for 256 sample imdct transform 178 MDCTContext imdct_256; //for 256 sample imdct transform
198 DSPContext dsp; //for optimization 179 DSPContext dsp; //for optimization
199 180
200 DECLARE_ALIGNED_16(float, output[MAX_CHANNELS][BLOCK_SIZE]); //output after imdct transform and windowing 181 DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS][BLOCK_SIZE]); //output after imdct transform and windowing
201 DECLARE_ALIGNED_16(float, delay[MAX_CHANNELS][BLOCK_SIZE]); //delay - added to the next block 182 DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS][BLOCK_SIZE]); //delay - added to the next block
202 DECLARE_ALIGNED_16(float, tmp_imdct[BLOCK_SIZE]); //temporary storage for imdct transform 183 DECLARE_ALIGNED_16(float, tmp_imdct[BLOCK_SIZE]); //temporary storage for imdct transform
203 DECLARE_ALIGNED_16(float, tmp_output[BLOCK_SIZE * 2]); //temporary storage for output before windowing 184 DECLARE_ALIGNED_16(float, tmp_output[BLOCK_SIZE * 2]); //temporary storage for output before windowing
204 DECLARE_ALIGNED_16(float, window[BLOCK_SIZE]); //window coefficients 185 DECLARE_ALIGNED_16(float, window[BLOCK_SIZE]); //window coefficients
205 186
206 /* Miscellaneous. */ 187 /* Miscellaneous. */
296 /* compute bndtab and masktab from bandsz */ 277 /* compute bndtab and masktab from bandsz */
297 k = 0; 278 k = 0;
298 l = 0; 279 l = 0;
299 for(i=0;i<50;i++) { 280 for(i=0;i<50;i++) {
300 bndtab[i] = l; 281 bndtab[i] = l;
301 v = bndsz[i]; 282 v = ff_ac3_bndsz[i];
302 for(j=0;j<v;j++) masktab[k++]=i; 283 for(j=0;j<v;j++) masktab[k++]=i;
303 l += v; 284 l += v;
304 } 285 }
305 masktab[253] = masktab[254] = masktab[255] = 0; 286 masktab[253] = masktab[254] = masktab[255] = 0;
306 bndtab[50] = 0; 287 bndtab[50] = 0;
362 343
363 static int ac3_decode_init(AVCodecContext *avctx) 344 static int ac3_decode_init(AVCodecContext *avctx)
364 { 345 {
365 AC3DecodeContext *ctx = avctx->priv_data; 346 AC3DecodeContext *ctx = avctx->priv_data;
366 347
348 ac3_common_init();
367 ac3_tables_init(); 349 ac3_tables_init();
368 ff_mdct_init(&ctx->imdct_256, 8, 1); 350 ff_mdct_init(&ctx->imdct_256, 8, 1);
369 ff_mdct_init(&ctx->imdct_512, 9, 1); 351 ff_mdct_init(&ctx->imdct_512, 9, 1);
370 ac3_window_init(ctx->window); 352 ac3_window_init(ctx->window);
371 dsputil_init(&ctx->dsp, avctx); 353 dsputil_init(&ctx->dsp, avctx);
412 if (ctx->fscod == 0x03) 394 if (ctx->fscod == 0x03)
413 return 0; 395 return 0;
414 frmsizecod = get_bits(gb, 6); 396 frmsizecod = get_bits(gb, 6);
415 if (frmsizecod >= 38) 397 if (frmsizecod >= 38)
416 return 0; 398 return 0;
417 ctx->sampling_rate = ac3_freqs[ctx->fscod]; 399 ctx->sampling_rate = ff_ac3_freqs[ctx->fscod];
418 ctx->bit_rate = ac3_bitratetab[frmsizecod >> 1]; 400 ctx->bit_rate = ff_ac3_bitratetab[frmsizecod >> 1];
419 401
420 /* we include it here in order to determine validity of ac3 frame */ 402 /* we include it here in order to determine validity of ac3 frame */
421 bsid = get_bits(gb, 5); 403 bsid = get_bits(gb, 5);
422 if (bsid > 0x08) 404 if (bsid > 0x08)
423 return 0; 405 return 0;
451 433
452 ctx->cmixlev = 0; 434 ctx->cmixlev = 0;
453 ctx->surmixlev = 0; 435 ctx->surmixlev = 0;
454 ctx->dsurmod = 0; 436 ctx->dsurmod = 0;
455 ctx->nfchans = 0; 437 ctx->nfchans = 0;
456 ctx->cpldeltbae = AC3_DBASTR_NONE; 438 ctx->cpldeltbae = DBA_NONE;
457 ctx->cpldeltnseg = 0; 439 ctx->cpldeltnseg = 0;
458 for (i = 0; i < 5; i++) { 440 for (i = 0; i < 5; i++) {
459 ctx->deltbae[i] = AC3_DBASTR_NONE; 441 ctx->deltbae[i] = DBA_NONE;
460 ctx->deltnseg[i] = 0; 442 ctx->deltnseg[i] = 0;
461 } 443 }
462 ctx->dynrng = 1.0; 444 ctx->dynrng = 1.0;
463 ctx->dynrng2 = 1.0; 445 ctx->dynrng2 = 1.0;
464 446
522 if (absexp > 24) { 504 if (absexp > 24) {
523 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps); 505 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps);
524 return -ngrps; 506 return -ngrps;
525 } 507 }
526 switch (expstr) { 508 switch (expstr) {
527 case AC3_EXPSTR_D45: 509 case EXP_D45:
528 *(dexps++) = absexp; 510 *(dexps++) = absexp;
529 *(dexps++) = absexp; 511 *(dexps++) = absexp;
530 case AC3_EXPSTR_D25: 512 case EXP_D25:
531 *(dexps++) = absexp; 513 *(dexps++) = absexp;
532 case AC3_EXPSTR_D15: 514 case EXP_D15:
533 *(dexps++) = absexp; 515 *(dexps++) = absexp;
534 } 516 }
535 517
536 absexp += exp_2[exps]; 518 absexp += exp_2[exps];
537 if (absexp > 24) { 519 if (absexp > 24) {
538 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps); 520 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps);
539 return -ngrps; 521 return -ngrps;
540 } 522 }
541 switch (expstr) { 523 switch (expstr) {
542 case AC3_EXPSTR_D45: 524 case EXP_D45:
543 *(dexps++) = absexp; 525 *(dexps++) = absexp;
544 *(dexps++) = absexp; 526 *(dexps++) = absexp;
545 case AC3_EXPSTR_D25: 527 case EXP_D25:
546 *(dexps++) = absexp; 528 *(dexps++) = absexp;
547 case AC3_EXPSTR_D15: 529 case EXP_D15:
548 *(dexps++) = absexp; 530 *(dexps++) = absexp;
549 } 531 }
550 532
551 absexp += exp_3[exps]; 533 absexp += exp_3[exps];
552 if (absexp > 24) { 534 if (absexp > 24) {
553 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps); 535 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps);
554 return -ngrps; 536 return -ngrps;
555 } 537 }
556 switch (expstr) { 538 switch (expstr) {
557 case AC3_EXPSTR_D45: 539 case EXP_D45:
558 *(dexps++) = absexp; 540 *(dexps++) = absexp;
559 *(dexps++) = absexp; 541 *(dexps++) = absexp;
560 case AC3_EXPSTR_D25: 542 case EXP_D25:
561 *(dexps++) = absexp; 543 *(dexps++) = absexp;
562 case AC3_EXPSTR_D15: 544 case EXP_D15:
563 *(dexps++) = absexp; 545 *(dexps++) = absexp;
564 } 546 }
565 } 547 }
566 548
567 return 0; 549 return 0;
574 int address; 556 int address;
575 557
576 address = FFMIN((ABS(c) >> 1), 255); 558 address = FFMIN((ABS(c) >> 1), 255);
577 559
578 if (c >= 0) 560 if (c >= 0)
579 return (a + latab[address]); 561 return (a + ff_ac3_latab[address]);
580 else 562 else
581 return (b + latab[address]); 563 return (b + ff_ac3_latab[address]);
582 } 564 }
583 565
584 static inline int calc_lowcomp(int a, int b0, int b1, int bin) 566 static inline int calc_lowcomp(int a, int b0, int b1, int bin)
585 { 567 {
586 if (bin < 7) { 568 if (bin < 7) {
615 int fscod = ctx->fscod; 597 int fscod = ctx->fscod;
616 uint8_t *deltoffst = 0, *deltlen = 0, *deltba = 0; 598 uint8_t *deltoffst = 0, *deltlen = 0, *deltba = 0;
617 uint8_t *exps = 0, *bap = 0; 599 uint8_t *exps = 0, *bap = 0;
618 600
619 /* initialization */ 601 /* initialization */
620 sdecay = sdecaytab[ctx->sdcycod]; 602 sdecay = ff_sdecaytab[ctx->sdcycod];
621 fdecay = fdecaytab[ctx->fdcycod]; 603 fdecay = ff_fdecaytab[ctx->fdcycod];
622 sgain = sgaintab[ctx->sgaincod]; 604 sgain = ff_sgaintab[ctx->sgaincod];
623 dbknee = dbkneetab[ctx->dbpbcod]; 605 dbknee = ff_dbkneetab[ctx->dbpbcod];
624 floor = floortab[ctx->floorcod]; 606 floor = ff_floortab[ctx->floorcod];
625 607
626 if (chnl == 5) { 608 if (chnl == 5) {
627 start = ctx->cplstrtmant; 609 start = ctx->cplstrtmant;
628 end = ctx->cplendmant; 610 end = ctx->cplendmant;
629 fgain = fgaintab[ctx->cplfgaincod]; 611 fgain = ff_fgaintab[ctx->cplfgaincod];
630 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->cplfsnroffst) << 2; 612 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->cplfsnroffst) << 2;
631 fastleak = (ctx->cplfleak << 8) + 768; 613 fastleak = (ctx->cplfleak << 8) + 768;
632 slowleak = (ctx->cplsleak << 8) + 768; 614 slowleak = (ctx->cplsleak << 8) + 768;
633 exps = ctx->dcplexps; 615 exps = ctx->dcplexps;
634 bap = ctx->cplbap; 616 bap = ctx->cplbap;
635 if (ctx->cpldeltbae == AC3_DBASTR_NEW || ctx->deltbae == AC3_DBASTR_REUSE) { 617 if (ctx->cpldeltbae == DBA_NEW || ctx->deltbae == DBA_REUSE) {
636 do_delta = 1; 618 do_delta = 1;
637 deltnseg = ctx->cpldeltnseg; 619 deltnseg = ctx->cpldeltnseg;
638 deltoffst = ctx->cpldeltoffst; 620 deltoffst = ctx->cpldeltoffst;
639 deltlen = ctx->cpldeltlen; 621 deltlen = ctx->cpldeltlen;
640 deltba = ctx->cpldeltba; 622 deltba = ctx->cpldeltba;
644 start = 0; 626 start = 0;
645 end = 7; 627 end = 7;
646 lowcomp = 0; 628 lowcomp = 0;
647 fastleak = 0; 629 fastleak = 0;
648 slowleak = 0; 630 slowleak = 0;
649 fgain = fgaintab[ctx->lfefgaincod]; 631 fgain = ff_fgaintab[ctx->lfefgaincod];
650 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->lfefsnroffst) << 2; 632 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->lfefsnroffst) << 2;
651 exps = ctx->dlfeexps; 633 exps = ctx->dlfeexps;
652 bap = ctx->lfebap; 634 bap = ctx->lfebap;
653 } 635 }
654 else { 636 else {
655 start = 0; 637 start = 0;
656 end = ctx->endmant[chnl]; 638 end = ctx->endmant[chnl];
657 lowcomp = 0; 639 lowcomp = 0;
658 fastleak = 0; 640 fastleak = 0;
659 slowleak = 0; 641 slowleak = 0;
660 fgain = fgaintab[ctx->fgaincod[chnl]]; 642 fgain = ff_fgaintab[ctx->fgaincod[chnl]];
661 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->fsnroffst[chnl]) << 2; 643 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->fsnroffst[chnl]) << 2;
662 exps = ctx->dexps[chnl]; 644 exps = ctx->dexps[chnl];
663 bap = ctx->bap[chnl]; 645 bap = ctx->bap[chnl];
664 if (ctx->deltbae[chnl] == AC3_DBASTR_NEW || ctx->deltbae[chnl] == AC3_DBASTR_REUSE) { 646 if (ctx->deltbae[chnl] == DBA_NEW || ctx->deltbae[chnl] == DBA_REUSE) {
665 do_delta = 1; 647 do_delta = 1;
666 deltnseg = ctx->deltnseg[chnl]; 648 deltnseg = ctx->deltnseg[chnl];
667 deltoffst = ctx->deltoffst[chnl]; 649 deltoffst = ctx->deltoffst[chnl];
668 deltlen = ctx->deltlen[chnl]; 650 deltlen = ctx->deltlen[chnl];
669 deltba = ctx->deltba[chnl]; 651 deltba = ctx->deltba[chnl];
675 657
676 /* psd integration */ 658 /* psd integration */
677 j = start; 659 j = start;
678 k = masktab[start]; 660 k = masktab[start];
679 do { 661 do {
680 lastbin = FFMIN((bndtab[k] + bndsz[k]), end); 662 lastbin = FFMIN((bndtab[k] + ff_ac3_bndsz[k]), end);
681 bndpsd[k] = psd[j]; 663 bndpsd[k] = psd[j];
682 j++; 664 j++;
683 for (i = j; i < lastbin; i++) { 665 for (i = j; i < lastbin; i++) {
684 bndpsd[k] = logadd(bndpsd[k], psd[j]); 666 bndpsd[k] = logadd(bndpsd[k], psd[j]);
685 j++; 667 j++;
732 714
733 /* compute the masking curve */ 715 /* compute the masking curve */
734 for (bin = bndstrt; bin < bndend; bin++) { 716 for (bin = bndstrt; bin < bndend; bin++) {
735 if (bndpsd[bin] < dbknee) 717 if (bndpsd[bin] < dbknee)
736 excite[bin] += ((dbknee - bndpsd[bin]) >> 2); 718 excite[bin] += ((dbknee - bndpsd[bin]) >> 2);
737 mask[bin] = FFMAX(excite[bin], hth[bin][fscod]); 719 mask[bin] = FFMAX(excite[bin], ff_ac3_hth[bin][fscod]);
738 } 720 }
739 721
740 /* apply the delta bit allocation */ 722 /* apply the delta bit allocation */
741 if (do_delta) { 723 if (do_delta) {
742 band = 0; 724 band = 0;
755 737
756 /*compute the bit allocation */ 738 /*compute the bit allocation */
757 i = start; 739 i = start;
758 j = masktab[start]; 740 j = masktab[start];
759 do { 741 do {
760 lastbin = FFMIN((bndtab[j] + bndsz[j]), end); 742 lastbin = FFMIN((bndtab[j] + ff_ac3_bndsz[j]), end);
761 mask[j] -= snroffset; 743 mask[j] -= snroffset;
762 mask[j] -= floor; 744 mask[j] -= floor;
763 if (mask[j] < 0) 745 if (mask[j] < 0)
764 mask[j] = 0; 746 mask[j] = 0;
765 mask[j] &= 0x1fe0; 747 mask[j] &= 0x1fe0;
766 mask[j] += floor; 748 mask[j] += floor;
767 for (k = i; k < lastbin; k++) { 749 for (k = i; k < lastbin; k++) {
768 address = (psd[i] - mask[j]) >> 5; 750 address = (psd[i] - mask[j]) >> 5;
769 address = FFMIN(63, (FFMAX(0, address))); 751 address = FFMIN(63, (FFMAX(0, address)));
770 bap[i] = baptab[address]; 752 bap[i] = ff_ac3_baptab[address];
771 i++; 753 i++;
772 } 754 }
773 j++; 755 j++;
774 } while (end > lastbin); 756 } while (end > lastbin);
775 } 757 }
1094 1076
1095 if (to == AC3_OUTPUT_UNMODIFIED) 1077 if (to == AC3_OUTPUT_UNMODIFIED)
1096 return; 1078 return;
1097 1079
1098 switch (from) { 1080 switch (from) {
1099 case AC3_INPUT_DUALMONO: 1081 case AC3_ACMOD_DUALMONO:
1100 switch (to) { 1082 switch (to) {
1101 case AC3_OUTPUT_MONO: 1083 case AC3_OUTPUT_MONO:
1102 case AC3_OUTPUT_STEREO: /* We Assume that sum of both mono channels is requested */ 1084 case AC3_OUTPUT_STEREO: /* We Assume that sum of both mono channels is requested */
1103 nf = 0.5; 1085 nf = 0.5;
1104 ctx->chcoeffs[0] *= nf; 1086 ctx->chcoeffs[0] *= nf;
1105 ctx->chcoeffs[1] *= nf; 1087 ctx->chcoeffs[1] *= nf;
1106 break; 1088 break;
1107 } 1089 }
1108 break; 1090 break;
1109 case AC3_INPUT_MONO: 1091 case AC3_ACMOD_MONO:
1110 switch (to) { 1092 switch (to) {
1111 case AC3_OUTPUT_STEREO: 1093 case AC3_OUTPUT_STEREO:
1112 nf = LEVEL_MINUS_3DB; 1094 nf = LEVEL_MINUS_3DB;
1113 ctx->chcoeffs[0] *= nf; 1095 ctx->chcoeffs[0] *= nf;
1114 break; 1096 break;
1115 } 1097 }
1116 break; 1098 break;
1117 case AC3_INPUT_STEREO: 1099 case AC3_ACMOD_STEREO:
1118 switch (to) { 1100 switch (to) {
1119 case AC3_OUTPUT_MONO: 1101 case AC3_OUTPUT_MONO:
1120 nf = LEVEL_MINUS_3DB; 1102 nf = LEVEL_MINUS_3DB;
1121 ctx->chcoeffs[0] *= nf; 1103 ctx->chcoeffs[0] *= nf;
1122 ctx->chcoeffs[1] *= nf; 1104 ctx->chcoeffs[1] *= nf;
1123 break; 1105 break;
1124 } 1106 }
1125 break; 1107 break;
1126 case AC3_INPUT_3F: 1108 case AC3_ACMOD_3F:
1127 switch (to) { 1109 switch (to) {
1128 case AC3_OUTPUT_MONO: 1110 case AC3_OUTPUT_MONO:
1129 nf = LEVEL_MINUS_3DB / (1.0 + clev); 1111 nf = LEVEL_MINUS_3DB / (1.0 + clev);
1130 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB); 1112 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1131 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB); 1113 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1137 ctx->chcoeffs[2] *= nf; 1119 ctx->chcoeffs[2] *= nf;
1138 ctx->chcoeffs[1] *= (nf * clev); 1120 ctx->chcoeffs[1] *= (nf * clev);
1139 break; 1121 break;
1140 } 1122 }
1141 break; 1123 break;
1142 case AC3_INPUT_2F_1R: 1124 case AC3_ACMOD_2F1R:
1143 switch (to) { 1125 switch (to) {
1144 case AC3_OUTPUT_MONO: 1126 case AC3_OUTPUT_MONO:
1145 nf = 2.0 * LEVEL_MINUS_3DB / (2.0 + slev); 1127 nf = 2.0 * LEVEL_MINUS_3DB / (2.0 + slev);
1146 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB); 1128 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1147 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB); 1129 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
1159 ctx->chcoeffs[1] *= nf; 1141 ctx->chcoeffs[1] *= nf;
1160 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB); 1142 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1161 break; 1143 break;
1162 } 1144 }
1163 break; 1145 break;
1164 case AC3_INPUT_3F_1R: 1146 case AC3_ACMOD_3F1R:
1165 switch (to) { 1147 switch (to) {
1166 case AC3_OUTPUT_MONO: 1148 case AC3_OUTPUT_MONO:
1167 nf = LEVEL_MINUS_3DB / (1.0 + clev + (slev / 2.0)); 1149 nf = LEVEL_MINUS_3DB / (1.0 + clev + (slev / 2.0));
1168 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB); 1150 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1169 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB); 1151 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1184 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB); 1166 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
1185 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB); 1167 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB);
1186 break; 1168 break;
1187 } 1169 }
1188 break; 1170 break;
1189 case AC3_INPUT_2F_2R: 1171 case AC3_ACMOD_2F2R:
1190 switch (to) { 1172 switch (to) {
1191 case AC3_OUTPUT_MONO: 1173 case AC3_OUTPUT_MONO:
1192 nf = LEVEL_MINUS_3DB / (1.0 + slev); 1174 nf = LEVEL_MINUS_3DB / (1.0 + slev);
1193 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB); 1175 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1194 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB); 1176 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
1209 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB); 1191 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1210 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB); 1192 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB);
1211 break; 1193 break;
1212 } 1194 }
1213 break; 1195 break;
1214 case AC3_INPUT_3F_2R: 1196 case AC3_ACMOD_3F2R:
1215 switch (to) { 1197 switch (to) {
1216 case AC3_OUTPUT_MONO: 1198 case AC3_OUTPUT_MONO:
1217 nf = LEVEL_MINUS_3DB / (1.0 + clev + slev); 1199 nf = LEVEL_MINUS_3DB / (1.0 + clev + slev);
1218 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB); 1200 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1219 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB); 1201 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1472 1454
1473 if (to == AC3_OUTPUT_UNMODIFIED) 1455 if (to == AC3_OUTPUT_UNMODIFIED)
1474 return; 1456 return;
1475 1457
1476 switch (from) { 1458 switch (from) {
1477 case AC3_INPUT_DUALMONO: 1459 case AC3_ACMOD_DUALMONO:
1478 switch (to) { 1460 switch (to) {
1479 case AC3_OUTPUT_MONO: 1461 case AC3_OUTPUT_MONO:
1480 mix_dualmono_to_mono(ctx); 1462 mix_dualmono_to_mono(ctx);
1481 break; 1463 break;
1482 case AC3_OUTPUT_STEREO: /* We assume that sum of both mono channels is requested */ 1464 case AC3_OUTPUT_STEREO: /* We assume that sum of both mono channels is requested */
1483 mix_dualmono_to_stereo(ctx); 1465 mix_dualmono_to_stereo(ctx);
1484 break; 1466 break;
1485 } 1467 }
1486 break; 1468 break;
1487 case AC3_INPUT_MONO: 1469 case AC3_ACMOD_MONO:
1488 switch (to) { 1470 switch (to) {
1489 case AC3_OUTPUT_STEREO: 1471 case AC3_OUTPUT_STEREO:
1490 upmix_mono_to_stereo(ctx); 1472 upmix_mono_to_stereo(ctx);
1491 break; 1473 break;
1492 } 1474 }
1493 break; 1475 break;
1494 case AC3_INPUT_STEREO: 1476 case AC3_ACMOD_STEREO:
1495 switch (to) { 1477 switch (to) {
1496 case AC3_OUTPUT_MONO: 1478 case AC3_OUTPUT_MONO:
1497 mix_stereo_to_mono(ctx); 1479 mix_stereo_to_mono(ctx);
1498 break; 1480 break;
1499 } 1481 }
1500 break; 1482 break;
1501 case AC3_INPUT_3F: 1483 case AC3_ACMOD_3F:
1502 switch (to) { 1484 switch (to) {
1503 case AC3_OUTPUT_MONO: 1485 case AC3_OUTPUT_MONO:
1504 mix_3f_to_mono(ctx); 1486 mix_3f_to_mono(ctx);
1505 break; 1487 break;
1506 case AC3_OUTPUT_STEREO: 1488 case AC3_OUTPUT_STEREO:
1507 mix_3f_to_stereo(ctx); 1489 mix_3f_to_stereo(ctx);
1508 break; 1490 break;
1509 } 1491 }
1510 break; 1492 break;
1511 case AC3_INPUT_2F_1R: 1493 case AC3_ACMOD_2F1R:
1512 switch (to) { 1494 switch (to) {
1513 case AC3_OUTPUT_MONO: 1495 case AC3_OUTPUT_MONO:
1514 mix_2f_1r_to_mono(ctx); 1496 mix_2f_1r_to_mono(ctx);
1515 break; 1497 break;
1516 case AC3_OUTPUT_STEREO: 1498 case AC3_OUTPUT_STEREO:
1519 case AC3_OUTPUT_DOLBY: 1501 case AC3_OUTPUT_DOLBY:
1520 mix_2f_1r_to_dolby(ctx); 1502 mix_2f_1r_to_dolby(ctx);
1521 break; 1503 break;
1522 } 1504 }
1523 break; 1505 break;
1524 case AC3_INPUT_3F_1R: 1506 case AC3_ACMOD_3F1R:
1525 switch (to) { 1507 switch (to) {
1526 case AC3_OUTPUT_MONO: 1508 case AC3_OUTPUT_MONO:
1527 mix_3f_1r_to_mono(ctx); 1509 mix_3f_1r_to_mono(ctx);
1528 break; 1510 break;
1529 case AC3_OUTPUT_STEREO: 1511 case AC3_OUTPUT_STEREO:
1532 case AC3_OUTPUT_DOLBY: 1514 case AC3_OUTPUT_DOLBY:
1533 mix_3f_1r_to_dolby(ctx); 1515 mix_3f_1r_to_dolby(ctx);
1534 break; 1516 break;
1535 } 1517 }
1536 break; 1518 break;
1537 case AC3_INPUT_2F_2R: 1519 case AC3_ACMOD_2F2R:
1538 switch (to) { 1520 switch (to) {
1539 case AC3_OUTPUT_MONO: 1521 case AC3_OUTPUT_MONO:
1540 mix_2f_2r_to_mono(ctx); 1522 mix_2f_2r_to_mono(ctx);
1541 break; 1523 break;
1542 case AC3_OUTPUT_STEREO: 1524 case AC3_OUTPUT_STEREO:
1545 case AC3_OUTPUT_DOLBY: 1527 case AC3_OUTPUT_DOLBY:
1546 mix_2f_2r_to_dolby(ctx); 1528 mix_2f_2r_to_dolby(ctx);
1547 break; 1529 break;
1548 } 1530 }
1549 break; 1531 break;
1550 case AC3_INPUT_3F_2R: 1532 case AC3_ACMOD_3F2R:
1551 switch (to) { 1533 switch (to) {
1552 case AC3_OUTPUT_MONO: 1534 case AC3_OUTPUT_MONO:
1553 mix_3f_2r_to_mono(ctx); 1535 mix_3f_2r_to_mono(ctx);
1554 break; 1536 break;
1555 case AC3_OUTPUT_STEREO: 1537 case AC3_OUTPUT_STEREO:
1753 for (rbnd = 0; rbnd < 2; rbnd++) 1735 for (rbnd = 0; rbnd < 2; rbnd++)
1754 ctx->rematflg |= get_bits1(gb) << rbnd; 1736 ctx->rematflg |= get_bits1(gb) << rbnd;
1755 } 1737 }
1756 } 1738 }
1757 1739
1758 ctx->cplexpstr = AC3_EXPSTR_REUSE; 1740 ctx->cplexpstr = EXP_REUSE;
1759 ctx->lfeexpstr = AC3_EXPSTR_REUSE; 1741 ctx->lfeexpstr = EXP_REUSE;
1760 if (ctx->cplinu) /* coupling exponent strategy */ 1742 if (ctx->cplinu) /* coupling exponent strategy */
1761 ctx->cplexpstr = get_bits(gb, 2); 1743 ctx->cplexpstr = get_bits(gb, 2);
1762 for (i = 0; i < nfchans; i++) /* channel exponent strategy */ 1744 for (i = 0; i < nfchans; i++) /* channel exponent strategy */
1763 ctx->chexpstr[i] = get_bits(gb, 2); 1745 ctx->chexpstr[i] = get_bits(gb, 2);
1764 if (ctx->lfeon) /* lfe exponent strategy */ 1746 if (ctx->lfeon) /* lfe exponent strategy */
1765 ctx->lfeexpstr = get_bits1(gb); 1747 ctx->lfeexpstr = get_bits1(gb);
1766 1748
1767 for (i = 0; i < nfchans; i++) /* channel bandwidth code */ 1749 for (i = 0; i < nfchans; i++) /* channel bandwidth code */
1768 if (ctx->chexpstr[i] != AC3_EXPSTR_REUSE) { 1750 if (ctx->chexpstr[i] != EXP_REUSE) {
1769 if ((ctx->chincpl >> i) & 1) 1751 if ((ctx->chincpl >> i) & 1)
1770 ctx->endmant[i] = ctx->cplstrtmant; 1752 ctx->endmant[i] = ctx->cplstrtmant;
1771 else { 1753 else {
1772 chbwcod = get_bits(gb, 6); 1754 chbwcod = get_bits(gb, 6);
1773 if (chbwcod > 60) { 1755 if (chbwcod > 60) {
1776 } 1758 }
1777 ctx->endmant[i] = chbwcod * 3 + 73; 1759 ctx->endmant[i] = chbwcod * 3 + 73;
1778 } 1760 }
1779 } 1761 }
1780 1762
1781 if (ctx->cplexpstr != AC3_EXPSTR_REUSE) {/* coupling exponents */ 1763 if (ctx->cplexpstr != EXP_REUSE) {/* coupling exponents */
1782 bit_alloc_flags = 64; 1764 bit_alloc_flags = 64;
1783 cplabsexp = get_bits(gb, 4) << 1; 1765 cplabsexp = get_bits(gb, 4) << 1;
1784 ngrps = (ctx->cplendmant - ctx->cplstrtmant) / (3 << (ctx->cplexpstr - 1)); 1766 ngrps = (ctx->cplendmant - ctx->cplstrtmant) / (3 << (ctx->cplexpstr - 1));
1785 if (decode_exponents(gb, ctx->cplexpstr, ngrps, cplabsexp, ctx->dcplexps + ctx->cplstrtmant)) { 1767 if (decode_exponents(gb, ctx->cplexpstr, ngrps, cplabsexp, ctx->dcplexps + ctx->cplstrtmant)) {
1786 av_log(NULL, AV_LOG_ERROR, "error decoding coupling exponents\n"); 1768 av_log(NULL, AV_LOG_ERROR, "error decoding coupling exponents\n");
1787 return -1; 1769 return -1;
1788 } 1770 }
1789 } 1771 }
1790 1772
1791 for (i = 0; i < nfchans; i++) /* fbw channel exponents */ 1773 for (i = 0; i < nfchans; i++) /* fbw channel exponents */
1792 if (ctx->chexpstr[i] != AC3_EXPSTR_REUSE) { 1774 if (ctx->chexpstr[i] != EXP_REUSE) {
1793 bit_alloc_flags |= 1 << i; 1775 bit_alloc_flags |= 1 << i;
1794 grpsize = 3 << (ctx->chexpstr[i] - 1); 1776 grpsize = 3 << (ctx->chexpstr[i] - 1);
1795 ngrps = (ctx->endmant[i] + grpsize - 4) / grpsize; 1777 ngrps = (ctx->endmant[i] + grpsize - 4) / grpsize;
1796 dexps = ctx->dexps[i]; 1778 dexps = ctx->dexps[i];
1797 dexps[0] = get_bits(gb, 4); 1779 dexps[0] = get_bits(gb, 4);
1800 return -1; 1782 return -1;
1801 } 1783 }
1802 skip_bits(gb, 2); /* skip gainrng */ 1784 skip_bits(gb, 2); /* skip gainrng */
1803 } 1785 }
1804 1786
1805 if (ctx->lfeexpstr != AC3_EXPSTR_REUSE) { /* lfe exponents */ 1787 if (ctx->lfeexpstr != EXP_REUSE) { /* lfe exponents */
1806 bit_alloc_flags |= 32; 1788 bit_alloc_flags |= 32;
1807 ctx->dlfeexps[0] = get_bits(gb, 4); 1789 ctx->dlfeexps[0] = get_bits(gb, 4);
1808 if (decode_exponents(gb, ctx->lfeexpstr, 2, ctx->dlfeexps[0], ctx->dlfeexps + 1)) { 1790 if (decode_exponents(gb, ctx->lfeexpstr, 2, ctx->dlfeexps[0], ctx->dlfeexps + 1)) {
1809 av_log(NULL, AV_LOG_ERROR, "error decoding lfe exponents\n"); 1791 av_log(NULL, AV_LOG_ERROR, "error decoding lfe exponents\n");
1810 return -1; 1792 return -1;
1846 if (get_bits1(gb)) { /* delta bit allocation information */ 1828 if (get_bits1(gb)) { /* delta bit allocation information */
1847 bit_alloc_flags = 127; 1829 bit_alloc_flags = 127;
1848 1830
1849 if (ctx->cplinu) { 1831 if (ctx->cplinu) {
1850 ctx->cpldeltbae = get_bits(gb, 2); 1832 ctx->cpldeltbae = get_bits(gb, 2);
1851 if (ctx->cpldeltbae == AC3_DBASTR_RESERVED) { 1833 if (ctx->cpldeltbae == DBA_RESERVED) {
1852 av_log(NULL, AV_LOG_ERROR, "coupling delta bit allocation strategy reserved\n"); 1834 av_log(NULL, AV_LOG_ERROR, "coupling delta bit allocation strategy reserved\n");
1853 return -1; 1835 return -1;
1854 } 1836 }
1855 } 1837 }
1856 1838
1857 for (i = 0; i < nfchans; i++) { 1839 for (i = 0; i < nfchans; i++) {
1858 ctx->deltbae[i] = get_bits(gb, 2); 1840 ctx->deltbae[i] = get_bits(gb, 2);
1859 if (ctx->deltbae[i] == AC3_DBASTR_RESERVED) { 1841 if (ctx->deltbae[i] == DBA_RESERVED) {
1860 av_log(NULL, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); 1842 av_log(NULL, AV_LOG_ERROR, "delta bit allocation strategy reserved\n");
1861 return -1; 1843 return -1;
1862 } 1844 }
1863 } 1845 }
1864 1846
1865 if (ctx->cplinu) 1847 if (ctx->cplinu)
1866 if (ctx->cpldeltbae == AC3_DBASTR_NEW) { /*coupling delta offset, len and bit allocation */ 1848 if (ctx->cpldeltbae == DBA_NEW) { /*coupling delta offset, len and bit allocation */
1867 ctx->cpldeltnseg = get_bits(gb, 3); 1849 ctx->cpldeltnseg = get_bits(gb, 3);
1868 for (seg = 0; seg <= ctx->cpldeltnseg; seg++) { 1850 for (seg = 0; seg <= ctx->cpldeltnseg; seg++) {
1869 ctx->cpldeltoffst[seg] = get_bits(gb, 5); 1851 ctx->cpldeltoffst[seg] = get_bits(gb, 5);
1870 ctx->cpldeltlen[seg] = get_bits(gb, 4); 1852 ctx->cpldeltlen[seg] = get_bits(gb, 4);
1871 ctx->cpldeltba[seg] = get_bits(gb, 3); 1853 ctx->cpldeltba[seg] = get_bits(gb, 3);
1872 } 1854 }
1873 } 1855 }
1874 1856
1875 for (i = 0; i < nfchans; i++) 1857 for (i = 0; i < nfchans; i++)
1876 if (ctx->deltbae[i] == AC3_DBASTR_NEW) {/*channel delta offset, len and bit allocation */ 1858 if (ctx->deltbae[i] == DBA_NEW) {/*channel delta offset, len and bit allocation */
1877 ctx->deltnseg[i] = get_bits(gb, 3); 1859 ctx->deltnseg[i] = get_bits(gb, 3);
1878 for (seg = 0; seg <= ctx->deltnseg[i]; seg++) { 1860 for (seg = 0; seg <= ctx->deltnseg[i]; seg++) {
1879 ctx->deltoffst[i][seg] = get_bits(gb, 5); 1861 ctx->deltoffst[i][seg] = get_bits(gb, 5);
1880 ctx->deltlen[i][seg] = get_bits(gb, 4); 1862 ctx->deltlen[i][seg] = get_bits(gb, 4);
1881 ctx->deltba[i][seg] = get_bits(gb, 3); 1863 ctx->deltba[i][seg] = get_bits(gb, 3);
2011 } 1993 }
2012 1994
2013 //av_log(avctx, AV_LOG_INFO, "channels = %d \t bit rate = %d \t sampling rate = %d \n", avctx->channels, avctx->bit_rate * 1000, avctx->sample_rate); 1995 //av_log(avctx, AV_LOG_INFO, "channels = %d \t bit rate = %d \t sampling rate = %d \n", avctx->channels, avctx->bit_rate * 1000, avctx->sample_rate);
2014 1996
2015 //Parse the Audio Blocks. 1997 //Parse the Audio Blocks.
2016 for (i = 0; i < AUDIO_BLOCKS; i++) { 1998 for (i = 0; i < NB_BLOCKS; i++) {
2017 if (ac3_parse_audio_block(ctx)) { 1999 if (ac3_parse_audio_block(ctx)) {
2018 av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n"); 2000 av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n");
2019 *data_size = 0; 2001 *data_size = 0;
2020 return ctx->frame_size; 2002 return ctx->frame_size;
2021 } 2003 }
2022 start = (ctx->blkoutput & AC3_OUTPUT_LFEON) ? 0 : 1; 2004 start = (ctx->blkoutput & AC3_OUTPUT_LFEON) ? 0 : 1;
2023 for (k = 0; k < BLOCK_SIZE; k++) 2005 for (k = 0; k < BLOCK_SIZE; k++)
2024 for (j = start; j <= avctx->channels; j++) 2006 for (j = start; j <= avctx->channels; j++)
2025 *(out_samples++) = convert(int_ptr[j][k]); 2007 *(out_samples++) = convert(int_ptr[j][k]);
2026 } 2008 }
2027 *data_size = AUDIO_BLOCKS * BLOCK_SIZE * avctx->channels * sizeof (int16_t); 2009 *data_size = NB_BLOCKS * BLOCK_SIZE * avctx->channels * sizeof (int16_t);
2028 return ctx->frame_size; 2010 return ctx->frame_size;
2029 } 2011 }
2030 2012
2031 /* Uninitialize ac3 decoder. 2013 /* Uninitialize ac3 decoder.
2032 */ 2014 */