Commit 7c4dbd1d authored by Clément Bœsch's avatar Clément Bœsch

Merge commit 'a5ebe5d1'

* commit 'a5ebe5d1':
  ac3dec: Split spx-specific code from decode_audio_block()
Merged-by: 's avatarClément Bœsch <u@pkh.me>
parents 8636ccb5 a5ebe5d1
......@@ -801,76 +801,28 @@ static void decode_band_structure(GetBitContext *gbc, int blk, int eac3,
memcpy(band_sizes, bnd_sz, n_bands);
}
/**
* Decode a single audio block from the AC-3 bitstream.
*/
static int decode_audio_block(AC3DecodeContext *s, int blk)
static inline int spx_strategy(AC3DecodeContext *s, int blk)
{
GetBitContext *bc = &s->gbc;
int fbw_channels = s->fbw_channels;
int channel_mode = s->channel_mode;
int i, bnd, seg, 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) {
int dst_start_freq, dst_end_freq, src_start_freq,
start_subband, end_subband;
start_subband, end_subband, ch;
/* determine which channels use spx */
if (s->channel_mode == AC3_CHMODE_MONO) {
s->channel_uses_spx[1] = 1;
} else {
for (ch = 1; ch <= fbw_channels; ch++)
s->channel_uses_spx[ch] = get_bits1(gbc);
s->channel_uses_spx[ch] = get_bits1(bc);
}
/* get the frequency bins of the spx copy region and the spx start
and end subbands */
dst_start_freq = get_bits(gbc, 2);
start_subband = get_bits(gbc, 3) + 2;
dst_start_freq = get_bits(bc, 2);
start_subband = get_bits(bc, 3) + 2;
if (start_subband > 7)
start_subband += start_subband - 7;
end_subband = get_bits(gbc, 3) + 5;
end_subband = get_bits(bc, 3) + 5;
#if USE_FIXED
s->spx_dst_end_freq = end_freq_inv_tab[end_subband-5];
#endif
......@@ -897,32 +849,29 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
if (!USE_FIXED)
s->spx_dst_end_freq = dst_end_freq;
decode_band_structure(gbc, blk, s->eac3, 0,
decode_band_structure(bc, blk, s->eac3, 0,
start_subband, end_subband,
ff_eac3_default_spx_band_struct,
&s->num_spx_bands,
s->spx_band_sizes);
}
}
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;
}
}
return 0;
}
static inline void spx_coordinates(AC3DecodeContext *s)
{
GetBitContext *bc = &s->gbc;
int fbw_channels = s->fbw_channels;
int ch, bnd;
/* spectral extension coordinates */
if (s->spx_in_use) {
for (ch = 1; ch <= fbw_channels; ch++) {
if (s->channel_uses_spx[ch]) {
if (s->first_spx_coords[ch] || get_bits1(gbc)) {
if (s->first_spx_coords[ch] || get_bits1(bc)) {
INTFLOAT spx_blend;
int bin, master_spx_coord;
s->first_spx_coords[ch] = 0;
spx_blend = AC3_SPX_BLEND(get_bits(gbc, 5));
master_spx_coord = get_bits(gbc, 2) * 3;
spx_blend = AC3_SPX_BLEND(get_bits(bc, 5));
master_spx_coord = get_bits(bc, 2) * 3;
bin = s->spx_src_start_freq;
for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
......@@ -961,8 +910,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
bin += bandsize;
/* decode spx coordinates */
spx_coord_exp = get_bits(gbc, 4);
spx_coord_mant = get_bits(gbc, 2);
spx_coord_exp = get_bits(bc, 4);
spx_coord_mant = get_bits(bc, 2);
if (spx_coord_exp == 15) spx_coord_mant <<= 1;
else spx_coord_mant += 4;
spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord);
......@@ -984,8 +933,76 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
s->first_spx_coords[ch] = 1;
}
}
}
/**
* 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)) {
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment