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);
144 for (
i = 0;
i <
s->spx_band_sizes[bnd];
i++) {
146 s->transform_coeffs[ch][bin] *= sscale;
147 s->transform_coeffs[ch][bin++] +=
noise;
155 #define COEFF_0 10273905LL
158 #define COEFF_1 11863283LL
161 #define COEFF_2 3070444LL
170 int even0, even1, even2, odd0, odd1, odd2;
172 odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
174 even2 = ( pre_mant[2] *
COEFF_0) >> 23;
176 odd0 = ((pre_mant[1] + pre_mant[5]) *
COEFF_2) >> 23;
178 even0 = pre_mant[0] + (
tmp >> 1);
179 even1 = pre_mant[0] -
tmp;
186 odd0 =
tmp + pre_mant[1] + pre_mant[3];
187 odd2 =
tmp + pre_mant[5] - pre_mant[3];
189 pre_mant[0] = even0 + odd0;
190 pre_mant[1] = even1 + odd1;
191 pre_mant[2] = even2 + odd2;
192 pre_mant[3] = even2 - odd2;
193 pre_mant[4] = even1 - odd1;
194 pre_mant[5] = even0 - odd0;
200 int end_bap, gaq_mode;
205 end_bap = (gaq_mode < 2) ? 12 : 17;
212 for (bin =
s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
213 if (
s->bap[ch][bin] > 7 &&
s->bap[ch][bin] < end_bap)
214 gaq_gain[gs++] =
get_bits1(gbc) << (gaq_mode-1);
219 for (bin =
s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
220 if (
s->bap[ch][bin] > 7 &&
s->bap[ch][bin] < 17) {
223 if (group_code > 26) {
237 for (bin =
s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
238 int hebap =
s->bap[ch][bin];
243 s->pre_mantissa[ch][bin][
blk] = (
av_lfg_get(&
s->dith_state) & 0x7FFFFF) - 0x400000;
245 }
else if (hebap < 8) {
255 log_gain = gaq_gain[gs++];
259 gbits =
bits - log_gain;
263 if (log_gain && mant == -(1 << (gbits-1))) {
266 int mbits =
bits - (2 - log_gain);
268 mant = ((unsigned)mant) << (23 - (mbits - 1));
271 b = 1 << (23 - log_gain);
277 mant *= (1 << 24 -
bits);
283 s->pre_mantissa[ch][bin][
blk] = mant;
286 idct6(
s->pre_mantissa[ch][bin]);
293 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
294 int parse_transient_proc_info;
309 if (
s->substreamid) {
311 if (!
s->eac3_subsbtreamid_found) {
312 s->eac3_subsbtreamid_found = 1;
329 for (
i = 0;
i < (
s->channel_mode ? 1 : 2);
i++) {
330 s->dialog_normalization[
i] = -
get_bits(gbc, 5);
331 if (
s->dialog_normalization[
i] == 0) {
332 s->dialog_normalization[
i] = -31;
334 if (
s->target_level != 0) {
336 (
float)(
s->target_level -
s->dialog_normalization[
i])/6.0f);
339 if (
s->compression_exists[
i]) {
351 for (
i = 0;
i < 16;
i++)
367 if (
s->channel_mode & 1) {
369 s->center_mix_level_ltrt =
get_bits(gbc, 3);
372 if (
s->channel_mode & 4) {
380 if (
s->lfe_on && (
s->lfe_mix_level_exists =
get_bits1(gbc))) {
386 for (
i = 0;
i < (
s->channel_mode ? 1 : 2);
i++) {
400 int mix_data_size = (
get_bits(gbc, 5) + 2) << 3;
407 for (
i = 0;
i < (
s->channel_mode ? 1 : 2);
i++) {
433 s->dolby_surround_mode =
get_bits(gbc, 2);
434 s->dolby_headphone_mode =
get_bits(gbc, 2);
437 s->dolby_surround_ex_mode =
get_bits(gbc, 2);
439 for (
i = 0;
i < (
s->channel_mode ? 1 : 2);
i++) {
466 for (
i = 0;
i < addbsil + 1;
i++) {
472 s->eac3_extension_type_a = 1;
482 if (
s->num_blocks == 6) {
488 ac3_exponent_strategy = 1;
492 s->snr_offset_strategy =
get_bits(gbc, 2);
493 parse_transient_proc_info =
get_bits1(gbc);
496 if (!
s->block_switch_syntax)
497 memset(
s->block_switch, 0,
sizeof(
s->block_switch));
500 if (!
s->dither_flag_syntax) {
501 for (ch = 1; ch <=
s->fbw_channels; ch++)
502 s->dither_flag[ch] = 1;
504 s->dither_flag[
CPL_CH] =
s->dither_flag[
s->lfe_ch] = 0;
507 if (!
s->bit_allocation_syntax) {
523 if (
s->channel_mode > 1) {
526 if (
s->cpl_strategy_exists[
blk]) {
529 s->cpl_in_use[
blk] =
s->cpl_in_use[
blk-1];
531 num_cpl_blocks +=
s->cpl_in_use[
blk];
534 memset(
s->cpl_in_use, 0,
sizeof(
s->cpl_in_use));
538 if (ac3_exponent_strategy) {
541 for (ch = !
s->cpl_in_use[
blk]; ch <= s->fbw_channels; ch++) {
547 for (ch = !((
s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
567 if (parse_aht_info) {
573 for (ch = (num_cpl_blocks != 6); ch <=
s->channels; ch++) {
577 (!ch &&
s->cpl_strategy_exists[
blk])) {
582 s->channel_uses_aht[ch] = use_aht &&
get_bits1(gbc);
585 memset(
s->channel_uses_aht, 0,
sizeof(
s->channel_uses_aht));
589 if (!
s->snr_offset_strategy) {
590 int csnroffst = (
get_bits(gbc, 6) - 15) << 4;
591 int snroffst = (csnroffst +
get_bits(gbc, 4)) << 2;
592 for (ch = 0; ch <=
s->channels; ch++)
593 s->snr_offset[ch] = snroffst;
597 if (parse_transient_proc_info) {
598 for (ch = 1; ch <=
s->fbw_channels; ch++) {
607 for (ch = 1; ch <=
s->fbw_channels; ch++) {
608 if (parse_spx_atten_data &&
get_bits1(gbc)) {
609 s->spx_atten_code[ch] =
get_bits(gbc, 5);
611 s->spx_atten_code[ch] = -1;
621 int block_start_bits = (
s->num_blocks-1) * (4 +
av_log2(
s->frame_size-2));
627 for (ch = 1; ch <=
s->fbw_channels; ch++) {
628 s->first_spx_coords[ch] = 1;
629 s->first_cpl_coords[ch] = 1;
631 s->first_cpl_leak = 1;