1 /******************************************************************************
2 * *
3 * Copyright (C) 2018 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************
18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #include <string.h>
21 #include "ixheaacd_sbr_common.h"
22 #include <ixheaacd_type_def.h>
23
24 #include "ixheaacd_constants.h"
25 #include <ixheaacd_basic_ops32.h>
26 #include <ixheaacd_basic_ops16.h>
27 #include <ixheaacd_basic_ops40.h>
28 #include "ixheaacd_basic_ops.h"
29
30 #include <ixheaacd_basic_op.h>
31 #include "ixheaacd_intrinsics.h"
32 #include "ixheaacd_common_rom.h"
33 #include "ixheaacd_basic_funcs.h"
34 #include "ixheaacd_bitbuffer.h"
35 #include "ixheaacd_defines.h"
36
37 #include "ixheaacd_pns.h"
38
39 #include <ixheaacd_aac_rom.h>
40 #include "ixheaacd_pulsedata.h"
41
42 #include "ixheaacd_drc_data_struct.h"
43 #include "ixheaacd_lt_predict.h"
44 #include "ixheaacd_channelinfo.h"
45 #include "ixheaacd_drc_dec.h"
46 #include "ixheaacd_sbrdecoder.h"
47
48 #include "ixheaacd_defines.h"
49 #include "ixheaacd_sbrdecoder.h"
50 #include "ixheaacd_definitions.h"
51 #include "ixheaacd_error_codes.h"
52
53 #include "ixheaacd_pulsedata.h"
54
55 #include "ixheaacd_sbrdecsettings.h"
56 #include "ixheaacd_sbr_scale.h"
57 #include "ixheaacd_lpp_tran.h"
58 #include "ixheaacd_env_extr_part.h"
59 #include <ixheaacd_sbr_rom.h>
60 #include "ixheaacd_hybrid.h"
61 #include "ixheaacd_ps_dec.h"
62 #include "ixheaacd_env_extr.h"
63
64 #include "ixheaacd_qmf_dec.h"
65
66 #include "ixheaacd_env_calc.h"
67 #include "ixheaacd_sbr_const.h"
68
69 #include "ixheaacd_pvc_dec.h"
70 #include "ixheaacd_sbr_dec.h"
71 #include "ixheaacd_env_extr.h"
72 #include "ixheaacd_env_calc.h"
73 #include "ixheaacd_ps_dec.h"
74 #include "ixheaacd_function_selector.h"
75
76 #include "ixheaacd_audioobjtypes.h"
77
ixheaacd_qmf_enrg_calc(ia_sbr_dec_struct * ptr_sbr_dec,WORD32 upsample_ratio_idx,WORD32 low_pow_flag)78 VOID ixheaacd_qmf_enrg_calc(ia_sbr_dec_struct *ptr_sbr_dec,
79 WORD32 upsample_ratio_idx, WORD32 low_pow_flag) {
80 WORD32 i, j;
81 if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
82 for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
83 for (j = 0; j < 16; j++) {
84 ptr_sbr_dec->qmf_energy_buf[i][j] =
85 ptr_sbr_dec->qmf_buf_real[2 + i][j] *
86 ptr_sbr_dec->qmf_buf_real[2 + i][j];
87 if (!low_pow_flag)
88 ptr_sbr_dec->qmf_energy_buf[i][j] +=
89 (ptr_sbr_dec->qmf_buf_imag[2 + i][j] *
90 ptr_sbr_dec->qmf_buf_imag[2 + i][j]);
91 }
92 }
93
94 for (i = 0; i < 16; i++) {
95 for (j = 0; j < 16; j++) {
96 ptr_sbr_dec->pvc_qmf_enrg_arr[32 * i + j] =
97 (ptr_sbr_dec->qmf_energy_buf[4 * i + 0][j] +
98 ptr_sbr_dec->qmf_energy_buf[4 * i + 1][j] +
99 ptr_sbr_dec->qmf_energy_buf[4 * i + 2][j] +
100 ptr_sbr_dec->qmf_energy_buf[4 * i + 3][j]) *
101 0.25f;
102 }
103 }
104 } else {
105 for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
106 for (j = 0; j < 32; j++) {
107 ptr_sbr_dec->qmf_energy_buf[i][j] =
108 ptr_sbr_dec->qmf_buf_real[2 + i][j] *
109 ptr_sbr_dec->qmf_buf_real[2 + i][j];
110 if (!low_pow_flag)
111 ptr_sbr_dec->qmf_energy_buf[i][j] +=
112 (ptr_sbr_dec->qmf_buf_imag[2 + i][j] *
113 ptr_sbr_dec->qmf_buf_imag[2 + i][j]);
114 }
115 }
116
117 for (i = 0; i < 16; i++) {
118 for (j = 0; j < 32; j++) {
119 ptr_sbr_dec->pvc_qmf_enrg_arr[32 * i + j] =
120 (ptr_sbr_dec->qmf_energy_buf[2 * i + 0][j] +
121 ptr_sbr_dec->qmf_energy_buf[2 * i + 1][j]) *
122 0.5f;
123 }
124 }
125 }
126 }
127
ixheaacd_hbe_repl_spec(WORD32 x_over_qmf[MAX_NUM_PATCHES],FLOAT32 qmf_buf_real[][64],FLOAT32 qmf_buf_imag[][64],WORD32 no_bins,WORD32 max_stretch)128 VOID ixheaacd_hbe_repl_spec(WORD32 x_over_qmf[MAX_NUM_PATCHES],
129 FLOAT32 qmf_buf_real[][64],
130 FLOAT32 qmf_buf_imag[][64], WORD32 no_bins,
131 WORD32 max_stretch) {
132 WORD32 patch_bands;
133 WORD32 patch, band, col, target, source_bands, i;
134 WORD32 num_patches = 0;
135
136 for (i = 1; i < MAX_NUM_PATCHES; i++) {
137 if (x_over_qmf[i] != 0) {
138 num_patches++;
139 }
140 }
141
142 for (patch = (max_stretch - 1); patch < num_patches; patch++) {
143 patch_bands = x_over_qmf[patch + 1] - x_over_qmf[patch];
144 target = x_over_qmf[patch];
145 source_bands = x_over_qmf[max_stretch - 1] - x_over_qmf[max_stretch - 2];
146 while (patch_bands > 0) {
147 WORD32 ixheaacd_num_bands = source_bands;
148 WORD32 start_band = x_over_qmf[max_stretch - 1] - 1;
149 if (target + ixheaacd_num_bands >= x_over_qmf[patch + 1]) {
150 ixheaacd_num_bands = x_over_qmf[patch + 1] - target;
151 }
152 if ((((target + ixheaacd_num_bands - 1) & 1) +
153 ((x_over_qmf[max_stretch - 1] - 1) & 1)) &
154 1) {
155 if (ixheaacd_num_bands == source_bands) {
156 ixheaacd_num_bands--;
157 } else {
158 start_band--;
159 }
160 }
161 if (!ixheaacd_num_bands) break;
162 for (col = 0; col < no_bins; col++) {
163 WORD32 i = 0;
164 band = target + ixheaacd_num_bands - 1;
165 if (64 <= band) {
166 band = 63;
167 }
168 if (x_over_qmf[patch + 1] <= band) {
169 band = x_over_qmf[patch + 1] - 1;
170 }
171 for (i = 0; i < ixheaacd_num_bands; i++, band--) {
172 qmf_buf_real[col][band] = qmf_buf_real[col][start_band - i];
173 qmf_buf_imag[col][band] = qmf_buf_imag[col][start_band - i];
174 }
175 }
176 target += ixheaacd_num_bands;
177 patch_bands -= ixheaacd_num_bands;
178 }
179 }
180 }
181
ixheaacd_esbr_analysis_filt_block(ia_sbr_dec_struct * ptr_sbr_dec,ia_sbr_tables_struct * sbr_tables_ptr,WORD32 op_delay)182 VOID ixheaacd_esbr_analysis_filt_block(ia_sbr_dec_struct *ptr_sbr_dec,
183 ia_sbr_tables_struct *sbr_tables_ptr,
184 WORD32 op_delay) {
185 FLOAT32 *core_coder_samples;
186 WORD32 *ptr_filt_states;
187 WORD32 *ptr_filt_states_1;
188 WORD32 *ptr_filt_states_2;
189 WORD32 *ptr_temp;
190 WORD32 *ptr_win_coeffs_1;
191 WORD32 *ptr_win_coeffs_2;
192 WORD32 *ptr_win_coeffs;
193 WORD32 *ploc_qmf_buf_real;
194 WORD32 *ploc_qmf_buf_imag;
195 WORD32 local_qmf_buffer[128] = {0};
196 WORD32 anal_buf[2 * 32];
197 WORD32 idx, z;
198 WORD32 core_syn_ch_index;
199 FLOAT32 gain;
200 WORD32 filt_offset;
201 WORD32 num_columns;
202 ia_qmf_dec_tables_struct *qmf_dec_tables_ptr =
203 sbr_tables_ptr->qmf_dec_tables_ptr;
204 ia_sbr_qmf_filter_bank_struct *pstr_qmf_anal_bank =
205 &ptr_sbr_dec->str_codec_qmf_bank;
206 core_coder_samples = ptr_sbr_dec->time_sample_buf;
207 ptr_filt_states = pstr_qmf_anal_bank->state_new_samples_pos_low_32;
208 ptr_win_coeffs_1 = pstr_qmf_anal_bank->filter_pos_32;
209 num_columns = pstr_qmf_anal_bank->no_channels;
210
211 switch (num_columns) {
212 case 16:
213 ptr_win_coeffs_2 = ptr_win_coeffs_1 + 64;
214 gain = 128.0f;
215 filt_offset = 64;
216 break;
217 case 24:
218 ptr_win_coeffs_2 = ptr_win_coeffs_1 + 24;
219 gain = 12.0f;
220 filt_offset = 24;
221 break;
222 case 32:
223 ptr_win_coeffs_2 = ptr_win_coeffs_1 + 64;
224 gain = 256.0f;
225 filt_offset = 64;
226 break;
227 default:
228 ptr_win_coeffs_2 = ptr_win_coeffs_1 + 64;
229 gain = 256.0f;
230 filt_offset = 64;
231 break;
232 }
233 gain = 1.0f / gain;
234
235 pstr_qmf_anal_bank->usb = num_columns;
236
237 ploc_qmf_buf_real = &local_qmf_buffer[0];
238 ploc_qmf_buf_imag = &local_qmf_buffer[64];
239
240 ptr_filt_states_1 = pstr_qmf_anal_bank->anal_filter_states_32;
241 ptr_filt_states_2 = pstr_qmf_anal_bank->anal_filter_states_32 + num_columns;
242
243 for (idx = 0; idx < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; idx++) {
244 for (z = 0; z < num_columns; z++) {
245 ptr_filt_states[num_columns - 1 - z] =
246 (WORD32)(core_coder_samples[z] * (1 << 15));
247 }
248 ixheaacd_esbr_qmfanal32_winadd(ptr_filt_states_1, ptr_filt_states_2,
249 ptr_win_coeffs_1, ptr_win_coeffs_2, anal_buf,
250 num_columns);
251
252 core_coder_samples += num_columns;
253
254 ptr_filt_states -= num_columns;
255 if (ptr_filt_states < pstr_qmf_anal_bank->anal_filter_states_32) {
256 ptr_filt_states = pstr_qmf_anal_bank->anal_filter_states_32 +
257 10 * num_columns - num_columns;
258 }
259
260 ptr_temp = ptr_filt_states_1;
261 ptr_filt_states_1 = ptr_filt_states_2;
262 ptr_filt_states_2 = ptr_temp;
263
264 ptr_win_coeffs_1 += filt_offset;
265 ptr_win_coeffs_2 += filt_offset;
266
267 ptr_win_coeffs = ptr_win_coeffs_1;
268 ptr_win_coeffs_1 = ptr_win_coeffs_2;
269 ptr_win_coeffs_2 = ptr_win_coeffs;
270
271 if (ptr_win_coeffs_2 >
272 (pstr_qmf_anal_bank->analy_win_coeff_32 + filt_offset * 10)) {
273 ptr_win_coeffs_1 = pstr_qmf_anal_bank->analy_win_coeff_32;
274 ptr_win_coeffs_2 = pstr_qmf_anal_bank->analy_win_coeff_32 + filt_offset;
275 }
276
277 ixheaacd_esbr_fwd_modulation(anal_buf, &ploc_qmf_buf_real[0],
278 &ploc_qmf_buf_imag[0], pstr_qmf_anal_bank,
279 qmf_dec_tables_ptr);
280 core_syn_ch_index = num_columns;
281
282 for (z = 0; z < core_syn_ch_index; z++) {
283 ptr_sbr_dec->qmf_buf_real[op_delay + idx][z] =
284 ((FLOAT32)ploc_qmf_buf_real[z] * gain);
285 ptr_sbr_dec->qmf_buf_imag[op_delay + idx][z] =
286 ((FLOAT32)ploc_qmf_buf_imag[z] * gain);
287 }
288 for (z = core_syn_ch_index; z < num_columns; z++) {
289 ptr_sbr_dec->qmf_buf_real[op_delay + idx][z] = (FLOAT32)0.0f;
290 ptr_sbr_dec->qmf_buf_imag[op_delay + idx][z] = (FLOAT32)0.0f;
291 }
292 }
293
294 pstr_qmf_anal_bank->filter_pos_32 = ptr_win_coeffs_1;
295 pstr_qmf_anal_bank->state_new_samples_pos_low_32 = ptr_filt_states;
296 }
297
ixheaacd_esbr_synthesis_regrp(FLOAT32 * qmf_buf_real,FLOAT32 * qmf_buf_imag,ia_sbr_dec_struct * ptr_sbr_dec,ia_sbr_frame_info_data_struct * ptr_frame_data,ia_sbr_header_data_struct * ptr_header_data,WORD32 stereo_config_idx,WORD32 apply_processing)298 VOID ixheaacd_esbr_synthesis_regrp(
299 FLOAT32 *qmf_buf_real, FLOAT32 *qmf_buf_imag,
300 ia_sbr_dec_struct *ptr_sbr_dec,
301 ia_sbr_frame_info_data_struct *ptr_frame_data,
302 ia_sbr_header_data_struct *ptr_header_data, WORD32 stereo_config_idx,
303 WORD32 apply_processing) {
304 WORD32 i, k;
305 WORD32 stop_border = 0;
306 WORD32 num_anal_bands = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
307 WORD32 x_over_band = num_anal_bands;
308
309 if (apply_processing) {
310 if (ptr_header_data->sbr_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
311 stop_border = 4 * ptr_frame_data->str_frame_info_details.border_vec[0];
312 } else {
313 stop_border = 2 * ptr_frame_data->str_frame_info_details.border_vec[0];
314 }
315 x_over_band = ptr_header_data->pstr_freq_band_data->qmf_sb_prev;
316 }
317
318 if (stereo_config_idx > 0) {
319 for (i = 0; i < stop_border; i++) {
320 for (k = 0; k < 3; k++) {
321 *qmf_buf_real++ =
322 ptr_sbr_dec->qmf_buf_real[(2) + i + HYBRID_FILTER_DELAY][k];
323 *qmf_buf_imag++ =
324 ptr_sbr_dec->qmf_buf_imag[(2) + i + HYBRID_FILTER_DELAY][k];
325 }
326
327 for (; k < x_over_band; k++) {
328 *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
329 *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
330 }
331
332 for (; k < 64; k++) {
333 *qmf_buf_real++ = ptr_sbr_dec->sbr_qmf_out_real[(2) + i][k];
334 *qmf_buf_imag++ = ptr_sbr_dec->sbr_qmf_out_imag[(2) + i][k];
335 }
336
337 qmf_buf_real += 14;
338 qmf_buf_imag += 14;
339 }
340
341 x_over_band = ptr_header_data->pstr_freq_band_data->sub_band_start;
342
343 for (; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
344 for (k = 0; k < 3; k++) {
345 *qmf_buf_real++ =
346 ptr_sbr_dec->qmf_buf_real[(2) + i + HYBRID_FILTER_DELAY][k];
347 *qmf_buf_imag++ =
348 ptr_sbr_dec->qmf_buf_imag[(2) + i + HYBRID_FILTER_DELAY][k];
349 }
350
351 for (; k < x_over_band; k++) {
352 *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
353 *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
354 }
355
356 for (; k < 64; k++) {
357 *qmf_buf_real++ = ptr_sbr_dec->sbr_qmf_out_real[(2) + i][k];
358 *qmf_buf_imag++ = ptr_sbr_dec->sbr_qmf_out_imag[(2) + i][k];
359 }
360
361 qmf_buf_real += 14;
362 qmf_buf_imag += 14;
363 }
364
365 } else {
366 for (i = 0; i < stop_border; i++) {
367 for (k = 0; k < x_over_band; k++) {
368 *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
369 *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
370 }
371
372 for (; k < 64; k++) {
373 *qmf_buf_real++ = ptr_sbr_dec->sbr_qmf_out_real[(2) + i][k];
374 *qmf_buf_imag++ = ptr_sbr_dec->sbr_qmf_out_imag[(2) + i][k];
375 }
376
377 qmf_buf_real += 14;
378 qmf_buf_imag += 14;
379 }
380
381 x_over_band = ptr_header_data->pstr_freq_band_data->sub_band_start;
382
383 for (; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
384 for (k = 0; k < x_over_band; k++) {
385 *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
386 *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
387 }
388
389 for (; k < 64; k++) {
390 *qmf_buf_real++ = ptr_sbr_dec->sbr_qmf_out_real[(2) + i][k];
391 *qmf_buf_imag++ = ptr_sbr_dec->sbr_qmf_out_imag[(2) + i][k];
392 }
393
394 qmf_buf_real += 14;
395 qmf_buf_imag += 14;
396 }
397 }
398 }
399
ixheaacd_mps_esbr_synthesis_regrp(FLOAT32 * qmf_buf_real,FLOAT32 * qmf_buf_imag,ia_sbr_dec_struct * ptr_sbr_dec,WORD32 stereo_config_idx)400 VOID ixheaacd_mps_esbr_synthesis_regrp(FLOAT32 *qmf_buf_real,
401 FLOAT32 *qmf_buf_imag,
402 ia_sbr_dec_struct *ptr_sbr_dec,
403 WORD32 stereo_config_idx) {
404 WORD32 i, k;
405 WORD32 num_anal_bands = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
406 WORD32 x_over_band = num_anal_bands;
407
408 if (stereo_config_idx > 0) {
409 for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
410 for (k = 0; k < 3; k++) {
411 *qmf_buf_real++ =
412 ptr_sbr_dec->qmf_buf_real[(2) + i + HYBRID_FILTER_DELAY][k];
413 *qmf_buf_imag++ =
414 ptr_sbr_dec->qmf_buf_imag[(2) + i + HYBRID_FILTER_DELAY][k];
415 }
416
417 for (; k < x_over_band; k++) {
418 *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
419 *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
420 }
421
422 for (; k < 64; k++) {
423 *qmf_buf_real++ = 0;
424 *qmf_buf_imag++ = 0;
425 }
426
427 qmf_buf_real += 14;
428 qmf_buf_imag += 14;
429 }
430 } else {
431 for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
432 for (k = 0; k < x_over_band; k++) {
433 *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
434 *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
435 }
436
437 for (; k < 64; k++) {
438 *qmf_buf_real++ = 0.0f;
439 *qmf_buf_imag++ = 0.0f;
440 }
441
442 qmf_buf_real += 14;
443 qmf_buf_imag += 14;
444 }
445 }
446 }
447
ixheaacd_esbr_synthesis_filt_block(ia_sbr_dec_struct * ptr_sbr_dec,ia_sbr_header_data_struct * ptr_header_data,ia_sbr_frame_info_data_struct * ptr_frame_data,WORD32 apply_processing,FLOAT32 ** qmf_buf_real,FLOAT32 ** qmf_buf_imag,WORD32 stereo_config_idx,ia_sbr_tables_struct * sbr_tables_ptr,WORD32 mps_sbr_flag,WORD32 ch_fac)448 VOID ixheaacd_esbr_synthesis_filt_block(
449 ia_sbr_dec_struct *ptr_sbr_dec, ia_sbr_header_data_struct *ptr_header_data,
450 ia_sbr_frame_info_data_struct *ptr_frame_data, WORD32 apply_processing,
451 FLOAT32 **qmf_buf_real, FLOAT32 **qmf_buf_imag, WORD32 stereo_config_idx,
452 ia_sbr_tables_struct *sbr_tables_ptr, WORD32 mps_sbr_flag, WORD32 ch_fac) {
453 WORD32 i, k, p1;
454 WORD32 *ptr_filt_states;
455 WORD32 *ptr_filt_states_1;
456 WORD32 *ptr_filt_states_2;
457 WORD32 *filter_l;
458 WORD32 *ploc_qmf_buf_real;
459 WORD32 *ploc_qmf_buf_imag;
460 WORD32 out_scalefactor;
461 WORD32 sixty4;
462 WORD32 no_synthesis_channels;
463 WORD32 ixheaacd_drc_offset;
464 FLOAT32 *syn_buffer;
465 WORD32 *local_qmf_buffer = ptr_sbr_dec->sbr_scratch_local;
466 WORD32 *time_out = &(ptr_sbr_dec->sbr_scratch_local[128]);
467
468 ia_sbr_qmf_filter_bank_struct *qmf_bank =
469 &ptr_sbr_dec->str_synthesis_qmf_bank;
470 ia_qmf_dec_tables_struct *qmf_dec_tables_ptr =
471 sbr_tables_ptr->qmf_dec_tables_ptr;
472
473 if (!mps_sbr_flag) {
474 ixheaacd_esbr_synthesis_regrp(&qmf_buf_real[0][0], &qmf_buf_imag[0][0],
475 ptr_sbr_dec, ptr_frame_data, ptr_header_data,
476 stereo_config_idx, apply_processing);
477 } else {
478 ixheaacd_mps_esbr_synthesis_regrp(&qmf_buf_real[0][0], &qmf_buf_imag[0][0],
479 ptr_sbr_dec, stereo_config_idx);
480 }
481
482 out_scalefactor = 5;
483 qmf_bank->no_channels = 64;
484 qmf_bank->esbr_cos_twiddle =
485 (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l64;
486 qmf_bank->esbr_alt_sin_twiddle =
487 (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l64;
488
489 qmf_bank->filter_pos_syn_32 +=
490 qmf_dec_tables_ptr->esbr_qmf_c - qmf_bank->p_filter_32;
491 qmf_bank->p_filter_32 = qmf_dec_tables_ptr->esbr_qmf_c;
492
493 sixty4 = NO_SYNTHESIS_CHANNELS;
494
495 ptr_filt_states = qmf_bank->filter_states_32;
496
497 no_synthesis_channels = qmf_bank->no_channels;
498 ptr_filt_states_1 = &ptr_filt_states[0];
499 ptr_filt_states_2 = ptr_filt_states_1 + no_synthesis_channels;
500
501 filter_l = qmf_bank->filter_pos_syn_32;
502
503 p1 = 0;
504
505 ixheaacd_drc_offset = qmf_bank->ixheaacd_drc_offset;
506
507 for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
508 for (k = 0; k < 64; k++) {
509 local_qmf_buffer[k + 0] = (WORD32)(qmf_buf_real[i][k] * 64);
510 local_qmf_buffer[k + 64] = (WORD32)(qmf_buf_imag[i][k] * 64);
511 }
512 ploc_qmf_buf_real = local_qmf_buffer;
513 ploc_qmf_buf_imag = local_qmf_buffer + 64;
514
515 ixheaacd_esbr_inv_modulation(ploc_qmf_buf_real,
516 &ptr_sbr_dec->str_synthesis_qmf_bank,
517 sbr_tables_ptr->qmf_dec_tables_ptr);
518
519 ixheaacd_shiftrountine_with_rnd_hq(ploc_qmf_buf_real, ploc_qmf_buf_imag,
520 &ptr_filt_states[ixheaacd_drc_offset],
521 no_synthesis_channels,
522 out_scalefactor + 1);
523
524 ixheaacd_esbr_qmfsyn64_winadd(ptr_filt_states_1, ptr_filt_states_2,
525 filter_l, &time_out[0], ch_fac);
526
527 syn_buffer = ptr_sbr_dec->time_sample_buf + i * 64;
528 for (k = 0; k < 64; k++) {
529 syn_buffer[k] = (FLOAT32)time_out[k] / (1 << 16);
530 }
531
532 ptr_filt_states_1 += sixty4;
533 ptr_filt_states_2 -= sixty4;
534 sixty4 = -sixty4;
535 ixheaacd_drc_offset -= 128;
536
537 if (ixheaacd_drc_offset < 0) ixheaacd_drc_offset += 1280;
538
539 filter_l += 64;
540
541 if (filter_l == qmf_bank->p_filter_32 + 640)
542 filter_l = (WORD32 *)qmf_bank->p_filter_32;
543
544 p1 += no_synthesis_channels;
545 }
546
547 qmf_bank->filter_pos_syn_32 = filter_l;
548 qmf_bank->ixheaacd_drc_offset = ixheaacd_drc_offset;
549
550 if (!mps_sbr_flag) ptr_frame_data->reset_flag = 0;
551
552 if (apply_processing && !mps_sbr_flag) {
553 ptr_header_data->pstr_freq_band_data->qmf_sb_prev =
554 ptr_header_data->pstr_freq_band_data->sub_band_start;
555 }
556 }
557
ixheaacd_sbr_dec(ia_sbr_dec_struct * ptr_sbr_dec,WORD16 * ptr_time_data,ia_sbr_header_data_struct * ptr_header_data,ia_sbr_frame_info_data_struct * ptr_frame_data,ia_sbr_prev_frame_data_struct * ptr_frame_data_prev,ia_ps_dec_struct * ptr_ps_dec,ia_sbr_qmf_filter_bank_struct * ptr_qmf_synth_bank_r,ia_sbr_scale_fact_struct * ptr_sbr_sf_r,FLAG apply_processing,FLAG low_pow_flag,WORD32 * ptr_work_buf_core,ia_sbr_tables_struct * sbr_tables_ptr,ixheaacd_misc_tables * pstr_common_tables,WORD ch_fac,ia_pvc_data_struct * ptr_pvc_data,FLAG drc_on,WORD32 drc_sbr_factors[][64],WORD32 audio_object_type)558 WORD32 ixheaacd_sbr_dec(ia_sbr_dec_struct *ptr_sbr_dec, WORD16 *ptr_time_data,
559 ia_sbr_header_data_struct *ptr_header_data,
560 ia_sbr_frame_info_data_struct *ptr_frame_data,
561 ia_sbr_prev_frame_data_struct *ptr_frame_data_prev,
562 ia_ps_dec_struct *ptr_ps_dec,
563 ia_sbr_qmf_filter_bank_struct *ptr_qmf_synth_bank_r,
564 ia_sbr_scale_fact_struct *ptr_sbr_sf_r,
565 FLAG apply_processing, FLAG low_pow_flag,
566 WORD32 *ptr_work_buf_core,
567 ia_sbr_tables_struct *sbr_tables_ptr,
568 ixheaacd_misc_tables *pstr_common_tables, WORD ch_fac,
569 ia_pvc_data_struct *ptr_pvc_data, FLAG drc_on,
570 WORD32 drc_sbr_factors[][64],
571 WORD32 audio_object_type) {
572 WORD i;
573 WORD slot, reserve;
574 WORD save_lb_scale;
575 WORD op_delay;
576
577 WORD32 *p_arr_qmf_buf_real[MAX_ENV_COLS] = {0};
578 WORD32 *p_arr_qmf_buf_imag[MAX_ENV_COLS] = {0};
579 WORD32 *ptr;
580 WORD hbe_flag = ptr_header_data->hbe_flag;
581
582 FLOAT32 **pp_qmf_buf_real = NULL;
583 FLOAT32 **pp_qmf_buf_imag = NULL;
584 FLOAT32 pvc_dec_out_buf[16 * 64];
585
586 WORD upsample_ratio_idx = ptr_header_data->sbr_ratio_idx;
587 WORD no_bins;
588 WORD mps_sbr_flag = ptr_frame_data->mps_sbr_flag;
589 WORD stereo_config_idx = ptr_frame_data->stereo_config_idx;
590 WORD sbr_mode = ptr_frame_data->sbr_mode;
591 WORD usac_flag = ptr_header_data->usac_flag;
592
593 FLOAT32 *pvc_qmf_enrg_arr = (FLOAT32 *)ptr_sbr_dec->pvc_qmf_enrg_arr;
594
595 memset(pvc_dec_out_buf, 0, 1024 * sizeof(FLOAT32));
596 memset(pvc_qmf_enrg_arr, 0, 512 * sizeof(FLOAT32));
597 if (audio_object_type == AOT_ER_AAC_ELD) {
598 op_delay = 0;
599 } else {
600 op_delay = 6;
601 }
602 if (usac_flag) {
603 pp_qmf_buf_real = ptr_sbr_dec->pp_qmf_buf_real;
604 pp_qmf_buf_imag = ptr_sbr_dec->pp_qmf_buf_imag;
605 if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
606 op_delay = 2 * 6;
607 }
608 }
609
610 no_bins = (ptr_header_data->num_time_slots * ptr_header_data->time_step);
611
612 if (!usac_flag) {
613 WORD32 num = op_delay;
614 WORD32 *ptr_pers_qmf_real = ptr_sbr_dec->ptr_sbr_overlap_buf;
615 WORD32 *p_scr_qmf_real = ptr_work_buf_core + (2 << (6 + !low_pow_flag));
616
617 if ((no_bins < LPC_ORDER) || ((no_bins + op_delay) > MAX_ENV_COLS))
618 return -1;
619
620 if (!low_pow_flag) {
621 num = num << 1;
622 }
623 if (audio_object_type != AOT_ER_AAC_ELD) {
624 memcpy(p_scr_qmf_real, ptr_pers_qmf_real,
625 sizeof(WORD32) * NO_SYNTHESIS_CHANNELS * num);
626 }
627 ptr = p_scr_qmf_real;
628
629 for (slot = 0; slot < op_delay + no_bins; slot++) {
630 p_arr_qmf_buf_real[slot] = ptr;
631 ptr += NO_SYNTHESIS_CHANNELS;
632
633 if (!low_pow_flag) {
634 p_arr_qmf_buf_imag[slot] = ptr;
635 ptr += NO_SYNTHESIS_CHANNELS;
636 }
637 }
638
639 ptr_sbr_dec->str_sbr_scale_fact.lb_scale = 0;
640
641 if (apply_processing) {
642 ixheaacd_rescale_x_overlap(ptr_sbr_dec, ptr_header_data, ptr_frame_data,
643 ptr_frame_data_prev, p_arr_qmf_buf_real,
644 p_arr_qmf_buf_imag, low_pow_flag);
645 }
646 }
647
648 if (usac_flag) {
649 WORD32 num_anal_bands = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
650 WORD32 codec_x_delay = 0;
651 WORD32 core_syn_ch_index = 0;
652 WORD32 frame_move = 288;
653 WORD32 core_frame_size = ptr_header_data->core_frame_size;
654
655 if (hbe_flag) {
656 codec_x_delay = 32;
657 }
658 if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
659 codec_x_delay = 2 * codec_x_delay;
660 }
661
662 if (hbe_flag || mps_sbr_flag) {
663 core_syn_ch_index = num_anal_bands;
664 } else {
665 core_syn_ch_index = ptr_header_data->pstr_freq_band_data->sub_band_start;
666 }
667
668 frame_move = 9 * num_anal_bands;
669
670 memmove(ptr_sbr_dec->core_sample_buf,
671 ptr_sbr_dec->core_sample_buf + core_frame_size,
672 frame_move * sizeof(FLOAT32));
673 memcpy(&ptr_sbr_dec->core_sample_buf[frame_move],
674 &ptr_sbr_dec->time_sample_buf[0], core_frame_size * sizeof(FLOAT32));
675
676 memmove(
677 &ptr_sbr_dec->qmf_buf_real[0][0],
678 &ptr_sbr_dec
679 ->qmf_buf_real[ptr_sbr_dec->str_codec_qmf_bank.num_time_slots][0],
680 (op_delay + SBR_HF_ADJ_OFFSET + codec_x_delay) * sizeof(FLOAT32) * 64);
681
682 memmove(
683 &ptr_sbr_dec->qmf_buf_imag[0][0],
684 &ptr_sbr_dec
685 ->qmf_buf_imag[ptr_sbr_dec->str_codec_qmf_bank.num_time_slots][0],
686 (op_delay + SBR_HF_ADJ_OFFSET + codec_x_delay) * sizeof(FLOAT32) * 64);
687
688 memmove(&ptr_sbr_dec->sbr_qmf_out_real[0][0],
689 &ptr_sbr_dec->sbr_qmf_out_real[ptr_sbr_dec->str_codec_qmf_bank
690 .num_time_slots][0],
691 (op_delay + SBR_HF_ADJ_OFFSET) * sizeof(FLOAT32) * 64);
692
693 memmove(&ptr_sbr_dec->sbr_qmf_out_imag[0][0],
694 &ptr_sbr_dec->sbr_qmf_out_imag[ptr_sbr_dec->str_codec_qmf_bank
695 .num_time_slots][0],
696 (op_delay + SBR_HF_ADJ_OFFSET) * sizeof(FLOAT32) * 64);
697
698 if (hbe_flag) {
699 memmove(&ptr_sbr_dec->ph_vocod_qmf_real[0][0],
700 &ptr_sbr_dec->ph_vocod_qmf_real[ptr_sbr_dec->str_codec_qmf_bank
701 .num_time_slots][0],
702 64 * sizeof(FLOAT32) * (op_delay + SBR_HF_ADJ_OFFSET));
703
704 memmove(ptr_sbr_dec->ph_vocod_qmf_imag,
705 ptr_sbr_dec->ph_vocod_qmf_imag +
706 ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
707 64 * sizeof(FLOAT32) * (op_delay + SBR_HF_ADJ_OFFSET));
708 }
709 ixheaacd_esbr_analysis_filt_block(
710 ptr_sbr_dec, sbr_tables_ptr,
711 op_delay + codec_x_delay + SBR_HF_ADJ_OFFSET);
712
713 if (hbe_flag) {
714 WORD32 err_code = ixheaacd_qmf_hbe_apply(
715 ptr_sbr_dec->p_hbe_txposer,
716 ptr_sbr_dec->qmf_buf_real + (op_delay + SBR_HF_ADJ_OFFSET) +
717 ESBR_HBE_DELAY_OFFSET,
718 ptr_sbr_dec->qmf_buf_imag + (op_delay + SBR_HF_ADJ_OFFSET) +
719 ESBR_HBE_DELAY_OFFSET,
720 ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
721 ptr_sbr_dec->ph_vocod_qmf_real + (op_delay + SBR_HF_ADJ_OFFSET),
722 ptr_sbr_dec->ph_vocod_qmf_imag + (op_delay + SBR_HF_ADJ_OFFSET),
723 ptr_frame_data->pitch_in_bins);
724 if (err_code) return err_code;
725
726 if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
727 ixheaacd_hbe_repl_spec(
728 &ptr_sbr_dec->p_hbe_txposer->x_over_qmf[0],
729 ptr_sbr_dec->ph_vocod_qmf_real + (op_delay + SBR_HF_ADJ_OFFSET),
730 ptr_sbr_dec->ph_vocod_qmf_imag + (op_delay + SBR_HF_ADJ_OFFSET),
731 ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
732 ptr_sbr_dec->p_hbe_txposer->max_stretch);
733 }
734 }
735 ixheaacd_qmf_enrg_calc(ptr_sbr_dec, upsample_ratio_idx, low_pow_flag);
736
737 if (!mps_sbr_flag && apply_processing) {
738 WORD32 err_code = 0;
739 err_code = ixheaacd_generate_hf(
740 ptr_sbr_dec->qmf_buf_real + (SBR_HF_ADJ_OFFSET),
741 ptr_sbr_dec->qmf_buf_imag + (SBR_HF_ADJ_OFFSET),
742 ptr_sbr_dec->ph_vocod_qmf_real + (SBR_HF_ADJ_OFFSET),
743 ptr_sbr_dec->ph_vocod_qmf_imag + (SBR_HF_ADJ_OFFSET),
744 ptr_sbr_dec->sbr_qmf_out_real + (SBR_HF_ADJ_OFFSET),
745 ptr_sbr_dec->sbr_qmf_out_imag + (SBR_HF_ADJ_OFFSET), ptr_frame_data,
746 ptr_header_data);
747 if (err_code) return err_code;
748
749 ptr_pvc_data->pvc_rate = ptr_header_data->upsamp_fac;
750
751 if (sbr_mode == PVC_SBR) {
752 ixheaacd_pvc_process(
753 ptr_pvc_data, ptr_header_data->pstr_freq_band_data->sub_band_start,
754 ptr_frame_data->str_pvc_frame_info.border_vec[0],
755 &pvc_qmf_enrg_arr[0], &pvc_dec_out_buf[0]);
756 ptr_pvc_data->prev_pvc_flg = 1;
757 } else {
758 memset(pvc_dec_out_buf, 0, 1024 * sizeof(FLOAT32));
759 ptr_pvc_data->prev_pvc_flg = 0;
760 }
761
762 ptr_pvc_data->prev_first_bnd_idx =
763 ptr_header_data->pstr_freq_band_data->sub_band_start;
764 ptr_pvc_data->prev_pvc_rate = ptr_pvc_data->pvc_rate;
765
766 ptr_frame_data->pstr_sbr_header = ptr_header_data;
767 err_code = ixheaacd_sbr_env_calc(
768 ptr_frame_data, ptr_sbr_dec->sbr_qmf_out_real + (SBR_HF_ADJ_OFFSET),
769 ptr_sbr_dec->sbr_qmf_out_imag + (SBR_HF_ADJ_OFFSET),
770 ptr_sbr_dec->qmf_buf_real + (SBR_HF_ADJ_OFFSET),
771 ptr_sbr_dec->qmf_buf_imag + (SBR_HF_ADJ_OFFSET),
772 (ptr_header_data->hbe_flag == 0)
773 ? NULL
774 : ptr_sbr_dec->p_hbe_txposer->x_over_qmf,
775 ptr_sbr_dec->scratch_buff, pvc_dec_out_buf);
776 if (err_code) return err_code;
777
778 } else {
779 for (i = 0; i < 64; i++) {
780 memset(ptr_sbr_dec->sbr_qmf_out_real[i], 0, 64 * sizeof(FLOAT32));
781 memset(ptr_sbr_dec->sbr_qmf_out_imag[i], 0, 64 * sizeof(FLOAT32));
782 }
783 }
784
785 ixheaacd_esbr_synthesis_filt_block(
786 ptr_sbr_dec, ptr_header_data, ptr_frame_data, apply_processing,
787 pp_qmf_buf_real, pp_qmf_buf_imag, stereo_config_idx, sbr_tables_ptr,
788 mps_sbr_flag, ch_fac);
789
790 ptr_frame_data->prev_sbr_mode = sbr_mode;
791
792 return 0;
793 }
794
795 ixheaacd_cplx_anal_qmffilt(
796 ptr_time_data, &ptr_sbr_dec->str_sbr_scale_fact,
797 &p_arr_qmf_buf_real[op_delay], &p_arr_qmf_buf_imag[op_delay],
798 &ptr_sbr_dec->str_codec_qmf_bank, sbr_tables_ptr->qmf_dec_tables_ptr,
799 ch_fac, low_pow_flag, audio_object_type);
800
801 {
802 WORD shift1, shift2;
803 WORD min_shift;
804 WORD shift_over;
805 WORD reserve_ov1, reserve_ov2;
806 WORD reservea[2];
807 WORD i = 0;
808 WORD usb = ptr_sbr_dec->str_codec_qmf_bank.usb;
809 WORD iter_val = 1;
810 if (audio_object_type == AOT_ER_AAC_ELD ||
811 audio_object_type == AOT_ER_AAC_LD) {
812 iter_val = 0;
813 }
814 do {
815 WORD t1 = op_delay;
816 WORD t2 = no_bins + op_delay;
817 if (i) {
818 t1 = 0;
819 t2 = op_delay;
820 }
821 reservea[i] = (*ixheaacd_ixheaacd_expsubbandsamples)(
822 p_arr_qmf_buf_real, p_arr_qmf_buf_imag, 0, usb, t1, t2, low_pow_flag);
823 i++;
824 } while (i <= iter_val);
825 ;
826
827 reserve = reservea[0];
828 if (audio_object_type != AOT_ER_AAC_ELD &&
829 audio_object_type != AOT_ER_AAC_LD)
830 reserve_ov1 = reservea[1];
831 else
832 reserve_ov1 = reserve;
833 ptr_sbr_dec->max_samp_val = ixheaacd_min32(reserve, reserve_ov1);
834
835 reserve_ov2 = (*ixheaacd_ixheaacd_expsubbandsamples)(
836 ptr_sbr_dec->str_hf_generator.lpc_filt_states_real,
837 ptr_sbr_dec->str_hf_generator.lpc_filt_states_imag, 0, usb, 0,
838 LPC_ORDER, low_pow_flag);
839
840 reserve_ov1 = ixheaacd_min32(reserve_ov1, reserve_ov2);
841
842 shift1 = ptr_sbr_dec->str_sbr_scale_fact.lb_scale + reserve;
843
844 shift2 = ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale + reserve_ov1;
845 min_shift = ixheaacd_min32(shift1, shift2);
846 shift_over = (shift2 - min_shift);
847 reserve -= (shift1 - min_shift);
848
849 ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale += (reserve_ov1 - shift_over);
850
851 (*ixheaacd_adjust_scale)(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, 0, usb, 0,
852 op_delay, reserve_ov1 - shift_over, low_pow_flag);
853
854 (*ixheaacd_adjust_scale)(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, 0, usb,
855 op_delay, (no_bins + op_delay), reserve,
856 low_pow_flag);
857
858 (*ixheaacd_adjust_scale)(ptr_sbr_dec->str_hf_generator.lpc_filt_states_real,
859 ptr_sbr_dec->str_hf_generator.lpc_filt_states_imag,
860 0, usb, 0, LPC_ORDER, reserve_ov1 - shift_over,
861 low_pow_flag);
862
863 ptr_sbr_dec->str_sbr_scale_fact.lb_scale += reserve;
864
865 save_lb_scale = ptr_sbr_dec->str_sbr_scale_fact.lb_scale;
866 }
867
868 {
869 WORD32 num = no_bins;
870 WORD32 *p_loc_qmf_real =
871 &p_arr_qmf_buf_real[op_delay][NO_ANALYSIS_CHANNELS];
872
873 if (!low_pow_flag) {
874 num = num << 1;
875 }
876
877 ixheaacd_clr_subsamples(p_loc_qmf_real, num - 1, (NO_SYN_ANA_CHANNELS));
878 }
879
880 if (apply_processing) {
881 WORD16 degree_alias[NO_SYNTHESIS_CHANNELS];
882 WORD16 *border_vec = ptr_frame_data->str_frame_info_details.border_vec;
883
884 if (low_pow_flag) {
885 memset(degree_alias, 0, NO_SYNTHESIS_CHANNELS * sizeof(WORD16));
886 }
887
888 if (low_pow_flag) {
889 WORD32 com_low_band_scale;
890 ixheaacd_low_pow_hf_generator(
891 &ptr_sbr_dec->str_hf_generator, p_arr_qmf_buf_real, degree_alias,
892 border_vec[0] * ptr_header_data->time_step,
893 ptr_header_data->time_step *
894 ixheaacd_sub16_sat(
895 border_vec[ptr_frame_data->str_frame_info_details.num_env],
896 ptr_header_data->num_time_slots),
897 ptr_header_data->pstr_freq_band_data->num_if_bands,
898 ptr_frame_data->max_qmf_subband_aac, ptr_frame_data->sbr_invf_mode,
899 ptr_frame_data_prev->sbr_invf_mode, ptr_sbr_dec->max_samp_val,
900 ptr_work_buf_core);
901
902 com_low_band_scale =
903 ixheaacd_min32(ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale,
904 ptr_sbr_dec->str_sbr_scale_fact.lb_scale);
905
906 ptr_sbr_dec->str_sbr_scale_fact.hb_scale =
907 (WORD16)(com_low_band_scale - 2);
908 } else {
909 ixheaacd_hf_generator(
910 &ptr_sbr_dec->str_hf_generator, &ptr_sbr_dec->str_sbr_scale_fact,
911 p_arr_qmf_buf_real, p_arr_qmf_buf_imag, ptr_header_data->time_step,
912 border_vec[0],
913 ixheaacd_sub16_sat(
914 border_vec[ptr_frame_data->str_frame_info_details.num_env],
915 ptr_header_data->num_time_slots),
916 ptr_header_data->pstr_freq_band_data->num_if_bands,
917 ptr_frame_data->max_qmf_subband_aac, ptr_frame_data->sbr_invf_mode,
918 ptr_frame_data_prev->sbr_invf_mode, ptr_work_buf_core,
919 audio_object_type);
920 }
921
922 ixheaacd_calc_sbrenvelope(
923 &ptr_sbr_dec->str_sbr_scale_fact, &ptr_sbr_dec->str_sbr_calc_env,
924 ptr_header_data, ptr_frame_data, ptr_frame_data_prev,
925 p_arr_qmf_buf_real, p_arr_qmf_buf_imag, degree_alias, low_pow_flag,
926 sbr_tables_ptr, pstr_common_tables,
927 ptr_work_buf_core + (LPC_ORDER << (6 + !low_pow_flag)),
928 audio_object_type);
929
930 memcpy(ptr_frame_data_prev->sbr_invf_mode, ptr_frame_data->sbr_invf_mode,
931 ptr_header_data->pstr_freq_band_data->num_if_bands * sizeof(WORD32));
932
933 ptr_frame_data_prev->coupling_mode = ptr_frame_data->coupling_mode;
934 ptr_frame_data_prev->max_qmf_subband_aac =
935 ptr_frame_data->max_qmf_subband_aac;
936 ptr_frame_data_prev->end_position =
937 border_vec[ptr_frame_data->str_frame_info_details.num_env];
938 ptr_frame_data_prev->amp_res = ptr_frame_data->amp_res;
939 } else {
940 ptr_sbr_dec->str_sbr_scale_fact.hb_scale = save_lb_scale;
941 }
942
943 if (!low_pow_flag) {
944 for (i = 0; i < LPC_ORDER; i++) {
945 WORD32 *p_loc_qmf_real = &p_arr_qmf_buf_real[no_bins - LPC_ORDER + i][0];
946 WORD32 *p_loc_qmf_imag = &p_arr_qmf_buf_imag[no_bins - LPC_ORDER + i][0];
947 WORD32 *plpc_filt_states_real =
948 &ptr_sbr_dec->str_hf_generator.lpc_filt_states_real[i][0];
949 WORD32 *plpc_filt_states_imag =
950 &ptr_sbr_dec->str_hf_generator.lpc_filt_states_imag[i][0];
951
952 memcpy(plpc_filt_states_real, p_loc_qmf_real,
953 sizeof(WORD32) * (ptr_sbr_dec->str_codec_qmf_bank.usb));
954 memcpy(plpc_filt_states_imag, p_loc_qmf_imag,
955 sizeof(WORD32) * (ptr_sbr_dec->str_codec_qmf_bank.usb));
956 }
957 } else {
958 for (i = 0; i < LPC_ORDER; i++) {
959 WORD32 *p_loc_qmf_real = &p_arr_qmf_buf_real[no_bins - LPC_ORDER + i][0];
960 WORD32 *plpc_filt_states_real =
961 &ptr_sbr_dec->str_hf_generator.lpc_filt_states_real[i][0];
962 memcpy(plpc_filt_states_real, p_loc_qmf_real,
963 sizeof(WORD32) * (ptr_sbr_dec->str_codec_qmf_bank.usb));
964 }
965 }
966
967 if (apply_processing && ptr_header_data->channel_mode == PS_STEREO &&
968 ((audio_object_type != AOT_ER_AAC_ELD) &&
969 (audio_object_type != AOT_ER_AAC_LD))) {
970 WORD32 ps_scale;
971
972 ixheaacd_init_ps_scale(ptr_ps_dec, &ptr_sbr_dec->str_sbr_scale_fact);
973
974 ixheaacd_cplx_synt_qmffilt(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, op_delay,
975 &ptr_sbr_dec->str_sbr_scale_fact, ptr_time_data,
976 &ptr_sbr_dec->str_synthesis_qmf_bank, ptr_ps_dec,
977 1, 0, sbr_tables_ptr, pstr_common_tables, ch_fac,
978 drc_on, drc_sbr_factors, audio_object_type);
979
980 ps_scale = ptr_sbr_dec->str_sbr_scale_fact.ps_scale;
981 ptr_sbr_sf_r->ov_lb_scale = ps_scale;
982 ptr_sbr_sf_r->lb_scale = ps_scale;
983 ptr_sbr_sf_r->hb_scale = ps_scale;
984
985 ixheaacd_cplx_synt_qmffilt(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, op_delay,
986 ptr_sbr_sf_r, ptr_time_data + 1,
987 ptr_qmf_synth_bank_r, ptr_ps_dec, 0, 0,
988 sbr_tables_ptr, pstr_common_tables, ch_fac,
989 drc_on, drc_sbr_factors, audio_object_type);
990 } else {
991 ixheaacd_cplx_synt_qmffilt(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, op_delay,
992 &ptr_sbr_dec->str_sbr_scale_fact, ptr_time_data,
993 &ptr_sbr_dec->str_synthesis_qmf_bank, ptr_ps_dec,
994 0, low_pow_flag, sbr_tables_ptr,
995 pstr_common_tables, ch_fac, drc_on,
996 drc_sbr_factors, audio_object_type);
997 }
998
999 {
1000 WORD32 num = op_delay;
1001 WORD32 *p_loc_qmf_real = ptr_sbr_dec->ptr_sbr_overlap_buf;
1002 WORD32 *p_loc_qmf_real_1 = &p_arr_qmf_buf_real[no_bins][0];
1003
1004 if (!low_pow_flag) {
1005 num = num << 1;
1006 }
1007
1008 memcpy(p_loc_qmf_real, p_loc_qmf_real_1,
1009 sizeof(WORD32) * NO_SYNTHESIS_CHANNELS * num);
1010 }
1011
1012 ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale = save_lb_scale;
1013 return 0;
1014 }
1015
ixheaacd_esbr_dec(ia_sbr_dec_struct * ptr_sbr_dec,ia_sbr_header_data_struct * ptr_header_data,ia_sbr_frame_info_data_struct * ptr_frame_data,FLAG apply_processing,FLAG low_pow_flag,ia_sbr_tables_struct * ptr_sbr_tables,WORD ch_fac)1016 WORD32 ixheaacd_esbr_dec(ia_sbr_dec_struct *ptr_sbr_dec,
1017 ia_sbr_header_data_struct *ptr_header_data,
1018 ia_sbr_frame_info_data_struct *ptr_frame_data,
1019 FLAG apply_processing, FLAG low_pow_flag,
1020 ia_sbr_tables_struct *ptr_sbr_tables, WORD ch_fac) {
1021 WORD32 i;
1022 WORD32 op_delay;
1023
1024 WORD32 codec_x_delay = 0;
1025
1026 FLOAT32 **pp_qmf_buf_real = ptr_sbr_dec->pp_qmf_buf_real;
1027 FLOAT32 **pp_qmf_buf_imag = ptr_sbr_dec->pp_qmf_buf_imag;
1028
1029 WORD32 upsample_ratio_idx = ptr_header_data->sbr_ratio_idx;
1030 WORD32 core_frame_size = ptr_header_data->core_frame_size;
1031
1032 WORD32 no_bins;
1033 WORD32 mps_sbr_flag = ptr_frame_data->mps_sbr_flag;
1034 WORD32 stereo_config_idx = ptr_frame_data->stereo_config_idx;
1035 WORD32 hbe_flag = ptr_header_data->hbe_flag;
1036 WORD32 sbr_mode = ptr_frame_data->sbr_mode;
1037
1038 op_delay = 6;
1039 if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
1040 op_delay = 2 * 6;
1041 }
1042
1043 no_bins = ptr_sbr_dec->str_codec_qmf_bank.num_time_slots;
1044
1045 ptr_sbr_dec->str_sbr_scale_fact.lb_scale = 0;
1046 {
1047 WORD32 num_anal_bands = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
1048 WORD32 frame_move = 288;
1049 if (hbe_flag) {
1050 codec_x_delay = 32;
1051 }
1052 if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
1053 codec_x_delay = 2 * codec_x_delay;
1054 }
1055
1056 frame_move = 9 * num_anal_bands;
1057
1058 memmove(ptr_sbr_dec->core_sample_buf,
1059 ptr_sbr_dec->core_sample_buf + core_frame_size,
1060 frame_move * sizeof(FLOAT32));
1061
1062 memcpy(&ptr_sbr_dec->core_sample_buf[frame_move],
1063 &ptr_sbr_dec->time_sample_buf[0], core_frame_size * sizeof(FLOAT32));
1064
1065 memmove(
1066 &ptr_sbr_dec->qmf_buf_real[0][0],
1067 &ptr_sbr_dec
1068 ->qmf_buf_real[ptr_sbr_dec->str_codec_qmf_bank.num_time_slots][0],
1069 (op_delay + SBR_HF_ADJ_OFFSET + codec_x_delay) * sizeof(FLOAT32) * 64);
1070 memmove(
1071 &ptr_sbr_dec->qmf_buf_imag[0][0],
1072 &ptr_sbr_dec
1073 ->qmf_buf_imag[ptr_sbr_dec->str_codec_qmf_bank.num_time_slots][0],
1074 (op_delay + SBR_HF_ADJ_OFFSET + codec_x_delay) * sizeof(FLOAT32) * 64);
1075
1076 memmove(&ptr_sbr_dec->sbr_qmf_out_real[0][0],
1077 &ptr_sbr_dec->sbr_qmf_out_real[ptr_sbr_dec->str_codec_qmf_bank
1078 .num_time_slots][0],
1079 (op_delay + SBR_HF_ADJ_OFFSET) * sizeof(FLOAT32) * 64);
1080 memmove(&ptr_sbr_dec->sbr_qmf_out_imag[0][0],
1081 &ptr_sbr_dec->sbr_qmf_out_imag[ptr_sbr_dec->str_codec_qmf_bank
1082 .num_time_slots][0],
1083 (op_delay + SBR_HF_ADJ_OFFSET) * sizeof(FLOAT32) * 64);
1084
1085 if (hbe_flag) {
1086 memmove(&ptr_sbr_dec->ph_vocod_qmf_real[0][0],
1087 &ptr_sbr_dec->ph_vocod_qmf_real[ptr_sbr_dec->str_codec_qmf_bank
1088 .num_time_slots][0],
1089 64 * sizeof(FLOAT32) * (op_delay + SBR_HF_ADJ_OFFSET));
1090 memmove(ptr_sbr_dec->ph_vocod_qmf_imag,
1091 ptr_sbr_dec->ph_vocod_qmf_imag +
1092 ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
1093 64 * sizeof(FLOAT32) * (op_delay + SBR_HF_ADJ_OFFSET));
1094 }
1095 }
1096
1097 ixheaacd_esbr_analysis_filt_block(
1098 ptr_sbr_dec, ptr_sbr_tables,
1099 op_delay + codec_x_delay + SBR_HF_ADJ_OFFSET);
1100
1101 if (hbe_flag) {
1102 WORD32 err = ixheaacd_qmf_hbe_apply(
1103 ptr_sbr_dec->p_hbe_txposer,
1104 ptr_sbr_dec->qmf_buf_real + (op_delay + SBR_HF_ADJ_OFFSET) +
1105 ESBR_HBE_DELAY_OFFSET,
1106 ptr_sbr_dec->qmf_buf_imag + (op_delay + SBR_HF_ADJ_OFFSET) +
1107 ESBR_HBE_DELAY_OFFSET,
1108 ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
1109 ptr_sbr_dec->ph_vocod_qmf_real + (op_delay + SBR_HF_ADJ_OFFSET),
1110 ptr_sbr_dec->ph_vocod_qmf_imag + (op_delay + SBR_HF_ADJ_OFFSET),
1111 ptr_frame_data->pitch_in_bins);
1112 if (err) return err;
1113
1114 if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
1115 ixheaacd_hbe_repl_spec(
1116 &ptr_sbr_dec->p_hbe_txposer->x_over_qmf[0],
1117 ptr_sbr_dec->ph_vocod_qmf_real + (op_delay + SBR_HF_ADJ_OFFSET),
1118 ptr_sbr_dec->ph_vocod_qmf_imag + (op_delay + SBR_HF_ADJ_OFFSET),
1119 ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
1120 ptr_sbr_dec->p_hbe_txposer->max_stretch);
1121 }
1122 }
1123 ixheaacd_qmf_enrg_calc(ptr_sbr_dec, upsample_ratio_idx, low_pow_flag);
1124
1125 for (i = 0; i < 64; i++) {
1126 memset(ptr_sbr_dec->sbr_qmf_out_real[i], 0, 64 * sizeof(FLOAT32));
1127 memset(ptr_sbr_dec->sbr_qmf_out_imag[i], 0, 64 * sizeof(FLOAT32));
1128 }
1129
1130 ixheaacd_esbr_synthesis_filt_block(
1131 ptr_sbr_dec, ptr_header_data, ptr_frame_data, apply_processing,
1132 pp_qmf_buf_real, pp_qmf_buf_imag, stereo_config_idx, ptr_sbr_tables,
1133 mps_sbr_flag, ch_fac);
1134
1135 ptr_frame_data->prev_sbr_mode = sbr_mode;
1136 return 0;
1137 }
1138
ixheaacd_sbr_dec_from_mps(FLOAT32 * p_mps_qmf_output,VOID * p_sbr_dec,VOID * p_sbr_frame,VOID * p_sbr_header)1139 WORD32 ixheaacd_sbr_dec_from_mps(FLOAT32 *p_mps_qmf_output, VOID *p_sbr_dec,
1140 VOID *p_sbr_frame, VOID *p_sbr_header) {
1141 WORD32 i, k;
1142 ia_sbr_frame_info_data_struct *ptr_frame_data =
1143 (ia_sbr_frame_info_data_struct *)p_sbr_frame;
1144 ia_sbr_header_data_struct *ptr_header_data =
1145 (ia_sbr_header_data_struct *)p_sbr_header;
1146 ia_sbr_dec_struct *ptr_sbr_dec = (ia_sbr_dec_struct *)p_sbr_dec;
1147 ia_frame_info_struct *p_frame_info = &ptr_frame_data->str_frame_info_details;
1148 WORD32 no_bins;
1149 WORD32 upsample_ratio_idx = ptr_header_data->sbr_ratio_idx;
1150 WORD32 op_delay = 6 + SBR_HF_ADJ_OFFSET;
1151 WORD32 num_anal_bands = 40;
1152 WORD32 mps_sbr_flag = ptr_frame_data->mps_sbr_flag;
1153 WORD32 err = 0;
1154
1155 if (ptr_header_data->is_usf_4) {
1156 op_delay += 6;
1157 }
1158
1159 num_anal_bands = num_anal_bands - (upsample_ratio_idx << 3);
1160
1161 if (!mps_sbr_flag) {
1162 return 0;
1163 }
1164
1165 no_bins = ptr_header_data->output_framesize / 64;
1166
1167 for (i = 0; i < no_bins; i++) {
1168 FLOAT32 *p_loc_mps_qmf_output =
1169 p_mps_qmf_output + i * (MAX_NUM_QMF_BANDS_ESBR * 2);
1170 for (k = 0; k < ptr_header_data->pstr_freq_band_data->sub_band_start; k++) {
1171 ptr_sbr_dec->mps_qmf_buf_real[op_delay + i][k] = *p_loc_mps_qmf_output++;
1172 ptr_sbr_dec->mps_qmf_buf_imag[op_delay + i][k] = *p_loc_mps_qmf_output++;
1173
1174 ptr_sbr_dec->mps_sbr_qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k] =
1175 ptr_sbr_dec->qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k];
1176 ptr_sbr_dec->mps_sbr_qmf_buf_imag[SBR_HF_ADJ_OFFSET + i][k] =
1177 ptr_sbr_dec->qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k];
1178 }
1179 }
1180
1181 if (ptr_frame_data->reset_flag) {
1182 WORD32 l;
1183 WORD32 start_band = ptr_header_data->pstr_freq_band_data->qmf_sb_prev;
1184 WORD32 end_band = num_anal_bands;
1185 WORD32 start_slot =
1186 SBR_HF_ADJ_OFFSET + ptr_frame_data->rate * p_frame_info->border_vec[0];
1187
1188 for (l = start_slot; l < op_delay; l++) {
1189 for (k = start_band; k < end_band; k++) {
1190 ptr_sbr_dec->mps_qmf_buf_real[l][k] = 0.0;
1191 ptr_sbr_dec->mps_qmf_buf_imag[l][k] = 0.0;
1192 }
1193 }
1194
1195 for (l = 0; l < SBR_HF_ADJ_OFFSET; l++) {
1196 for (k = start_band; k < end_band; k++) {
1197 ptr_sbr_dec->mps_qmf_buf_real[l][k] = 0.0;
1198 ptr_sbr_dec->mps_qmf_buf_imag[l][k] = 0.0;
1199 }
1200 }
1201 }
1202 ptr_header_data->pstr_freq_band_data->qmf_sb_prev =
1203 ptr_header_data->pstr_freq_band_data->sub_band_start;
1204
1205 err = ixheaacd_generate_hf(
1206 ptr_sbr_dec->mps_qmf_buf_real + SBR_HF_ADJ_OFFSET,
1207 ptr_sbr_dec->mps_qmf_buf_imag + SBR_HF_ADJ_OFFSET, NULL, NULL,
1208 ptr_sbr_dec->mps_sbr_qmf_buf_real + SBR_HF_ADJ_OFFSET,
1209 ptr_sbr_dec->mps_sbr_qmf_buf_imag + SBR_HF_ADJ_OFFSET, ptr_frame_data,
1210 ptr_header_data);
1211 if (err) return err;
1212
1213 ptr_frame_data->pstr_sbr_header = ptr_header_data;
1214 ptr_frame_data->sbr_mode = ORIG_SBR;
1215 ptr_frame_data->prev_sbr_mode = ORIG_SBR;
1216 err = ixheaacd_sbr_env_calc(
1217 ptr_frame_data, ptr_sbr_dec->mps_sbr_qmf_buf_real + SBR_HF_ADJ_OFFSET,
1218 ptr_sbr_dec->mps_sbr_qmf_buf_imag + SBR_HF_ADJ_OFFSET,
1219 ptr_sbr_dec->mps_qmf_buf_real + SBR_HF_ADJ_OFFSET,
1220 ptr_sbr_dec->mps_qmf_buf_imag + SBR_HF_ADJ_OFFSET,
1221 (ptr_header_data->hbe_flag == 0) ? NULL
1222 : ptr_sbr_dec->p_hbe_txposer->x_over_qmf,
1223 ptr_sbr_dec->scratch_buff, NULL);
1224
1225 if (err) return err;
1226 for (i = 0; i < no_bins; i++) {
1227 FLOAT32 *p_loc_mps_qmf_output =
1228 p_mps_qmf_output + i * (MAX_NUM_QMF_BANDS_ESBR * 2);
1229 for (k = 0; k < ptr_header_data->pstr_freq_band_data->sub_band_start; k++) {
1230 *p_loc_mps_qmf_output++ =
1231 ptr_sbr_dec->mps_qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k];
1232 *p_loc_mps_qmf_output++ =
1233 ptr_sbr_dec->mps_qmf_buf_imag[SBR_HF_ADJ_OFFSET + i][k];
1234 }
1235 for (k = ptr_header_data->pstr_freq_band_data->sub_band_start; k < 64;
1236 k++) {
1237 *p_loc_mps_qmf_output++ =
1238 ptr_sbr_dec->mps_sbr_qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k];
1239 *p_loc_mps_qmf_output++ =
1240 ptr_sbr_dec->mps_sbr_qmf_buf_imag[SBR_HF_ADJ_OFFSET + i][k];
1241 }
1242 }
1243
1244 for (i = 0; i < op_delay; i++) {
1245 memmove(ptr_sbr_dec->mps_qmf_buf_real[i],
1246 ptr_sbr_dec->mps_qmf_buf_real[no_bins + i], 64 * sizeof(FLOAT32));
1247
1248 memmove(ptr_sbr_dec->mps_qmf_buf_imag[i],
1249 ptr_sbr_dec->mps_qmf_buf_imag[no_bins + i], 64 * sizeof(FLOAT32));
1250
1251 memmove(ptr_sbr_dec->mps_sbr_qmf_buf_real[i],
1252 ptr_sbr_dec->mps_sbr_qmf_buf_real[no_bins + i],
1253 64 * sizeof(FLOAT32));
1254
1255 memmove(ptr_sbr_dec->mps_sbr_qmf_buf_imag[i],
1256 ptr_sbr_dec->mps_sbr_qmf_buf_imag[no_bins + i],
1257 64 * sizeof(FLOAT32));
1258 }
1259
1260 ptr_frame_data->reset_flag = 0;
1261 return err;
1262 }
1263