|
|
@ -65,16 +65,16 @@ static float b5_mantissas[16]; |
|
|
|
* Quantization table: levels for symmetric. bits for asymmetric. |
|
|
|
* Quantization table: levels for symmetric. bits for asymmetric. |
|
|
|
* reference: Table 7.18 Mapping of bap to Quantizer |
|
|
|
* reference: Table 7.18 Mapping of bap to Quantizer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static const uint8_t qntztab[16] = { |
|
|
|
static const uint8_t quantization_tab[16] = { |
|
|
|
0, 3, 5, 7, 11, 15, |
|
|
|
0, 3, 5, 7, 11, 15, |
|
|
|
5, 6, 7, 8, 9, 10, 11, 12, 14, 16 |
|
|
|
5, 6, 7, 8, 9, 10, 11, 12, 14, 16 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** dynamic range table. converts codes to scale factors. */ |
|
|
|
/** dynamic range table. converts codes to scale factors. */ |
|
|
|
static float dynrng_tab[256]; |
|
|
|
static float dynamic_range_tab[256]; |
|
|
|
|
|
|
|
|
|
|
|
/** dialog normalization table */ |
|
|
|
/** dialog normalization table */ |
|
|
|
static float dialnorm_tab[32]; |
|
|
|
static float dialog_norm_tab[32]; |
|
|
|
|
|
|
|
|
|
|
|
/** Adjustments in dB gain */ |
|
|
|
/** Adjustments in dB gain */ |
|
|
|
#define LEVEL_MINUS_3DB 0.7071067811865476 |
|
|
|
#define LEVEL_MINUS_3DB 0.7071067811865476 |
|
|
@ -130,17 +130,17 @@ static const uint8_t ac3_default_coeffs[8][5][2] = { |
|
|
|
typedef struct { |
|
|
|
typedef struct { |
|
|
|
int channel_mode; ///< channel mode (acmod)
|
|
|
|
int channel_mode; ///< channel mode (acmod)
|
|
|
|
int dolby_surround_mode; ///< dolby surround mode
|
|
|
|
int dolby_surround_mode; ///< dolby surround mode
|
|
|
|
int blksw[AC3_MAX_CHANNELS]; ///< block switch flags
|
|
|
|
int block_switch[AC3_MAX_CHANNELS]; ///< block switch flags
|
|
|
|
int dithflag[AC3_MAX_CHANNELS]; ///< dither flags
|
|
|
|
int dither_flag[AC3_MAX_CHANNELS]; ///< dither flags
|
|
|
|
int dither_all; ///< true if all channels are dithered
|
|
|
|
int dither_all; ///< true if all channels are dithered
|
|
|
|
int cplinu; ///< coupling in use
|
|
|
|
int cpl_in_use; ///< coupling in use
|
|
|
|
int chincpl[AC3_MAX_CHANNELS]; ///< channel in coupling
|
|
|
|
int channel_in_cpl[AC3_MAX_CHANNELS]; ///< channel in coupling
|
|
|
|
int phsflginu; ///< phase flags in use
|
|
|
|
int phase_flags_in_use; ///< phase flags in use
|
|
|
|
int cplbndstrc[18]; ///< coupling band structure
|
|
|
|
int cpl_band_struct[18]; ///< coupling band structure
|
|
|
|
int rematstr; ///< rematrixing strategy
|
|
|
|
int rematrixing_strategy; ///< rematrixing strategy
|
|
|
|
int nrematbnd; ///< number of rematrixing bands
|
|
|
|
int num_rematrixing_bands; ///< number of rematrixing bands
|
|
|
|
int rematflg[4]; ///< rematrixing flags
|
|
|
|
int rematrixing_flags[4]; ///< rematrixing flags
|
|
|
|
int expstr[AC3_MAX_CHANNELS]; ///< exponent strategies
|
|
|
|
int exp_strategy[AC3_MAX_CHANNELS]; ///< exponent strategies
|
|
|
|
int snr_offset[AC3_MAX_CHANNELS]; ///< signal-to-noise ratio offsets
|
|
|
|
int snr_offset[AC3_MAX_CHANNELS]; ///< signal-to-noise ratio offsets
|
|
|
|
int fast_gain[AC3_MAX_CHANNELS]; ///< fast gain values (signal-to-mask ratio)
|
|
|
|
int fast_gain[AC3_MAX_CHANNELS]; ///< fast gain values (signal-to-mask ratio)
|
|
|
|
int dba_mode[AC3_MAX_CHANNELS]; ///< delta bit allocation mode
|
|
|
|
int dba_mode[AC3_MAX_CHANNELS]; ///< delta bit allocation mode
|
|
|
@ -153,21 +153,21 @@ typedef struct { |
|
|
|
int bit_rate; ///< stream bit rate, in bits-per-second
|
|
|
|
int bit_rate; ///< stream bit rate, in bits-per-second
|
|
|
|
int frame_size; ///< current frame size, in bytes
|
|
|
|
int frame_size; ///< current frame size, in bytes
|
|
|
|
|
|
|
|
|
|
|
|
int nchans; ///< number of total channels
|
|
|
|
int channels; ///< number of total channels
|
|
|
|
int nfchans; ///< number of full-bandwidth channels
|
|
|
|
int fbw_channels; ///< number of full-bandwidth channels
|
|
|
|
int lfe_on; ///< lfe channel in use
|
|
|
|
int lfe_on; ///< lfe channel in use
|
|
|
|
int lfe_ch; ///< index of LFE channel
|
|
|
|
int lfe_ch; ///< index of LFE channel
|
|
|
|
int output_mode; ///< output channel configuration
|
|
|
|
int output_mode; ///< output channel configuration
|
|
|
|
int out_channels; ///< number of output channels
|
|
|
|
int out_channels; ///< number of output channels
|
|
|
|
|
|
|
|
|
|
|
|
float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients
|
|
|
|
float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients
|
|
|
|
float dialnorm[2]; ///< dialog normalization
|
|
|
|
float dialog_norm[2]; ///< dialog normalization
|
|
|
|
float dynrng[2]; ///< dynamic range
|
|
|
|
float dynamic_range[2]; ///< dynamic range
|
|
|
|
float cplco[AC3_MAX_CHANNELS][18]; ///< coupling coordinates
|
|
|
|
float cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates
|
|
|
|
int ncplbnd; ///< number of coupling bands
|
|
|
|
int num_cpl_bands; ///< number of coupling bands
|
|
|
|
int ncplsubnd; ///< number of coupling sub bands
|
|
|
|
int num_cpl_subbands; ///< number of coupling sub bands
|
|
|
|
int startmant[AC3_MAX_CHANNELS]; ///< start frequency bin
|
|
|
|
int start_freq[AC3_MAX_CHANNELS]; ///< start frequency bin
|
|
|
|
int endmant[AC3_MAX_CHANNELS]; ///< end frequency bin
|
|
|
|
int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin
|
|
|
|
AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters
|
|
|
|
AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters
|
|
|
|
|
|
|
|
|
|
|
|
int8_t dexps[AC3_MAX_CHANNELS][256]; ///< decoded exponents
|
|
|
|
int8_t dexps[AC3_MAX_CHANNELS][256]; ///< decoded exponents
|
|
|
@ -273,16 +273,16 @@ static void ac3_tables_init(void) |
|
|
|
reference: Section 7.7.1 Dynamic Range Control */ |
|
|
|
reference: Section 7.7.1 Dynamic Range Control */ |
|
|
|
for(i=0; i<256; i++) { |
|
|
|
for(i=0; i<256; i++) { |
|
|
|
int v = (i >> 5) - ((i >> 7) << 3) - 5; |
|
|
|
int v = (i >> 5) - ((i >> 7) << 3) - 5; |
|
|
|
dynrng_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); |
|
|
|
dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* generate dialog normalization table
|
|
|
|
/* generate dialog normalization table
|
|
|
|
references: Section 5.4.2.8 dialnorm |
|
|
|
references: Section 5.4.2.8 dialnorm |
|
|
|
Section 7.6 Dialogue Normalization */ |
|
|
|
Section 7.6 Dialogue Normalization */ |
|
|
|
for(i=1; i<32; i++) { |
|
|
|
for(i=1; i<32; i++) { |
|
|
|
dialnorm_tab[i] = expf((i-31) * M_LN10 / 20.0f); |
|
|
|
dialog_norm_tab[i] = expf((i-31) * M_LN10 / 20.0f); |
|
|
|
} |
|
|
|
} |
|
|
|
dialnorm_tab[0] = dialnorm_tab[31]; |
|
|
|
dialog_norm_tab[0] = dialog_norm_tab[31]; |
|
|
|
|
|
|
|
|
|
|
|
/* generate scale factors for exponents and asymmetrical dequantization
|
|
|
|
/* generate scale factors for exponents and asymmetrical dequantization
|
|
|
|
reference: Section 7.3.2 Expansion of Mantissas for Asymmetric Quantization */ |
|
|
|
reference: Section 7.3.2 Expansion of Mantissas for Asymmetric Quantization */ |
|
|
@ -353,13 +353,13 @@ static int ac3_parse_header(AC3DecodeContext *ctx) |
|
|
|
ctx->bit_alloc_params.sr_shift = hdr.sr_shift; |
|
|
|
ctx->bit_alloc_params.sr_shift = hdr.sr_shift; |
|
|
|
ctx->sampling_rate = hdr.sample_rate; |
|
|
|
ctx->sampling_rate = hdr.sample_rate; |
|
|
|
ctx->bit_rate = hdr.bit_rate; |
|
|
|
ctx->bit_rate = hdr.bit_rate; |
|
|
|
ctx->nchans = hdr.channels; |
|
|
|
ctx->channels = hdr.channels; |
|
|
|
ctx->nfchans = ctx->nchans - ctx->lfe_on; |
|
|
|
ctx->fbw_channels = ctx->channels - ctx->lfe_on; |
|
|
|
ctx->lfe_ch = ctx->nfchans + 1; |
|
|
|
ctx->lfe_ch = ctx->fbw_channels + 1; |
|
|
|
ctx->frame_size = hdr.frame_size; |
|
|
|
ctx->frame_size = hdr.frame_size; |
|
|
|
|
|
|
|
|
|
|
|
/* set default output to all source channels */ |
|
|
|
/* set default output to all source channels */ |
|
|
|
ctx->out_channels = ctx->nchans; |
|
|
|
ctx->out_channels = ctx->channels; |
|
|
|
ctx->output_mode = ctx->channel_mode; |
|
|
|
ctx->output_mode = ctx->channel_mode; |
|
|
|
if(ctx->lfe_on) |
|
|
|
if(ctx->lfe_on) |
|
|
|
ctx->output_mode |= AC3_OUTPUT_LFEON; |
|
|
|
ctx->output_mode |= AC3_OUTPUT_LFEON; |
|
|
@ -382,7 +382,7 @@ static int ac3_parse_header(AC3DecodeContext *ctx) |
|
|
|
/* read the rest of the bsi. read twice for dual mono mode. */ |
|
|
|
/* read the rest of the bsi. read twice for dual mono mode. */ |
|
|
|
i = !(ctx->channel_mode); |
|
|
|
i = !(ctx->channel_mode); |
|
|
|
do { |
|
|
|
do { |
|
|
|
ctx->dialnorm[i] = dialnorm_tab[get_bits(gb, 5)]; // dialog normalization
|
|
|
|
ctx->dialog_norm[i] = dialog_norm_tab[get_bits(gb, 5)]; // dialog normalization
|
|
|
|
if (get_bits1(gb)) |
|
|
|
if (get_bits1(gb)) |
|
|
|
skip_bits(gb, 8); //skip compression
|
|
|
|
skip_bits(gb, 8); //skip compression
|
|
|
|
if (get_bits1(gb)) |
|
|
|
if (get_bits1(gb)) |
|
|
@ -410,7 +410,7 @@ static int ac3_parse_header(AC3DecodeContext *ctx) |
|
|
|
|
|
|
|
|
|
|
|
/* set stereo downmixing coefficients
|
|
|
|
/* set stereo downmixing coefficients
|
|
|
|
reference: Section 7.8.2 Downmixing Into Two Channels */ |
|
|
|
reference: Section 7.8.2 Downmixing Into Two Channels */ |
|
|
|
for(i=0; i<ctx->nfchans; i++) { |
|
|
|
for(i=0; i<ctx->fbw_channels; i++) { |
|
|
|
ctx->downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[ctx->channel_mode][i][0]]; |
|
|
|
ctx->downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[ctx->channel_mode][i][0]]; |
|
|
|
ctx->downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[ctx->channel_mode][i][1]]; |
|
|
|
ctx->downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[ctx->channel_mode][i][1]]; |
|
|
|
} |
|
|
|
} |
|
|
@ -433,15 +433,15 @@ static int ac3_parse_header(AC3DecodeContext *ctx) |
|
|
|
* Decode the grouped exponents according to exponent strategy. |
|
|
|
* Decode the grouped exponents according to exponent strategy. |
|
|
|
* reference: Section 7.1.3 Exponent Decoding |
|
|
|
* reference: Section 7.1.3 Exponent Decoding |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void decode_exponents(GetBitContext *gb, int expstr, int ngrps, |
|
|
|
static void decode_exponents(GetBitContext *gb, int exp_strategy, int ngrps, |
|
|
|
uint8_t absexp, int8_t *dexps) |
|
|
|
uint8_t absexp, int8_t *dexps) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i, j, grp, grpsize; |
|
|
|
int i, j, grp, group_size; |
|
|
|
int dexp[256]; |
|
|
|
int dexp[256]; |
|
|
|
int expacc, prevexp; |
|
|
|
int expacc, prevexp; |
|
|
|
|
|
|
|
|
|
|
|
/* unpack groups */ |
|
|
|
/* unpack groups */ |
|
|
|
grpsize = expstr + (expstr == EXP_D45); |
|
|
|
group_size = exp_strategy + (exp_strategy == EXP_D45); |
|
|
|
for(grp=0,i=0; grp<ngrps; grp++) { |
|
|
|
for(grp=0,i=0; grp<ngrps; grp++) { |
|
|
|
expacc = get_bits(gb, 7); |
|
|
|
expacc = get_bits(gb, 7); |
|
|
|
dexp[i++] = exp_ungroup_tab[expacc][0]; |
|
|
|
dexp[i++] = exp_ungroup_tab[expacc][0]; |
|
|
@ -453,8 +453,8 @@ static void decode_exponents(GetBitContext *gb, int expstr, int ngrps, |
|
|
|
prevexp = absexp; |
|
|
|
prevexp = absexp; |
|
|
|
for(i=0; i<ngrps*3; i++) { |
|
|
|
for(i=0; i<ngrps*3; i++) { |
|
|
|
prevexp = av_clip(prevexp + dexp[i]-2, 0, 24); |
|
|
|
prevexp = av_clip(prevexp + dexp[i]-2, 0, 24); |
|
|
|
for(j=0; j<grpsize; j++) { |
|
|
|
for(j=0; j<group_size; j++) { |
|
|
|
dexps[(i*grpsize)+j] = prevexp; |
|
|
|
dexps[(i*group_size)+j] = prevexp; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -469,18 +469,18 @@ static void uncouple_channels(AC3DecodeContext *ctx) |
|
|
|
int i, j, ch, bnd, subbnd; |
|
|
|
int i, j, ch, bnd, subbnd; |
|
|
|
|
|
|
|
|
|
|
|
subbnd = -1; |
|
|
|
subbnd = -1; |
|
|
|
i = ctx->startmant[CPL_CH]; |
|
|
|
i = ctx->start_freq[CPL_CH]; |
|
|
|
for(bnd=0; bnd<ctx->ncplbnd; bnd++) { |
|
|
|
for(bnd=0; bnd<ctx->num_cpl_bands; bnd++) { |
|
|
|
do { |
|
|
|
do { |
|
|
|
subbnd++; |
|
|
|
subbnd++; |
|
|
|
for(j=0; j<12; j++) { |
|
|
|
for(j=0; j<12; j++) { |
|
|
|
for(ch=1; ch<=ctx->nfchans; ch++) { |
|
|
|
for(ch=1; ch<=ctx->fbw_channels; ch++) { |
|
|
|
if(ctx->chincpl[ch]) |
|
|
|
if(ctx->channel_in_cpl[ch]) |
|
|
|
ctx->transform_coeffs[ch][i] = ctx->transform_coeffs[CPL_CH][i] * ctx->cplco[ch][bnd] * 8.0f; |
|
|
|
ctx->transform_coeffs[ch][i] = ctx->transform_coeffs[CPL_CH][i] * ctx->cpl_coords[ch][bnd] * 8.0f; |
|
|
|
} |
|
|
|
} |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
} |
|
|
|
} |
|
|
|
} while(ctx->cplbndstrc[subbnd]); |
|
|
|
} while(ctx->cpl_band_struct[subbnd]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -511,8 +511,8 @@ static int get_transform_coeffs_ch(AC3DecodeContext *ctx, int ch_index, mant_gro |
|
|
|
exps = ctx->dexps[ch_index]; |
|
|
|
exps = ctx->dexps[ch_index]; |
|
|
|
bap = ctx->bap[ch_index]; |
|
|
|
bap = ctx->bap[ch_index]; |
|
|
|
coeffs = ctx->transform_coeffs[ch_index]; |
|
|
|
coeffs = ctx->transform_coeffs[ch_index]; |
|
|
|
start = ctx->startmant[ch_index]; |
|
|
|
start = ctx->start_freq[ch_index]; |
|
|
|
end = ctx->endmant[ch_index]; |
|
|
|
end = ctx->end_freq[ch_index]; |
|
|
|
|
|
|
|
|
|
|
|
for (i = start; i < end; i++) { |
|
|
|
for (i = start; i < end; i++) { |
|
|
|
tbap = bap[i]; |
|
|
|
tbap = bap[i]; |
|
|
@ -563,7 +563,7 @@ static int get_transform_coeffs_ch(AC3DecodeContext *ctx, int ch_index, mant_gro |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
/* asymmetric dequantization */ |
|
|
|
/* asymmetric dequantization */ |
|
|
|
coeffs[i] = get_sbits(gb, qntztab[tbap]) * scale_factors[qntztab[tbap]-1]; |
|
|
|
coeffs[i] = get_sbits(gb, quantization_tab[tbap]) * scale_factors[quantization_tab[tbap]-1]; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
coeffs[i] *= scale_factors[exps[i]]; |
|
|
|
coeffs[i] *= scale_factors[exps[i]]; |
|
|
@ -582,21 +582,21 @@ static void remove_dithering(AC3DecodeContext *ctx) { |
|
|
|
float *coeffs; |
|
|
|
float *coeffs; |
|
|
|
uint8_t *bap; |
|
|
|
uint8_t *bap; |
|
|
|
|
|
|
|
|
|
|
|
for(ch=1; ch<=ctx->nfchans; ch++) { |
|
|
|
for(ch=1; ch<=ctx->fbw_channels; ch++) { |
|
|
|
if(!ctx->dithflag[ch]) { |
|
|
|
if(!ctx->dither_flag[ch]) { |
|
|
|
coeffs = ctx->transform_coeffs[ch]; |
|
|
|
coeffs = ctx->transform_coeffs[ch]; |
|
|
|
bap = ctx->bap[ch]; |
|
|
|
bap = ctx->bap[ch]; |
|
|
|
if(ctx->chincpl[ch]) |
|
|
|
if(ctx->channel_in_cpl[ch]) |
|
|
|
end = ctx->startmant[CPL_CH]; |
|
|
|
end = ctx->start_freq[CPL_CH]; |
|
|
|
else |
|
|
|
else |
|
|
|
end = ctx->endmant[ch]; |
|
|
|
end = ctx->end_freq[ch]; |
|
|
|
for(i=0; i<end; i++) { |
|
|
|
for(i=0; i<end; i++) { |
|
|
|
if(bap[i] == 0) |
|
|
|
if(bap[i] == 0) |
|
|
|
coeffs[i] = 0.0f; |
|
|
|
coeffs[i] = 0.0f; |
|
|
|
} |
|
|
|
} |
|
|
|
if(ctx->chincpl[ch]) { |
|
|
|
if(ctx->channel_in_cpl[ch]) { |
|
|
|
bap = ctx->bap[CPL_CH]; |
|
|
|
bap = ctx->bap[CPL_CH]; |
|
|
|
for(; i<ctx->endmant[CPL_CH]; i++) { |
|
|
|
for(; i<ctx->end_freq[CPL_CH]; i++) { |
|
|
|
if(bap[i] == 0) |
|
|
|
if(bap[i] == 0) |
|
|
|
coeffs[i] = 0.0f; |
|
|
|
coeffs[i] = 0.0f; |
|
|
|
} |
|
|
|
} |
|
|
@ -616,13 +616,13 @@ static int get_transform_coeffs(AC3DecodeContext * ctx) |
|
|
|
|
|
|
|
|
|
|
|
m.b1ptr = m.b2ptr = m.b4ptr = 3; |
|
|
|
m.b1ptr = m.b2ptr = m.b4ptr = 3; |
|
|
|
|
|
|
|
|
|
|
|
for (ch = 1; ch <= ctx->nchans; ch++) { |
|
|
|
for (ch = 1; ch <= ctx->channels; ch++) { |
|
|
|
/* transform coefficients for full-bandwidth channel */ |
|
|
|
/* transform coefficients for full-bandwidth channel */ |
|
|
|
if (get_transform_coeffs_ch(ctx, ch, &m)) |
|
|
|
if (get_transform_coeffs_ch(ctx, ch, &m)) |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
/* tranform coefficients for coupling channel come right after the
|
|
|
|
/* tranform coefficients for coupling channel come right after the
|
|
|
|
coefficients for the first coupled channel*/ |
|
|
|
coefficients for the first coupled channel*/ |
|
|
|
if (ctx->chincpl[ch]) { |
|
|
|
if (ctx->channel_in_cpl[ch]) { |
|
|
|
if (!got_cplchan) { |
|
|
|
if (!got_cplchan) { |
|
|
|
if (get_transform_coeffs_ch(ctx, CPL_CH, &m)) { |
|
|
|
if (get_transform_coeffs_ch(ctx, CPL_CH, &m)) { |
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "error in decoupling channels\n"); |
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "error in decoupling channels\n"); |
|
|
@ -631,9 +631,9 @@ static int get_transform_coeffs(AC3DecodeContext * ctx) |
|
|
|
uncouple_channels(ctx); |
|
|
|
uncouple_channels(ctx); |
|
|
|
got_cplchan = 1; |
|
|
|
got_cplchan = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
end = ctx->endmant[CPL_CH]; |
|
|
|
end = ctx->end_freq[CPL_CH]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
end = ctx->endmant[ch]; |
|
|
|
end = ctx->end_freq[ch]; |
|
|
|
} |
|
|
|
} |
|
|
|
do |
|
|
|
do |
|
|
|
ctx->transform_coeffs[ch][end] = 0; |
|
|
|
ctx->transform_coeffs[ch][end] = 0; |
|
|
@ -657,10 +657,10 @@ static void do_rematrixing(AC3DecodeContext *ctx) |
|
|
|
int end, bndend; |
|
|
|
int end, bndend; |
|
|
|
float tmp0, tmp1; |
|
|
|
float tmp0, tmp1; |
|
|
|
|
|
|
|
|
|
|
|
end = FFMIN(ctx->endmant[1], ctx->endmant[2]); |
|
|
|
end = FFMIN(ctx->end_freq[1], ctx->end_freq[2]); |
|
|
|
|
|
|
|
|
|
|
|
for(bnd=0; bnd<ctx->nrematbnd; bnd++) { |
|
|
|
for(bnd=0; bnd<ctx->num_rematrixing_bands; bnd++) { |
|
|
|
if(ctx->rematflg[bnd]) { |
|
|
|
if(ctx->rematrixing_flags[bnd]) { |
|
|
|
bndend = FFMIN(end, rematrix_band_tab[bnd+1]); |
|
|
|
bndend = FFMIN(end, rematrix_band_tab[bnd+1]); |
|
|
|
for(i=rematrix_band_tab[bnd]; i<bndend; i++) { |
|
|
|
for(i=rematrix_band_tab[bnd]; i<bndend; i++) { |
|
|
|
tmp0 = ctx->transform_coeffs[1][i]; |
|
|
|
tmp0 = ctx->transform_coeffs[1][i]; |
|
|
@ -721,15 +721,15 @@ static void do_imdct_256(AC3DecodeContext *ctx, int chindex) |
|
|
|
static inline void do_imdct(AC3DecodeContext *ctx) |
|
|
|
static inline void do_imdct(AC3DecodeContext *ctx) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int ch; |
|
|
|
int ch; |
|
|
|
int nchans; |
|
|
|
int channels; |
|
|
|
|
|
|
|
|
|
|
|
/* Don't perform the IMDCT on the LFE channel unless it's used in the output */ |
|
|
|
/* Don't perform the IMDCT on the LFE channel unless it's used in the output */ |
|
|
|
nchans = ctx->nfchans; |
|
|
|
channels = ctx->fbw_channels; |
|
|
|
if(ctx->output_mode & AC3_OUTPUT_LFEON) |
|
|
|
if(ctx->output_mode & AC3_OUTPUT_LFEON) |
|
|
|
nchans++; |
|
|
|
channels++; |
|
|
|
|
|
|
|
|
|
|
|
for (ch=1; ch<=nchans; ch++) { |
|
|
|
for (ch=1; ch<=channels; ch++) { |
|
|
|
if (ctx->blksw[ch]) { |
|
|
|
if (ctx->block_switch[ch]) { |
|
|
|
do_imdct_256(ctx, ch); |
|
|
|
do_imdct_256(ctx, ch); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output, |
|
|
|
ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output, |
|
|
@ -750,7 +750,7 @@ static inline void do_imdct(AC3DecodeContext *ctx) |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Downmix the output to mono or stereo. |
|
|
|
* Downmix the output to mono or stereo. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void ac3_downmix(float samples[AC3_MAX_CHANNELS][256], int nfchans, |
|
|
|
static void ac3_downmix(float samples[AC3_MAX_CHANNELS][256], int fbw_channels, |
|
|
|
int output_mode, float coef[AC3_MAX_CHANNELS][2]) |
|
|
|
int output_mode, float coef[AC3_MAX_CHANNELS][2]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i, j; |
|
|
|
int i, j; |
|
|
@ -758,7 +758,7 @@ static void ac3_downmix(float samples[AC3_MAX_CHANNELS][256], int nfchans, |
|
|
|
|
|
|
|
|
|
|
|
for(i=0; i<256; i++) { |
|
|
|
for(i=0; i<256; i++) { |
|
|
|
v0 = v1 = s0 = s1 = 0.0f; |
|
|
|
v0 = v1 = s0 = s1 = 0.0f; |
|
|
|
for(j=0; j<nfchans; j++) { |
|
|
|
for(j=0; j<fbw_channels; j++) { |
|
|
|
v0 += samples[j][i] * coef[j][0]; |
|
|
|
v0 += samples[j][i] * coef[j][0]; |
|
|
|
v1 += samples[j][i] * coef[j][1]; |
|
|
|
v1 += samples[j][i] * coef[j][1]; |
|
|
|
s0 += coef[j][0]; |
|
|
|
s0 += coef[j][0]; |
|
|
@ -780,7 +780,7 @@ static void ac3_downmix(float samples[AC3_MAX_CHANNELS][256], int nfchans, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int nfchans = ctx->nfchans; |
|
|
|
int fbw_channels = ctx->fbw_channels; |
|
|
|
int channel_mode = ctx->channel_mode; |
|
|
|
int channel_mode = ctx->channel_mode; |
|
|
|
int i, bnd, seg, ch; |
|
|
|
int i, bnd, seg, ch; |
|
|
|
GetBitContext *gb = &ctx->gb; |
|
|
|
GetBitContext *gb = &ctx->gb; |
|
|
@ -789,14 +789,14 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); |
|
|
|
memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); |
|
|
|
|
|
|
|
|
|
|
|
/* block switch flags */ |
|
|
|
/* block switch flags */ |
|
|
|
for (ch = 1; ch <= nfchans; ch++) |
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) |
|
|
|
ctx->blksw[ch] = get_bits1(gb); |
|
|
|
ctx->block_switch[ch] = get_bits1(gb); |
|
|
|
|
|
|
|
|
|
|
|
/* dithering flags */ |
|
|
|
/* dithering flags */ |
|
|
|
ctx->dither_all = 1; |
|
|
|
ctx->dither_all = 1; |
|
|
|
for (ch = 1; ch <= nfchans; ch++) { |
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
ctx->dithflag[ch] = get_bits1(gb); |
|
|
|
ctx->dither_flag[ch] = get_bits1(gb); |
|
|
|
if(!ctx->dithflag[ch]) |
|
|
|
if(!ctx->dither_flag[ch]) |
|
|
|
ctx->dither_all = 0; |
|
|
|
ctx->dither_all = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -804,142 +804,142 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
i = !(ctx->channel_mode); |
|
|
|
i = !(ctx->channel_mode); |
|
|
|
do { |
|
|
|
do { |
|
|
|
if(get_bits1(gb)) { |
|
|
|
if(get_bits1(gb)) { |
|
|
|
ctx->dynrng[i] = dynrng_tab[get_bits(gb, 8)]; |
|
|
|
ctx->dynamic_range[i] = dynamic_range_tab[get_bits(gb, 8)]; |
|
|
|
} else if(blk == 0) { |
|
|
|
} else if(blk == 0) { |
|
|
|
ctx->dynrng[i] = 1.0f; |
|
|
|
ctx->dynamic_range[i] = 1.0f; |
|
|
|
} |
|
|
|
} |
|
|
|
} while(i--); |
|
|
|
} while(i--); |
|
|
|
|
|
|
|
|
|
|
|
/* coupling strategy */ |
|
|
|
/* coupling strategy */ |
|
|
|
if (get_bits1(gb)) { |
|
|
|
if (get_bits1(gb)) { |
|
|
|
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
|
|
|
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
|
|
|
ctx->cplinu = get_bits1(gb); |
|
|
|
ctx->cpl_in_use = get_bits1(gb); |
|
|
|
if (ctx->cplinu) { |
|
|
|
if (ctx->cpl_in_use) { |
|
|
|
/* coupling in use */ |
|
|
|
/* coupling in use */ |
|
|
|
int cplbegf, cplendf; |
|
|
|
int cpl_begin_freq, cpl_end_freq; |
|
|
|
|
|
|
|
|
|
|
|
/* determine which channels are coupled */ |
|
|
|
/* determine which channels are coupled */ |
|
|
|
for (ch = 1; ch <= nfchans; ch++) |
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) |
|
|
|
ctx->chincpl[ch] = get_bits1(gb); |
|
|
|
ctx->channel_in_cpl[ch] = get_bits1(gb); |
|
|
|
|
|
|
|
|
|
|
|
/* phase flags in use */ |
|
|
|
/* phase flags in use */ |
|
|
|
if (channel_mode == AC3_CHMODE_STEREO) |
|
|
|
if (channel_mode == AC3_CHMODE_STEREO) |
|
|
|
ctx->phsflginu = get_bits1(gb); |
|
|
|
ctx->phase_flags_in_use = get_bits1(gb); |
|
|
|
|
|
|
|
|
|
|
|
/* coupling frequency range and band structure */ |
|
|
|
/* coupling frequency range and band structure */ |
|
|
|
cplbegf = get_bits(gb, 4); |
|
|
|
cpl_begin_freq = get_bits(gb, 4); |
|
|
|
cplendf = get_bits(gb, 4); |
|
|
|
cpl_end_freq = get_bits(gb, 4); |
|
|
|
if (3 + cplendf - cplbegf < 0) { |
|
|
|
if (3 + cpl_end_freq - cpl_begin_freq < 0) { |
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "cplendf = %d < cplbegf = %d\n", cplendf, cplbegf); |
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "3+cplendf = %d < cplbegf = %d\n", 3+cpl_end_freq, cpl_begin_freq); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
ctx->ncplbnd = ctx->ncplsubnd = 3 + cplendf - cplbegf; |
|
|
|
ctx->num_cpl_bands = ctx->num_cpl_subbands = 3 + cpl_end_freq - cpl_begin_freq; |
|
|
|
ctx->startmant[CPL_CH] = cplbegf * 12 + 37; |
|
|
|
ctx->start_freq[CPL_CH] = cpl_begin_freq * 12 + 37; |
|
|
|
ctx->endmant[CPL_CH] = cplendf * 12 + 73; |
|
|
|
ctx->end_freq[CPL_CH] = cpl_end_freq * 12 + 73; |
|
|
|
for (bnd = 0; bnd < ctx->ncplsubnd - 1; bnd++) { |
|
|
|
for (bnd = 0; bnd < ctx->num_cpl_subbands - 1; bnd++) { |
|
|
|
if (get_bits1(gb)) { |
|
|
|
if (get_bits1(gb)) { |
|
|
|
ctx->cplbndstrc[bnd] = 1; |
|
|
|
ctx->cpl_band_struct[bnd] = 1; |
|
|
|
ctx->ncplbnd--; |
|
|
|
ctx->num_cpl_bands--; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
/* coupling not in use */ |
|
|
|
/* coupling not in use */ |
|
|
|
for (ch = 1; ch <= nfchans; ch++) |
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) |
|
|
|
ctx->chincpl[ch] = 0; |
|
|
|
ctx->channel_in_cpl[ch] = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* coupling coordinates */ |
|
|
|
/* coupling coordinates */ |
|
|
|
if (ctx->cplinu) { |
|
|
|
if (ctx->cpl_in_use) { |
|
|
|
int cplcoe = 0; |
|
|
|
int cpl_coords_exist = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (ch = 1; ch <= nfchans; ch++) { |
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
if (ctx->chincpl[ch]) { |
|
|
|
if (ctx->channel_in_cpl[ch]) { |
|
|
|
if (get_bits1(gb)) { |
|
|
|
if (get_bits1(gb)) { |
|
|
|
int mstrcplco, cplcoexp, cplcomant; |
|
|
|
int master_cpl_coord, cpl_coord_exp, cpl_coord_mant; |
|
|
|
cplcoe = 1; |
|
|
|
cpl_coords_exist = 1; |
|
|
|
mstrcplco = 3 * get_bits(gb, 2); |
|
|
|
master_cpl_coord = 3 * get_bits(gb, 2); |
|
|
|
for (bnd = 0; bnd < ctx->ncplbnd; bnd++) { |
|
|
|
for (bnd = 0; bnd < ctx->num_cpl_bands; bnd++) { |
|
|
|
cplcoexp = get_bits(gb, 4); |
|
|
|
cpl_coord_exp = get_bits(gb, 4); |
|
|
|
cplcomant = get_bits(gb, 4); |
|
|
|
cpl_coord_mant = get_bits(gb, 4); |
|
|
|
if (cplcoexp == 15) |
|
|
|
if (cpl_coord_exp == 15) |
|
|
|
ctx->cplco[ch][bnd] = cplcomant / 16.0f; |
|
|
|
ctx->cpl_coords[ch][bnd] = cpl_coord_mant / 16.0f; |
|
|
|
else |
|
|
|
else |
|
|
|
ctx->cplco[ch][bnd] = (cplcomant + 16.0f) / 32.0f; |
|
|
|
ctx->cpl_coords[ch][bnd] = (cpl_coord_mant + 16.0f) / 32.0f; |
|
|
|
ctx->cplco[ch][bnd] *= scale_factors[cplcoexp + mstrcplco]; |
|
|
|
ctx->cpl_coords[ch][bnd] *= scale_factors[cpl_coord_exp + master_cpl_coord]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
/* phase flags */ |
|
|
|
/* phase flags */ |
|
|
|
if (channel_mode == AC3_CHMODE_STEREO && ctx->phsflginu && cplcoe) { |
|
|
|
if (channel_mode == AC3_CHMODE_STEREO && ctx->phase_flags_in_use && cpl_coords_exist) { |
|
|
|
for (bnd = 0; bnd < ctx->ncplbnd; bnd++) { |
|
|
|
for (bnd = 0; bnd < ctx->num_cpl_bands; bnd++) { |
|
|
|
if (get_bits1(gb)) |
|
|
|
if (get_bits1(gb)) |
|
|
|
ctx->cplco[2][bnd] = -ctx->cplco[2][bnd]; |
|
|
|
ctx->cpl_coords[2][bnd] = -ctx->cpl_coords[2][bnd]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* stereo rematrixing strategy and band structure */ |
|
|
|
/* stereo rematrixing strategy and band structure */ |
|
|
|
if (channel_mode == AC3_CHMODE_STEREO) { |
|
|
|
if (channel_mode == AC3_CHMODE_STEREO) { |
|
|
|
ctx->rematstr = get_bits1(gb); |
|
|
|
ctx->rematrixing_strategy = get_bits1(gb); |
|
|
|
if (ctx->rematstr) { |
|
|
|
if (ctx->rematrixing_strategy) { |
|
|
|
ctx->nrematbnd = 4; |
|
|
|
ctx->num_rematrixing_bands = 4; |
|
|
|
if(ctx->cplinu && ctx->startmant[CPL_CH] <= 61) |
|
|
|
if(ctx->cpl_in_use && ctx->start_freq[CPL_CH] <= 61) |
|
|
|
ctx->nrematbnd -= 1 + (ctx->startmant[CPL_CH] == 37); |
|
|
|
ctx->num_rematrixing_bands -= 1 + (ctx->start_freq[CPL_CH] == 37); |
|
|
|
for(bnd=0; bnd<ctx->nrematbnd; bnd++) |
|
|
|
for(bnd=0; bnd<ctx->num_rematrixing_bands; bnd++) |
|
|
|
ctx->rematflg[bnd] = get_bits1(gb); |
|
|
|
ctx->rematrixing_flags[bnd] = get_bits1(gb); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* exponent strategies for each channel */ |
|
|
|
/* exponent strategies for each channel */ |
|
|
|
ctx->expstr[CPL_CH] = EXP_REUSE; |
|
|
|
ctx->exp_strategy[CPL_CH] = EXP_REUSE; |
|
|
|
ctx->expstr[ctx->lfe_ch] = EXP_REUSE; |
|
|
|
ctx->exp_strategy[ctx->lfe_ch] = EXP_REUSE; |
|
|
|
for (ch = !ctx->cplinu; ch <= ctx->nchans; ch++) { |
|
|
|
for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) { |
|
|
|
if(ch == ctx->lfe_ch) |
|
|
|
if(ch == ctx->lfe_ch) |
|
|
|
ctx->expstr[ch] = get_bits(gb, 1); |
|
|
|
ctx->exp_strategy[ch] = get_bits(gb, 1); |
|
|
|
else |
|
|
|
else |
|
|
|
ctx->expstr[ch] = get_bits(gb, 2); |
|
|
|
ctx->exp_strategy[ch] = get_bits(gb, 2); |
|
|
|
if(ctx->expstr[ch] != EXP_REUSE) |
|
|
|
if(ctx->exp_strategy[ch] != EXP_REUSE) |
|
|
|
bit_alloc_stages[ch] = 3; |
|
|
|
bit_alloc_stages[ch] = 3; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* channel bandwidth */ |
|
|
|
/* channel bandwidth */ |
|
|
|
for (ch = 1; ch <= nfchans; ch++) { |
|
|
|
for (ch = 1; ch <= fbw_channels; ch++) { |
|
|
|
ctx->startmant[ch] = 0; |
|
|
|
ctx->start_freq[ch] = 0; |
|
|
|
if (ctx->expstr[ch] != EXP_REUSE) { |
|
|
|
if (ctx->exp_strategy[ch] != EXP_REUSE) { |
|
|
|
int prev = ctx->endmant[ch]; |
|
|
|
int prev = ctx->end_freq[ch]; |
|
|
|
if (ctx->chincpl[ch]) |
|
|
|
if (ctx->channel_in_cpl[ch]) |
|
|
|
ctx->endmant[ch] = ctx->startmant[CPL_CH]; |
|
|
|
ctx->end_freq[ch] = ctx->start_freq[CPL_CH]; |
|
|
|
else { |
|
|
|
else { |
|
|
|
int chbwcod = get_bits(gb, 6); |
|
|
|
int bandwidth_code = get_bits(gb, 6); |
|
|
|
if (chbwcod > 60) { |
|
|
|
if (bandwidth_code > 60) { |
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "chbwcod = %d > 60", chbwcod); |
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60", bandwidth_code); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
ctx->endmant[ch] = chbwcod * 3 + 73; |
|
|
|
ctx->end_freq[ch] = bandwidth_code * 3 + 73; |
|
|
|
} |
|
|
|
} |
|
|
|
if(blk > 0 && ctx->endmant[ch] != prev) |
|
|
|
if(blk > 0 && ctx->end_freq[ch] != prev) |
|
|
|
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
|
|
|
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ctx->startmant[ctx->lfe_ch] = 0; |
|
|
|
ctx->start_freq[ctx->lfe_ch] = 0; |
|
|
|
ctx->endmant[ctx->lfe_ch] = 7; |
|
|
|
ctx->end_freq[ctx->lfe_ch] = 7; |
|
|
|
|
|
|
|
|
|
|
|
/* decode exponents for each channel */ |
|
|
|
/* decode exponents for each channel */ |
|
|
|
for (ch = !ctx->cplinu; ch <= ctx->nchans; ch++) { |
|
|
|
for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) { |
|
|
|
if (ctx->expstr[ch] != EXP_REUSE) { |
|
|
|
if (ctx->exp_strategy[ch] != EXP_REUSE) { |
|
|
|
int grpsize, ngrps; |
|
|
|
int group_size, num_groups; |
|
|
|
grpsize = 3 << (ctx->expstr[ch] - 1); |
|
|
|
group_size = 3 << (ctx->exp_strategy[ch] - 1); |
|
|
|
if(ch == CPL_CH) |
|
|
|
if(ch == CPL_CH) |
|
|
|
ngrps = (ctx->endmant[ch] - ctx->startmant[ch]) / grpsize; |
|
|
|
num_groups = (ctx->end_freq[ch] - ctx->start_freq[ch]) / group_size; |
|
|
|
else if(ch == ctx->lfe_ch) |
|
|
|
else if(ch == ctx->lfe_ch) |
|
|
|
ngrps = 2; |
|
|
|
num_groups = 2; |
|
|
|
else |
|
|
|
else |
|
|
|
ngrps = (ctx->endmant[ch] + grpsize - 4) / grpsize; |
|
|
|
num_groups = (ctx->end_freq[ch] + group_size - 4) / group_size; |
|
|
|
ctx->dexps[ch][0] = get_bits(gb, 4) << !ch; |
|
|
|
ctx->dexps[ch][0] = get_bits(gb, 4) << !ch; |
|
|
|
decode_exponents(gb, ctx->expstr[ch], ngrps, ctx->dexps[ch][0], |
|
|
|
decode_exponents(gb, ctx->exp_strategy[ch], num_groups, ctx->dexps[ch][0], |
|
|
|
&ctx->dexps[ch][ctx->startmant[ch]+!!ch]); |
|
|
|
&ctx->dexps[ch][ctx->start_freq[ch]+!!ch]); |
|
|
|
if(ch != CPL_CH && ch != ctx->lfe_ch) |
|
|
|
if(ch != CPL_CH && ch != ctx->lfe_ch) |
|
|
|
skip_bits(gb, 2); /* skip gainrng */ |
|
|
|
skip_bits(gb, 2); /* skip gainrng */ |
|
|
|
} |
|
|
|
} |
|
|
@ -952,7 +952,7 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
ctx->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gb, 2)]; |
|
|
|
ctx->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gb, 2)]; |
|
|
|
ctx->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gb, 2)]; |
|
|
|
ctx->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gb, 2)]; |
|
|
|
ctx->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gb, 3)]; |
|
|
|
ctx->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gb, 3)]; |
|
|
|
for(ch=!ctx->cplinu; ch<=ctx->nchans; ch++) { |
|
|
|
for(ch=!ctx->cpl_in_use; ch<=ctx->channels; ch++) { |
|
|
|
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
|
|
|
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -961,7 +961,7 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
if (get_bits1(gb)) { |
|
|
|
if (get_bits1(gb)) { |
|
|
|
int csnr; |
|
|
|
int csnr; |
|
|
|
csnr = (get_bits(gb, 6) - 15) << 4; |
|
|
|
csnr = (get_bits(gb, 6) - 15) << 4; |
|
|
|
for (ch = !ctx->cplinu; ch <= ctx->nchans; ch++) { /* snr offset and fast gain */ |
|
|
|
for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) { /* snr offset and fast gain */ |
|
|
|
ctx->snr_offset[ch] = (csnr + get_bits(gb, 4)) << 2; |
|
|
|
ctx->snr_offset[ch] = (csnr + get_bits(gb, 4)) << 2; |
|
|
|
ctx->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gb, 3)]; |
|
|
|
ctx->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gb, 3)]; |
|
|
|
} |
|
|
|
} |
|
|
@ -969,7 +969,7 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* coupling leak information */ |
|
|
|
/* coupling leak information */ |
|
|
|
if (ctx->cplinu && get_bits1(gb)) { |
|
|
|
if (ctx->cpl_in_use && get_bits1(gb)) { |
|
|
|
ctx->bit_alloc_params.cpl_fast_leak = get_bits(gb, 3); |
|
|
|
ctx->bit_alloc_params.cpl_fast_leak = get_bits(gb, 3); |
|
|
|
ctx->bit_alloc_params.cpl_slow_leak = get_bits(gb, 3); |
|
|
|
ctx->bit_alloc_params.cpl_slow_leak = get_bits(gb, 3); |
|
|
|
bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); |
|
|
|
bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); |
|
|
@ -978,7 +978,7 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
/* delta bit allocation information */ |
|
|
|
/* delta bit allocation information */ |
|
|
|
if (get_bits1(gb)) { |
|
|
|
if (get_bits1(gb)) { |
|
|
|
/* delta bit allocation exists (strategy) */ |
|
|
|
/* delta bit allocation exists (strategy) */ |
|
|
|
for (ch = !ctx->cplinu; ch <= nfchans; ch++) { |
|
|
|
for (ch = !ctx->cpl_in_use; ch <= fbw_channels; ch++) { |
|
|
|
ctx->dba_mode[ch] = get_bits(gb, 2); |
|
|
|
ctx->dba_mode[ch] = get_bits(gb, 2); |
|
|
|
if (ctx->dba_mode[ch] == DBA_RESERVED) { |
|
|
|
if (ctx->dba_mode[ch] == DBA_RESERVED) { |
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); |
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); |
|
|
@ -987,7 +987,7 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
|
|
|
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
|
|
|
} |
|
|
|
} |
|
|
|
/* channel delta offset, len and bit allocation */ |
|
|
|
/* channel delta offset, len and bit allocation */ |
|
|
|
for (ch = !ctx->cplinu; ch <= nfchans; ch++) { |
|
|
|
for (ch = !ctx->cpl_in_use; ch <= fbw_channels; ch++) { |
|
|
|
if (ctx->dba_mode[ch] == DBA_NEW) { |
|
|
|
if (ctx->dba_mode[ch] == DBA_NEW) { |
|
|
|
ctx->dba_nsegs[ch] = get_bits(gb, 3); |
|
|
|
ctx->dba_nsegs[ch] = get_bits(gb, 3); |
|
|
|
for (seg = 0; seg <= ctx->dba_nsegs[ch]; seg++) { |
|
|
|
for (seg = 0; seg <= ctx->dba_nsegs[ch]; seg++) { |
|
|
@ -998,24 +998,24 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if(blk == 0) { |
|
|
|
} else if(blk == 0) { |
|
|
|
for(ch=0; ch<=ctx->nchans; ch++) { |
|
|
|
for(ch=0; ch<=ctx->channels; ch++) { |
|
|
|
ctx->dba_mode[ch] = DBA_NONE; |
|
|
|
ctx->dba_mode[ch] = DBA_NONE; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Bit allocation */ |
|
|
|
/* Bit allocation */ |
|
|
|
for(ch=!ctx->cplinu; ch<=ctx->nchans; ch++) { |
|
|
|
for(ch=!ctx->cpl_in_use; ch<=ctx->channels; ch++) { |
|
|
|
if(bit_alloc_stages[ch] > 2) { |
|
|
|
if(bit_alloc_stages[ch] > 2) { |
|
|
|
/* Exponent mapping into PSD and PSD integration */ |
|
|
|
/* Exponent mapping into PSD and PSD integration */ |
|
|
|
ff_ac3_bit_alloc_calc_psd(ctx->dexps[ch], |
|
|
|
ff_ac3_bit_alloc_calc_psd(ctx->dexps[ch], |
|
|
|
ctx->startmant[ch], ctx->endmant[ch], |
|
|
|
ctx->start_freq[ch], ctx->end_freq[ch], |
|
|
|
ctx->psd[ch], ctx->band_psd[ch]); |
|
|
|
ctx->psd[ch], ctx->band_psd[ch]); |
|
|
|
} |
|
|
|
} |
|
|
|
if(bit_alloc_stages[ch] > 1) { |
|
|
|
if(bit_alloc_stages[ch] > 1) { |
|
|
|
/* Compute excitation function, Compute masking curve, and
|
|
|
|
/* Compute excitation function, Compute masking curve, and
|
|
|
|
Apply delta bit allocation */ |
|
|
|
Apply delta bit allocation */ |
|
|
|
ff_ac3_bit_alloc_calc_mask(&ctx->bit_alloc_params, ctx->band_psd[ch], |
|
|
|
ff_ac3_bit_alloc_calc_mask(&ctx->bit_alloc_params, ctx->band_psd[ch], |
|
|
|
ctx->startmant[ch], ctx->endmant[ch], |
|
|
|
ctx->start_freq[ch], ctx->end_freq[ch], |
|
|
|
ctx->fast_gain[ch], (ch == ctx->lfe_ch), |
|
|
|
ctx->fast_gain[ch], (ch == ctx->lfe_ch), |
|
|
|
ctx->dba_mode[ch], ctx->dba_nsegs[ch], |
|
|
|
ctx->dba_mode[ch], ctx->dba_nsegs[ch], |
|
|
|
ctx->dba_offsets[ch], ctx->dba_lengths[ch], |
|
|
|
ctx->dba_offsets[ch], ctx->dba_lengths[ch], |
|
|
@ -1024,7 +1024,7 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
if(bit_alloc_stages[ch] > 0) { |
|
|
|
if(bit_alloc_stages[ch] > 0) { |
|
|
|
/* Compute bit allocation */ |
|
|
|
/* Compute bit allocation */ |
|
|
|
ff_ac3_bit_alloc_calc_bap(ctx->mask[ch], ctx->psd[ch], |
|
|
|
ff_ac3_bit_alloc_calc_bap(ctx->mask[ch], ctx->psd[ch], |
|
|
|
ctx->startmant[ch], ctx->endmant[ch], |
|
|
|
ctx->start_freq[ch], ctx->end_freq[ch], |
|
|
|
ctx->snr_offset[ch], |
|
|
|
ctx->snr_offset[ch], |
|
|
|
ctx->bit_alloc_params.floor, |
|
|
|
ctx->bit_alloc_params.floor, |
|
|
|
ctx->bap[ch]); |
|
|
|
ctx->bap[ch]); |
|
|
@ -1050,14 +1050,14 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
do_rematrixing(ctx); |
|
|
|
do_rematrixing(ctx); |
|
|
|
|
|
|
|
|
|
|
|
/* apply scaling to coefficients (headroom, dialnorm, dynrng) */ |
|
|
|
/* apply scaling to coefficients (headroom, dialnorm, dynrng) */ |
|
|
|
for(ch=1; ch<=ctx->nchans; ch++) { |
|
|
|
for(ch=1; ch<=ctx->channels; ch++) { |
|
|
|
float gain = 2.0f * ctx->mul_bias; |
|
|
|
float gain = 2.0f * ctx->mul_bias; |
|
|
|
if(ctx->channel_mode == AC3_CHMODE_DUALMONO) { |
|
|
|
if(ctx->channel_mode == AC3_CHMODE_DUALMONO) { |
|
|
|
gain *= ctx->dialnorm[ch-1] * ctx->dynrng[ch-1]; |
|
|
|
gain *= ctx->dialog_norm[ch-1] * ctx->dynamic_range[ch-1]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
gain *= ctx->dialnorm[0] * ctx->dynrng[0]; |
|
|
|
gain *= ctx->dialog_norm[0] * ctx->dynamic_range[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
for(i=0; i<ctx->endmant[ch]; i++) { |
|
|
|
for(i=0; i<ctx->end_freq[ch]; i++) { |
|
|
|
ctx->transform_coeffs[ch][i] *= gain; |
|
|
|
ctx->transform_coeffs[ch][i] *= gain; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1065,9 +1065,9 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
|
|
|
do_imdct(ctx); |
|
|
|
do_imdct(ctx); |
|
|
|
|
|
|
|
|
|
|
|
/* downmix output if needed */ |
|
|
|
/* downmix output if needed */ |
|
|
|
if(ctx->nchans != ctx->out_channels && !((ctx->output_mode & AC3_OUTPUT_LFEON) && |
|
|
|
if(ctx->channels != ctx->out_channels && !((ctx->output_mode & AC3_OUTPUT_LFEON) && |
|
|
|
ctx->nfchans == ctx->out_channels)) { |
|
|
|
ctx->fbw_channels == ctx->out_channels)) { |
|
|
|
ac3_downmix(ctx->output, ctx->nfchans, ctx->output_mode, |
|
|
|
ac3_downmix(ctx->output, ctx->fbw_channels, ctx->output_mode, |
|
|
|
ctx->downmix_coeffs); |
|
|
|
ctx->downmix_coeffs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1127,7 +1127,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* channel config */ |
|
|
|
/* channel config */ |
|
|
|
ctx->out_channels = ctx->nchans; |
|
|
|
ctx->out_channels = ctx->channels; |
|
|
|
if (avctx->channels == 0) { |
|
|
|
if (avctx->channels == 0) { |
|
|
|
avctx->channels = ctx->out_channels; |
|
|
|
avctx->channels = ctx->out_channels; |
|
|
|
} else if(ctx->out_channels < avctx->channels) { |
|
|
|
} else if(ctx->out_channels < avctx->channels) { |
|
|
|