Revision 75b9b036

View differences:

libavcodec/ac3dec.c
551 551
 */
552 552
static int get_transform_coeffs(AC3DecodeContext * ctx)
553 553
{
554
    int i, end;
554
    int ch, i, end;
555 555
    int got_cplchan = 0;
556 556
    mant_groups m;
557 557

  
558 558
    m.b1ptr = m.b2ptr = m.b4ptr = 3;
559 559

  
560
    for (i = 0; i < ctx->nfchans; i++) {
560
    for (ch = 0; ch < ctx->nfchans; ch++) {
561 561
        /* transform coefficients for individual channel */
562
        if (get_transform_coeffs_ch(ctx, i, &m))
562
        if (get_transform_coeffs_ch(ctx, ch, &m))
563 563
            return -1;
564 564
        /* tranform coefficients for coupling channels */
565
        if (ctx->chincpl[i])  {
565
        if (ctx->chincpl[ch])  {
566 566
            if (!got_cplchan) {
567 567
                if (get_transform_coeffs_ch(ctx, -2, &m)) {
568 568
                    av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n");
......
573 573
            }
574 574
            end = ctx->cplendmant;
575 575
        } else {
576
            end = ctx->endmant[i];
576
            end = ctx->endmant[ch];
577 577
        }
578 578
        do
579
            ctx->transform_coeffs[i + 1][end] = 0;
579
            ctx->transform_coeffs[ch + 1][end] = 0;
580 580
        while(++end < 256);
581 581
    }
582 582
    if (ctx->lfeon) {
......
701 701
    GetBitContext *gb = &ctx->gb;
702 702
    int bit_alloc_flags = 0;
703 703

  
704
    for (i = 0; i < nfchans; i++) /*block switch flag */
705
        ctx->blksw[i] = get_bits1(gb);
704
    for (ch = 0; ch < nfchans; ch++) /*block switch flag */
705
        ctx->blksw[ch] = get_bits1(gb);
706 706

  
707 707
    ctx->dither_all = 1;
708
    for (i = 0; i < nfchans; i++) { /* dithering flag */
709
        ctx->dithflag[i] = get_bits1(gb);
710
        if(!ctx->dithflag[i])
708
    for (ch = 0; ch < nfchans; ch++) { /* dithering flag */
709
        ctx->dithflag[ch] = get_bits1(gb);
710
        if(!ctx->dithflag[ch])
711 711
            ctx->dither_all = 0;
712 712
    }
713 713

  
......
730 730
        if (ctx->cplinu) { /* coupling in use */
731 731
            int cplbegf, cplendf;
732 732

  
733
            for (i = 0; i < nfchans; i++)
734
                ctx->chincpl[i] = get_bits1(gb);
733
            for (ch = 0; ch < nfchans; ch++)
734
                ctx->chincpl[ch] = get_bits1(gb);
735 735

  
736 736
            if (acmod == AC3_ACMOD_STEREO)
737 737
                ctx->phsflginu = get_bits1(gb); //phase flag in use
......
747 747
            ctx->ncplbnd = ctx->ncplsubnd = 3 + cplendf - cplbegf;
748 748
            ctx->cplstrtmant = cplbegf * 12 + 37;
749 749
            ctx->cplendmant = cplendf * 12 + 73;
750
            for (i = 0; i < ctx->ncplsubnd - 1; i++) { /* coupling band structure */
750
            for (bnd = 0; bnd < ctx->ncplsubnd - 1; bnd++) { /* coupling band structure */
751 751
                if (get_bits1(gb)) {
752
                    ctx->cplbndstrc[i] = 1;
752
                    ctx->cplbndstrc[bnd] = 1;
753 753
                    ctx->ncplbnd--;
754 754
                }
755 755
            }
756 756
        } else {
757
            for (i = 0; i < nfchans; i++)
758
                ctx->chincpl[i] = 0;
757
            for (ch = 0; ch < nfchans; ch++)
758
                ctx->chincpl[ch] = 0;
759 759
        }
760 760
    }
761 761

  
762 762
    if (ctx->cplinu) {
763 763
        int cplcoe = 0;
764 764

  
765
        for (i = 0; i < nfchans; i++) {
766
            if (ctx->chincpl[i]) {
765
        for (ch = 0; ch < nfchans; ch++) {
766
            if (ctx->chincpl[ch]) {
767 767
                if (get_bits1(gb)) { /* coupling co-ordinates */
768 768
                    int mstrcplco, cplcoexp, cplcomant;
769 769
                    cplcoe = 1;
......
772 772
                        cplcoexp = get_bits(gb, 4);
773 773
                        cplcomant = get_bits(gb, 4);
774 774
                        if (cplcoexp == 15)
775
                            ctx->cplco[i][bnd] = cplcomant / 16.0f;
775
                            ctx->cplco[ch][bnd] = cplcomant / 16.0f;
776 776
                        else
777
                            ctx->cplco[i][bnd] = (cplcomant + 16.0f) / 32.0f;
778
                        ctx->cplco[i][bnd] *= scale_factors[cplcoexp + mstrcplco];
777
                            ctx->cplco[ch][bnd] = (cplcomant + 16.0f) / 32.0f;
778
                        ctx->cplco[ch][bnd] *= scale_factors[cplcoexp + mstrcplco];
779 779
                    }
780 780
                }
781 781
            }
......
804 804
    ctx->lfeexpstr = EXP_REUSE;
805 805
    if (ctx->cplinu) /* coupling exponent strategy */
806 806
        ctx->cplexpstr = get_bits(gb, 2);
807
    for (i = 0; i < nfchans; i++)  /* channel exponent strategy */
808
        ctx->chexpstr[i] = get_bits(gb, 2);
807
    for (ch = 0; ch < nfchans; ch++)  /* channel exponent strategy */
808
        ctx->chexpstr[ch] = get_bits(gb, 2);
809 809
    if (ctx->lfeon)  /* lfe exponent strategy */
810 810
        ctx->lfeexpstr = get_bits1(gb);
811 811

  
812
    for (i = 0; i < nfchans; i++) { /* channel bandwidth code */
813
        if (ctx->chexpstr[i] != EXP_REUSE) {
814
            if (ctx->chincpl[i])
815
                ctx->endmant[i] = ctx->cplstrtmant;
812
    for (ch = 0; ch < nfchans; ch++) { /* channel bandwidth code */
813
        if (ctx->chexpstr[ch] != EXP_REUSE) {
814
            if (ctx->chincpl[ch])
815
                ctx->endmant[ch] = ctx->cplstrtmant;
816 816
            else {
817 817
                int chbwcod = get_bits(gb, 6);
818 818
                if (chbwcod > 60) {
819 819
                    av_log(NULL, AV_LOG_ERROR, "chbwcod = %d > 60", chbwcod);
820 820
                    return -1;
821 821
                }
822
                ctx->endmant[i] = chbwcod * 3 + 73;
822
                ctx->endmant[ch] = chbwcod * 3 + 73;
823 823
            }
824 824
        }
825 825
    }
......
833 833
        decode_exponents(gb, ctx->cplexpstr, ngrps, absexp, &ctx->dcplexps[ctx->cplstrtmant]);
834 834
    }
835 835

  
836
    for (i = 0; i < nfchans; i++) { /* fbw channel exponents */
837
        if (ctx->chexpstr[i] != EXP_REUSE) {
836
    for (ch = 0; ch < nfchans; ch++) { /* fbw channel exponents */
837
        if (ctx->chexpstr[ch] != EXP_REUSE) {
838 838
            int grpsize, ngrps, absexp;
839
            bit_alloc_flags |= 1 << i;
840
            grpsize = 3 << (ctx->chexpstr[i] - 1);
841
            ngrps = (ctx->endmant[i] + grpsize - 4) / grpsize;
842
            absexp = ctx->dexps[i][0] = get_bits(gb, 4);
843
            decode_exponents(gb, ctx->chexpstr[i], ngrps, absexp, &ctx->dexps[i][1]);
839
            bit_alloc_flags |= 1 << ch;
840
            grpsize = 3 << (ctx->chexpstr[ch] - 1);
841
            ngrps = (ctx->endmant[ch] + grpsize - 4) / grpsize;
842
            absexp = ctx->dexps[ch][0] = get_bits(gb, 4);
843
            decode_exponents(gb, ctx->chexpstr[ch], ngrps, absexp, &ctx->dexps[ch][1]);
844 844
            skip_bits(gb, 2); /* skip gainrng */
845 845
        }
846 846
    }
......
870 870
            ctx->cplsnroffst = (csnr + get_bits(gb, 4)) << 2;
871 871
            ctx->cplfgain = ff_fgaintab[get_bits(gb, 3)];
872 872
        }
873
        for (i = 0; i < nfchans; i++) { /* channel fine snr offset and fast gain code */
874
            ctx->snroffst[i] = (csnr + get_bits(gb, 4)) << 2;
875
            ctx->fgain[i] = ff_fgaintab[get_bits(gb, 3)];
873
        for (ch = 0; ch < nfchans; ch++) { /* channel fine snr offset and fast gain code */
874
            ctx->snroffst[ch] = (csnr + get_bits(gb, 4)) << 2;
875
            ctx->fgain[ch] = ff_fgaintab[get_bits(gb, 3)];
876 876
        }
877 877
        if (ctx->lfeon) { /* lfe fine snr offset and fast gain code */
878 878
            ctx->lfesnroffst = (csnr + get_bits(gb, 4)) << 2;
......
897 897
            }
898 898
        }
899 899

  
900
        for (i = 0; i < nfchans; i++) {
901
            ctx->deltbae[i] = get_bits(gb, 2);
902
            if (ctx->deltbae[i] == DBA_RESERVED) {
900
        for (ch = 0; ch < nfchans; ch++) {
901
            ctx->deltbae[ch] = get_bits(gb, 2);
902
            if (ctx->deltbae[ch] == DBA_RESERVED) {
903 903
                av_log(NULL, AV_LOG_ERROR, "delta bit allocation strategy reserved\n");
904 904
                return -1;
905 905
            }
......
916 916
            }
917 917
        }
918 918

  
919
        for (i = 0; i < nfchans; i++) {
920
            if (ctx->deltbae[i] == DBA_NEW) {/*channel delta offset, len and bit allocation */
921
                ctx->deltnseg[i] = get_bits(gb, 3);
922
                for (seg = 0; seg <= ctx->deltnseg[i]; seg++) {
923
                    ctx->deltoffst[i][seg] = get_bits(gb, 5);
924
                    ctx->deltlen[i][seg] = get_bits(gb, 4);
925
                    ctx->deltba[i][seg] = get_bits(gb, 3);
919
        for (ch = 0; ch < nfchans; ch++) {
920
            if (ctx->deltbae[ch] == DBA_NEW) {/*channel delta offset, len and bit allocation */
921
                ctx->deltnseg[ch] = get_bits(gb, 3);
922
                for (seg = 0; seg <= ctx->deltnseg[ch]; seg++) {
923
                    ctx->deltoffst[ch][seg] = get_bits(gb, 5);
924
                    ctx->deltlen[ch][seg] = get_bits(gb, 4);
925
                    ctx->deltba[ch][seg] = get_bits(gb, 3);
926 926
                }
927 927
            }
928 928
        }
929 929
    } else if(blk == 0) {
930 930
        if(ctx->cplinu)
931 931
            ctx->cpldeltbae = DBA_NONE;
932
        for(i=0; i<nfchans; i++) {
933
            ctx->deltbae[i] = DBA_NONE;
932
        for(ch=0; ch<nfchans; ch++) {
933
            ctx->deltbae[ch] = DBA_NONE;
934 934
        }
935 935
    }
936 936

  
......
944 944
                                          ctx->cpldeltoffst, ctx->cpldeltlen,
945 945
                                          ctx->cpldeltba);
946 946
        }
947
        for (i = 0; i < nfchans; i++) {
948
            if ((bit_alloc_flags >> i) & 1) {
947
        for (ch = 0; ch < nfchans; ch++) {
948
            if ((bit_alloc_flags >> ch) & 1) {
949 949
                ac3_parametric_bit_allocation(&ctx->bit_alloc_params,
950
                                              ctx->bap[i], ctx->dexps[i], 0,
951
                                              ctx->endmant[i], ctx->snroffst[i],
952
                                              ctx->fgain[i], 0, ctx->deltbae[i],
953
                                              ctx->deltnseg[i], ctx->deltoffst[i],
954
                                              ctx->deltlen[i], ctx->deltba[i]);
950
                                              ctx->bap[ch], ctx->dexps[ch], 0,
951
                                              ctx->endmant[ch], ctx->snroffst[ch],
952
                                              ctx->fgain[ch], 0, ctx->deltbae[ch],
953
                                              ctx->deltnseg[ch], ctx->deltoffst[ch],
954
                                              ctx->deltlen[ch], ctx->deltba[ch]);
955 955
            }
956 956
        }
957 957
        if (ctx->lfeon && (bit_alloc_flags & 32)) {
......
1024 1024
{
1025 1025
    AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
1026 1026
    int16_t *out_samples = (int16_t *)data;
1027
    int i, j, k, start;
1027
    int i, blk, ch, start;
1028 1028
    int32_t *int_ptr[6];
1029 1029

  
1030
    for (i = 0; i < 6; i++)
1031
        int_ptr[i] = (int32_t *)(&ctx->output[i]);
1030
    for (ch = 0; ch < 6; ch++)
1031
        int_ptr[ch] = (int32_t *)(&ctx->output[ch]);
1032 1032

  
1033 1033
    //Initialize the GetBitContext with the start of valid AC3 Frame.
1034 1034
    init_get_bits(&ctx->gb, buf, buf_size * 8);
......
1056 1056
    //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);
1057 1057

  
1058 1058
    //Parse the Audio Blocks.
1059
    for (i = 0; i < NB_BLOCKS; i++) {
1060
        if (ac3_parse_audio_block(ctx, i)) {
1059
    for (blk = 0; blk < NB_BLOCKS; blk++) {
1060
        if (ac3_parse_audio_block(ctx, blk)) {
1061 1061
            av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n");
1062 1062
            *data_size = 0;
1063 1063
            return ctx->frame_size;
1064 1064
        }
1065 1065
        start = (ctx->output_mode & AC3_OUTPUT_LFEON) ? 0 : 1;
1066
        for (k = 0; k < 256; k++)
1067
            for (j = start; j <= ctx->nfchans; j++)
1068
                *(out_samples++) = convert(int_ptr[j][k]);
1066
        for (i = 0; i < 256; i++)
1067
            for (ch = start; ch <= ctx->nfchans; ch++)
1068
                *(out_samples++) = convert(int_ptr[ch][i]);
1069 1069
    }
1070 1070
    *data_size = NB_BLOCKS * 256 * avctx->channels * sizeof (int16_t);
1071 1071
    return ctx->frame_size;

Also available in: Unified diff