57 #define EAC3_SR_CODE_REDUCED 3 62 uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
63 float rms_energy[SPX_MAX_BANDS];
67 bin = s->spx_dst_start_freq;
68 num_copy_sections = 0;
69 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
71 int bandsize = s->spx_band_sizes[bnd];
72 if (bin + bandsize > s->spx_src_start_freq) {
73 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
74 bin = s->spx_dst_start_freq;
77 for (i = 0; i < bandsize; i += copysize) {
78 if (bin == s->spx_src_start_freq) {
79 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
80 bin = s->spx_dst_start_freq;
82 copysize =
FFMIN(bandsize - i, s->spx_src_start_freq - bin);
86 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
88 for (ch = 1; ch <= s->fbw_channels; ch++) {
89 if (!s->channel_uses_spx[ch])
93 bin = s->spx_src_start_freq;
94 for (i = 0; i < num_copy_sections; i++) {
95 memcpy(&s->transform_coeffs[ch][bin],
96 &s->transform_coeffs[ch][s->spx_dst_start_freq],
102 bin = s->spx_src_start_freq;
103 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
104 int bandsize = s->spx_band_sizes[bnd];
106 for (i = 0; i < bandsize; i++) {
107 float coeff = s->transform_coeffs[ch][bin++];
108 accum += coeff *
coeff;
110 rms_energy[bnd] = sqrtf(accum / bandsize);
115 if (s->spx_atten_code[ch] >= 0) {
117 bin = s->spx_src_start_freq - 2;
118 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
120 INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
121 coeffs[0] *= atten_tab[0];
122 coeffs[1] *= atten_tab[1];
123 coeffs[2] *= atten_tab[2];
124 coeffs[3] *= atten_tab[1];
125 coeffs[4] *= atten_tab[0];
127 bin += s->spx_band_sizes[bnd];
134 bin = s->spx_src_start_freq;
135 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
136 float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
137 float sscale = s->spx_signal_blend[ch][bnd];
140 nscale *= 1.0 / (1<<23);
141 sscale *= 1.0 / (1<<23);
143 for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
145 s->transform_coeffs[ch][bin] *= sscale;
146 s->transform_coeffs[ch][bin++] +=
noise;
154 #define COEFF_0 10273905LL 157 #define COEFF_1 11863283LL 160 #define COEFF_2 3070444LL 169 int even0, even1, even2, odd0, odd1, odd2;
171 odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
173 even2 = ( pre_mant[2] *
COEFF_0) >> 23;
174 tmp = ( pre_mant[4] *
COEFF_1) >> 23;
175 odd0 = ((pre_mant[1] + pre_mant[5]) *
COEFF_2) >> 23;
177 even0 = pre_mant[0] + (tmp >> 1);
178 even1 = pre_mant[0] -
tmp;
185 odd0 = tmp + pre_mant[1] + pre_mant[3];
186 odd2 = tmp + pre_mant[5] - pre_mant[3];
188 pre_mant[0] = even0 + odd0;
189 pre_mant[1] = even1 + odd1;
190 pre_mant[2] = even2 + odd2;
191 pre_mant[3] = even2 - odd2;
192 pre_mant[4] = even1 - odd1;
193 pre_mant[5] = even0 - odd0;
199 int end_bap, gaq_mode;
204 end_bap = (gaq_mode < 2) ? 12 : 17;
211 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
212 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
213 gaq_gain[gs++] =
get_bits1(gbc) << (gaq_mode-1);
218 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
219 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
222 if (group_code > 26) {
236 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
237 int hebap = s->bap[ch][bin];
241 for (blk = 0; blk < 6; blk++) {
242 s->pre_mantissa[ch][bin][
blk] = (
av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
244 }
else if (hebap < 8) {
247 for (blk = 0; blk < 6; blk++) {
254 log_gain = gaq_gain[gs++];
258 gbits = bits - log_gain;
260 for (blk = 0; blk < 6; blk++) {
262 if (log_gain && mant == -(1 << (gbits-1))) {
265 int mbits = bits - (2 - log_gain);
267 mant = ((unsigned)mant) << (23 - (mbits - 1));
270 b = 1 << (23 - log_gain);
276 mant *= (1 << 24 -
bits);
282 s->pre_mantissa[ch][bin][
blk] = mant;
285 idct6(s->pre_mantissa[ch][bin]);
292 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
293 int parse_transient_proc_info;
308 if (s->substreamid) {
310 if (!s->eac3_subsbtreamid_found) {
311 s->eac3_subsbtreamid_found = 1;
328 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
329 s->dialog_normalization[
i] = -
get_bits(gbc, 5);
330 if (s->dialog_normalization[i] == 0) {
331 s->dialog_normalization[
i] = -31;
333 if (s->target_level != 0) {
334 s->level_gain[
i] =
powf(2.0
f,
335 (
float)(s->target_level - s->dialog_normalization[i])/6.0f);
338 if (s->compression_exists[i]) {
346 int64_t channel_layout = 0;
347 int channel_map =
get_bits(gbc, 16);
350 for (i = 0; i < 16; i++)
357 s->channel_map = channel_map;
365 s->preferred_downmix =
get_bits(gbc, 2);
366 if (s->channel_mode & 1) {
368 s->center_mix_level_ltrt =
get_bits(gbc, 3);
369 s->center_mix_level =
get_bits(gbc, 3);
371 if (s->channel_mode & 4) {
373 s->surround_mix_level_ltrt = av_clip(
get_bits(gbc, 3), 3, 7);
374 s->surround_mix_level = av_clip(
get_bits(gbc, 3), 3, 7);
379 if (s->lfe_on && (s->lfe_mix_level_exists =
get_bits1(gbc))) {
380 s->lfe_mix_level =
get_bits(gbc, 5);
385 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
399 int mix_data_size = (
get_bits(gbc, 5) + 2) << 3;
406 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
418 for (blk = 0; blk < s->num_blocks; blk++) {
419 if (s->num_blocks == 1 ||
get_bits1(gbc)) {
429 s->bitstream_mode =
get_bits(gbc, 3);
432 s->dolby_surround_mode =
get_bits(gbc, 2);
433 s->dolby_headphone_mode =
get_bits(gbc, 2);
436 s->dolby_surround_ex_mode =
get_bits(gbc, 2);
438 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
458 (s->num_blocks == 6 ||
get_bits1(gbc))) {
465 for (i = 0; i < addbsil + 1; i++) {
472 if (s->num_blocks == 6) {
478 ac3_exponent_strategy = 1;
482 s->snr_offset_strategy =
get_bits(gbc, 2);
483 parse_transient_proc_info =
get_bits1(gbc);
486 if (!s->block_switch_syntax)
487 memset(s->block_switch, 0,
sizeof(s->block_switch));
490 if (!s->dither_flag_syntax) {
491 for (ch = 1; ch <= s->fbw_channels; ch++)
492 s->dither_flag[ch] = 1;
494 s->dither_flag[
CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
496 s->bit_allocation_syntax =
get_bits1(gbc);
497 if (!s->bit_allocation_syntax) {
513 if (s->channel_mode > 1) {
514 for (blk = 0; blk < s->num_blocks; blk++) {
516 if (s->cpl_strategy_exists[blk]) {
519 s->cpl_in_use[
blk] = s->cpl_in_use[blk-1];
521 num_cpl_blocks += s->cpl_in_use[
blk];
524 memset(s->cpl_in_use, 0,
sizeof(s->cpl_in_use));
528 if (ac3_exponent_strategy) {
530 for (blk = 0; blk < s->num_blocks; blk++) {
531 for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
537 for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
539 for (blk = 0; blk < 6; blk++) {
546 for (blk = 0; blk < s->num_blocks; blk++) {
552 (s->num_blocks == 6 ||
get_bits1(gbc))) {
557 if (parse_aht_info) {
562 s->channel_uses_aht[
CPL_CH]=0;
563 for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
565 for (blk = 1; blk < 6; blk++) {
566 if ((s->exp_strategy[blk][ch] !=
EXP_REUSE) ||
567 (!ch && s->cpl_strategy_exists[blk])) {
572 s->channel_uses_aht[ch] = use_aht &&
get_bits1(gbc);
575 memset(s->channel_uses_aht, 0,
sizeof(s->channel_uses_aht));
579 if (!s->snr_offset_strategy) {
580 int csnroffst = (
get_bits(gbc, 6) - 15) << 4;
581 int snroffst = (csnroffst +
get_bits(gbc, 4)) << 2;
582 for (ch = 0; ch <= s->channels; ch++)
583 s->snr_offset[ch] = snroffst;
587 if (parse_transient_proc_info) {
588 for (ch = 1; ch <= s->fbw_channels; ch++) {
597 for (ch = 1; ch <= s->fbw_channels; ch++) {
598 if (parse_spx_atten_data &&
get_bits1(gbc)) {
599 s->spx_atten_code[ch] =
get_bits(gbc, 5);
601 s->spx_atten_code[ch] = -1;
606 if (s->num_blocks > 1 &&
get_bits1(gbc)) {
611 int block_start_bits = (s->num_blocks-1) * (4 +
av_log2(s->frame_size-2));
617 for (ch = 1; ch <= s->fbw_channels; ch++) {
618 s->first_spx_coords[ch] = 1;
619 s->first_cpl_coords[ch] = 1;
621 s->first_cpl_leak = 1;
EAC3GaqMode
gain adaptive quantization mode
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
const uint8_t ff_ac3_slow_decay_tab[4]
const float ff_eac3_spx_atten_tab[32][3]
Table E.25: Spectral Extension Attenuation Table ff_eac3_spx_atten_tab[code][bin]=pow(2.0,(bin+1)*(code+1)/-15.0);.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3]
Table used to ungroup 3 values stored in 5 bits.
static int ff_eac3_parse_header(AC3DecodeContext *s)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
#define avpriv_request_sample(...)
const uint16_t ff_ac3_slow_gain_tab[4]
static int get_sbits(GetBitContext *s, int n)
#define COEFF_0
lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23))
static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const uint8_t ff_ac3_fast_decay_tab[4]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define COEFF_2
lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23))
#define EAC3_SR_CODE_REDUCED
static void idct6(int pre_mant[6])
Calculate 6-point IDCT of the pre-mantissas.
#define AC3_HEAVY_RANGE(x)
const int16_t ff_eac3_gaq_remap_1[12]
Table E3.6, Gk=1 No gain (Gk=1) inverse quantization, remapping scale factors ff_eac3_gaq_remap[hebap...
const int16_t ff_eac3_gaq_remap_2_4_a[9][2]
Table E3.6, Gk=2 & Gk=4, A Large mantissa inverse quantization, remapping scale factors ff_eac3_gaq_r...
#define COEFF_1
lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23))
const uint8_t ff_eac3_bits_vs_hebap[20]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define CPL_CH
coupling channel index
Libavcodec external API header.
const int16_t ff_eac3_gaq_remap_2_4_b[9][2]
Table E3.6, Gk=2 & Gk=4, B Large mantissa inverse quantization, negative mantissa remapping offsets f...
static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
const int16_t ff_ac3_floor_tab[8]
static int noise(AVBSFContext *ctx, AVPacket *pkt)
const uint64_t ff_eac3_custom_channel_map_locations[16][2]
common internal api header.
const uint8_t ff_eac3_frm_expstr[32][6]
Table E2.14 Frame Exponent Strategy Combinations.
#define EAC3_MAX_CHANNELS
maximum number of channels in EAC3
static const double coeff[2][5]
const int16_t(*const [8] ff_eac3_mantissa_vq)[6]
const uint16_t ff_ac3_db_per_bit_tab[4]
Common code between the AC-3 encoder and decoder.