• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_cnst.h"
45 #include "ixheaacd_ec_defines.h"
46 #include "ixheaacd_ec_struct_def.h"
47 #include "ixheaacd_channelinfo.h"
48 #include "ixheaacd_drc_dec.h"
49 #include "ixheaacd_sbrdecoder.h"
50 
51 #include "ixheaacd_defines.h"
52 #include "ixheaacd_sbrdecoder.h"
53 #include "ixheaacd_definitions.h"
54 #include "ixheaacd_error_codes.h"
55 
56 #include "ixheaacd_pulsedata.h"
57 
58 #include "ixheaacd_sbrdecsettings.h"
59 #include "ixheaacd_sbr_scale.h"
60 #include "ixheaacd_lpp_tran.h"
61 #include "ixheaacd_env_extr_part.h"
62 #include "ixheaacd_sbr_rom.h"
63 #include "ixheaacd_hybrid.h"
64 #include "ixheaacd_ps_dec.h"
65 #include "ixheaacd_env_extr.h"
66 
67 #include "ixheaacd_qmf_dec.h"
68 
69 #include "ixheaacd_env_calc.h"
70 #include "ixheaacd_sbr_const.h"
71 
72 #include "ixheaacd_pvc_dec.h"
73 #include "ixheaacd_sbr_dec.h"
74 #include "ixheaacd_env_extr.h"
75 #include "ixheaacd_env_calc.h"
76 #include "ixheaacd_ps_dec.h"
77 #include "ixheaacd_function_selector.h"
78 
79 #include "ixheaacd_audioobjtypes.h"
80 
ixheaacd_qmf_enrg_calc(ia_sbr_dec_struct * ptr_sbr_dec,WORD32 upsample_ratio_idx,WORD32 low_pow_flag)81 VOID ixheaacd_qmf_enrg_calc(ia_sbr_dec_struct *ptr_sbr_dec,
82                             WORD32 upsample_ratio_idx, WORD32 low_pow_flag) {
83   WORD32 i, j;
84   if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
85     for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
86       for (j = 0; j < 16; j++) {
87         ptr_sbr_dec->qmf_energy_buf[i][j] =
88             ptr_sbr_dec->qmf_buf_real[2 + i][j] *
89             ptr_sbr_dec->qmf_buf_real[2 + i][j];
90         if (!low_pow_flag)
91           ptr_sbr_dec->qmf_energy_buf[i][j] +=
92               (ptr_sbr_dec->qmf_buf_imag[2 + i][j] *
93                ptr_sbr_dec->qmf_buf_imag[2 + i][j]);
94       }
95     }
96 
97     for (i = 0; i < 16; i++) {
98       for (j = 0; j < 16; j++) {
99         ptr_sbr_dec->pvc_qmf_enrg_arr[32 * i + j] =
100             (ptr_sbr_dec->qmf_energy_buf[4 * i + 0][j] +
101              ptr_sbr_dec->qmf_energy_buf[4 * i + 1][j] +
102              ptr_sbr_dec->qmf_energy_buf[4 * i + 2][j] +
103              ptr_sbr_dec->qmf_energy_buf[4 * i + 3][j]) *
104             0.25f;
105       }
106     }
107   } else {
108     for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
109       for (j = 0; j < 32; j++) {
110         ptr_sbr_dec->qmf_energy_buf[i][j] =
111             ptr_sbr_dec->qmf_buf_real[2 + i][j] *
112             ptr_sbr_dec->qmf_buf_real[2 + i][j];
113         if (!low_pow_flag)
114           ptr_sbr_dec->qmf_energy_buf[i][j] +=
115               (ptr_sbr_dec->qmf_buf_imag[2 + i][j] *
116                ptr_sbr_dec->qmf_buf_imag[2 + i][j]);
117       }
118     }
119 
120     for (i = 0; i < 16; i++) {
121       for (j = 0; j < 32; j++) {
122         ptr_sbr_dec->pvc_qmf_enrg_arr[32 * i + j] =
123             (ptr_sbr_dec->qmf_energy_buf[2 * i + 0][j] +
124              ptr_sbr_dec->qmf_energy_buf[2 * i + 1][j]) *
125             0.5f;
126       }
127     }
128   }
129 }
130 
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)131 VOID ixheaacd_hbe_repl_spec(WORD32 x_over_qmf[MAX_NUM_PATCHES],
132                             FLOAT32 qmf_buf_real[][64],
133                             FLOAT32 qmf_buf_imag[][64], WORD32 no_bins,
134                             WORD32 max_stretch) {
135   WORD32 patch_bands;
136   WORD32 patch, band, col, target, source_bands, i;
137   WORD32 num_patches = 0;
138 
139   for (i = 1; i < MAX_NUM_PATCHES; i++) {
140     if (x_over_qmf[i] != 0) {
141       num_patches++;
142     }
143   }
144 
145   for (patch = (max_stretch - 1); patch < num_patches; patch++) {
146     patch_bands = x_over_qmf[patch + 1] - x_over_qmf[patch];
147     target = x_over_qmf[patch];
148     source_bands = x_over_qmf[max_stretch - 1] - x_over_qmf[max_stretch - 2];
149     while (patch_bands > 0) {
150       WORD32 ixheaacd_num_bands = source_bands;
151       WORD32 start_band = x_over_qmf[max_stretch - 1] - 1;
152       if (target + ixheaacd_num_bands >= x_over_qmf[patch + 1]) {
153         ixheaacd_num_bands = x_over_qmf[patch + 1] - target;
154       }
155       if ((((target + ixheaacd_num_bands - 1) & 1) +
156            ((x_over_qmf[max_stretch - 1] - 1) & 1)) &
157           1) {
158         if (ixheaacd_num_bands == source_bands) {
159           ixheaacd_num_bands--;
160         } else {
161           start_band--;
162         }
163       }
164       if (!ixheaacd_num_bands) break;
165       for (col = 0; col < no_bins; col++) {
166         WORD32 i = 0;
167         band = target + ixheaacd_num_bands - 1;
168         if (64 <= band) {
169           band = 63;
170         }
171         if (x_over_qmf[patch + 1] <= band) {
172           band = x_over_qmf[patch + 1] - 1;
173         }
174         for (i = 0; i < ixheaacd_num_bands; i++, band--) {
175           qmf_buf_real[col][band] = qmf_buf_real[col][start_band - i];
176           qmf_buf_imag[col][band] = qmf_buf_imag[col][start_band - i];
177         }
178       }
179       target += ixheaacd_num_bands;
180       patch_bands -= ixheaacd_num_bands;
181     }
182   }
183 }
184 
ixheaacd_esbr_analysis_filt_block(ia_sbr_dec_struct * ptr_sbr_dec,ia_sbr_tables_struct * sbr_tables_ptr,WORD32 op_delay)185 VOID ixheaacd_esbr_analysis_filt_block(ia_sbr_dec_struct *ptr_sbr_dec,
186                                        ia_sbr_tables_struct *sbr_tables_ptr,
187                                        WORD32 op_delay) {
188   FLOAT32 *core_coder_samples;
189   WORD32 *ptr_filt_states;
190   WORD32 *ptr_filt_states_1;
191   WORD32 *ptr_filt_states_2;
192   WORD32 *ptr_temp;
193   WORD32 *ptr_win_coeffs_1;
194   WORD32 *ptr_win_coeffs_2;
195   WORD32 *ptr_win_coeffs;
196   WORD32 *ploc_qmf_buf_real;
197   WORD32 *ploc_qmf_buf_imag;
198   WORD32 local_qmf_buffer[128] = {0};
199   WORD32 anal_buf[2 * 32];
200   WORD32 idx, z;
201   WORD32 core_syn_ch_index;
202   FLOAT32 gain;
203   WORD32 filt_offset;
204   WORD32 num_columns;
205   ia_qmf_dec_tables_struct *qmf_dec_tables_ptr =
206       sbr_tables_ptr->qmf_dec_tables_ptr;
207   ia_sbr_qmf_filter_bank_struct *pstr_qmf_anal_bank =
208       &ptr_sbr_dec->str_codec_qmf_bank;
209   core_coder_samples = ptr_sbr_dec->time_sample_buf;
210   ptr_filt_states = pstr_qmf_anal_bank->state_new_samples_pos_low_32;
211   ptr_win_coeffs_1 = pstr_qmf_anal_bank->filter_pos_32;
212   num_columns = pstr_qmf_anal_bank->no_channels;
213 
214   switch (num_columns) {
215     case 16:
216       ptr_win_coeffs_2 = ptr_win_coeffs_1 + 64;
217       gain = 128.0f;
218       filt_offset = 64;
219       break;
220     case 24:
221       ptr_win_coeffs_2 = ptr_win_coeffs_1 + 24;
222       gain = 12.0f;
223       filt_offset = 24;
224       break;
225     case 32:
226       ptr_win_coeffs_2 = ptr_win_coeffs_1 + 64;
227       gain = 256.0f;
228       filt_offset = 64;
229       break;
230     default:
231       ptr_win_coeffs_2 = ptr_win_coeffs_1 + 64;
232       gain = 256.0f;
233       filt_offset = 64;
234       break;
235   }
236   gain = 1.0f / gain;
237 
238   pstr_qmf_anal_bank->usb = num_columns;
239 
240   ploc_qmf_buf_real = &local_qmf_buffer[0];
241   ploc_qmf_buf_imag = &local_qmf_buffer[64];
242 
243   ptr_filt_states_1 = pstr_qmf_anal_bank->anal_filter_states_32;
244   ptr_filt_states_2 = pstr_qmf_anal_bank->anal_filter_states_32 + num_columns;
245 
246   for (idx = 0; idx < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; idx++) {
247     for (z = 0; z < num_columns; z++) {
248       ptr_filt_states[num_columns - 1 - z] =
249           (WORD32)(core_coder_samples[z] * (1 << 15));
250     }
251     ixheaacd_esbr_qmfanal32_winadd(ptr_filt_states_1, ptr_filt_states_2,
252                                    ptr_win_coeffs_1, ptr_win_coeffs_2, anal_buf,
253                                    num_columns);
254 
255     core_coder_samples += num_columns;
256 
257     ptr_filt_states -= num_columns;
258     if (ptr_filt_states < pstr_qmf_anal_bank->anal_filter_states_32) {
259       ptr_filt_states = pstr_qmf_anal_bank->anal_filter_states_32 +
260                         10 * num_columns - num_columns;
261     }
262 
263     ptr_temp = ptr_filt_states_1;
264     ptr_filt_states_1 = ptr_filt_states_2;
265     ptr_filt_states_2 = ptr_temp;
266 
267     ptr_win_coeffs_1 += filt_offset;
268     ptr_win_coeffs_2 += filt_offset;
269 
270     ptr_win_coeffs = ptr_win_coeffs_1;
271     ptr_win_coeffs_1 = ptr_win_coeffs_2;
272     ptr_win_coeffs_2 = ptr_win_coeffs;
273 
274     if (ptr_win_coeffs_2 >
275         (pstr_qmf_anal_bank->analy_win_coeff_32 + filt_offset * 10)) {
276       ptr_win_coeffs_1 = pstr_qmf_anal_bank->analy_win_coeff_32;
277       ptr_win_coeffs_2 = pstr_qmf_anal_bank->analy_win_coeff_32 + filt_offset;
278     }
279 
280     ixheaacd_esbr_fwd_modulation(anal_buf, &ploc_qmf_buf_real[0],
281                                  &ploc_qmf_buf_imag[0], pstr_qmf_anal_bank,
282                                  qmf_dec_tables_ptr);
283     core_syn_ch_index = num_columns;
284 
285     for (z = 0; z < core_syn_ch_index; z++) {
286       ptr_sbr_dec->qmf_buf_real[op_delay + idx][z] =
287           ((FLOAT32)ploc_qmf_buf_real[z] * gain);
288       ptr_sbr_dec->qmf_buf_imag[op_delay + idx][z] =
289           ((FLOAT32)ploc_qmf_buf_imag[z] * gain);
290     }
291   }
292 
293   pstr_qmf_anal_bank->filter_pos_32 = ptr_win_coeffs_1;
294   pstr_qmf_anal_bank->state_new_samples_pos_low_32 = ptr_filt_states;
295 }
296 
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)297 VOID ixheaacd_esbr_synthesis_regrp(
298     FLOAT32 *qmf_buf_real, FLOAT32 *qmf_buf_imag,
299     ia_sbr_dec_struct *ptr_sbr_dec,
300     ia_sbr_frame_info_data_struct *ptr_frame_data,
301     ia_sbr_header_data_struct *ptr_header_data, WORD32 stereo_config_idx,
302     WORD32 apply_processing) {
303   WORD32 i, k;
304   WORD32 stop_border = 0;
305   WORD32 num_anal_bands = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
306   WORD32 x_over_band = num_anal_bands;
307 
308   if (apply_processing) {
309     if (ptr_header_data->sbr_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
310       stop_border = 4 * ptr_frame_data->str_frame_info_details.border_vec[0];
311     } else {
312       stop_border = 2 * ptr_frame_data->str_frame_info_details.border_vec[0];
313     }
314     x_over_band = ptr_header_data->pstr_freq_band_data->qmf_sb_prev;
315   }
316 
317   if (stereo_config_idx > 0) {
318     for (i = 0; i < stop_border; i++) {
319       for (k = 0; k < 3; k++) {
320         *qmf_buf_real++ =
321             ptr_sbr_dec->qmf_buf_real[(2) + i + HYBRID_FILTER_DELAY][k];
322         *qmf_buf_imag++ =
323             ptr_sbr_dec->qmf_buf_imag[(2) + i + HYBRID_FILTER_DELAY][k];
324       }
325 
326       for (; k < x_over_band; k++) {
327         *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
328         *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
329       }
330 
331       for (; k < 64; k++) {
332         *qmf_buf_real++ = ptr_sbr_dec->sbr_qmf_out_real[(2) + i][k];
333         *qmf_buf_imag++ = ptr_sbr_dec->sbr_qmf_out_imag[(2) + i][k];
334       }
335 
336       qmf_buf_real += 14;
337       qmf_buf_imag += 14;
338     }
339 
340     x_over_band = ptr_header_data->pstr_freq_band_data->sub_band_start;
341 
342     for (; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
343       for (k = 0; k < 3; k++) {
344         *qmf_buf_real++ =
345             ptr_sbr_dec->qmf_buf_real[(2) + i + HYBRID_FILTER_DELAY][k];
346         *qmf_buf_imag++ =
347             ptr_sbr_dec->qmf_buf_imag[(2) + i + HYBRID_FILTER_DELAY][k];
348       }
349 
350       for (; k < x_over_band; k++) {
351         *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
352         *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
353       }
354 
355       for (; k < 64; k++) {
356         *qmf_buf_real++ = ptr_sbr_dec->sbr_qmf_out_real[(2) + i][k];
357         *qmf_buf_imag++ = ptr_sbr_dec->sbr_qmf_out_imag[(2) + i][k];
358       }
359 
360       qmf_buf_real += 14;
361       qmf_buf_imag += 14;
362     }
363 
364   } else {
365     for (i = 0; i < stop_border; i++) {
366       for (k = 0; k < x_over_band; k++) {
367         *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
368         *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
369       }
370 
371       for (; k < 64; k++) {
372         *qmf_buf_real++ = ptr_sbr_dec->sbr_qmf_out_real[(2) + i][k];
373         *qmf_buf_imag++ = ptr_sbr_dec->sbr_qmf_out_imag[(2) + i][k];
374       }
375 
376       qmf_buf_real += 14;
377       qmf_buf_imag += 14;
378     }
379 
380     x_over_band = ptr_header_data->pstr_freq_band_data->sub_band_start;
381 
382     for (; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
383       for (k = 0; k < x_over_band; k++) {
384         *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
385         *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
386       }
387 
388       for (; k < 64; k++) {
389         *qmf_buf_real++ = ptr_sbr_dec->sbr_qmf_out_real[(2) + i][k];
390         *qmf_buf_imag++ = ptr_sbr_dec->sbr_qmf_out_imag[(2) + i][k];
391       }
392 
393       qmf_buf_real += 14;
394       qmf_buf_imag += 14;
395     }
396   }
397 }
398 
ixheaacd_mps_esbr_synthesis_regrp(FLOAT32 * qmf_buf_real,FLOAT32 * qmf_buf_imag,ia_sbr_dec_struct * ptr_sbr_dec,WORD32 stereo_config_idx)399 VOID ixheaacd_mps_esbr_synthesis_regrp(FLOAT32 *qmf_buf_real,
400                                        FLOAT32 *qmf_buf_imag,
401                                        ia_sbr_dec_struct *ptr_sbr_dec,
402                                        WORD32 stereo_config_idx) {
403   WORD32 i, k;
404   WORD32 num_anal_bands = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
405   WORD32 x_over_band = num_anal_bands;
406 
407   if (stereo_config_idx > 0) {
408     for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
409       for (k = 0; k < 3; k++) {
410         *qmf_buf_real++ =
411             ptr_sbr_dec->qmf_buf_real[(2) + i + HYBRID_FILTER_DELAY][k];
412         *qmf_buf_imag++ =
413             ptr_sbr_dec->qmf_buf_imag[(2) + i + HYBRID_FILTER_DELAY][k];
414       }
415 
416       for (; k < x_over_band; k++) {
417         *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
418         *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
419       }
420 
421       for (; k < 64; k++) {
422         *qmf_buf_real++ = 0;
423         *qmf_buf_imag++ = 0;
424       }
425 
426       qmf_buf_real += 14;
427       qmf_buf_imag += 14;
428     }
429   } else {
430     for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
431       for (k = 0; k < x_over_band; k++) {
432         *qmf_buf_real++ = ptr_sbr_dec->qmf_buf_real[(2) + i][k];
433         *qmf_buf_imag++ = ptr_sbr_dec->qmf_buf_imag[(2) + i][k];
434       }
435 
436       for (; k < 64; k++) {
437         *qmf_buf_real++ = 0.0f;
438         *qmf_buf_imag++ = 0.0f;
439       }
440 
441       qmf_buf_real += 14;
442       qmf_buf_imag += 14;
443     }
444   }
445 }
446 
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,WORD32 ps_enable,WORD32 skip_re_grouping,ia_ps_dec_struct * ptr_ps_dec,FLAG drc_on,WORD32 drc_sbr_factors[][64])447 VOID ixheaacd_esbr_synthesis_filt_block(
448     ia_sbr_dec_struct *ptr_sbr_dec, ia_sbr_header_data_struct *ptr_header_data,
449     ia_sbr_frame_info_data_struct *ptr_frame_data, WORD32 apply_processing,
450     FLOAT32 **qmf_buf_real, FLOAT32 **qmf_buf_imag, WORD32 stereo_config_idx,
451     ia_sbr_tables_struct *sbr_tables_ptr, WORD32 mps_sbr_flag, WORD32 ch_fac,
452     WORD32 ps_enable, WORD32 skip_re_grouping, ia_ps_dec_struct *ptr_ps_dec,
453     FLAG drc_on, WORD32 drc_sbr_factors[][64]) {
454 
455     WORD32 i, k;
456     WORD32 *ptr_filt_states;
457     WORD32 *ptr_filt_states_1;
458     WORD32 *ptr_filt_states_2;
459     WORD32 *filter_l;
460     WORD32 *ploc_qmf_buf_real;
461     WORD32 *ploc_qmf_buf_imag;
462     WORD32 out_scalefactor;
463     WORD32 sixty4, thrity2;
464     WORD32 no_synthesis_channels;
465     WORD32 ixheaacd_drc_offset;
466     FLOAT32 *syn_buffer;
467     WORD32 *local_qmf_buffer = ptr_sbr_dec->sbr_scratch_local;
468     WORD32 *time_out = &(ptr_sbr_dec->sbr_scratch_local[128]);
469   FLOAT32 *time_sample_buf;
470   if (ps_enable) {
471     time_sample_buf = ptr_ps_dec->time_sample_buf[0];
472   } else {
473     time_sample_buf = ptr_sbr_dec->time_sample_buf;
474   }
475     ia_sbr_qmf_filter_bank_struct *qmf_bank =
476         &ptr_sbr_dec->str_synthesis_qmf_bank;
477     ia_qmf_dec_tables_struct *qmf_dec_tables_ptr =
478         sbr_tables_ptr->qmf_dec_tables_ptr;
479 
480   if (!skip_re_grouping) {
481     if (!mps_sbr_flag) {
482       ixheaacd_esbr_synthesis_regrp(&qmf_buf_real[0][0], &qmf_buf_imag[0][0],
483                                     ptr_sbr_dec, ptr_frame_data, ptr_header_data,
484                                     stereo_config_idx, apply_processing);
485       if (ps_enable) {
486         FLOAT32 factor = 1.0f;
487         for (i = ptr_ps_dec->num_sub_samples;i < (WORD32)ptr_ps_dec->num_sub_samples + 6;i++) {
488           for (k = 0; k < 5; k++)
489           {
490             if (drc_on)
491             {
492               if (ptr_sbr_dec->str_codec_qmf_bank.num_time_slots == 30)
493               {
494                 factor = (FLOAT32)drc_sbr_factors[i + 30 - 25][k] / Q25;
495               }
496               else
497               {
498                 factor = (FLOAT32)drc_sbr_factors[i + 32 - 26][k] / Q25;
499               }
500             }
501             ptr_ps_dec->pp_qmf_buf_real[0][i][k] =
502               factor * ptr_sbr_dec->qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k];
503             ptr_ps_dec->pp_qmf_buf_imag[0][i][k] =
504               factor * ptr_sbr_dec->qmf_buf_imag[SBR_HF_ADJ_OFFSET + i][k];
505           }
506         }
507       }
508       if (ps_enable && apply_processing) {
509         WORD32 usb = ptr_header_data->pstr_freq_band_data->sub_band_end;
510 
511         ixheaacd_esbr_apply_ps(ptr_ps_dec,
512                                ptr_ps_dec->pp_qmf_buf_real[0],
513                                ptr_ps_dec->pp_qmf_buf_imag[0],
514                                ptr_ps_dec->pp_qmf_buf_real[1],
515                                ptr_ps_dec->pp_qmf_buf_imag[1],
516                                usb, sbr_tables_ptr->ps_tables_ptr,
517                                ptr_header_data->num_time_slots);
518       } else if (ps_enable) {
519         for (i = 0; i < (ptr_header_data->num_time_slots * 2); i++) {
520           for (k = 0; k < 64; k++) {
521             ptr_ps_dec->pp_qmf_buf_real[1][i][k] = ptr_ps_dec->pp_qmf_buf_real[0][i][k];
522             ptr_ps_dec->pp_qmf_buf_imag[1][i][k] = ptr_ps_dec->pp_qmf_buf_imag[0][i][k];
523           }
524         }
525       }
526     } else {
527       ixheaacd_mps_esbr_synthesis_regrp(&qmf_buf_real[0][0], &qmf_buf_imag[0][0],
528                                         ptr_sbr_dec, stereo_config_idx);
529     }
530   } else {
531     if (ps_enable) {
532       time_sample_buf = ptr_ps_dec->time_sample_buf[1];
533     }
534   }
535 
536   if (drc_on)
537   {
538     FLOAT32 factor = 1.0f;
539     for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++)
540     {
541       for (k = 0; k < 64; k++)
542       {
543         if (ptr_sbr_dec->str_codec_qmf_bank.num_time_slots == 30)
544         {
545           factor = (FLOAT32)drc_sbr_factors[i + 30 - 25][k] / Q25;
546         }
547         else
548         {
549           factor = (FLOAT32)drc_sbr_factors[i + 32 - 26][k] / Q25;
550         }
551         qmf_buf_real[i][k] *= factor;
552         qmf_buf_imag[i][k] *= factor;
553       }
554     }
555   }
556 
557   if (stereo_config_idx <= 0) {
558     out_scalefactor = 5;
559     no_synthesis_channels = qmf_bank->no_channels;
560     sixty4 = NO_SYNTHESIS_CHANNELS;
561     thrity2 = qmf_bank->no_channels;
562 
563     if (no_synthesis_channels == NO_SYNTHESIS_CHANNELS_DOWN_SAMPLED)
564     {
565         qmf_bank->esbr_cos_twiddle =
566           (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l32;
567         qmf_bank->esbr_alt_sin_twiddle =
568           (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l32;
569     }
570     else
571     {
572       qmf_bank->esbr_cos_twiddle =
573         (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l64;
574       qmf_bank->esbr_alt_sin_twiddle =
575         (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l64;
576     }
577 
578     qmf_bank->filter_pos_syn_32 +=
579         qmf_dec_tables_ptr->esbr_qmf_c - qmf_bank->p_filter_32;
580     qmf_bank->p_filter_32 = qmf_dec_tables_ptr->esbr_qmf_c;
581 
582     ptr_filt_states = qmf_bank->filter_states_32;
583 
584     ptr_filt_states_1 = &ptr_filt_states[0];
585     ptr_filt_states_2 = ptr_filt_states_1 + no_synthesis_channels;
586 
587     filter_l = qmf_bank->filter_pos_syn_32;
588 
589     ixheaacd_drc_offset = qmf_bank->ixheaacd_drc_offset;
590 
591     for (i = 0; i < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots; i++) {
592       for (k = 0; k < 64; k++) {
593         local_qmf_buffer[k + 0] = (WORD32)(qmf_buf_real[i][k] * 64);
594         local_qmf_buffer[k + 64] = (WORD32)(qmf_buf_imag[i][k] * 64);
595       }
596       ploc_qmf_buf_real = local_qmf_buffer;
597       ploc_qmf_buf_imag = local_qmf_buffer + 64;
598 
599       ixheaacd_esbr_inv_modulation(ploc_qmf_buf_real,
600                                    &ptr_sbr_dec->str_synthesis_qmf_bank,
601                                    sbr_tables_ptr->qmf_dec_tables_ptr,
602                                    no_synthesis_channels);
603 
604       ixheaacd_shiftrountine_with_rnd_hq(ploc_qmf_buf_real, ploc_qmf_buf_imag,
605                                          &ptr_filt_states[ixheaacd_drc_offset],
606                                          no_synthesis_channels,
607                                          out_scalefactor + 1);
608 
609       if (no_synthesis_channels == NO_SYNTHESIS_CHANNELS_DOWN_SAMPLED) {
610         ixheaacd_esbr_qmfsyn32_winadd(ptr_filt_states_1, ptr_filt_states_2,
611                                       filter_l, &time_out[0], ch_fac);
612 
613         if (!mps_sbr_flag) {
614           syn_buffer = time_sample_buf + i * 32;
615         } else {
616           syn_buffer = ptr_sbr_dec->time_sample_buf + i * 32;
617         }
618         for (k = 0; k < 32; k++) {
619           syn_buffer[k] = (FLOAT32)time_out[k] / (1 << 16);
620         }
621 
622         ptr_filt_states_1 += thrity2;
623         ptr_filt_states_2 -= thrity2;
624         thrity2 = -thrity2;
625         ixheaacd_drc_offset -= 64;
626 
627         if (ixheaacd_drc_offset < 0) ixheaacd_drc_offset += 640;
628       } else {
629         ixheaacd_esbr_qmfsyn64_winadd(ptr_filt_states_1, ptr_filt_states_2,
630                                       filter_l, &time_out[0], ch_fac);
631 
632         if (!mps_sbr_flag) {
633           syn_buffer = time_sample_buf + i * 64;
634         } else {
635           syn_buffer = ptr_sbr_dec->time_sample_buf + i * 64;
636         }
637         for (k = 0; k < 64; k++) {
638           syn_buffer[k] = (FLOAT32)time_out[k] / (1 << 16);
639         }
640 
641         ptr_filt_states_1 += sixty4;
642         ptr_filt_states_2 -= sixty4;
643         sixty4 = -sixty4;
644         ixheaacd_drc_offset -= 128;
645 
646         if (ixheaacd_drc_offset < 0) ixheaacd_drc_offset += 1280;
647       }
648 
649       filter_l += 64;
650 
651       if (filter_l == qmf_bank->p_filter_32 + 640)
652         filter_l = (WORD32 *)qmf_bank->p_filter_32;
653     }
654 
655     qmf_bank->filter_pos_syn_32 = filter_l;
656     qmf_bank->ixheaacd_drc_offset = ixheaacd_drc_offset;
657   }
658 
659   if (!mps_sbr_flag) ptr_frame_data->reset_flag = 0;
660 }
661 
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,WORD32 ldmps_present,VOID * self,WORD32 heaac_mps_present,WORD32 ec_flag)662 WORD32 ixheaacd_sbr_dec(
663     ia_sbr_dec_struct *ptr_sbr_dec, WORD16 *ptr_time_data,
664     ia_sbr_header_data_struct *ptr_header_data, ia_sbr_frame_info_data_struct *ptr_frame_data,
665     ia_sbr_prev_frame_data_struct *ptr_frame_data_prev, ia_ps_dec_struct *ptr_ps_dec,
666     ia_sbr_qmf_filter_bank_struct *ptr_qmf_synth_bank_r, ia_sbr_scale_fact_struct *ptr_sbr_sf_r,
667     FLAG apply_processing, FLAG low_pow_flag, WORD32 *ptr_work_buf_core,
668     ia_sbr_tables_struct *sbr_tables_ptr, ixheaacd_misc_tables *pstr_common_tables, WORD ch_fac,
669     ia_pvc_data_struct *ptr_pvc_data, FLAG drc_on, WORD32 drc_sbr_factors[][64],
670     WORD32 audio_object_type, WORD32 ldmps_present, VOID *self, WORD32 heaac_mps_present,
671     WORD32 ec_flag) {
672   WORD i, j, k;
673   WORD slot, reserve;
674   WORD save_lb_scale;
675   WORD op_delay;
676   IA_ERRORCODE err_code = IA_NO_ERROR;
677 
678   WORD32 *p_arr_qmf_buf_real[MAX_ENV_COLS] = {0};
679   WORD32 *p_arr_qmf_buf_imag[MAX_ENV_COLS] = {0};
680   WORD32 *ptr;
681   WORD hbe_flag = ptr_header_data->hbe_flag;
682 
683   FLOAT32 **pp_qmf_buf_real = NULL;
684   FLOAT32 **pp_qmf_buf_imag = NULL;
685   FLOAT32 pvc_dec_out_buf[16 * 64];
686 
687   WORD upsample_ratio_idx = ptr_header_data->sbr_ratio_idx;
688   WORD no_bins;
689   WORD mps_sbr_flag = ptr_frame_data->mps_sbr_flag;
690   WORD stereo_config_idx = ptr_frame_data->stereo_config_idx;
691   WORD sbr_mode = ptr_frame_data->sbr_mode;
692   WORD usac_flag = ptr_header_data->usac_flag;
693   WORD add_slot = 0;
694 
695   FLOAT32 *pvc_qmf_enrg_arr = (FLOAT32 *)ptr_sbr_dec->pvc_qmf_enrg_arr;
696 
697   WORD32 dft_hbe_flag = ptr_header_data->esbr_hq;
698   WORD32 esbr_hbe_delay_offsets;
699   if (ptr_header_data->num_time_slots == 15)
700     esbr_hbe_delay_offsets = ESBR_HBE_DELAY_OFFSET_960;
701   else
702     esbr_hbe_delay_offsets = ESBR_HBE_DELAY_OFFSET;
703 
704   memset(pvc_dec_out_buf, 0, 1024 * sizeof(FLOAT32));
705   memset(pvc_qmf_enrg_arr, 0, 512 * sizeof(FLOAT32));
706   if (audio_object_type == AOT_ER_AAC_ELD) {
707     op_delay = 0;
708   } else {
709     op_delay = 6;
710   }
711 
712   if (ldmps_present == 1) add_slot = SBR_HF_ADJ_OFFSET;
713 
714   if (!((audio_object_type == AOT_ER_AAC_ELD) || (audio_object_type == AOT_ER_AAC_LD))) {
715     ch_fac = 1;
716     pp_qmf_buf_real = ptr_sbr_dec->pp_qmf_buf_real;
717     pp_qmf_buf_imag = ptr_sbr_dec->pp_qmf_buf_imag;
718     if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
719       op_delay = 2 * 6;
720     }
721   }
722 
723   no_bins = (ptr_header_data->num_time_slots * ptr_header_data->time_step);
724 
725   if ((audio_object_type == AOT_ER_AAC_ELD) ||
726       (audio_object_type == AOT_ER_AAC_LD)) {
727     WORD32 num = op_delay;
728     WORD32 *ptr_pers_qmf_real = ptr_sbr_dec->ptr_sbr_overlap_buf;
729     WORD32 *p_scr_qmf_real = ptr_work_buf_core + (2 << (6 + !low_pow_flag));
730 
731     if (ptr_header_data->num_time_slots != 15) {
732       if ((no_bins < LPC_ORDER) || ((no_bins + op_delay) > MAX_ENV_COLS)) {
733         if (ec_flag)
734           no_bins = LPC_ORDER;
735         else
736           return -1;
737       }
738     } else {
739       if ((no_bins < LPC_ORDER) || ((no_bins + op_delay) > MAX_ENV_COLS_960)) {
740         if (ec_flag)
741           no_bins = LPC_ORDER;
742         else
743           return -1;
744       }
745     }
746 
747     if (!low_pow_flag) {
748       num = num << 1;
749     }
750     if (audio_object_type != AOT_ER_AAC_ELD) {
751       memcpy(p_scr_qmf_real, ptr_pers_qmf_real,
752              sizeof(WORD32) * NO_SYNTHESIS_CHANNELS * num);
753     }
754     ptr = p_scr_qmf_real;
755 
756     for (slot = 0; slot < op_delay + no_bins + add_slot; slot++) {
757       p_arr_qmf_buf_real[slot] = ptr;
758       ptr += NO_SYNTHESIS_CHANNELS;
759 
760       if (!low_pow_flag) {
761         p_arr_qmf_buf_imag[slot] = ptr;
762         ptr += NO_SYNTHESIS_CHANNELS;
763       }
764     }
765 
766     ptr_sbr_dec->str_sbr_scale_fact.lb_scale = 0;
767 
768     if (apply_processing) {
769       ixheaacd_rescale_x_overlap(ptr_sbr_dec, ptr_header_data, ptr_frame_data,
770                                  ptr_frame_data_prev, p_arr_qmf_buf_real,
771                                  p_arr_qmf_buf_imag, low_pow_flag);
772     }
773   }
774 
775   if ((audio_object_type == AOT_AAC_LC) && (heaac_mps_present == 1)) {
776     WORD32 num_anal_bands = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
777     WORD32 frame_move = 9 * num_anal_bands;
778     WORD32 core_frame_size = ptr_header_data->core_frame_size;
779 
780     memcpy(&ptr_sbr_dec->core_sample_buf[core_frame_size],
781            &ptr_sbr_dec->time_sample_buf[core_frame_size - frame_move],
782            frame_move * sizeof(FLOAT32));
783 
784     memmove(&ptr_sbr_dec->time_sample_buf[frame_move], &ptr_sbr_dec->time_sample_buf[0],
785             (core_frame_size - frame_move));
786 
787     memcpy(&ptr_sbr_dec->time_sample_buf[0], &ptr_sbr_dec->core_sample_buf[0],
788            frame_move * sizeof(FLOAT32));
789 
790     memcpy(&ptr_sbr_dec->core_sample_buf[0], &ptr_sbr_dec->core_sample_buf[core_frame_size],
791            frame_move * sizeof(FLOAT32));
792   }
793 
794 
795   if ((audio_object_type != AOT_ER_AAC_ELD) &&
796       (audio_object_type != AOT_ER_AAC_LD)) {
797     WORD32 codec_x_delay = 0;
798 
799     if (hbe_flag || !usac_flag) {
800       codec_x_delay = esbr_hbe_delay_offsets;
801     }
802     if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
803       codec_x_delay = 2 * codec_x_delay;
804     }
805     /* fixed decoder delay for bitstreams with SBR 4:1 and stereoConfigIndex 3
806      */
807     if (ptr_header_data->num_time_slots != 15) {
808       if (mps_sbr_flag) op_delay = MPS_SBR_DELAY;
809     } else {
810       if (mps_sbr_flag) op_delay = MPS_SBR_DELAY_960;
811     }
812 
813     {
814     memmove(
815         &ptr_sbr_dec->qmf_buf_real[0][0],
816         &ptr_sbr_dec
817              ->qmf_buf_real[ptr_sbr_dec->str_codec_qmf_bank.num_time_slots][0],
818         (op_delay + SBR_HF_ADJ_OFFSET + codec_x_delay) * sizeof(FLOAT32) * 64);
819 
820     memmove(
821         &ptr_sbr_dec->qmf_buf_imag[0][0],
822         &ptr_sbr_dec
823              ->qmf_buf_imag[ptr_sbr_dec->str_codec_qmf_bank.num_time_slots][0],
824         (op_delay + SBR_HF_ADJ_OFFSET + codec_x_delay) * sizeof(FLOAT32) * 64);
825 
826     memmove(&ptr_sbr_dec->sbr_qmf_out_real[0][0],
827             &ptr_sbr_dec->sbr_qmf_out_real[ptr_sbr_dec->str_codec_qmf_bank
828                                                .num_time_slots][0],
829             (op_delay + SBR_HF_ADJ_OFFSET) * sizeof(FLOAT32) * 64);
830 
831     memmove(&ptr_sbr_dec->sbr_qmf_out_imag[0][0],
832             &ptr_sbr_dec->sbr_qmf_out_imag[ptr_sbr_dec->str_codec_qmf_bank
833                                                .num_time_slots][0],
834             (op_delay + SBR_HF_ADJ_OFFSET) * sizeof(FLOAT32) * 64);
835 
836     if (hbe_flag) {
837       memmove(&ptr_sbr_dec->ph_vocod_qmf_real[0][0],
838               &ptr_sbr_dec->ph_vocod_qmf_real[ptr_sbr_dec->str_codec_qmf_bank
839                                                   .num_time_slots][0],
840               64 * sizeof(FLOAT32) * (op_delay + SBR_HF_ADJ_OFFSET));
841 
842       memmove(ptr_sbr_dec->ph_vocod_qmf_imag,
843               ptr_sbr_dec->ph_vocod_qmf_imag +
844                   ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
845               64 * sizeof(FLOAT32) * (op_delay + SBR_HF_ADJ_OFFSET));
846         if (!usac_flag) {
847           WORD32 qmf_sb_prev = ptr_header_data->pstr_freq_band_data->qmf_sb_prev;
848           for (i = SBR_HF_ADJ_OFFSET; i < op_delay + SBR_HF_ADJ_OFFSET; ++i) {
849             memset(&ptr_sbr_dec->qmf_buf_real[i][qmf_sb_prev], 0, (64 - qmf_sb_prev));
850             memset(&ptr_sbr_dec->qmf_buf_imag[i][qmf_sb_prev], 0, (64 - qmf_sb_prev));
851           }
852         }
853       }
854     }
855     ixheaacd_esbr_analysis_filt_block(
856         ptr_sbr_dec, sbr_tables_ptr,
857         op_delay + codec_x_delay + SBR_HF_ADJ_OFFSET);
858 
859     if (hbe_flag && apply_processing) {
860       if (dft_hbe_flag == 1) {
861         WORD32 err_code = 0;
862         ptr_sbr_dec->p_hbe_txposer->oversampling_flag =
863             ptr_frame_data->over_sampling_flag;
864         err_code = ixheaacd_dft_hbe_apply(
865           ptr_sbr_dec->p_hbe_txposer,
866           ptr_sbr_dec->qmf_buf_real + (op_delay + SBR_HF_ADJ_OFFSET) +
867           esbr_hbe_delay_offsets,
868           ptr_sbr_dec->qmf_buf_imag + (op_delay + SBR_HF_ADJ_OFFSET) +
869           esbr_hbe_delay_offsets,
870           ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
871           ptr_sbr_dec->ph_vocod_qmf_real + (op_delay + SBR_HF_ADJ_OFFSET),
872           ptr_sbr_dec->ph_vocod_qmf_imag + (op_delay + SBR_HF_ADJ_OFFSET),
873           ptr_frame_data->pitch_in_bins, (FLOAT32 *)ptr_work_buf_core);
874         if (err_code) return err_code;
875       } else {
876           WORD32 err_code = ixheaacd_qmf_hbe_apply(
877               ptr_sbr_dec->p_hbe_txposer,
878               ptr_sbr_dec->qmf_buf_real + (op_delay + SBR_HF_ADJ_OFFSET) +
879               esbr_hbe_delay_offsets,
880               ptr_sbr_dec->qmf_buf_imag + (op_delay + SBR_HF_ADJ_OFFSET) +
881               esbr_hbe_delay_offsets,
882               ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
883               ptr_sbr_dec->ph_vocod_qmf_real + (op_delay + SBR_HF_ADJ_OFFSET),
884               ptr_sbr_dec->ph_vocod_qmf_imag + (op_delay + SBR_HF_ADJ_OFFSET),
885               ptr_frame_data->pitch_in_bins, ptr_header_data);
886           if (err_code) return err_code;
887 
888         if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
889           ixheaacd_hbe_repl_spec(
890               &ptr_sbr_dec->p_hbe_txposer->x_over_qmf[0],
891               ptr_sbr_dec->ph_vocod_qmf_real + (op_delay + SBR_HF_ADJ_OFFSET),
892               ptr_sbr_dec->ph_vocod_qmf_imag + (op_delay + SBR_HF_ADJ_OFFSET),
893               ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
894               ptr_sbr_dec->p_hbe_txposer->max_stretch);
895         }
896       }
897     }
898     if (!mps_sbr_flag && apply_processing) {
899       err_code = ixheaacd_generate_hf(ptr_sbr_dec->qmf_buf_real + (SBR_HF_ADJ_OFFSET),
900                                       ptr_sbr_dec->qmf_buf_imag + (SBR_HF_ADJ_OFFSET),
901                                       ptr_sbr_dec->ph_vocod_qmf_real + (SBR_HF_ADJ_OFFSET),
902                                       ptr_sbr_dec->ph_vocod_qmf_imag + (SBR_HF_ADJ_OFFSET),
903                                       ptr_sbr_dec->sbr_qmf_out_real + (SBR_HF_ADJ_OFFSET),
904                                       ptr_sbr_dec->sbr_qmf_out_imag + (SBR_HF_ADJ_OFFSET),
905                                       ptr_frame_data, ptr_header_data, ldmps_present,
906                                       ptr_sbr_dec->str_codec_qmf_bank.num_time_slots, ec_flag);
907       if (err_code) return err_code;
908 
909       ptr_pvc_data->pvc_rate = ptr_header_data->upsamp_fac;
910 
911       if (sbr_mode == PVC_SBR) {
912         ixheaacd_qmf_enrg_calc(ptr_sbr_dec, upsample_ratio_idx, low_pow_flag);
913         if (ec_flag) {
914           ptr_pvc_data->pvc_mode = 1;
915         }
916         err_code = ixheaacd_pvc_process(
917             ptr_pvc_data, ptr_header_data->pstr_freq_band_data->sub_band_start,
918             ptr_frame_data->str_pvc_frame_info.border_vec[0],
919             &pvc_qmf_enrg_arr[0], &pvc_dec_out_buf[0]);
920 
921         if (err_code) return err_code;
922 
923         ptr_pvc_data->prev_pvc_flg = 1;
924       } else {
925         memset(pvc_dec_out_buf, 0, 1024 * sizeof(FLOAT32));
926         ptr_pvc_data->prev_pvc_flg = 0;
927       }
928 
929       ptr_pvc_data->prev_first_bnd_idx =
930           ptr_header_data->pstr_freq_band_data->sub_band_start;
931       ptr_pvc_data->prev_pvc_rate = ptr_pvc_data->pvc_rate;
932 
933       ptr_frame_data->pstr_sbr_header = ptr_header_data;
934       err_code = ixheaacd_sbr_env_calc(
935           ptr_frame_data, ptr_sbr_dec->sbr_qmf_out_real + (SBR_HF_ADJ_OFFSET),
936           ptr_sbr_dec->sbr_qmf_out_imag + (SBR_HF_ADJ_OFFSET),
937           ptr_sbr_dec->qmf_buf_real + (SBR_HF_ADJ_OFFSET),
938           ptr_sbr_dec->qmf_buf_imag + (SBR_HF_ADJ_OFFSET),
939           (ptr_header_data->hbe_flag == 0) ? NULL : ptr_sbr_dec->p_hbe_txposer->x_over_qmf,
940           ptr_sbr_dec->scratch_buff, pvc_dec_out_buf, ldmps_present, ec_flag);
941 
942       if (err_code) return err_code;
943 
944     } else {
945       for (i = 0; i < 64; i++) {
946         memset(ptr_sbr_dec->sbr_qmf_out_real[i], 0, 64 * sizeof(FLOAT32));
947         memset(ptr_sbr_dec->sbr_qmf_out_imag[i], 0, 64 * sizeof(FLOAT32));
948       }
949     }
950 
951     if (!mps_sbr_flag) {
952       ptr_sbr_dec->band_count =
953           ptr_header_data->pstr_freq_band_data->sub_band_end;
954     } else
955       ptr_sbr_dec->band_count = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
956 
957     ixheaacd_esbr_synthesis_filt_block(
958         ptr_sbr_dec, ptr_header_data, ptr_frame_data, apply_processing,
959         pp_qmf_buf_real, pp_qmf_buf_imag, stereo_config_idx, sbr_tables_ptr,
960         mps_sbr_flag, ch_fac,
961         ((ptr_header_data->channel_mode == PS_STEREO) || ptr_header_data->enh_sbr_ps),
962         0, ptr_ps_dec, drc_on, drc_sbr_factors);
963 
964     if (ptr_header_data->enh_sbr_ps || ptr_header_data->channel_mode == PS_STEREO) {
965       pp_qmf_buf_real = ptr_ps_dec->pp_qmf_buf_real[1];
966       pp_qmf_buf_imag = ptr_ps_dec->pp_qmf_buf_imag[1];
967       ixheaacd_esbr_synthesis_filt_block(
968           (ia_sbr_dec_struct *)
969           (&(((ia_handle_sbr_dec_inst_struct)self)->pstr_sbr_channel[1]->str_sbr_dec)),
970           (ia_sbr_header_data_struct *)
971           (&(((ia_handle_sbr_dec_inst_struct)self)->pstr_sbr_header[1])),
972           (ia_sbr_frame_info_data_struct *)
973           (&(((ia_handle_sbr_dec_inst_struct)self)->frame_buffer[1])), apply_processing,
974           pp_qmf_buf_real, pp_qmf_buf_imag, stereo_config_idx, sbr_tables_ptr,
975           mps_sbr_flag, ch_fac,
976           ((ptr_header_data->channel_mode == PS_STEREO) || ptr_header_data->enh_sbr_ps),
977           1, ptr_ps_dec, drc_on, drc_sbr_factors);
978     }
979     if (apply_processing && ec_flag) {
980       WORD16 *border_vec = ptr_frame_data->str_frame_info_details.border_vec;
981       ptr_frame_data_prev->end_position =
982           border_vec[ptr_frame_data->str_frame_info_details.num_env];
983     }
984     ptr_frame_data->prev_sbr_mode = sbr_mode;
985 
986     return 0;
987   }
988 
989   if (ldmps_present) {
990     if (ptr_sbr_dec->str_codec_qmf_bank.no_channels > 32) {
991       if (ec_flag) {
992         ptr_sbr_dec->str_codec_qmf_bank.no_channels = 32;
993       } else {
994         return IA_FATAL_ERROR;
995       }
996     }
997     ixheaacd_cplx_anal_qmffilt_32(
998         (WORD32 *)ptr_time_data, &ptr_sbr_dec->str_sbr_scale_fact,
999         &p_arr_qmf_buf_real[op_delay], &p_arr_qmf_buf_imag[op_delay],
1000         &ptr_sbr_dec->str_codec_qmf_bank, sbr_tables_ptr->qmf_dec_tables_ptr,
1001         ch_fac, 1);
1002   } else {
1003     ixheaacd_cplx_anal_qmffilt(
1004         ptr_time_data, &ptr_sbr_dec->str_sbr_scale_fact, &p_arr_qmf_buf_real[op_delay],
1005         &p_arr_qmf_buf_imag[op_delay], &ptr_sbr_dec->str_codec_qmf_bank,
1006         sbr_tables_ptr->qmf_dec_tables_ptr, ch_fac, low_pow_flag, audio_object_type);
1007   }
1008 
1009   if (ldmps_present == 1) {
1010     for (j = SBR_HF_ADJ_OFFSET;
1011          j < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots + SBR_HF_ADJ_OFFSET;
1012          j++) {
1013       for (k = 0; k < 64; k++) {
1014         WORD32 scale = 7;
1015         ptr_sbr_dec->mps_qmf_buf_real[j][k] = 0.0f;
1016         ptr_sbr_dec->mps_qmf_buf_imag[j][k] = 0.0f;
1017         if (k < ptr_sbr_dec->str_codec_qmf_bank.usb) {
1018           ptr_sbr_dec->mps_qmf_buf_real[j][k] +=
1019               (FLOAT32)(p_arr_qmf_buf_real[j][k] / (FLOAT32)(1 << scale));
1020           ptr_sbr_dec->mps_qmf_buf_imag[j][k] +=
1021               (FLOAT32)(p_arr_qmf_buf_imag[j][k] / (FLOAT32)(1 << scale));
1022         }
1023       }
1024     }
1025   }
1026   /*ITTIAM : the size of real and img coeff are not same as that of the mps
1027    * analysis.*/
1028   {
1029     WORD shift1, shift2;
1030     WORD min_shift;
1031     WORD shift_over;
1032     WORD reserve_ov1, reserve_ov2;
1033     WORD reservea[2];
1034     WORD i = 0;
1035     WORD usb = ptr_sbr_dec->str_codec_qmf_bank.usb;
1036     WORD iter_val = 1;
1037     if (audio_object_type == AOT_ER_AAC_ELD ||
1038         audio_object_type == AOT_ER_AAC_LD) {
1039       iter_val = 0;
1040     }
1041     do {
1042       WORD t1 = op_delay;
1043       WORD t2 = no_bins + op_delay;
1044       if (i) {
1045         t1 = 0;
1046         t2 = op_delay;
1047       }
1048       reservea[i] = (*ixheaacd_ixheaacd_expsubbandsamples)(
1049           p_arr_qmf_buf_real, p_arr_qmf_buf_imag, 0, usb, t1, t2, low_pow_flag);
1050       i++;
1051     } while (i <= iter_val);
1052     ;
1053 
1054     reserve = reservea[0];
1055     if (audio_object_type != AOT_ER_AAC_ELD &&
1056         audio_object_type != AOT_ER_AAC_LD)
1057       reserve_ov1 = reservea[1];
1058     else
1059       reserve_ov1 = reserve;
1060     ptr_sbr_dec->max_samp_val = ixheaacd_min32(reserve, reserve_ov1);
1061 
1062     reserve_ov2 = (*ixheaacd_ixheaacd_expsubbandsamples)(
1063         ptr_sbr_dec->str_hf_generator.lpc_filt_states_real,
1064         ptr_sbr_dec->str_hf_generator.lpc_filt_states_imag, 0, usb, 0,
1065         LPC_ORDER, low_pow_flag);
1066 
1067     reserve_ov1 = ixheaacd_min32(reserve_ov1, reserve_ov2);
1068 
1069     shift1 = ptr_sbr_dec->str_sbr_scale_fact.lb_scale + reserve;
1070 
1071     shift2 = ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale + reserve_ov1;
1072     min_shift = ixheaacd_min32(shift1, shift2);
1073     shift_over = (shift2 - min_shift);
1074     reserve -= (shift1 - min_shift);
1075 
1076     ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale += (reserve_ov1 - shift_over);
1077 
1078     (*ixheaacd_adjust_scale)(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, 0, usb, 0,
1079                              op_delay, reserve_ov1 - shift_over, low_pow_flag);
1080 
1081     (*ixheaacd_adjust_scale)(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, 0, usb,
1082                              op_delay, (no_bins + op_delay), reserve,
1083                              low_pow_flag);
1084 
1085     (*ixheaacd_adjust_scale)(ptr_sbr_dec->str_hf_generator.lpc_filt_states_real,
1086                              ptr_sbr_dec->str_hf_generator.lpc_filt_states_imag,
1087                              0, usb, 0, LPC_ORDER, reserve_ov1 - shift_over,
1088                              low_pow_flag);
1089 
1090     ptr_sbr_dec->str_sbr_scale_fact.lb_scale += reserve;
1091 
1092     save_lb_scale = ptr_sbr_dec->str_sbr_scale_fact.lb_scale;
1093   }
1094 
1095   {
1096     WORD32 num = no_bins;
1097     WORD32 *p_loc_qmf_real =
1098         &p_arr_qmf_buf_real[op_delay][NO_ANALYSIS_CHANNELS];
1099 
1100     if (!low_pow_flag) {
1101       num = num << 1;
1102     }
1103 
1104     ixheaacd_clr_subsamples(p_loc_qmf_real, num - 1, (NO_SYN_ANA_CHANNELS));
1105   }
1106 
1107   if (apply_processing) {
1108     WORD16 degree_alias[NO_SYNTHESIS_CHANNELS];
1109     WORD16 *border_vec = ptr_frame_data->str_frame_info_details.border_vec;
1110 
1111     if (low_pow_flag) {
1112       memset(degree_alias, 0, NO_SYNTHESIS_CHANNELS * sizeof(WORD16));
1113     }
1114 
1115     if (low_pow_flag) {
1116       WORD32 com_low_band_scale;
1117       ixheaacd_low_pow_hf_generator(
1118           &ptr_sbr_dec->str_hf_generator, p_arr_qmf_buf_real, degree_alias,
1119           border_vec[0] * ptr_header_data->time_step,
1120           ptr_header_data->time_step *
1121               ixheaacd_sub16_sat(
1122                   border_vec[ptr_frame_data->str_frame_info_details.num_env],
1123                   ptr_header_data->num_time_slots),
1124           ptr_header_data->pstr_freq_band_data->num_if_bands,
1125           ptr_frame_data->max_qmf_subband_aac, ptr_frame_data->sbr_invf_mode,
1126           ptr_frame_data_prev->sbr_invf_mode, ptr_sbr_dec->max_samp_val,
1127           ptr_work_buf_core);
1128 
1129       com_low_band_scale =
1130           ixheaacd_min32(ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale,
1131                          ptr_sbr_dec->str_sbr_scale_fact.lb_scale);
1132 
1133       ptr_sbr_dec->str_sbr_scale_fact.hb_scale =
1134           (WORD16)(com_low_band_scale - 2);
1135     } else {
1136       if (ldmps_present == 1) {
1137         err_code = ixheaacd_generate_hf(ptr_sbr_dec->mps_qmf_buf_real + (SBR_HF_ADJ_OFFSET),
1138                                         ptr_sbr_dec->mps_qmf_buf_imag + (SBR_HF_ADJ_OFFSET),
1139                                         ptr_sbr_dec->ph_vocod_qmf_real + (SBR_HF_ADJ_OFFSET),
1140                                         ptr_sbr_dec->ph_vocod_qmf_imag + (SBR_HF_ADJ_OFFSET),
1141                                         ptr_sbr_dec->sbr_qmf_out_real + (SBR_HF_ADJ_OFFSET),
1142                                         ptr_sbr_dec->sbr_qmf_out_imag + (SBR_HF_ADJ_OFFSET),
1143                                         ptr_frame_data, ptr_header_data, ldmps_present,
1144                                         ptr_sbr_dec->str_codec_qmf_bank.num_time_slots, ec_flag);
1145         if (err_code) return err_code;
1146       } else {
1147         ixheaacd_hf_generator(
1148             &ptr_sbr_dec->str_hf_generator, &ptr_sbr_dec->str_sbr_scale_fact,
1149             p_arr_qmf_buf_real, p_arr_qmf_buf_imag, ptr_header_data->time_step,
1150             border_vec[0],
1151             ixheaacd_sub16_sat(
1152                 border_vec[ptr_frame_data->str_frame_info_details.num_env],
1153                 ptr_header_data->num_time_slots),
1154             ptr_header_data->pstr_freq_band_data->num_if_bands,
1155             ptr_frame_data->max_qmf_subband_aac, ptr_frame_data->sbr_invf_mode,
1156             ptr_frame_data_prev->sbr_invf_mode, ptr_work_buf_core,
1157             audio_object_type);
1158       }
1159     }
1160     if (ldmps_present == 1) {
1161       ptr_frame_data->pstr_sbr_header = ptr_header_data;
1162       err_code = ixheaacd_sbr_env_calc(
1163           ptr_frame_data, ptr_sbr_dec->sbr_qmf_out_real + (SBR_HF_ADJ_OFFSET),
1164           ptr_sbr_dec->sbr_qmf_out_imag + (SBR_HF_ADJ_OFFSET),
1165           ptr_sbr_dec->qmf_buf_real + (SBR_HF_ADJ_OFFSET),
1166           ptr_sbr_dec->qmf_buf_imag + (SBR_HF_ADJ_OFFSET), NULL, ptr_sbr_dec->scratch_buff,
1167           pvc_dec_out_buf, ldmps_present, ec_flag);
1168 
1169       for (j = 0; j < ptr_sbr_dec->str_codec_qmf_bank.num_time_slots + 2; j++) {
1170         for (k = ptr_sbr_dec->str_codec_qmf_bank.usb; k < 64; k++) {
1171           ptr_sbr_dec->mps_qmf_buf_real[j][k] +=
1172               ptr_sbr_dec->sbr_qmf_out_real[j][k];
1173           ptr_sbr_dec->mps_qmf_buf_imag[j][k] +=
1174               ptr_sbr_dec->sbr_qmf_out_imag[j][k];
1175         }
1176       }
1177     } else {
1178       err_code = ixheaacd_calc_sbrenvelope(
1179           &ptr_sbr_dec->str_sbr_scale_fact, &ptr_sbr_dec->str_sbr_calc_env,
1180           ptr_header_data, ptr_frame_data, ptr_frame_data_prev,
1181           p_arr_qmf_buf_real, p_arr_qmf_buf_imag, degree_alias, low_pow_flag,
1182           sbr_tables_ptr, pstr_common_tables,
1183           ptr_work_buf_core + (LPC_ORDER << (6 + !low_pow_flag)),
1184           audio_object_type);
1185       if (err_code) return err_code;
1186     }
1187 
1188     memcpy(ptr_frame_data_prev->sbr_invf_mode, ptr_frame_data->sbr_invf_mode,
1189            ptr_header_data->pstr_freq_band_data->num_if_bands * sizeof(WORD32));
1190 
1191     ptr_frame_data_prev->coupling_mode = ptr_frame_data->coupling_mode;
1192     ptr_frame_data_prev->max_qmf_subband_aac =
1193         ptr_frame_data->max_qmf_subband_aac;
1194     ptr_frame_data_prev->end_position =
1195         border_vec[ptr_frame_data->str_frame_info_details.num_env];
1196     ptr_frame_data_prev->amp_res = ptr_frame_data->amp_res;
1197   } else {
1198     ptr_sbr_dec->str_sbr_scale_fact.hb_scale = save_lb_scale;
1199   }
1200 
1201   if (!low_pow_flag) {
1202     for (i = 0; i < LPC_ORDER; i++) {
1203       WORD32 *p_loc_qmf_real = &p_arr_qmf_buf_real[no_bins - LPC_ORDER + i][0];
1204       WORD32 *p_loc_qmf_imag = &p_arr_qmf_buf_imag[no_bins - LPC_ORDER + i][0];
1205       WORD32 *plpc_filt_states_real =
1206           &ptr_sbr_dec->str_hf_generator.lpc_filt_states_real[i][0];
1207       WORD32 *plpc_filt_states_imag =
1208           &ptr_sbr_dec->str_hf_generator.lpc_filt_states_imag[i][0];
1209 
1210       memcpy(plpc_filt_states_real, p_loc_qmf_real,
1211              sizeof(WORD32) * (ptr_sbr_dec->str_codec_qmf_bank.usb));
1212       memcpy(plpc_filt_states_imag, p_loc_qmf_imag,
1213              sizeof(WORD32) * (ptr_sbr_dec->str_codec_qmf_bank.usb));
1214     }
1215   } else {
1216     for (i = 0; i < LPC_ORDER; i++) {
1217       WORD32 *p_loc_qmf_real = &p_arr_qmf_buf_real[no_bins - LPC_ORDER + i][0];
1218       WORD32 *plpc_filt_states_real =
1219           &ptr_sbr_dec->str_hf_generator.lpc_filt_states_real[i][0];
1220       memcpy(plpc_filt_states_real, p_loc_qmf_real,
1221              sizeof(WORD32) * (ptr_sbr_dec->str_codec_qmf_bank.usb));
1222     }
1223   }
1224 
1225   if (apply_processing && ptr_header_data->channel_mode == PS_STEREO &&
1226       ((audio_object_type != AOT_ER_AAC_ELD) &&
1227        (audio_object_type != AOT_ER_AAC_LD))) {
1228     WORD32 ps_scale;
1229 
1230     ixheaacd_init_ps_scale(ptr_ps_dec, &ptr_sbr_dec->str_sbr_scale_fact);
1231 
1232     ixheaacd_cplx_synt_qmffilt(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, op_delay,
1233                                &ptr_sbr_dec->str_sbr_scale_fact, ptr_time_data,
1234                                &ptr_sbr_dec->str_synthesis_qmf_bank, ptr_ps_dec,
1235                                1, 0, sbr_tables_ptr, pstr_common_tables, ch_fac,
1236                                drc_on, drc_sbr_factors, audio_object_type);
1237 
1238     ps_scale = ptr_sbr_dec->str_sbr_scale_fact.ps_scale;
1239     ptr_sbr_sf_r->ov_lb_scale = ps_scale;
1240     ptr_sbr_sf_r->lb_scale = ps_scale;
1241     ptr_sbr_sf_r->hb_scale = ps_scale;
1242 
1243     ixheaacd_cplx_synt_qmffilt(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, op_delay,
1244                                ptr_sbr_sf_r, ptr_time_data + 1,
1245                                ptr_qmf_synth_bank_r, ptr_ps_dec, 0, 0,
1246                                sbr_tables_ptr, pstr_common_tables, ch_fac,
1247                                drc_on, drc_sbr_factors, audio_object_type);
1248   } else {
1249     ixheaacd_cplx_synt_qmffilt(p_arr_qmf_buf_real, p_arr_qmf_buf_imag, op_delay,
1250                                &ptr_sbr_dec->str_sbr_scale_fact, ptr_time_data,
1251                                &ptr_sbr_dec->str_synthesis_qmf_bank, ptr_ps_dec,
1252                                0, low_pow_flag, sbr_tables_ptr,
1253                                pstr_common_tables, ch_fac, drc_on,
1254                                drc_sbr_factors, audio_object_type);
1255   }
1256 
1257   {
1258     WORD32 num = op_delay;
1259     WORD32 *p_loc_qmf_real = ptr_sbr_dec->ptr_sbr_overlap_buf;
1260     WORD32 *p_loc_qmf_real_1 = &p_arr_qmf_buf_real[no_bins][0];
1261 
1262     if (!low_pow_flag) {
1263       num = num << 1;
1264     }
1265 
1266     memcpy(p_loc_qmf_real, p_loc_qmf_real_1,
1267            sizeof(WORD32) * NO_SYNTHESIS_CHANNELS * num);
1268 
1269     if (ldmps_present == 1) {
1270       memmove(&ptr_sbr_dec->mps_qmf_buf_real[0][0],
1271               &ptr_sbr_dec->mps_qmf_buf_real[ptr_sbr_dec->str_codec_qmf_bank
1272                                                  .num_time_slots][0],
1273               SBR_HF_ADJ_OFFSET * sizeof(FLOAT32) * 64);
1274 
1275       memmove(&ptr_sbr_dec->mps_qmf_buf_imag[0][0],
1276               &ptr_sbr_dec->mps_qmf_buf_imag[ptr_sbr_dec->str_codec_qmf_bank
1277                                                  .num_time_slots][0],
1278               SBR_HF_ADJ_OFFSET * sizeof(FLOAT32) * 64);
1279     }
1280   }
1281 
1282   ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale = save_lb_scale;
1283   return 0;
1284 }
1285 
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)1286 WORD32 ixheaacd_esbr_dec(ia_sbr_dec_struct *ptr_sbr_dec,
1287                          ia_sbr_header_data_struct *ptr_header_data,
1288                          ia_sbr_frame_info_data_struct *ptr_frame_data,
1289                          FLAG apply_processing, FLAG low_pow_flag,
1290                          ia_sbr_tables_struct *ptr_sbr_tables, WORD ch_fac) {
1291   WORD32 i;
1292   WORD32 op_delay;
1293 
1294   WORD32 codec_x_delay = 0;
1295 
1296   FLOAT32 **pp_qmf_buf_real = ptr_sbr_dec->pp_qmf_buf_real;
1297   FLOAT32 **pp_qmf_buf_imag = ptr_sbr_dec->pp_qmf_buf_imag;
1298 
1299   WORD32 upsample_ratio_idx = ptr_header_data->sbr_ratio_idx;
1300 
1301   WORD32 mps_sbr_flag = ptr_frame_data->mps_sbr_flag;
1302   WORD32 stereo_config_idx = ptr_frame_data->stereo_config_idx;
1303   WORD32 hbe_flag = ptr_header_data->hbe_flag;
1304   WORD32 sbr_mode = ptr_frame_data->sbr_mode;
1305 
1306   op_delay = 6;
1307   if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
1308     op_delay = 2 * 6;
1309   }
1310 
1311   ptr_sbr_dec->str_sbr_scale_fact.lb_scale = 0;
1312   {
1313     if (hbe_flag) {
1314       codec_x_delay = 32;
1315     }
1316     if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
1317       codec_x_delay = 2 * codec_x_delay;
1318     }
1319 
1320     memmove(
1321         &ptr_sbr_dec->qmf_buf_real[0][0],
1322         &ptr_sbr_dec
1323              ->qmf_buf_real[ptr_sbr_dec->str_codec_qmf_bank.num_time_slots][0],
1324         (op_delay + SBR_HF_ADJ_OFFSET + codec_x_delay) * sizeof(FLOAT32) * 64);
1325     memmove(
1326         &ptr_sbr_dec->qmf_buf_imag[0][0],
1327         &ptr_sbr_dec
1328              ->qmf_buf_imag[ptr_sbr_dec->str_codec_qmf_bank.num_time_slots][0],
1329         (op_delay + SBR_HF_ADJ_OFFSET + codec_x_delay) * sizeof(FLOAT32) * 64);
1330 
1331     memmove(&ptr_sbr_dec->sbr_qmf_out_real[0][0],
1332             &ptr_sbr_dec->sbr_qmf_out_real[ptr_sbr_dec->str_codec_qmf_bank
1333                                                .num_time_slots][0],
1334             (op_delay + SBR_HF_ADJ_OFFSET) * sizeof(FLOAT32) * 64);
1335     memmove(&ptr_sbr_dec->sbr_qmf_out_imag[0][0],
1336             &ptr_sbr_dec->sbr_qmf_out_imag[ptr_sbr_dec->str_codec_qmf_bank
1337                                                .num_time_slots][0],
1338             (op_delay + SBR_HF_ADJ_OFFSET) * sizeof(FLOAT32) * 64);
1339 
1340     if (hbe_flag) {
1341       memmove(&ptr_sbr_dec->ph_vocod_qmf_real[0][0],
1342               &ptr_sbr_dec->ph_vocod_qmf_real[ptr_sbr_dec->str_codec_qmf_bank
1343                                                   .num_time_slots][0],
1344               64 * sizeof(FLOAT32) * (op_delay + SBR_HF_ADJ_OFFSET));
1345       memmove(ptr_sbr_dec->ph_vocod_qmf_imag,
1346               ptr_sbr_dec->ph_vocod_qmf_imag +
1347                   ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
1348               64 * sizeof(FLOAT32) * (op_delay + SBR_HF_ADJ_OFFSET));
1349     }
1350   }
1351 
1352   ixheaacd_esbr_analysis_filt_block(
1353       ptr_sbr_dec, ptr_sbr_tables,
1354       op_delay + codec_x_delay + SBR_HF_ADJ_OFFSET);
1355 
1356   if (hbe_flag) {
1357     WORD32 err = ixheaacd_qmf_hbe_apply(
1358         ptr_sbr_dec->p_hbe_txposer,
1359         ptr_sbr_dec->qmf_buf_real + (op_delay + SBR_HF_ADJ_OFFSET) +
1360             ESBR_HBE_DELAY_OFFSET,
1361         ptr_sbr_dec->qmf_buf_imag + (op_delay + SBR_HF_ADJ_OFFSET) +
1362             ESBR_HBE_DELAY_OFFSET,
1363         ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
1364         ptr_sbr_dec->ph_vocod_qmf_real + (op_delay + SBR_HF_ADJ_OFFSET),
1365         ptr_sbr_dec->ph_vocod_qmf_imag + (op_delay + SBR_HF_ADJ_OFFSET),
1366         ptr_frame_data->pitch_in_bins, ptr_header_data);
1367     if (err) return err;
1368 
1369     if (upsample_ratio_idx == SBR_UPSAMPLE_IDX_4_1) {
1370       ixheaacd_hbe_repl_spec(
1371           &ptr_sbr_dec->p_hbe_txposer->x_over_qmf[0],
1372           ptr_sbr_dec->ph_vocod_qmf_real + (op_delay + SBR_HF_ADJ_OFFSET),
1373           ptr_sbr_dec->ph_vocod_qmf_imag + (op_delay + SBR_HF_ADJ_OFFSET),
1374           ptr_sbr_dec->str_codec_qmf_bank.num_time_slots,
1375           ptr_sbr_dec->p_hbe_txposer->max_stretch);
1376     }
1377   }
1378   ixheaacd_qmf_enrg_calc(ptr_sbr_dec, upsample_ratio_idx, low_pow_flag);
1379 
1380   for (i = 0; i < 64; i++) {
1381     memset(ptr_sbr_dec->sbr_qmf_out_real[i], 0, 64 * sizeof(FLOAT32));
1382     memset(ptr_sbr_dec->sbr_qmf_out_imag[i], 0, 64 * sizeof(FLOAT32));
1383   }
1384 
1385   ptr_sbr_dec->band_count = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
1386 
1387   ixheaacd_esbr_synthesis_filt_block(
1388       ptr_sbr_dec, ptr_header_data, ptr_frame_data, apply_processing,
1389       pp_qmf_buf_real, pp_qmf_buf_imag, stereo_config_idx, ptr_sbr_tables,
1390       mps_sbr_flag, ch_fac, 0, 0, NULL, 0, NULL);
1391 
1392   ptr_frame_data->prev_sbr_mode = sbr_mode;
1393   return 0;
1394 }
1395 
ixheaacd_sbr_dec_from_mps(FLOAT32 * p_mps_qmf_output,VOID * p_sbr_dec,VOID * p_sbr_frame,VOID * p_sbr_header,WORD32 ec_flag)1396 WORD32 ixheaacd_sbr_dec_from_mps(FLOAT32 *p_mps_qmf_output, VOID *p_sbr_dec, VOID *p_sbr_frame,
1397                                  VOID *p_sbr_header, WORD32 ec_flag) {
1398   WORD32 i, k;
1399   ia_sbr_frame_info_data_struct *ptr_frame_data =
1400       (ia_sbr_frame_info_data_struct *)p_sbr_frame;
1401   ia_sbr_header_data_struct *ptr_header_data =
1402       (ia_sbr_header_data_struct *)p_sbr_header;
1403   ia_sbr_dec_struct *ptr_sbr_dec = (ia_sbr_dec_struct *)p_sbr_dec;
1404   ia_frame_info_struct *p_frame_info = &ptr_frame_data->str_frame_info_details;
1405   WORD32 no_bins;
1406   WORD32 upsample_ratio_idx = ptr_header_data->sbr_ratio_idx;
1407   WORD32 op_delay = 6 + SBR_HF_ADJ_OFFSET;
1408   WORD32 num_anal_bands = 40;
1409   WORD32 mps_sbr_flag = ptr_frame_data->mps_sbr_flag;
1410   WORD32 err = 0;
1411 
1412   if (ptr_header_data->is_usf_4) {
1413     op_delay += 6;
1414   }
1415 
1416   num_anal_bands = num_anal_bands - (upsample_ratio_idx << 3);
1417 
1418   if (!mps_sbr_flag) {
1419     return 0;
1420   } else {
1421     ptr_frame_data->cov_count = ptr_sbr_dec->str_codec_qmf_bank.no_channels;
1422   }
1423 
1424   no_bins = ptr_header_data->output_framesize / 64;
1425 
1426   for (i = 0; i < no_bins; i++) {
1427     FLOAT32 *p_loc_mps_qmf_output =
1428         p_mps_qmf_output + i * (MAX_NUM_QMF_BANDS_ESBR * 2);
1429     for (k = 0; k < ptr_header_data->pstr_freq_band_data->sub_band_start; k++) {
1430       ptr_sbr_dec->mps_qmf_buf_real[op_delay + i][k] = *p_loc_mps_qmf_output++;
1431       ptr_sbr_dec->mps_qmf_buf_imag[op_delay + i][k] = *p_loc_mps_qmf_output++;
1432 
1433       ptr_sbr_dec->mps_sbr_qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k] =
1434           ptr_sbr_dec->qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k];
1435       ptr_sbr_dec->mps_sbr_qmf_buf_imag[SBR_HF_ADJ_OFFSET + i][k] =
1436           ptr_sbr_dec->qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k];
1437     }
1438   }
1439 
1440   if (ptr_frame_data->reset_flag) {
1441     WORD32 l;
1442     WORD32 start_band = ptr_header_data->pstr_freq_band_data->qmf_sb_prev;
1443     WORD32 end_band = num_anal_bands;
1444     WORD32 start_slot =
1445         SBR_HF_ADJ_OFFSET + ptr_frame_data->rate * p_frame_info->border_vec[0];
1446 
1447     for (l = start_slot; l < op_delay; l++) {
1448       for (k = start_band; k < end_band; k++) {
1449         ptr_sbr_dec->mps_qmf_buf_real[l][k] = 0.0;
1450         ptr_sbr_dec->mps_qmf_buf_imag[l][k] = 0.0;
1451       }
1452     }
1453 
1454     for (l = 0; l < SBR_HF_ADJ_OFFSET; l++) {
1455       for (k = start_band; k < end_band; k++) {
1456         ptr_sbr_dec->mps_qmf_buf_real[l][k] = 0.0;
1457         ptr_sbr_dec->mps_qmf_buf_imag[l][k] = 0.0;
1458       }
1459     }
1460   }
1461   ptr_header_data->pstr_freq_band_data->qmf_sb_prev =
1462       ptr_header_data->pstr_freq_band_data->sub_band_start;
1463 
1464   err = ixheaacd_generate_hf(ptr_sbr_dec->mps_qmf_buf_real + SBR_HF_ADJ_OFFSET,
1465                              ptr_sbr_dec->mps_qmf_buf_imag + SBR_HF_ADJ_OFFSET, NULL, NULL,
1466                              ptr_sbr_dec->mps_sbr_qmf_buf_real + SBR_HF_ADJ_OFFSET,
1467                              ptr_sbr_dec->mps_sbr_qmf_buf_imag + SBR_HF_ADJ_OFFSET,
1468                              ptr_frame_data, ptr_header_data, 0,
1469                              ptr_sbr_dec->str_codec_qmf_bank.num_time_slots, ec_flag);
1470   if (err) return err;
1471 
1472   ptr_frame_data->pstr_sbr_header = ptr_header_data;
1473   ptr_frame_data->sbr_mode = ORIG_SBR;
1474   ptr_frame_data->prev_sbr_mode = ORIG_SBR;
1475   err = ixheaacd_sbr_env_calc(
1476       ptr_frame_data, ptr_sbr_dec->mps_sbr_qmf_buf_real + SBR_HF_ADJ_OFFSET,
1477       ptr_sbr_dec->mps_sbr_qmf_buf_imag + SBR_HF_ADJ_OFFSET,
1478       ptr_sbr_dec->mps_qmf_buf_real + SBR_HF_ADJ_OFFSET,
1479       ptr_sbr_dec->mps_qmf_buf_imag + SBR_HF_ADJ_OFFSET,
1480       (ptr_header_data->hbe_flag == 0) ? NULL : ptr_sbr_dec->p_hbe_txposer->x_over_qmf,
1481       ptr_sbr_dec->scratch_buff, NULL, 0, ec_flag);
1482 
1483   if (err) return err;
1484   for (i = 0; i < no_bins; i++) {
1485     FLOAT32 *p_loc_mps_qmf_output =
1486         p_mps_qmf_output + i * (MAX_NUM_QMF_BANDS_ESBR * 2);
1487     for (k = 0; k < ptr_header_data->pstr_freq_band_data->sub_band_start; k++) {
1488       *p_loc_mps_qmf_output++ =
1489           ptr_sbr_dec->mps_qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k];
1490       *p_loc_mps_qmf_output++ =
1491           ptr_sbr_dec->mps_qmf_buf_imag[SBR_HF_ADJ_OFFSET + i][k];
1492     }
1493     for (k = ptr_header_data->pstr_freq_band_data->sub_band_start; k < 64;
1494          k++) {
1495       *p_loc_mps_qmf_output++ =
1496           ptr_sbr_dec->mps_sbr_qmf_buf_real[SBR_HF_ADJ_OFFSET + i][k];
1497       *p_loc_mps_qmf_output++ =
1498           ptr_sbr_dec->mps_sbr_qmf_buf_imag[SBR_HF_ADJ_OFFSET + i][k];
1499     }
1500   }
1501 
1502   for (i = 0; i < op_delay; i++) {
1503     memmove(ptr_sbr_dec->mps_qmf_buf_real[i],
1504             ptr_sbr_dec->mps_qmf_buf_real[no_bins + i], 64 * sizeof(FLOAT32));
1505 
1506     memmove(ptr_sbr_dec->mps_qmf_buf_imag[i],
1507             ptr_sbr_dec->mps_qmf_buf_imag[no_bins + i], 64 * sizeof(FLOAT32));
1508 
1509     memmove(ptr_sbr_dec->mps_sbr_qmf_buf_real[i],
1510             ptr_sbr_dec->mps_sbr_qmf_buf_real[no_bins + i],
1511             64 * sizeof(FLOAT32));
1512 
1513     memmove(ptr_sbr_dec->mps_sbr_qmf_buf_imag[i],
1514             ptr_sbr_dec->mps_sbr_qmf_buf_imag[no_bins + i],
1515             64 * sizeof(FLOAT32));
1516   }
1517 
1518   ptr_frame_data->reset_flag = 0;
1519   return err;
1520 }
1521