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)
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)
733
int subbnd, bnd, n_subbands, n_bands, bnd_sz[22];
735
n_subbands = end_subband - start_subband;
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);
744
&default_band_struct[start_subband+1],
747
band_struct[n_subbands-1] = 0;
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
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]) {
759
bnd_sz[bnd] += subbnd_size;
761
bnd_sz[++bnd] = subbnd_size;
766
/* set optional output params */
768
*num_subbands = n_subbands;
770
*num_bands = n_bands;
772
memcpy(band_sizes, bnd_sz, sizeof(int)*n_bands);
714
776
* Decode a single audio block from the AC-3 bitstream.
716
778
static int decode_audio_block(AC3DecodeContext *s, int blk)
772
834
s->cpl_in_use[blk] = get_bits1(gbc);
773
835
if (s->cpl_in_use[blk]) {
774
836
/* coupling in use */
775
int cpl_begin_freq, cpl_end_freq;
837
int cpl_start_subband, cpl_end_subband;
777
839
if (channel_mode < AC3_CHMODE_STEREO) {
778
840
av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n");
802
864
/* coupling frequency range */
803
865
/* TODO: modify coupling end freq if spectral extension is used */
804
cpl_begin_freq = get_bits(gbc, 4);
805
cpl_end_freq = get_bits(gbc, 4);
806
if (3 + cpl_end_freq - cpl_begin_freq < 0) {
807
av_log(s->avctx, AV_LOG_ERROR, "3+cplendf = %d < cplbegf = %d\n", 3+cpl_end_freq, cpl_begin_freq);
866
cpl_start_subband = get_bits(gbc, 4);
867
cpl_end_subband = get_bits(gbc, 4) + 3;
868
s->num_cpl_subbands = cpl_end_subband - cpl_start_subband;
869
if (s->num_cpl_subbands < 0) {
870
av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d > %d)\n",
871
cpl_start_subband, cpl_end_subband);
810
s->num_cpl_bands = s->num_cpl_subbands = 3 + cpl_end_freq - cpl_begin_freq;
811
s->start_freq[CPL_CH] = cpl_begin_freq * 12 + 37;
812
s->end_freq[CPL_CH] = cpl_end_freq * 12 + 73;
814
/* coupling band structure */
815
if (!s->eac3 || get_bits1(gbc)) {
816
for (bnd = 0; bnd < s->num_cpl_subbands - 1; bnd++) {
817
s->cpl_band_struct[bnd] = get_bits1(gbc);
820
memcpy(s->cpl_band_struct,
821
&ff_eac3_default_cpl_band_struct[cpl_begin_freq+1],
822
s->num_cpl_subbands-1);
824
s->cpl_band_struct[s->num_cpl_subbands-1] = 0;
826
/* calculate number of coupling bands based on band structure */
827
for (bnd = 0; bnd < s->num_cpl_subbands-1; bnd++) {
828
s->num_cpl_bands -= s->cpl_band_struct[bnd];
874
s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37;
875
s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37;
877
decode_band_structure(gbc, blk, s->eac3, 0,
878
cpl_start_subband, cpl_end_subband,
879
ff_eac3_default_cpl_band_struct,
880
s->cpl_band_struct, &s->num_cpl_subbands,
881
&s->num_cpl_bands, NULL);
831
883
/* coupling not in use */
832
884
for (ch = 1; ch <= fbw_channels; ch++) {
917
969
int bandwidth_code = get_bits(gbc, 6);
918
970
if (bandwidth_code > 60) {
919
av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60", bandwidth_code);
971
av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60\n", bandwidth_code);
922
974
s->end_freq[ch] = bandwidth_code * 3 + 73;