59 uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60 float rms_energy[SPX_MAX_BANDS];
64 bin =
s->spx_dst_start_freq;
65 num_copy_sections = 0;
66 for (bnd = 0; bnd <
s->num_spx_bands; bnd++) {
68 int bandsize =
s->spx_band_sizes[bnd];
69 if (bin + bandsize >
s->spx_src_start_freq) {
70 copy_sizes[num_copy_sections++] = bin -
s->spx_dst_start_freq;
71 bin =
s->spx_dst_start_freq;
74 for (
i = 0;
i < bandsize;
i += copysize) {
75 if (bin ==
s->spx_src_start_freq) {
76 copy_sizes[num_copy_sections++] = bin -
s->spx_dst_start_freq;
77 bin =
s->spx_dst_start_freq;
79 copysize =
FFMIN(bandsize -
i,
s->spx_src_start_freq - bin);
83 copy_sizes[num_copy_sections++] = bin -
s->spx_dst_start_freq;
85 for (ch = 1; ch <=
s->fbw_channels; ch++) {
86 if (!
s->channel_uses_spx[ch])
90 bin =
s->spx_src_start_freq;
91 for (
i = 0;
i < num_copy_sections;
i++) {
92 memcpy(&
s->transform_coeffs[ch][bin],
93 &
s->transform_coeffs[ch][
s->spx_dst_start_freq],
99 bin =
s->spx_src_start_freq;
100 for (bnd = 0; bnd <
s->num_spx_bands; bnd++) {
101 int bandsize =
s->spx_band_sizes[bnd];
103 for (
i = 0;
i < bandsize;
i++) {
104 float coeff =
s->transform_coeffs[ch][bin++];
107 rms_energy[bnd] =
sqrtf(accum / bandsize);
112 if (
s->spx_atten_code[ch] >= 0) {
114 bin =
s->spx_src_start_freq - 2;
115 for (bnd = 0; bnd <
s->num_spx_bands; bnd++) {
117 INTFLOAT *coeffs = &
s->transform_coeffs[ch][bin];
118 coeffs[0] *= atten_tab[0];
119 coeffs[1] *= atten_tab[1];
120 coeffs[2] *= atten_tab[2];
121 coeffs[3] *= atten_tab[1];
122 coeffs[4] *= atten_tab[0];
124 bin +=
s->spx_band_sizes[bnd];
131 bin =
s->spx_src_start_freq;
132 for (bnd = 0; bnd <
s->num_spx_bands; bnd++) {
133 float nscale =
s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134 float sscale =
s->spx_signal_blend[ch][bnd];
137 nscale *= 1.0 / (1<<23);
138 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;
326 for (
i = 0;
i < (
s->channel_mode ? 1 : 2);
i++) {
328 if (
s->dialog_normalization[
i] == 0) {
329 s->dialog_normalization[
i] = -31;
331 if (
s->target_level != 0) {
333 (
float)(
s->target_level -
s->dialog_normalization[
i])/6.0f);
362 if (
s->num_blocks == 6) {
368 ac3_exponent_strategy = 1;
372 s->snr_offset_strategy =
get_bits(gbc, 2);
373 parse_transient_proc_info =
get_bits1(gbc);
376 if (!
s->block_switch_syntax)
377 memset(
s->block_switch, 0,
sizeof(
s->block_switch));
380 if (!
s->dither_flag_syntax) {
381 for (ch = 1; ch <=
s->fbw_channels; ch++)
382 s->dither_flag[ch] = 1;
384 s->dither_flag[
CPL_CH] =
s->dither_flag[
s->lfe_ch] = 0;
387 if (!
s->bit_allocation_syntax) {
403 if (
s->channel_mode > 1) {
406 if (
s->cpl_strategy_exists[
blk]) {
409 s->cpl_in_use[
blk] =
s->cpl_in_use[
blk-1];
411 num_cpl_blocks +=
s->cpl_in_use[
blk];
414 memset(
s->cpl_in_use, 0,
sizeof(
s->cpl_in_use));
418 if (ac3_exponent_strategy) {
421 for (ch = !
s->cpl_in_use[
blk]; ch <= s->fbw_channels; ch++) {
427 for (ch = !((
s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
447 if (parse_aht_info) {
453 for (ch = (num_cpl_blocks != 6); ch <=
s->channels; ch++) {
457 (!ch &&
s->cpl_strategy_exists[
blk])) {
462 s->channel_uses_aht[ch] = use_aht &&
get_bits1(gbc);
465 memset(
s->channel_uses_aht, 0,
sizeof(
s->channel_uses_aht));
469 if (!
s->snr_offset_strategy) {
470 int csnroffst = (
get_bits(gbc, 6) - 15) << 4;
471 int snroffst = (csnroffst +
get_bits(gbc, 4)) << 2;
472 for (ch = 0; ch <=
s->channels; ch++)
473 s->snr_offset[ch] = snroffst;
477 if (parse_transient_proc_info) {
478 for (ch = 1; ch <=
s->fbw_channels; ch++) {
487 for (ch = 1; ch <=
s->fbw_channels; ch++) {
488 if (parse_spx_atten_data &&
get_bits1(gbc)) {
489 s->spx_atten_code[ch] =
get_bits(gbc, 5);
491 s->spx_atten_code[ch] = -1;
501 int block_start_bits = (
s->num_blocks-1) * (4 +
av_log2(
s->frame_size-2));
507 for (ch = 1; ch <=
s->fbw_channels; ch++) {
508 s->first_spx_coords[ch] = 1;
509 s->first_cpl_coords[ch] = 1;
511 s->first_cpl_leak = 1;