56 #define EAC3_SR_CODE_REDUCED 3
61 uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
62 float rms_energy[SPX_MAX_BANDS];
66 bin =
s->spx_dst_start_freq;
67 num_copy_sections = 0;
68 for (bnd = 0; bnd <
s->num_spx_bands; bnd++) {
70 int bandsize =
s->spx_band_sizes[bnd];
71 if (bin + bandsize >
s->spx_src_start_freq) {
72 copy_sizes[num_copy_sections++] = bin -
s->spx_dst_start_freq;
73 bin =
s->spx_dst_start_freq;
76 for (
i = 0;
i < bandsize;
i += copysize) {
77 if (bin ==
s->spx_src_start_freq) {
78 copy_sizes[num_copy_sections++] = bin -
s->spx_dst_start_freq;
79 bin =
s->spx_dst_start_freq;
81 copysize =
FFMIN(bandsize -
i,
s->spx_src_start_freq - bin);
85 copy_sizes[num_copy_sections++] = bin -
s->spx_dst_start_freq;
87 for (ch = 1; ch <=
s->fbw_channels; ch++) {
88 if (!
s->channel_uses_spx[ch])
92 bin =
s->spx_src_start_freq;
93 for (
i = 0;
i < num_copy_sections;
i++) {
94 memcpy(&
s->transform_coeffs[ch][bin],
95 &
s->transform_coeffs[ch][
s->spx_dst_start_freq],
101 bin =
s->spx_src_start_freq;
102 for (bnd = 0; bnd <
s->num_spx_bands; bnd++) {
103 int bandsize =
s->spx_band_sizes[bnd];
105 for (
i = 0;
i < bandsize;
i++) {
106 float coeff =
s->transform_coeffs[ch][bin++];
109 rms_energy[bnd] =
sqrtf(accum / bandsize);
114 if (
s->spx_atten_code[ch] >= 0) {
116 bin =
s->spx_src_start_freq - 2;
117 for (bnd = 0; bnd <
s->num_spx_bands; bnd++) {
119 INTFLOAT *coeffs = &
s->transform_coeffs[ch][bin];
120 coeffs[0] *= atten_tab[0];
121 coeffs[1] *= atten_tab[1];
122 coeffs[2] *= atten_tab[2];
123 coeffs[3] *= atten_tab[1];
124 coeffs[4] *= atten_tab[0];
126 bin +=
s->spx_band_sizes[bnd];
133 bin =
s->spx_src_start_freq;
134 for (bnd = 0; bnd <
s->num_spx_bands; bnd++) {
135 float nscale =
s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
136 float sscale =
s->spx_signal_blend[ch][bnd];
139 nscale *= 1.0 / (1<<23);
140 sscale *= 1.0 / (1<<23);
142 for (
i = 0;
i <
s->spx_band_sizes[bnd];
i++) {
144 s->transform_coeffs[ch][bin] *= sscale;
145 s->transform_coeffs[ch][bin++] +=
noise;
153 #define COEFF_0 10273905LL
156 #define COEFF_1 11863283LL
159 #define COEFF_2 3070444LL
168 int even0, even1, even2, odd0, odd1, odd2;
170 odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
172 even2 = ( pre_mant[2] *
COEFF_0) >> 23;
174 odd0 = ((pre_mant[1] + pre_mant[5]) *
COEFF_2) >> 23;
176 even0 = pre_mant[0] + (
tmp >> 1);
177 even1 = pre_mant[0] -
tmp;
184 odd0 =
tmp + pre_mant[1] + pre_mant[3];
185 odd2 =
tmp + pre_mant[5] - pre_mant[3];
187 pre_mant[0] = even0 + odd0;
188 pre_mant[1] = even1 + odd1;
189 pre_mant[2] = even2 + odd2;
190 pre_mant[3] = even2 - odd2;
191 pre_mant[4] = even1 - odd1;
192 pre_mant[5] = even0 - odd0;
198 int end_bap, gaq_mode;
203 end_bap = (gaq_mode < 2) ? 12 : 17;
210 for (bin =
s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211 if (
s->bap[ch][bin] > 7 &&
s->bap[ch][bin] < end_bap)
212 gaq_gain[gs++] =
get_bits1(gbc) << (gaq_mode-1);
217 for (bin =
s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218 if (
s->bap[ch][bin] > 7 &&
s->bap[ch][bin] < 17) {
221 if (group_code > 26) {
235 for (bin =
s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236 int hebap =
s->bap[ch][bin];
241 s->pre_mantissa[ch][bin][
blk] = (
av_lfg_get(&
s->dith_state) & 0x7FFFFF) - 0x400000;
243 }
else if (hebap < 8) {
253 log_gain = gaq_gain[gs++];
257 gbits =
bits - log_gain;
261 if (log_gain && mant == -(1 << (gbits-1))) {
264 int mbits =
bits - (2 - log_gain);
266 mant = ((unsigned)mant) << (23 - (mbits - 1));
269 b = 1 << (23 - log_gain);
275 mant *= (1 << 24 -
bits);
281 s->pre_mantissa[ch][bin][
blk] = mant;
284 idct6(
s->pre_mantissa[ch][bin]);
291 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292 int parse_transient_proc_info;
307 if (
s->substreamid) {
309 if (!
s->eac3_subsbtreamid_found) {
310 s->eac3_subsbtreamid_found = 1;
327 for (
i = 0;
i < (
s->channel_mode ? 1 : 2);
i++) {
328 s->dialog_normalization[
i] = -
get_bits(gbc, 5);
329 if (
s->dialog_normalization[
i] == 0) {
330 s->dialog_normalization[
i] = -31;
332 if (
s->target_level != 0) {
334 (
float)(
s->target_level -
s->dialog_normalization[
i])/6.0f);
337 if (
s->compression_exists[
i]) {
345 int64_t channel_layout = 0;
346 int channel_map =
get_bits(gbc, 16);
349 for (
i = 0;
i < 16;
i++)
356 s->channel_map = channel_map;
365 if (
s->channel_mode & 1) {
367 s->center_mix_level_ltrt =
get_bits(gbc, 3);
370 if (
s->channel_mode & 4) {
378 if (
s->lfe_on && (
s->lfe_mix_level_exists =
get_bits1(gbc))) {
384 for (
i = 0;
i < (
s->channel_mode ? 1 : 2);
i++) {
398 int mix_data_size = (
get_bits(gbc, 5) + 2) << 3;
405 for (
i = 0;
i < (
s->channel_mode ? 1 : 2);
i++) {
431 s->dolby_surround_mode =
get_bits(gbc, 2);
432 s->dolby_headphone_mode =
get_bits(gbc, 2);
435 s->dolby_surround_ex_mode =
get_bits(gbc, 2);
437 for (
i = 0;
i < (
s->channel_mode ? 1 : 2);
i++) {
464 for (
i = 0;
i < addbsil + 1;
i++) {
471 if (
s->num_blocks == 6) {
477 ac3_exponent_strategy = 1;
481 s->snr_offset_strategy =
get_bits(gbc, 2);
482 parse_transient_proc_info =
get_bits1(gbc);
485 if (!
s->block_switch_syntax)
486 memset(
s->block_switch, 0,
sizeof(
s->block_switch));
489 if (!
s->dither_flag_syntax) {
490 for (ch = 1; ch <=
s->fbw_channels; ch++)
491 s->dither_flag[ch] = 1;
493 s->dither_flag[
CPL_CH] =
s->dither_flag[
s->lfe_ch] = 0;
496 if (!
s->bit_allocation_syntax) {
512 if (
s->channel_mode > 1) {
515 if (
s->cpl_strategy_exists[
blk]) {
518 s->cpl_in_use[
blk] =
s->cpl_in_use[
blk-1];
520 num_cpl_blocks +=
s->cpl_in_use[
blk];
523 memset(
s->cpl_in_use, 0,
sizeof(
s->cpl_in_use));
527 if (ac3_exponent_strategy) {
530 for (ch = !
s->cpl_in_use[
blk]; ch <= s->fbw_channels; ch++) {
536 for (ch = !((
s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
556 if (parse_aht_info) {
562 for (ch = (num_cpl_blocks != 6); ch <=
s->channels; ch++) {
566 (!ch &&
s->cpl_strategy_exists[
blk])) {
571 s->channel_uses_aht[ch] = use_aht &&
get_bits1(gbc);
574 memset(
s->channel_uses_aht, 0,
sizeof(
s->channel_uses_aht));
578 if (!
s->snr_offset_strategy) {
579 int csnroffst = (
get_bits(gbc, 6) - 15) << 4;
580 int snroffst = (csnroffst +
get_bits(gbc, 4)) << 2;
581 for (ch = 0; ch <=
s->channels; ch++)
582 s->snr_offset[ch] = snroffst;
586 if (parse_transient_proc_info) {
587 for (ch = 1; ch <=
s->fbw_channels; ch++) {
596 for (ch = 1; ch <=
s->fbw_channels; ch++) {
597 if (parse_spx_atten_data &&
get_bits1(gbc)) {
598 s->spx_atten_code[ch] =
get_bits(gbc, 5);
600 s->spx_atten_code[ch] = -1;
610 int block_start_bits = (
s->num_blocks-1) * (4 +
av_log2(
s->frame_size-2));
616 for (ch = 1; ch <=
s->fbw_channels; ch++) {
617 s->first_spx_coords[ch] = 1;
618 s->first_cpl_coords[ch] = 1;
620 s->first_cpl_leak = 1;