Mercurial > libavcodec.hg
comparison ac3dec.c @ 7664:a78c2ebb8149 libavcodec
add some approved parts of the E-AC-3 decoder
author | jbr |
---|---|
date | Sat, 23 Aug 2008 01:51:42 +0000 |
parents | 93c5703328d6 |
children | 762007251900 |
comparison
equal
deleted
inserted
replaced
7663:66fb1f3937fa | 7664:a78c2ebb8149 |
---|---|
759 } else if(blk == 0) { | 759 } else if(blk == 0) { |
760 s->dynamic_range[i] = 1.0f; | 760 s->dynamic_range[i] = 1.0f; |
761 } | 761 } |
762 } while(i--); | 762 } while(i--); |
763 | 763 |
764 /* spectral extension strategy */ | |
765 if (s->eac3 && (!blk || get_bits1(gbc))) { | |
766 if (get_bits1(gbc)) { | |
767 av_log_missing_feature(s->avctx, "Spectral extension", 1); | |
768 return -1; | |
769 } | |
770 /* TODO: parse spectral extension strategy info */ | |
771 } | |
772 | |
773 /* TODO: spectral extension coordinates */ | |
774 | |
764 /* coupling strategy */ | 775 /* coupling strategy */ |
765 if (get_bits1(gbc)) { | 776 if (get_bits1(gbc)) { |
766 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); | 777 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
778 if (!s->eac3) | |
767 s->cpl_in_use[blk] = get_bits1(gbc); | 779 s->cpl_in_use[blk] = get_bits1(gbc); |
768 if (s->cpl_in_use[blk]) { | 780 if (s->cpl_in_use[blk]) { |
769 /* coupling in use */ | 781 /* coupling in use */ |
770 int cpl_begin_freq, cpl_end_freq; | 782 int cpl_begin_freq, cpl_end_freq; |
771 | 783 |
772 if (channel_mode < AC3_CHMODE_STEREO) { | 784 if (channel_mode < AC3_CHMODE_STEREO) { |
773 av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n"); | 785 av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n"); |
774 return -1; | 786 return -1; |
775 } | 787 } |
776 | 788 |
789 /* check for enhanced coupling */ | |
790 if (s->eac3 && get_bits1(gbc)) { | |
791 /* TODO: parse enhanced coupling strategy info */ | |
792 av_log_missing_feature(s->avctx, "Enhanced coupling", 1); | |
793 return -1; | |
794 } | |
795 | |
777 /* determine which channels are coupled */ | 796 /* determine which channels are coupled */ |
797 if (s->eac3 && s->channel_mode == AC3_CHMODE_STEREO) { | |
798 s->channel_in_cpl[1] = 1; | |
799 s->channel_in_cpl[2] = 1; | |
800 } else { | |
778 for (ch = 1; ch <= fbw_channels; ch++) | 801 for (ch = 1; ch <= fbw_channels; ch++) |
779 s->channel_in_cpl[ch] = get_bits1(gbc); | 802 s->channel_in_cpl[ch] = get_bits1(gbc); |
803 } | |
780 | 804 |
781 /* phase flags in use */ | 805 /* phase flags in use */ |
782 if (channel_mode == AC3_CHMODE_STEREO) | 806 if (channel_mode == AC3_CHMODE_STEREO) |
783 s->phase_flags_in_use = get_bits1(gbc); | 807 s->phase_flags_in_use = get_bits1(gbc); |
784 | 808 |
785 /* coupling frequency range and band structure */ | 809 /* coupling frequency range */ |
810 /* TODO: modify coupling end freq if spectral extension is used */ | |
786 cpl_begin_freq = get_bits(gbc, 4); | 811 cpl_begin_freq = get_bits(gbc, 4); |
787 cpl_end_freq = get_bits(gbc, 4); | 812 cpl_end_freq = get_bits(gbc, 4); |
788 if (3 + cpl_end_freq - cpl_begin_freq < 0) { | 813 if (3 + cpl_end_freq - cpl_begin_freq < 0) { |
789 av_log(s->avctx, AV_LOG_ERROR, "3+cplendf = %d < cplbegf = %d\n", 3+cpl_end_freq, cpl_begin_freq); | 814 av_log(s->avctx, AV_LOG_ERROR, "3+cplendf = %d < cplbegf = %d\n", 3+cpl_end_freq, cpl_begin_freq); |
790 return -1; | 815 return -1; |
791 } | 816 } |
792 s->num_cpl_bands = s->num_cpl_subbands = 3 + cpl_end_freq - cpl_begin_freq; | 817 s->num_cpl_bands = s->num_cpl_subbands = 3 + cpl_end_freq - cpl_begin_freq; |
793 s->start_freq[CPL_CH] = cpl_begin_freq * 12 + 37; | 818 s->start_freq[CPL_CH] = cpl_begin_freq * 12 + 37; |
794 s->end_freq[CPL_CH] = cpl_end_freq * 12 + 73; | 819 s->end_freq[CPL_CH] = cpl_end_freq * 12 + 73; |
820 | |
821 /* coupling band structure */ | |
822 if (!s->eac3 || get_bits1(gbc)) { | |
795 for (bnd = 0; bnd < s->num_cpl_subbands - 1; bnd++) { | 823 for (bnd = 0; bnd < s->num_cpl_subbands - 1; bnd++) { |
796 if (get_bits1(gbc)) { | 824 s->cpl_band_struct[bnd] = get_bits1(gbc); |
797 s->cpl_band_struct[bnd] = 1; | |
798 s->num_cpl_bands--; | |
799 } | 825 } |
826 } else if (!blk) { | |
800 } | 827 } |
801 s->cpl_band_struct[s->num_cpl_subbands-1] = 0; | 828 s->cpl_band_struct[s->num_cpl_subbands-1] = 0; |
829 | |
830 /* calculate number of coupling bands based on band structure */ | |
831 for (bnd = 0; bnd < s->num_cpl_subbands-1; bnd++) { | |
832 s->num_cpl_bands -= s->cpl_band_struct[bnd]; | |
833 } | |
802 } else { | 834 } else { |
803 /* coupling not in use */ | 835 /* coupling not in use */ |
804 for (ch = 1; ch <= fbw_channels; ch++) | 836 for (ch = 1; ch <= fbw_channels; ch++) { |
805 s->channel_in_cpl[ch] = 0; | 837 s->channel_in_cpl[ch] = 0; |
806 } | 838 s->first_cpl_coords[ch] = 1; |
807 } else if (!blk) { | 839 } |
840 s->first_cpl_leak = 1; | |
841 s->phase_flags_in_use = 0; | |
842 } | |
843 } else if (!s->eac3) { | |
844 if(!blk) { | |
808 av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must be present in block 0\n"); | 845 av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must be present in block 0\n"); |
809 return -1; | 846 return -1; |
810 } else { | 847 } else { |
811 s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; | 848 s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; |
849 } | |
812 } | 850 } |
813 cpl_in_use = s->cpl_in_use[blk]; | 851 cpl_in_use = s->cpl_in_use[blk]; |
814 | 852 |
815 /* coupling coordinates */ | 853 /* coupling coordinates */ |
816 if (cpl_in_use) { | 854 if (cpl_in_use) { |
845 } | 883 } |
846 } | 884 } |
847 | 885 |
848 /* stereo rematrixing strategy and band structure */ | 886 /* stereo rematrixing strategy and band structure */ |
849 if (channel_mode == AC3_CHMODE_STEREO) { | 887 if (channel_mode == AC3_CHMODE_STEREO) { |
850 if (get_bits1(gbc)) { | 888 if ((s->eac3 && !blk) || get_bits1(gbc)) { |
851 s->num_rematrixing_bands = 4; | 889 s->num_rematrixing_bands = 4; |
852 if(cpl_in_use && s->start_freq[CPL_CH] <= 61) | 890 if(cpl_in_use && s->start_freq[CPL_CH] <= 61) |
853 s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); | 891 s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); |
854 for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) | 892 for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) |
855 s->rematrixing_flags[bnd] = get_bits1(gbc); | 893 s->rematrixing_flags[bnd] = get_bits1(gbc); |
933 } | 971 } |
934 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); | 972 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
935 } else if (!blk) { | 973 } else if (!blk) { |
936 av_log(s->avctx, AV_LOG_ERROR, "new snr offsets must be present in block 0\n"); | 974 av_log(s->avctx, AV_LOG_ERROR, "new snr offsets must be present in block 0\n"); |
937 return -1; | 975 return -1; |
976 } | |
977 | |
978 /* fast gain (E-AC-3 only) */ | |
979 if (s->fast_gain_syntax && get_bits1(gbc)) { | |
980 for (ch = !cpl_in_use; ch <= s->channels; ch++) { | |
981 int prev = s->fast_gain[ch]; | |
982 s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; | |
983 /* run last 2 bit allocation stages if fast gain changes */ | |
984 if(blk && prev != s->fast_gain[ch]) | |
985 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); | |
986 } | |
987 } else if (s->eac3 && !blk) { | |
988 for (ch = !cpl_in_use; ch <= s->channels; ch++) | |
989 s->fast_gain[ch] = ff_ac3_fast_gain_tab[4]; | |
990 } | |
991 | |
992 /* E-AC-3 to AC-3 converter SNR offset */ | |
993 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && get_bits1(gbc)) { | |
994 skip_bits(gbc, 10); // skip converter snr offset | |
938 } | 995 } |
939 | 996 |
940 /* coupling leak information */ | 997 /* coupling leak information */ |
941 if (cpl_in_use) { | 998 if (cpl_in_use) { |
942 if (get_bits1(gbc)) { | 999 if (get_bits1(gbc)) { |