|
|
@ -935,79 +935,17 @@ static inline void spx_coordinates(AC3DecodeContext *s) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
static inline int coupling_strategy(AC3DecodeContext *s, int blk, |
|
|
|
* Decode a single audio block from the AC-3 bitstream. |
|
|
|
uint8_t *bit_alloc_stages) |
|
|
|
*/ |
|
|
|
|
|
|
|
static int decode_audio_block(AC3DecodeContext *s, int blk) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
GetBitContext *bc = &s->gbc; |
|
|
|
int fbw_channels = s->fbw_channels; |
|
|
|
int fbw_channels = s->fbw_channels; |
|
|
|
int channel_mode = s->channel_mode; |
|
|
|
int channel_mode = s->channel_mode; |
|
|
|
int i, bnd, seg, ch, ret; |
|
|
|
int ch; |
|
|
|
int different_transforms; |
|
|
|
|
|
|
|
int downmix_output; |
|
|
|
|
|
|
|
int cpl_in_use; |
|
|
|
|
|
|
|
GetBitContext *gbc = &s->gbc; |
|
|
|
|
|
|
|
uint8_t bit_alloc_stages[AC3_MAX_CHANNELS] = { 0 }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* block switch flags */ |
|
|
|
|
|
|
|
different_transforms = 0; |
|
|
|
|
|
|
|
if (s->block_switch_syntax) { |
|
|
|
|
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
|
|
|
|
s->block_switch[ch] = get_bits1(gbc); |
|
|
|
|
|
|
|
if (ch > 1 && s->block_switch[ch] != s->block_switch[1]) |
|
|
|
|
|
|
|
different_transforms = 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dithering flags */ |
|
|
|
|
|
|
|
if (s->dither_flag_syntax) { |
|
|
|
|
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
|
|
|
|
s->dither_flag[ch] = get_bits1(gbc); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dynamic range */ |
|
|
|
|
|
|
|
i = !s->channel_mode; |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
if (get_bits1(gbc)) { |
|
|
|
|
|
|
|
/* Allow asymmetric application of DRC when drc_scale > 1.
|
|
|
|
|
|
|
|
Amplification of quiet sounds is enhanced */ |
|
|
|
|
|
|
|
int range_bits = get_bits(gbc, 8); |
|
|
|
|
|
|
|
INTFLOAT range = AC3_RANGE(range_bits); |
|
|
|
|
|
|
|
if (range_bits <= 127 || s->drc_scale <= 1.0) |
|
|
|
|
|
|
|
s->dynamic_range[i] = AC3_DYNAMIC_RANGE(range); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
s->dynamic_range[i] = range; |
|
|
|
|
|
|
|
} else if (blk == 0) { |
|
|
|
|
|
|
|
s->dynamic_range[i] = AC3_DYNAMIC_RANGE1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while (i--); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* spectral extension strategy */ |
|
|
|
|
|
|
|
if (s->eac3 && (!blk || get_bits1(gbc))) { |
|
|
|
|
|
|
|
s->spx_in_use = get_bits1(gbc); |
|
|
|
|
|
|
|
if (s->spx_in_use) { |
|
|
|
|
|
|
|
if ((ret = spx_strategy(s, blk)) < 0) |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!s->eac3 || !s->spx_in_use) { |
|
|
|
|
|
|
|
s->spx_in_use = 0; |
|
|
|
|
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
|
|
|
|
s->channel_uses_spx[ch] = 0; |
|
|
|
|
|
|
|
s->first_spx_coords[ch] = 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* spectral extension coordinates */ |
|
|
|
|
|
|
|
if (s->spx_in_use) |
|
|
|
|
|
|
|
spx_coordinates(s); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* coupling strategy */ |
|
|
|
|
|
|
|
if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) { |
|
|
|
|
|
|
|
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
|
|
|
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
|
|
|
if (!s->eac3) |
|
|
|
if (!s->eac3) |
|
|
|
s->cpl_in_use[blk] = get_bits1(gbc); |
|
|
|
s->cpl_in_use[blk] = get_bits1(bc); |
|
|
|
if (s->cpl_in_use[blk]) { |
|
|
|
if (s->cpl_in_use[blk]) { |
|
|
|
/* coupling in use */ |
|
|
|
/* coupling in use */ |
|
|
|
int cpl_start_subband, cpl_end_subband; |
|
|
|
int cpl_start_subband, cpl_end_subband; |
|
|
@ -1018,7 +956,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* check for enhanced coupling */ |
|
|
|
/* check for enhanced coupling */ |
|
|
|
if (s->eac3 && get_bits1(gbc)) { |
|
|
|
if (s->eac3 && get_bits1(bc)) { |
|
|
|
/* TODO: parse enhanced coupling strategy info */ |
|
|
|
/* TODO: parse enhanced coupling strategy info */ |
|
|
|
avpriv_request_sample(s->avctx, "Enhanced coupling"); |
|
|
|
avpriv_request_sample(s->avctx, "Enhanced coupling"); |
|
|
|
return AVERROR_PATCHWELCOME; |
|
|
|
return AVERROR_PATCHWELCOME; |
|
|
@ -1030,17 +968,17 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
|
|
|
s->channel_in_cpl[2] = 1; |
|
|
|
s->channel_in_cpl[2] = 1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) |
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) |
|
|
|
s->channel_in_cpl[ch] = get_bits1(gbc); |
|
|
|
s->channel_in_cpl[ch] = get_bits1(bc); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* phase flags in use */ |
|
|
|
/* phase flags in use */ |
|
|
|
if (channel_mode == AC3_CHMODE_STEREO) |
|
|
|
if (channel_mode == AC3_CHMODE_STEREO) |
|
|
|
s->phase_flags_in_use = get_bits1(gbc); |
|
|
|
s->phase_flags_in_use = get_bits1(bc); |
|
|
|
|
|
|
|
|
|
|
|
/* coupling frequency range */ |
|
|
|
/* coupling frequency range */ |
|
|
|
cpl_start_subband = get_bits(gbc, 4); |
|
|
|
cpl_start_subband = get_bits(bc, 4); |
|
|
|
cpl_end_subband = s->spx_in_use ? (s->spx_src_start_freq - 37) / 12 : |
|
|
|
cpl_end_subband = s->spx_in_use ? (s->spx_src_start_freq - 37) / 12 : |
|
|
|
get_bits(gbc, 4) + 3; |
|
|
|
get_bits(bc, 4) + 3; |
|
|
|
if (cpl_start_subband >= cpl_end_subband) { |
|
|
|
if (cpl_start_subband >= cpl_end_subband) { |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n", |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n", |
|
|
|
cpl_start_subband, cpl_end_subband); |
|
|
|
cpl_start_subband, cpl_end_subband); |
|
|
@ -1049,7 +987,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
|
|
|
s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37; |
|
|
|
s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37; |
|
|
|
s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37; |
|
|
|
s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37; |
|
|
|
|
|
|
|
|
|
|
|
decode_band_structure(gbc, blk, s->eac3, 0, cpl_start_subband, |
|
|
|
decode_band_structure(bc, blk, s->eac3, 0, cpl_start_subband, |
|
|
|
cpl_end_subband, |
|
|
|
cpl_end_subband, |
|
|
|
ff_eac3_default_cpl_band_struct, |
|
|
|
ff_eac3_default_cpl_band_struct, |
|
|
|
&s->num_cpl_bands, s->cpl_band_sizes); |
|
|
|
&s->num_cpl_bands, s->cpl_band_sizes); |
|
|
@ -1062,31 +1000,27 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
|
|
|
s->first_cpl_leak = s->eac3; |
|
|
|
s->first_cpl_leak = s->eac3; |
|
|
|
s->phase_flags_in_use = 0; |
|
|
|
s->phase_flags_in_use = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (!s->eac3) { |
|
|
|
|
|
|
|
if (!blk) { |
|
|
|
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must " |
|
|
|
|
|
|
|
"be present in block 0\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cpl_in_use = s->cpl_in_use[blk]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* coupling coordinates */ |
|
|
|
return 0; |
|
|
|
if (cpl_in_use) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline int coupling_coordinates(AC3DecodeContext *s, int blk) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
GetBitContext *bc = &s->gbc; |
|
|
|
|
|
|
|
int fbw_channels = s->fbw_channels; |
|
|
|
|
|
|
|
int ch, bnd; |
|
|
|
int cpl_coords_exist = 0; |
|
|
|
int cpl_coords_exist = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
if (s->channel_in_cpl[ch]) { |
|
|
|
if (s->channel_in_cpl[ch]) { |
|
|
|
if ((s->eac3 && s->first_cpl_coords[ch]) || get_bits1(gbc)) { |
|
|
|
if ((s->eac3 && s->first_cpl_coords[ch]) || get_bits1(bc)) { |
|
|
|
int master_cpl_coord, cpl_coord_exp, cpl_coord_mant; |
|
|
|
int master_cpl_coord, cpl_coord_exp, cpl_coord_mant; |
|
|
|
s->first_cpl_coords[ch] = 0; |
|
|
|
s->first_cpl_coords[ch] = 0; |
|
|
|
cpl_coords_exist = 1; |
|
|
|
cpl_coords_exist = 1; |
|
|
|
master_cpl_coord = 3 * get_bits(gbc, 2); |
|
|
|
master_cpl_coord = 3 * get_bits(bc, 2); |
|
|
|
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { |
|
|
|
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { |
|
|
|
cpl_coord_exp = get_bits(gbc, 4); |
|
|
|
cpl_coord_exp = get_bits(bc, 4); |
|
|
|
cpl_coord_mant = get_bits(gbc, 4); |
|
|
|
cpl_coord_mant = get_bits(bc, 4); |
|
|
|
if (cpl_coord_exp == 15) |
|
|
|
if (cpl_coord_exp == 15) |
|
|
|
s->cpl_coords[ch][bnd] = cpl_coord_mant << 22; |
|
|
|
s->cpl_coords[ch][bnd] = cpl_coord_mant << 22; |
|
|
|
else |
|
|
|
else |
|
|
@ -1104,11 +1038,102 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
/* phase flags */ |
|
|
|
/* phase flags */ |
|
|
|
if (channel_mode == AC3_CHMODE_STEREO && cpl_coords_exist) { |
|
|
|
if (s->channel_mode == AC3_CHMODE_STEREO && cpl_coords_exist) { |
|
|
|
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { |
|
|
|
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { |
|
|
|
s->phase_flags[bnd] = s->phase_flags_in_use? get_bits1(gbc) : 0; |
|
|
|
s->phase_flags[bnd] = s->phase_flags_in_use ? get_bits1(bc) : 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Decode a single audio block from the AC-3 bitstream. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static int decode_audio_block(AC3DecodeContext *s, int blk) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int fbw_channels = s->fbw_channels; |
|
|
|
|
|
|
|
int channel_mode = s->channel_mode; |
|
|
|
|
|
|
|
int i, bnd, seg, ch, ret; |
|
|
|
|
|
|
|
int different_transforms; |
|
|
|
|
|
|
|
int downmix_output; |
|
|
|
|
|
|
|
int cpl_in_use; |
|
|
|
|
|
|
|
GetBitContext *gbc = &s->gbc; |
|
|
|
|
|
|
|
uint8_t bit_alloc_stages[AC3_MAX_CHANNELS] = { 0 }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* block switch flags */ |
|
|
|
|
|
|
|
different_transforms = 0; |
|
|
|
|
|
|
|
if (s->block_switch_syntax) { |
|
|
|
|
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
|
|
|
|
s->block_switch[ch] = get_bits1(gbc); |
|
|
|
|
|
|
|
if (ch > 1 && s->block_switch[ch] != s->block_switch[1]) |
|
|
|
|
|
|
|
different_transforms = 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dithering flags */ |
|
|
|
|
|
|
|
if (s->dither_flag_syntax) { |
|
|
|
|
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
|
|
|
|
s->dither_flag[ch] = get_bits1(gbc); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dynamic range */ |
|
|
|
|
|
|
|
i = !s->channel_mode; |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
if (get_bits1(gbc)) { |
|
|
|
|
|
|
|
/* Allow asymmetric application of DRC when drc_scale > 1.
|
|
|
|
|
|
|
|
Amplification of quiet sounds is enhanced */ |
|
|
|
|
|
|
|
int range_bits = get_bits(gbc, 8); |
|
|
|
|
|
|
|
INTFLOAT range = AC3_RANGE(range_bits); |
|
|
|
|
|
|
|
if (range_bits <= 127 || s->drc_scale <= 1.0) |
|
|
|
|
|
|
|
s->dynamic_range[i] = AC3_DYNAMIC_RANGE(range); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
s->dynamic_range[i] = range; |
|
|
|
|
|
|
|
} else if (blk == 0) { |
|
|
|
|
|
|
|
s->dynamic_range[i] = AC3_DYNAMIC_RANGE1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while (i--); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* spectral extension strategy */ |
|
|
|
|
|
|
|
if (s->eac3 && (!blk || get_bits1(gbc))) { |
|
|
|
|
|
|
|
s->spx_in_use = get_bits1(gbc); |
|
|
|
|
|
|
|
if (s->spx_in_use) { |
|
|
|
|
|
|
|
if ((ret = spx_strategy(s, blk)) < 0) |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!s->eac3 || !s->spx_in_use) { |
|
|
|
|
|
|
|
s->spx_in_use = 0; |
|
|
|
|
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
|
|
|
|
s->channel_uses_spx[ch] = 0; |
|
|
|
|
|
|
|
s->first_spx_coords[ch] = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* spectral extension coordinates */ |
|
|
|
|
|
|
|
if (s->spx_in_use) |
|
|
|
|
|
|
|
spx_coordinates(s); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* coupling strategy */ |
|
|
|
|
|
|
|
if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) { |
|
|
|
|
|
|
|
if ((ret = coupling_strategy(s, blk, bit_alloc_stages)) < 0) |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} else if (!s->eac3) { |
|
|
|
|
|
|
|
if (!blk) { |
|
|
|
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must " |
|
|
|
|
|
|
|
"be present in block 0\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cpl_in_use = s->cpl_in_use[blk]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* coupling coordinates */ |
|
|
|
|
|
|
|
if (cpl_in_use) { |
|
|
|
|
|
|
|
if ((ret = coupling_coordinates(s, blk)) < 0) |
|
|
|
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* stereo rematrixing strategy and band structure */ |
|
|
|
/* stereo rematrixing strategy and band structure */ |
|
|
|