Mercurial > libavcodec.hg
comparison ac3dec.c @ 5415:8bf7358978c8 libavcodec
simplify stereo rematrixing
author | jbr |
---|---|
date | Sun, 29 Jul 2007 00:58:32 +0000 |
parents | 9746c9a0384f |
children | fff2e4b07e28 |
comparison
equal
deleted
inserted
replaced
5414:9746c9a0384f | 5415:8bf7358978c8 |
---|---|
36 #include "ac3_parser.h" | 36 #include "ac3_parser.h" |
37 #include "bitstream.h" | 37 #include "bitstream.h" |
38 #include "dsputil.h" | 38 #include "dsputil.h" |
39 #include "random.h" | 39 #include "random.h" |
40 | 40 |
41 /** | |
42 * Table of bin locations for rematrixing bands | |
43 * reference: Section 7.5.2 Rematrixing : Frequency Band Definitions | |
44 */ | |
45 static const uint8_t rematrix_band_tbl[5] = { 13, 25, 37, 61, 253 }; | |
46 | |
41 /* table for exponent to scale_factor mapping | 47 /* table for exponent to scale_factor mapping |
42 * scale_factor[i] = 2 ^ -(i + 15) | 48 * scale_factor[i] = 2 ^ -(i + 15) |
43 */ | 49 */ |
44 static float scale_factors[25]; | 50 static float scale_factors[25]; |
45 | 51 |
90 int chincpl[AC3_MAX_CHANNELS]; | 96 int chincpl[AC3_MAX_CHANNELS]; |
91 int phsflginu; | 97 int phsflginu; |
92 int cplcoe; | 98 int cplcoe; |
93 uint32_t cplbndstrc; | 99 uint32_t cplbndstrc; |
94 int rematstr; | 100 int rematstr; |
101 int nrematbnd; | |
95 int rematflg[AC3_MAX_CHANNELS]; | 102 int rematflg[AC3_MAX_CHANNELS]; |
96 int cplexpstr; | 103 int cplexpstr; |
97 int lfeexpstr; | 104 int lfeexpstr; |
98 int chexpstr[5]; | 105 int chexpstr[5]; |
99 int cplsnroffst; | 106 int cplsnroffst; |
646 } | 653 } |
647 | 654 |
648 return 0; | 655 return 0; |
649 } | 656 } |
650 | 657 |
651 /* Rematrixing routines. */ | 658 /** |
652 static void do_rematrixing1(AC3DecodeContext *ctx, int start, int end) | 659 * Performs stereo rematrixing. |
653 { | 660 * reference: Section 7.5.4 Rematrixing : Decoding Technique |
661 */ | |
662 static void do_rematrixing(AC3DecodeContext *ctx) | |
663 { | |
664 int bnd, i; | |
665 int end, bndend; | |
654 float tmp0, tmp1; | 666 float tmp0, tmp1; |
655 | 667 |
656 while (start < end) { | |
657 tmp0 = ctx->transform_coeffs[1][start]; | |
658 tmp1 = ctx->transform_coeffs[2][start]; | |
659 ctx->transform_coeffs[1][start] = tmp0 + tmp1; | |
660 ctx->transform_coeffs[2][start] = tmp0 - tmp1; | |
661 start++; | |
662 } | |
663 } | |
664 | |
665 static void do_rematrixing(AC3DecodeContext *ctx) | |
666 { | |
667 int bnd1 = 13, bnd2 = 25, bnd3 = 37, bnd4 = 61; | |
668 int end, bndend; | |
669 | |
670 end = FFMIN(ctx->endmant[0], ctx->endmant[1]); | 668 end = FFMIN(ctx->endmant[0], ctx->endmant[1]); |
671 | 669 |
672 if (ctx->rematflg[0]) | 670 for(bnd=0; bnd<ctx->nrematbnd; bnd++) { |
673 do_rematrixing1(ctx, bnd1, bnd2); | 671 if(ctx->rematflg[bnd]) { |
674 | 672 bndend = FFMIN(end, rematrix_band_tbl[bnd+1]); |
675 if (ctx->rematflg[1]) | 673 for(i=rematrix_band_tbl[bnd]; i<bndend; i++) { |
676 do_rematrixing1(ctx, bnd2, bnd3); | 674 tmp0 = ctx->transform_coeffs[1][i]; |
677 | 675 tmp1 = ctx->transform_coeffs[2][i]; |
678 bndend = bnd4; | 676 ctx->transform_coeffs[1][i] = tmp0 + tmp1; |
679 if (bndend > end) { | 677 ctx->transform_coeffs[2][i] = tmp0 - tmp1; |
680 bndend = end; | 678 } |
681 if (ctx->rematflg[2]) | 679 } |
682 do_rematrixing1(ctx, bnd3, bndend); | |
683 } else { | |
684 if (ctx->rematflg[2]) | |
685 do_rematrixing1(ctx, bnd3, bnd4); | |
686 if (ctx->rematflg[3]) | |
687 do_rematrixing1(ctx, bnd4, end); | |
688 } | 680 } |
689 } | 681 } |
690 | 682 |
691 /* This function performs the imdct on 256 sample transform | 683 /* This function performs the imdct on 256 sample transform |
692 * coefficients. | 684 * coefficients. |
764 */ | 756 */ |
765 static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) | 757 static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
766 { | 758 { |
767 int nfchans = ctx->nfchans; | 759 int nfchans = ctx->nfchans; |
768 int acmod = ctx->acmod; | 760 int acmod = ctx->acmod; |
769 int i, bnd, rbnd, seg, grpsize, ch; | 761 int i, bnd, seg, grpsize, ch; |
770 GetBitContext *gb = &ctx->gb; | 762 GetBitContext *gb = &ctx->gb; |
771 int bit_alloc_flags = 0; | 763 int bit_alloc_flags = 0; |
772 int8_t *dexps; | 764 int8_t *dexps; |
773 int mstrcplco, cplcoexp, cplcomant; | 765 int mstrcplco, cplcoexp, cplcomant; |
774 int dynrng, chbwcod, ngrps, cplabsexp, skipl; | 766 int dynrng, chbwcod, ngrps, cplabsexp, skipl; |
855 } | 847 } |
856 | 848 |
857 if (acmod == AC3_ACMOD_STEREO) {/* rematrixing */ | 849 if (acmod == AC3_ACMOD_STEREO) {/* rematrixing */ |
858 ctx->rematstr = get_bits1(gb); | 850 ctx->rematstr = get_bits1(gb); |
859 if (ctx->rematstr) { | 851 if (ctx->rematstr) { |
860 if (!(ctx->cplinu) || ctx->cplstrtmant > 61) | 852 ctx->nrematbnd = 4; |
861 for (rbnd = 0; rbnd < 4; rbnd++) | 853 if(ctx->cplinu && ctx->cplstrtmant <= 61) |
862 ctx->rematflg[rbnd] = get_bits1(gb); | 854 ctx->nrematbnd -= 1 + (ctx->cplstrtmant == 37); |
863 if (ctx->cplstrtmant > 37 && ctx->cplstrtmant <= 61 && ctx->cplinu) | 855 for(bnd=0; bnd<ctx->nrematbnd; bnd++) |
864 for (rbnd = 0; rbnd < 3; rbnd++) | 856 ctx->rematflg[bnd] = get_bits1(gb); |
865 ctx->rematflg[rbnd] = get_bits1(gb); | |
866 if (ctx->cplstrtmant == 37 && ctx->cplinu) | |
867 for (rbnd = 0; rbnd < 2; rbnd++) | |
868 ctx->rematflg[rbnd] = get_bits1(gb); | |
869 } | 857 } |
870 } | 858 } |
871 | 859 |
872 ctx->cplexpstr = EXP_REUSE; | 860 ctx->cplexpstr = EXP_REUSE; |
873 ctx->lfeexpstr = EXP_REUSE; | 861 ctx->lfeexpstr = EXP_REUSE; |