Mercurial > libavcodec.hg
comparison ac3dec.c @ 5474:3e07472540c6 libavcodec
cosmetics: use more appropriate names for iterator variables.
author | jbr |
---|---|
date | Sat, 04 Aug 2007 13:52:56 +0000 |
parents | 11585a021898 |
children | aedc8e0ade8c |
comparison
equal
deleted
inserted
replaced
5473:a0d7ec11b87e | 5474:3e07472540c6 |
---|---|
549 * This function extracts the tranform coefficients form the ac3 bitstream. | 549 * This function extracts the tranform coefficients form the ac3 bitstream. |
550 * This function is called after bit allocation is performed. | 550 * This function is called after bit allocation is performed. |
551 */ | 551 */ |
552 static int get_transform_coeffs(AC3DecodeContext * ctx) | 552 static int get_transform_coeffs(AC3DecodeContext * ctx) |
553 { | 553 { |
554 int i, end; | 554 int ch, i, end; |
555 int got_cplchan = 0; | 555 int got_cplchan = 0; |
556 mant_groups m; | 556 mant_groups m; |
557 | 557 |
558 m.b1ptr = m.b2ptr = m.b4ptr = 3; | 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 /* transform coefficients for individual channel */ | 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 return -1; | 563 return -1; |
564 /* tranform coefficients for coupling channels */ | 564 /* tranform coefficients for coupling channels */ |
565 if (ctx->chincpl[i]) { | 565 if (ctx->chincpl[ch]) { |
566 if (!got_cplchan) { | 566 if (!got_cplchan) { |
567 if (get_transform_coeffs_ch(ctx, -2, &m)) { | 567 if (get_transform_coeffs_ch(ctx, -2, &m)) { |
568 av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n"); | 568 av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n"); |
569 return -1; | 569 return -1; |
570 } | 570 } |
571 uncouple_channels(ctx); | 571 uncouple_channels(ctx); |
572 got_cplchan = 1; | 572 got_cplchan = 1; |
573 } | 573 } |
574 end = ctx->cplendmant; | 574 end = ctx->cplendmant; |
575 } else { | 575 } else { |
576 end = ctx->endmant[i]; | 576 end = ctx->endmant[ch]; |
577 } | 577 } |
578 do | 578 do |
579 ctx->transform_coeffs[i + 1][end] = 0; | 579 ctx->transform_coeffs[ch + 1][end] = 0; |
580 while(++end < 256); | 580 while(++end < 256); |
581 } | 581 } |
582 if (ctx->lfeon) { | 582 if (ctx->lfeon) { |
583 if (get_transform_coeffs_ch(ctx, -1, &m)) | 583 if (get_transform_coeffs_ch(ctx, -1, &m)) |
584 return -1; | 584 return -1; |
699 int acmod = ctx->acmod; | 699 int acmod = ctx->acmod; |
700 int i, bnd, seg, ch; | 700 int i, bnd, seg, ch; |
701 GetBitContext *gb = &ctx->gb; | 701 GetBitContext *gb = &ctx->gb; |
702 int bit_alloc_flags = 0; | 702 int bit_alloc_flags = 0; |
703 | 703 |
704 for (i = 0; i < nfchans; i++) /*block switch flag */ | 704 for (ch = 0; ch < nfchans; ch++) /*block switch flag */ |
705 ctx->blksw[i] = get_bits1(gb); | 705 ctx->blksw[ch] = get_bits1(gb); |
706 | 706 |
707 ctx->dither_all = 1; | 707 ctx->dither_all = 1; |
708 for (i = 0; i < nfchans; i++) { /* dithering flag */ | 708 for (ch = 0; ch < nfchans; ch++) { /* dithering flag */ |
709 ctx->dithflag[i] = get_bits1(gb); | 709 ctx->dithflag[ch] = get_bits1(gb); |
710 if(!ctx->dithflag[i]) | 710 if(!ctx->dithflag[ch]) |
711 ctx->dither_all = 0; | 711 ctx->dither_all = 0; |
712 } | 712 } |
713 | 713 |
714 if (get_bits1(gb)) { /* dynamic range */ | 714 if (get_bits1(gb)) { /* dynamic range */ |
715 ctx->dynrng = dynrng_tbl[get_bits(gb, 8)]; | 715 ctx->dynrng = dynrng_tbl[get_bits(gb, 8)]; |
728 if (get_bits1(gb)) { /* coupling strategy */ | 728 if (get_bits1(gb)) { /* coupling strategy */ |
729 ctx->cplinu = get_bits1(gb); | 729 ctx->cplinu = get_bits1(gb); |
730 if (ctx->cplinu) { /* coupling in use */ | 730 if (ctx->cplinu) { /* coupling in use */ |
731 int cplbegf, cplendf; | 731 int cplbegf, cplendf; |
732 | 732 |
733 for (i = 0; i < nfchans; i++) | 733 for (ch = 0; ch < nfchans; ch++) |
734 ctx->chincpl[i] = get_bits1(gb); | 734 ctx->chincpl[ch] = get_bits1(gb); |
735 | 735 |
736 if (acmod == AC3_ACMOD_STEREO) | 736 if (acmod == AC3_ACMOD_STEREO) |
737 ctx->phsflginu = get_bits1(gb); //phase flag in use | 737 ctx->phsflginu = get_bits1(gb); //phase flag in use |
738 | 738 |
739 cplbegf = get_bits(gb, 4); | 739 cplbegf = get_bits(gb, 4); |
745 } | 745 } |
746 | 746 |
747 ctx->ncplbnd = ctx->ncplsubnd = 3 + cplendf - cplbegf; | 747 ctx->ncplbnd = ctx->ncplsubnd = 3 + cplendf - cplbegf; |
748 ctx->cplstrtmant = cplbegf * 12 + 37; | 748 ctx->cplstrtmant = cplbegf * 12 + 37; |
749 ctx->cplendmant = cplendf * 12 + 73; | 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 if (get_bits1(gb)) { | 751 if (get_bits1(gb)) { |
752 ctx->cplbndstrc[i] = 1; | 752 ctx->cplbndstrc[bnd] = 1; |
753 ctx->ncplbnd--; | 753 ctx->ncplbnd--; |
754 } | 754 } |
755 } | 755 } |
756 } else { | 756 } else { |
757 for (i = 0; i < nfchans; i++) | 757 for (ch = 0; ch < nfchans; ch++) |
758 ctx->chincpl[i] = 0; | 758 ctx->chincpl[ch] = 0; |
759 } | 759 } |
760 } | 760 } |
761 | 761 |
762 if (ctx->cplinu) { | 762 if (ctx->cplinu) { |
763 int cplcoe = 0; | 763 int cplcoe = 0; |
764 | 764 |
765 for (i = 0; i < nfchans; i++) { | 765 for (ch = 0; ch < nfchans; ch++) { |
766 if (ctx->chincpl[i]) { | 766 if (ctx->chincpl[ch]) { |
767 if (get_bits1(gb)) { /* coupling co-ordinates */ | 767 if (get_bits1(gb)) { /* coupling co-ordinates */ |
768 int mstrcplco, cplcoexp, cplcomant; | 768 int mstrcplco, cplcoexp, cplcomant; |
769 cplcoe = 1; | 769 cplcoe = 1; |
770 mstrcplco = 3 * get_bits(gb, 2); | 770 mstrcplco = 3 * get_bits(gb, 2); |
771 for (bnd = 0; bnd < ctx->ncplbnd; bnd++) { | 771 for (bnd = 0; bnd < ctx->ncplbnd; bnd++) { |
772 cplcoexp = get_bits(gb, 4); | 772 cplcoexp = get_bits(gb, 4); |
773 cplcomant = get_bits(gb, 4); | 773 cplcomant = get_bits(gb, 4); |
774 if (cplcoexp == 15) | 774 if (cplcoexp == 15) |
775 ctx->cplco[i][bnd] = cplcomant / 16.0f; | 775 ctx->cplco[ch][bnd] = cplcomant / 16.0f; |
776 else | 776 else |
777 ctx->cplco[i][bnd] = (cplcomant + 16.0f) / 32.0f; | 777 ctx->cplco[ch][bnd] = (cplcomant + 16.0f) / 32.0f; |
778 ctx->cplco[i][bnd] *= scale_factors[cplcoexp + mstrcplco]; | 778 ctx->cplco[ch][bnd] *= scale_factors[cplcoexp + mstrcplco]; |
779 } | 779 } |
780 } | 780 } |
781 } | 781 } |
782 } | 782 } |
783 | 783 |
802 | 802 |
803 ctx->cplexpstr = EXP_REUSE; | 803 ctx->cplexpstr = EXP_REUSE; |
804 ctx->lfeexpstr = EXP_REUSE; | 804 ctx->lfeexpstr = EXP_REUSE; |
805 if (ctx->cplinu) /* coupling exponent strategy */ | 805 if (ctx->cplinu) /* coupling exponent strategy */ |
806 ctx->cplexpstr = get_bits(gb, 2); | 806 ctx->cplexpstr = get_bits(gb, 2); |
807 for (i = 0; i < nfchans; i++) /* channel exponent strategy */ | 807 for (ch = 0; ch < nfchans; ch++) /* channel exponent strategy */ |
808 ctx->chexpstr[i] = get_bits(gb, 2); | 808 ctx->chexpstr[ch] = get_bits(gb, 2); |
809 if (ctx->lfeon) /* lfe exponent strategy */ | 809 if (ctx->lfeon) /* lfe exponent strategy */ |
810 ctx->lfeexpstr = get_bits1(gb); | 810 ctx->lfeexpstr = get_bits1(gb); |
811 | 811 |
812 for (i = 0; i < nfchans; i++) { /* channel bandwidth code */ | 812 for (ch = 0; ch < nfchans; ch++) { /* channel bandwidth code */ |
813 if (ctx->chexpstr[i] != EXP_REUSE) { | 813 if (ctx->chexpstr[ch] != EXP_REUSE) { |
814 if (ctx->chincpl[i]) | 814 if (ctx->chincpl[ch]) |
815 ctx->endmant[i] = ctx->cplstrtmant; | 815 ctx->endmant[ch] = ctx->cplstrtmant; |
816 else { | 816 else { |
817 int chbwcod = get_bits(gb, 6); | 817 int chbwcod = get_bits(gb, 6); |
818 if (chbwcod > 60) { | 818 if (chbwcod > 60) { |
819 av_log(NULL, AV_LOG_ERROR, "chbwcod = %d > 60", chbwcod); | 819 av_log(NULL, AV_LOG_ERROR, "chbwcod = %d > 60", chbwcod); |
820 return -1; | 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 } |
826 | 826 |
827 if (ctx->cplexpstr != EXP_REUSE) {/* coupling exponents */ | 827 if (ctx->cplexpstr != EXP_REUSE) {/* coupling exponents */ |
831 ngrps = (ctx->cplendmant - ctx->cplstrtmant) / grpsize; | 831 ngrps = (ctx->cplendmant - ctx->cplstrtmant) / grpsize; |
832 absexp = get_bits(gb, 4) << 1; | 832 absexp = get_bits(gb, 4) << 1; |
833 decode_exponents(gb, ctx->cplexpstr, ngrps, absexp, &ctx->dcplexps[ctx->cplstrtmant]); | 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 */ | 836 for (ch = 0; ch < nfchans; ch++) { /* fbw channel exponents */ |
837 if (ctx->chexpstr[i] != EXP_REUSE) { | 837 if (ctx->chexpstr[ch] != EXP_REUSE) { |
838 int grpsize, ngrps, absexp; | 838 int grpsize, ngrps, absexp; |
839 bit_alloc_flags |= 1 << i; | 839 bit_alloc_flags |= 1 << ch; |
840 grpsize = 3 << (ctx->chexpstr[i] - 1); | 840 grpsize = 3 << (ctx->chexpstr[ch] - 1); |
841 ngrps = (ctx->endmant[i] + grpsize - 4) / grpsize; | 841 ngrps = (ctx->endmant[ch] + grpsize - 4) / grpsize; |
842 absexp = ctx->dexps[i][0] = get_bits(gb, 4); | 842 absexp = ctx->dexps[ch][0] = get_bits(gb, 4); |
843 decode_exponents(gb, ctx->chexpstr[i], ngrps, absexp, &ctx->dexps[i][1]); | 843 decode_exponents(gb, ctx->chexpstr[ch], ngrps, absexp, &ctx->dexps[ch][1]); |
844 skip_bits(gb, 2); /* skip gainrng */ | 844 skip_bits(gb, 2); /* skip gainrng */ |
845 } | 845 } |
846 } | 846 } |
847 | 847 |
848 if (ctx->lfeexpstr != EXP_REUSE) { /* lfe exponents */ | 848 if (ctx->lfeexpstr != EXP_REUSE) { /* lfe exponents */ |
868 csnr = (get_bits(gb, 6) - 15) << 4; | 868 csnr = (get_bits(gb, 6) - 15) << 4; |
869 if (ctx->cplinu) { /* coupling fine snr offset and fast gain code */ | 869 if (ctx->cplinu) { /* coupling fine snr offset and fast gain code */ |
870 ctx->cplsnroffst = (csnr + get_bits(gb, 4)) << 2; | 870 ctx->cplsnroffst = (csnr + get_bits(gb, 4)) << 2; |
871 ctx->cplfgain = ff_fgaintab[get_bits(gb, 3)]; | 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 */ | 873 for (ch = 0; ch < nfchans; ch++) { /* channel fine snr offset and fast gain code */ |
874 ctx->snroffst[i] = (csnr + get_bits(gb, 4)) << 2; | 874 ctx->snroffst[ch] = (csnr + get_bits(gb, 4)) << 2; |
875 ctx->fgain[i] = ff_fgaintab[get_bits(gb, 3)]; | 875 ctx->fgain[ch] = ff_fgaintab[get_bits(gb, 3)]; |
876 } | 876 } |
877 if (ctx->lfeon) { /* lfe fine snr offset and fast gain code */ | 877 if (ctx->lfeon) { /* lfe fine snr offset and fast gain code */ |
878 ctx->lfesnroffst = (csnr + get_bits(gb, 4)) << 2; | 878 ctx->lfesnroffst = (csnr + get_bits(gb, 4)) << 2; |
879 ctx->lfefgain = ff_fgaintab[get_bits(gb, 3)]; | 879 ctx->lfefgain = ff_fgaintab[get_bits(gb, 3)]; |
880 } | 880 } |
895 av_log(NULL, AV_LOG_ERROR, "coupling delta bit allocation strategy reserved\n"); | 895 av_log(NULL, AV_LOG_ERROR, "coupling delta bit allocation strategy reserved\n"); |
896 return -1; | 896 return -1; |
897 } | 897 } |
898 } | 898 } |
899 | 899 |
900 for (i = 0; i < nfchans; i++) { | 900 for (ch = 0; ch < nfchans; ch++) { |
901 ctx->deltbae[i] = get_bits(gb, 2); | 901 ctx->deltbae[ch] = get_bits(gb, 2); |
902 if (ctx->deltbae[i] == DBA_RESERVED) { | 902 if (ctx->deltbae[ch] == DBA_RESERVED) { |
903 av_log(NULL, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); | 903 av_log(NULL, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); |
904 return -1; | 904 return -1; |
905 } | 905 } |
906 } | 906 } |
907 | 907 |
914 ctx->cpldeltba[seg] = get_bits(gb, 3); | 914 ctx->cpldeltba[seg] = get_bits(gb, 3); |
915 } | 915 } |
916 } | 916 } |
917 } | 917 } |
918 | 918 |
919 for (i = 0; i < nfchans; i++) { | 919 for (ch = 0; ch < nfchans; ch++) { |
920 if (ctx->deltbae[i] == DBA_NEW) {/*channel delta offset, len and bit allocation */ | 920 if (ctx->deltbae[ch] == DBA_NEW) {/*channel delta offset, len and bit allocation */ |
921 ctx->deltnseg[i] = get_bits(gb, 3); | 921 ctx->deltnseg[ch] = get_bits(gb, 3); |
922 for (seg = 0; seg <= ctx->deltnseg[i]; seg++) { | 922 for (seg = 0; seg <= ctx->deltnseg[ch]; seg++) { |
923 ctx->deltoffst[i][seg] = get_bits(gb, 5); | 923 ctx->deltoffst[ch][seg] = get_bits(gb, 5); |
924 ctx->deltlen[i][seg] = get_bits(gb, 4); | 924 ctx->deltlen[ch][seg] = get_bits(gb, 4); |
925 ctx->deltba[i][seg] = get_bits(gb, 3); | 925 ctx->deltba[ch][seg] = get_bits(gb, 3); |
926 } | 926 } |
927 } | 927 } |
928 } | 928 } |
929 } else if(blk == 0) { | 929 } else if(blk == 0) { |
930 if(ctx->cplinu) | 930 if(ctx->cplinu) |
931 ctx->cpldeltbae = DBA_NONE; | 931 ctx->cpldeltbae = DBA_NONE; |
932 for(i=0; i<nfchans; i++) { | 932 for(ch=0; ch<nfchans; ch++) { |
933 ctx->deltbae[i] = DBA_NONE; | 933 ctx->deltbae[ch] = DBA_NONE; |
934 } | 934 } |
935 } | 935 } |
936 | 936 |
937 if (bit_alloc_flags) { | 937 if (bit_alloc_flags) { |
938 if (ctx->cplinu && (bit_alloc_flags & 64)) { | 938 if (ctx->cplinu && (bit_alloc_flags & 64)) { |
942 ctx->cplfgain, 0, | 942 ctx->cplfgain, 0, |
943 ctx->cpldeltbae, ctx->cpldeltnseg, | 943 ctx->cpldeltbae, ctx->cpldeltnseg, |
944 ctx->cpldeltoffst, ctx->cpldeltlen, | 944 ctx->cpldeltoffst, ctx->cpldeltlen, |
945 ctx->cpldeltba); | 945 ctx->cpldeltba); |
946 } | 946 } |
947 for (i = 0; i < nfchans; i++) { | 947 for (ch = 0; ch < nfchans; ch++) { |
948 if ((bit_alloc_flags >> i) & 1) { | 948 if ((bit_alloc_flags >> ch) & 1) { |
949 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, | 949 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, |
950 ctx->bap[i], ctx->dexps[i], 0, | 950 ctx->bap[ch], ctx->dexps[ch], 0, |
951 ctx->endmant[i], ctx->snroffst[i], | 951 ctx->endmant[ch], ctx->snroffst[ch], |
952 ctx->fgain[i], 0, ctx->deltbae[i], | 952 ctx->fgain[ch], 0, ctx->deltbae[ch], |
953 ctx->deltnseg[i], ctx->deltoffst[i], | 953 ctx->deltnseg[ch], ctx->deltoffst[ch], |
954 ctx->deltlen[i], ctx->deltba[i]); | 954 ctx->deltlen[ch], ctx->deltba[ch]); |
955 } | 955 } |
956 } | 956 } |
957 if (ctx->lfeon && (bit_alloc_flags & 32)) { | 957 if (ctx->lfeon && (bit_alloc_flags & 32)) { |
958 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->lfebap, | 958 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->lfebap, |
959 ctx->dlfeexps, 0, 7, ctx->lfesnroffst, | 959 ctx->dlfeexps, 0, 7, ctx->lfesnroffst, |
1022 */ | 1022 */ |
1023 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size) | 1023 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size) |
1024 { | 1024 { |
1025 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data; | 1025 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data; |
1026 int16_t *out_samples = (int16_t *)data; | 1026 int16_t *out_samples = (int16_t *)data; |
1027 int i, j, k, start; | 1027 int i, blk, ch, start; |
1028 int32_t *int_ptr[6]; | 1028 int32_t *int_ptr[6]; |
1029 | 1029 |
1030 for (i = 0; i < 6; i++) | 1030 for (ch = 0; ch < 6; ch++) |
1031 int_ptr[i] = (int32_t *)(&ctx->output[i]); | 1031 int_ptr[ch] = (int32_t *)(&ctx->output[ch]); |
1032 | 1032 |
1033 //Initialize the GetBitContext with the start of valid AC3 Frame. | 1033 //Initialize the GetBitContext with the start of valid AC3 Frame. |
1034 init_get_bits(&ctx->gb, buf, buf_size * 8); | 1034 init_get_bits(&ctx->gb, buf, buf_size * 8); |
1035 | 1035 |
1036 //Parse the syncinfo. | 1036 //Parse the syncinfo. |
1054 } | 1054 } |
1055 | 1055 |
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); | 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 //Parse the Audio Blocks. | 1058 //Parse the Audio Blocks. |
1059 for (i = 0; i < NB_BLOCKS; i++) { | 1059 for (blk = 0; blk < NB_BLOCKS; blk++) { |
1060 if (ac3_parse_audio_block(ctx, i)) { | 1060 if (ac3_parse_audio_block(ctx, blk)) { |
1061 av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n"); | 1061 av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n"); |
1062 *data_size = 0; | 1062 *data_size = 0; |
1063 return ctx->frame_size; | 1063 return ctx->frame_size; |
1064 } | 1064 } |
1065 start = (ctx->output_mode & AC3_OUTPUT_LFEON) ? 0 : 1; | 1065 start = (ctx->output_mode & AC3_OUTPUT_LFEON) ? 0 : 1; |
1066 for (k = 0; k < 256; k++) | 1066 for (i = 0; i < 256; i++) |
1067 for (j = start; j <= ctx->nfchans; j++) | 1067 for (ch = start; ch <= ctx->nfchans; ch++) |
1068 *(out_samples++) = convert(int_ptr[j][k]); | 1068 *(out_samples++) = convert(int_ptr[ch][i]); |
1069 } | 1069 } |
1070 *data_size = NB_BLOCKS * 256 * avctx->channels * sizeof (int16_t); | 1070 *data_size = NB_BLOCKS * 256 * avctx->channels * sizeof (int16_t); |
1071 return ctx->frame_size; | 1071 return ctx->frame_size; |
1072 } | 1072 } |
1073 | 1073 |