Mercurial > libavcodec.hg
comparison ac3dec.c @ 8135:c82f8f5657ff libavcodec
add a generic function to decode banding structure for coupling, spectral
extension, or enhanced coupling
author | jbr |
---|---|
date | Thu, 13 Nov 2008 03:18:07 +0000 |
parents | 10541875e559 |
children | 3085502c4f33 |
comparison
equal
deleted
inserted
replaced
8134:10541875e559 | 8135:c82f8f5657ff |
---|---|
709 break; | 709 break; |
710 } | 710 } |
711 } | 711 } |
712 | 712 |
713 /** | 713 /** |
714 * Decode band structure for coupling, spectral extension, or enhanced coupling. | |
715 * @param[in] gbc bit reader context | |
716 * @param[in] blk block number | |
717 * @param[in] eac3 flag to indicate E-AC-3 | |
718 * @param[in] ecpl flag to indicate enhanced coupling | |
719 * @param[in] start_subband subband number for start of range | |
720 * @param[in] end_subband subband number for end of range | |
721 * @param[in] default_band_struct default band structure table | |
722 * @param[out] band_struct decoded band structure | |
723 * @param[out] num_subbands number of subbands (optionally NULL) | |
724 * @param[out] num_bands number of bands (optionally NULL) | |
725 * @param[out] band_sizes array containing the number of bins in each band (optionally NULL) | |
726 */ | |
727 static void decode_band_structure(GetBitContext *gbc, int blk, int eac3, | |
728 int ecpl, int start_subband, int end_subband, | |
729 const uint8_t *default_band_struct, | |
730 uint8_t *band_struct, int *num_subbands, | |
731 int *num_bands, int *band_sizes) | |
732 { | |
733 int subbnd, bnd, n_subbands, n_bands, bnd_sz[22]; | |
734 | |
735 n_subbands = end_subband - start_subband; | |
736 | |
737 /* decode band structure from bitstream or use default */ | |
738 if (!eac3 || get_bits1(gbc)) { | |
739 for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) { | |
740 band_struct[subbnd] = get_bits1(gbc); | |
741 } | |
742 } else if (!blk) { | |
743 memcpy(band_struct, | |
744 &default_band_struct[start_subband+1], | |
745 n_subbands-1); | |
746 } | |
747 band_struct[n_subbands-1] = 0; | |
748 | |
749 /* calculate number of bands and band sizes based on band structure. | |
750 note that the first 4 subbands in enhanced coupling span only 6 bins | |
751 instead of 12. */ | |
752 if (num_bands || band_sizes ) { | |
753 n_bands = n_subbands; | |
754 bnd_sz[0] = ecpl ? 6 : 12; | |
755 for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) { | |
756 int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12; | |
757 if (band_struct[subbnd-1]) { | |
758 n_bands--; | |
759 bnd_sz[bnd] += subbnd_size; | |
760 } else { | |
761 bnd_sz[++bnd] = subbnd_size; | |
762 } | |
763 } | |
764 } | |
765 | |
766 /* set optional output params */ | |
767 if (num_subbands) | |
768 *num_subbands = n_subbands; | |
769 if (num_bands) | |
770 *num_bands = n_bands; | |
771 if (band_sizes) | |
772 memcpy(band_sizes, bnd_sz, sizeof(int)*n_bands); | |
773 } | |
774 | |
775 /** | |
714 * Decode a single audio block from the AC-3 bitstream. | 776 * Decode a single audio block from the AC-3 bitstream. |
715 */ | 777 */ |
716 static int decode_audio_block(AC3DecodeContext *s, int blk) | 778 static int decode_audio_block(AC3DecodeContext *s, int blk) |
717 { | 779 { |
718 int fbw_channels = s->fbw_channels; | 780 int fbw_channels = s->fbw_channels; |
810 return -1; | 872 return -1; |
811 } | 873 } |
812 s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37; | 874 s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37; |
813 s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37; | 875 s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37; |
814 | 876 |
815 /* coupling band structure */ | 877 decode_band_structure(gbc, blk, s->eac3, 0, |
816 s->num_cpl_bands = s->num_cpl_subbands; | 878 cpl_start_subband, cpl_end_subband, |
817 if (!s->eac3 || get_bits1(gbc)) { | 879 ff_eac3_default_cpl_band_struct, |
818 for (bnd = 0; bnd < s->num_cpl_subbands - 1; bnd++) { | 880 s->cpl_band_struct, &s->num_cpl_subbands, |
819 s->cpl_band_struct[bnd] = get_bits1(gbc); | 881 &s->num_cpl_bands, NULL); |
820 } | |
821 } else if (!blk) { | |
822 memcpy(s->cpl_band_struct, | |
823 &ff_eac3_default_cpl_band_struct[cpl_start_subband+1], | |
824 s->num_cpl_subbands-1); | |
825 } | |
826 s->cpl_band_struct[s->num_cpl_subbands-1] = 0; | |
827 | |
828 /* calculate number of coupling bands based on band structure */ | |
829 for (bnd = 0; bnd < s->num_cpl_subbands-1; bnd++) { | |
830 s->num_cpl_bands -= s->cpl_band_struct[bnd]; | |
831 } | |
832 } else { | 882 } else { |
833 /* coupling not in use */ | 883 /* coupling not in use */ |
834 for (ch = 1; ch <= fbw_channels; ch++) { | 884 for (ch = 1; ch <= fbw_channels; ch++) { |
835 s->channel_in_cpl[ch] = 0; | 885 s->channel_in_cpl[ch] = 0; |
836 s->first_cpl_coords[ch] = 1; | 886 s->first_cpl_coords[ch] = 1; |