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 <math.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "ixheaacd_type_def.h"
25 
26 #include "ixheaacd_bitbuffer.h"
27 
28 #include "ixheaacd_interface.h"
29 
30 #include "ixheaacd_tns_usac.h"
31 #include "ixheaacd_cnst.h"
32 
33 #include "ixheaacd_acelp_info.h"
34 
35 #include "ixheaacd_sbrdecsettings.h"
36 #include "ixheaacd_info.h"
37 #include "ixheaacd_sbr_common.h"
38 #include "ixheaacd_drc_data_struct.h"
39 #include "ixheaacd_drc_dec.h"
40 #include "ixheaacd_sbrdecoder.h"
41 #include "ixheaacd_mps_polyphase.h"
42 #include "ixheaacd_sbr_const.h"
43 
44 #include "ixheaacd_env_extr_part.h"
45 #include "ixheaacd_sbr_rom.h"
46 #include "ixheaacd_common_rom.h"
47 #include "ixheaacd_hybrid.h"
48 #include "ixheaacd_sbr_scale.h"
49 #include "ixheaacd_ps_dec.h"
50 #include "ixheaacd_freq_sca.h"
51 #include "ixheaacd_lpp_tran.h"
52 #include "ixheaacd_bitbuffer.h"
53 #include "ixheaacd_env_extr.h"
54 #include "ixheaacd_qmf_dec.h"
55 #include "ixheaacd_env_calc.h"
56 #include "ixheaacd_pvc_dec.h"
57 
58 #include "ixheaacd_sbr_dec.h"
59 #include "ixheaacd_error_standards.h"
60 #include "ixheaacd_sbrqmftrans.h"
61 #include "ixheaacd_qmf_poly.h"
62 
63 #include "ixheaacd_constants.h"
64 #include "ixheaacd_basic_ops32.h"
65 #include "ixheaacd_basic_op.h"
66 
67 #include "ixheaacd_esbr_rom.h"
68 
69 #define SBR_CONST_PMIN 1.0f
70 
ixheaacd_map_prot_filter(WORD32 filt_length)71 static FLOAT32 *ixheaacd_map_prot_filter(WORD32 filt_length) {
72   switch (filt_length) {
73     case 4:
74       return (FLOAT32 *)&ixheaacd_sub_samp_qmf_window_coeff[0];
75       break;
76     case 8:
77       return (FLOAT32 *)&ixheaacd_sub_samp_qmf_window_coeff[40];
78       break;
79     case 12:
80       return (FLOAT32 *)&ixheaacd_sub_samp_qmf_window_coeff[120];
81       break;
82     case 16:
83       return (FLOAT32 *)&ixheaacd_sub_samp_qmf_window_coeff[240];
84       break;
85     case 20:
86       return (FLOAT32 *)&ixheaacd_sub_samp_qmf_window_coeff[400];
87       break;
88     case 24:
89       return (FLOAT32 *)&ixheaacd_sub_samp_qmf_window_coeff[600];
90       break;
91     case 32:
92       return (FLOAT32 *)&ixheaacd_sub_samp_qmf_window_coeff[840];
93       break;
94     case 40:
95       return (FLOAT32 *)&ixheaacd_sub_samp_qmf_window_coeff[1160];
96       break;
97     default:
98       return (FLOAT32 *)&ixheaacd_sub_samp_qmf_window_coeff[0];
99   }
100 }
101 
ixheaacd_qmf_hbe_data_reinit(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD16 * p_freq_band_tab[2],WORD16 * p_num_sfb,WORD32 upsamp_4_flag)102 WORD32 ixheaacd_qmf_hbe_data_reinit(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
103                                     WORD16 *p_freq_band_tab[2],
104                                     WORD16 *p_num_sfb, WORD32 upsamp_4_flag) {
105   WORD32 synth_size, sfb, patch, stop_patch;
106 
107   if (ptr_hbe_txposer != NULL) {
108     ptr_hbe_txposer->start_band = p_freq_band_tab[LOW][0];
109     ptr_hbe_txposer->end_band = p_freq_band_tab[LOW][p_num_sfb[LOW]];
110 
111     ptr_hbe_txposer->synth_size =
112         4 * ((ptr_hbe_txposer->start_band + 4) / 8 + 1);
113     ptr_hbe_txposer->k_start =
114         ixheaacd_start_subband2kL_tbl[ptr_hbe_txposer->start_band];
115 
116     ptr_hbe_txposer->upsamp_4_flag = upsamp_4_flag;
117 
118     if (upsamp_4_flag) {
119       if (ptr_hbe_txposer->k_start + ptr_hbe_txposer->synth_size > 16)
120         ptr_hbe_txposer->k_start = 16 - ptr_hbe_txposer->synth_size;
121     } else if (ptr_hbe_txposer->core_frame_length == 768) {
122       if (ptr_hbe_txposer->k_start + ptr_hbe_txposer->synth_size > 24)
123         ptr_hbe_txposer->k_start = 24 - ptr_hbe_txposer->synth_size;
124     }
125 
126     memset(ptr_hbe_txposer->synth_buf, 0, 1280 * sizeof(FLOAT32));
127     synth_size = ptr_hbe_txposer->synth_size;
128     ptr_hbe_txposer->synth_buf_offset = 18 * synth_size;
129     switch (synth_size) {
130       case 4:
131         ptr_hbe_txposer->synth_cos_tab =
132             (FLOAT32 *)ixheaacd_synth_cos_table_kl_4;
133         ptr_hbe_txposer->analy_cos_sin_tab =
134             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_8;
135         ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
136         ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
137         break;
138       case 8:
139         ptr_hbe_txposer->synth_cos_tab =
140             (FLOAT32 *)ixheaacd_synth_cos_table_kl_8;
141         ptr_hbe_txposer->analy_cos_sin_tab =
142             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_16;
143         ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
144         ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
145         break;
146       case 12:
147         ptr_hbe_txposer->synth_cos_tab =
148             (FLOAT32 *)ixheaacd_synth_cos_table_kl_12;
149         ptr_hbe_txposer->analy_cos_sin_tab =
150             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_24;
151         ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p3;
152         ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p3;
153         break;
154       case 16:
155         ptr_hbe_txposer->synth_cos_tab =
156             (FLOAT32 *)ixheaacd_synth_cos_table_kl_16;
157         ptr_hbe_txposer->analy_cos_sin_tab =
158             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_32;
159         ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
160         ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
161         break;
162       case 20:
163         ptr_hbe_txposer->synth_cos_tab =
164             (FLOAT32 *)ixheaacd_synth_cos_table_kl_20;
165         ptr_hbe_txposer->analy_cos_sin_tab =
166             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_40;
167         break;
168       default:
169         ptr_hbe_txposer->synth_cos_tab =
170             (FLOAT32 *)ixheaacd_synth_cos_table_kl_4;
171         ptr_hbe_txposer->analy_cos_sin_tab =
172             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_8;
173         ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
174         ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
175     }
176 
177     ptr_hbe_txposer->synth_wind_coeff = ixheaacd_map_prot_filter(synth_size);
178 
179     memset(ptr_hbe_txposer->analy_buf, 0, 640 * sizeof(FLOAT32));
180     synth_size = 2 * ptr_hbe_txposer->synth_size;
181     ptr_hbe_txposer->analy_wind_coeff = ixheaacd_map_prot_filter(synth_size);
182 
183     memset(ptr_hbe_txposer->x_over_qmf, 0, MAX_NUM_PATCHES * sizeof(WORD32));
184     sfb = 0;
185     if (upsamp_4_flag) {
186       stop_patch = MAX_NUM_PATCHES;
187       ptr_hbe_txposer->max_stretch = MAX_STRETCH;
188     } else {
189       stop_patch = MAX_STRETCH;
190     }
191 
192     for (patch = 1; patch <= stop_patch; patch++) {
193       while (sfb <= p_num_sfb[LOW] &&
194              p_freq_band_tab[LOW][sfb] <= patch * ptr_hbe_txposer->start_band)
195         sfb++;
196       if (sfb <= p_num_sfb[LOW]) {
197         if ((patch * ptr_hbe_txposer->start_band -
198              p_freq_band_tab[LOW][sfb - 1]) <= 3) {
199           ptr_hbe_txposer->x_over_qmf[patch - 1] =
200               p_freq_band_tab[LOW][sfb - 1];
201         } else {
202           WORD32 sfb = 0;
203           while (sfb <= p_num_sfb[HIGH] &&
204                  p_freq_band_tab[HIGH][sfb] <=
205                      patch * ptr_hbe_txposer->start_band)
206             sfb++;
207           ptr_hbe_txposer->x_over_qmf[patch - 1] =
208               p_freq_band_tab[HIGH][sfb - 1];
209         }
210       } else {
211         ptr_hbe_txposer->x_over_qmf[patch - 1] = ptr_hbe_txposer->end_band;
212         ptr_hbe_txposer->max_stretch = min(patch, MAX_STRETCH);
213         break;
214       }
215     }
216     if (ptr_hbe_txposer->k_start < 0) {
217       return -1;
218     }
219   }
220   return 0;
221 }
222 
ixheaacd_qmf_hbe_apply(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,FLOAT32 qmf_buf_real[][64],FLOAT32 qmf_buf_imag[][64],WORD32 num_columns,FLOAT32 pv_qmf_buf_real[][64],FLOAT32 pv_qmf_buf_imag[][64],WORD32 pitch_in_bins)223 WORD32 ixheaacd_qmf_hbe_apply(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
224                               FLOAT32 qmf_buf_real[][64],
225                               FLOAT32 qmf_buf_imag[][64], WORD32 num_columns,
226                               FLOAT32 pv_qmf_buf_real[][64],
227                               FLOAT32 pv_qmf_buf_imag[][64],
228                               WORD32 pitch_in_bins) {
229   WORD32 i, qmf_band_idx;
230   WORD32 qmf_voc_columns = ptr_hbe_txposer->no_bins / 2;
231   WORD32 err_code = 0;
232 
233   memcpy(ptr_hbe_txposer->ptr_input_buf,
234          ptr_hbe_txposer->ptr_input_buf +
235              ptr_hbe_txposer->no_bins * ptr_hbe_txposer->synth_size,
236          ptr_hbe_txposer->synth_size * sizeof(FLOAT32));
237 
238   err_code = ixheaacd_real_synth_filt(ptr_hbe_txposer, num_columns,
239                                       qmf_buf_real, qmf_buf_imag);
240   if (err_code) return err_code;
241 
242   for (i = 0; i < HBE_OPER_WIN_LEN - 1; i++) {
243     memcpy(ptr_hbe_txposer->qmf_in_buf[i],
244            ptr_hbe_txposer->qmf_in_buf[i + qmf_voc_columns],
245            TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32));
246   }
247 
248   err_code = ixheaacd_complex_anal_filt(ptr_hbe_txposer);
249   if (err_code) return err_code;
250 
251   for (i = 0; i < (ptr_hbe_txposer->hbe_qmf_out_len - ptr_hbe_txposer->no_bins);
252        i++) {
253     memcpy(ptr_hbe_txposer->qmf_out_buf[i],
254            ptr_hbe_txposer->qmf_out_buf[i + ptr_hbe_txposer->no_bins],
255            TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32));
256   }
257 
258   for (; i < ptr_hbe_txposer->hbe_qmf_out_len; i++) {
259     memset(ptr_hbe_txposer->qmf_out_buf[i], 0,
260            TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32));
261   }
262 
263   err_code = ixheaacd_hbe_post_anal_process(ptr_hbe_txposer, pitch_in_bins,
264                                             ptr_hbe_txposer->upsamp_4_flag);
265   if (err_code) return err_code;
266 
267   for (i = 0; i < ptr_hbe_txposer->no_bins; i++) {
268     for (qmf_band_idx = ptr_hbe_txposer->start_band;
269          qmf_band_idx < ptr_hbe_txposer->end_band; qmf_band_idx++) {
270       pv_qmf_buf_real[i][qmf_band_idx] =
271           (FLOAT32)(ptr_hbe_txposer->qmf_out_buf[i][2 * qmf_band_idx] *
272                         ixheaacd_phase_vocoder_cos_table[qmf_band_idx] -
273                     ptr_hbe_txposer->qmf_out_buf[i][2 * qmf_band_idx + 1] *
274                         ixheaacd_phase_vocoder_sin_table[qmf_band_idx]);
275 
276       pv_qmf_buf_imag[i][qmf_band_idx] =
277           (FLOAT32)(ptr_hbe_txposer->qmf_out_buf[i][2 * qmf_band_idx] *
278                         ixheaacd_phase_vocoder_sin_table[qmf_band_idx] +
279                     ptr_hbe_txposer->qmf_out_buf[i][2 * qmf_band_idx + 1] *
280                         ixheaacd_phase_vocoder_cos_table[qmf_band_idx]);
281     }
282   }
283   return 0;
284 }
285 
ixheaacd_norm_qmf_in_buf_4(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_band_idx)286 VOID ixheaacd_norm_qmf_in_buf_4(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
287                                 WORD32 qmf_band_idx) {
288   WORD32 i;
289   FLOAT32 *in_buf = &ptr_hbe_txposer->qmf_in_buf[0][2 * qmf_band_idx];
290   FLOAT32 *norm_buf = &ptr_hbe_txposer->norm_qmf_in_buf[0][2 * qmf_band_idx];
291 
292   for (; qmf_band_idx <= ptr_hbe_txposer->x_over_qmf[3]; qmf_band_idx++) {
293     for (i = 0; i < ptr_hbe_txposer->hbe_qmf_in_len; i++) {
294       FLOAT32 mag_scaling_fac = 0.0f;
295       FLOAT32 x_r, x_i, temp;
296       FLOAT64 base = 1e-17;
297       x_r = in_buf[0];
298       x_i = in_buf[1];
299 
300       temp = x_r * x_r;
301       base = base + temp;
302       temp = x_i * x_i;
303       base = base + temp;
304 
305       temp = (FLOAT32)sqrt(sqrt(base));
306       mag_scaling_fac = temp * (FLOAT32)(sqrt(temp));
307 
308       mag_scaling_fac = 1 / mag_scaling_fac;
309 
310       x_r *= mag_scaling_fac;
311       x_i *= mag_scaling_fac;
312 
313       norm_buf[0] = x_r;
314       norm_buf[1] = x_i;
315 
316       in_buf += 128;
317       norm_buf += 128;
318     }
319 
320     in_buf -= (128 * (ptr_hbe_txposer->hbe_qmf_in_len) - 2);
321     norm_buf -= (128 * (ptr_hbe_txposer->hbe_qmf_in_len) - 2);
322   }
323 }
324 
ixheaacd_norm_qmf_in_buf_2(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_band_idx)325 VOID ixheaacd_norm_qmf_in_buf_2(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
326                                 WORD32 qmf_band_idx) {
327   WORD32 i;
328   FLOAT32 *in_buf = &ptr_hbe_txposer->qmf_in_buf[0][2 * qmf_band_idx];
329   FLOAT32 *norm_buf = &ptr_hbe_txposer->norm_qmf_in_buf[0][2 * qmf_band_idx];
330 
331   for (; qmf_band_idx <= ptr_hbe_txposer->x_over_qmf[1]; qmf_band_idx++) {
332     for (i = 0; i < ptr_hbe_txposer->hbe_qmf_in_len; i++) {
333       FLOAT32 mag_scaling_fac = 0.0f;
334       FLOAT32 x_r, x_i, temp;
335       FLOAT64 base = 1e-17;
336       x_r = in_buf[0];
337       x_i = in_buf[1];
338 
339       temp = x_r * x_r;
340       base = base + temp;
341       temp = x_i * x_i;
342       base = base + x_i * x_i;
343 
344       mag_scaling_fac = (FLOAT32)(1.0f / base);
345       mag_scaling_fac = (FLOAT32)sqrt(sqrt(mag_scaling_fac));
346 
347       x_r *= mag_scaling_fac;
348       x_i *= mag_scaling_fac;
349 
350       norm_buf[0] = x_r;
351       norm_buf[1] = x_i;
352 
353       in_buf += 128;
354       norm_buf += 128;
355     }
356 
357     in_buf -= (128 * (ptr_hbe_txposer->hbe_qmf_in_len) - 2);
358     norm_buf -= (128 * (ptr_hbe_txposer->hbe_qmf_in_len) - 2);
359   }
360 }
361 
ixheaacd_hbe_xprod_proc_3(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_band_idx,WORD32 qmf_col_idx,FLOAT32 p,WORD32 pitch_in_bins_idx)362 VOID ixheaacd_hbe_xprod_proc_3(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
363                                WORD32 qmf_band_idx, WORD32 qmf_col_idx,
364                                FLOAT32 p, WORD32 pitch_in_bins_idx) {
365   WORD32 tr, n1, n2, max_trans_fac, max_n1, max_n2;
366   WORD32 k, addrshift;
367   WORD32 inp_band_idx = 2 * qmf_band_idx / 3;
368 
369   FLOAT64 temp_fac;
370   FLOAT32 max_mag_value;
371   FLOAT32 mag_zero_band, mag_n1_band, mag_n2_band, temp;
372   FLOAT32 temp_r, temp_i;
373   FLOAT32 mag_cmplx_gain = 1.8856f;
374 
375   FLOAT32 *qmf_in_buf_ri =
376       ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + HBE_ZERO_BAND_IDX];
377 
378   mag_zero_band =
379       qmf_in_buf_ri[2 * inp_band_idx] * qmf_in_buf_ri[2 * inp_band_idx] +
380       qmf_in_buf_ri[2 * inp_band_idx + 1] * qmf_in_buf_ri[2 * inp_band_idx + 1];
381   max_mag_value = 0;
382   max_n1 = max_n2 = max_trans_fac = 0;
383 
384   for (tr = 1; tr < 3; tr++) {
385     temp_fac = (2.0f * qmf_band_idx + 1 - tr * p) * 0.3333334;
386 
387     n1 = (WORD32)(temp_fac);
388     n2 = (WORD32)(temp_fac + p);
389 
390     mag_n1_band = qmf_in_buf_ri[2 * n1] * qmf_in_buf_ri[2 * n1] +
391                   qmf_in_buf_ri[2 * n1 + 1] * qmf_in_buf_ri[2 * n1 + 1];
392     mag_n2_band = qmf_in_buf_ri[2 * n2] * qmf_in_buf_ri[2 * n2] +
393                   qmf_in_buf_ri[2 * n2 + 1] * qmf_in_buf_ri[2 * n2 + 1];
394     temp = min(mag_n1_band, mag_n2_band);
395 
396     if (temp > max_mag_value) {
397       max_mag_value = temp;
398       max_trans_fac = tr;
399       max_n1 = n1;
400       max_n2 = n2;
401     }
402   }
403 
404   if (max_mag_value > mag_zero_band && max_n1 >= 0 &&
405       max_n2 < NO_QMF_SYNTH_CHANNELS) {
406     FLOAT32 vec_y_r[2], vec_y_i[2], vec_o_r[2], vec_o_i[2];
407     FLOAT32 coeff_real[2], coeff_imag[2];
408     FLOAT32 d1, d2;
409     WORD32 mid_trans_fac, idx;
410     FLOAT64 base = 1e-17;
411     FLOAT32 mag_scaling_fac = 0;
412     FLOAT32 x_zero_band_r;
413     FLOAT32 x_zero_band_i;
414 
415     x_zero_band_r = 0;
416     x_zero_band_i = 0;
417     mid_trans_fac = 3 - max_trans_fac;
418     if (max_trans_fac == 1) {
419       WORD32 idx;
420       d1 = 0;
421       d2 = 1.5;
422       x_zero_band_r = qmf_in_buf_ri[2 * max_n1];
423       x_zero_band_i = qmf_in_buf_ri[2 * max_n1 + 1];
424 
425       idx = max_n2 & 3;
426       idx = (idx + 1) & 3;
427       coeff_real[0] = ixheaacd_hbe_post_anal_proc_interp_coeff[idx][0];
428       coeff_imag[0] = ixheaacd_hbe_post_anal_proc_interp_coeff[idx][1];
429 
430       coeff_real[1] = coeff_real[0];
431       coeff_imag[1] = -coeff_imag[0];
432 
433       vec_y_r[1] = qmf_in_buf_ri[2 * max_n2];
434       vec_y_i[1] = qmf_in_buf_ri[2 * max_n2 + 1];
435 
436       addrshift = -2;
437       temp_r = ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + addrshift +
438                                            HBE_ZERO_BAND_IDX][2 * max_n2];
439       temp_i = ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + addrshift +
440                                            HBE_ZERO_BAND_IDX][2 * max_n2 + 1];
441 
442       vec_y_r[0] = coeff_real[1] * temp_r - coeff_imag[1] * temp_i;
443       vec_y_i[0] = coeff_imag[1] * temp_r + coeff_real[1] * temp_i;
444 
445       temp_r = ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + addrshift + 1 +
446                                            HBE_ZERO_BAND_IDX][2 * max_n2];
447       temp_i = ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + addrshift + 1 +
448                                            HBE_ZERO_BAND_IDX][2 * max_n2 + 1];
449 
450       vec_y_r[0] += coeff_real[0] * temp_r - coeff_imag[0] * temp_i;
451       vec_y_i[0] += coeff_imag[0] * temp_r + coeff_real[0] * temp_i;
452 
453     } else {
454       WORD32 idx;
455       d1 = 1.5;
456       d2 = 0;
457       mid_trans_fac = max_trans_fac;
458       max_trans_fac = 3 - max_trans_fac;
459 
460       x_zero_band_r = qmf_in_buf_ri[2 * max_n2];
461       x_zero_band_i = qmf_in_buf_ri[2 * max_n2 + 1];
462 
463       idx = (max_n1 & 3);
464       idx = (idx + 1) & 3;
465       coeff_real[0] = ixheaacd_hbe_post_anal_proc_interp_coeff[idx][0];
466       coeff_imag[0] = ixheaacd_hbe_post_anal_proc_interp_coeff[idx][1];
467 
468       coeff_real[1] = coeff_real[0];
469       coeff_imag[1] = -coeff_imag[0];
470 
471       vec_y_r[1] = qmf_in_buf_ri[2 * max_n1];
472       vec_y_i[1] = qmf_in_buf_ri[2 * max_n1 + 1];
473 
474       addrshift = -2;
475 
476       temp_r = ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + addrshift +
477                                            HBE_ZERO_BAND_IDX][2 * max_n1];
478       temp_i = ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + addrshift +
479                                            HBE_ZERO_BAND_IDX][2 * max_n1 + 1];
480 
481       vec_y_r[0] = coeff_real[1] * temp_r - coeff_imag[1] * temp_i;
482       vec_y_i[0] = coeff_imag[1] * temp_r + coeff_real[1] * temp_i;
483 
484       temp_r = ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + addrshift + 1 +
485                                            HBE_ZERO_BAND_IDX][2 * max_n1];
486       temp_i = ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + addrshift + 1 +
487                                            HBE_ZERO_BAND_IDX][2 * max_n1 + 1];
488 
489       vec_y_r[0] += coeff_real[0] * temp_r - coeff_imag[0] * temp_i;
490       vec_y_i[0] += coeff_imag[0] * temp_r + coeff_real[0] * temp_i;
491     }
492 
493     base = 1e-17;
494     base = base + x_zero_band_r * x_zero_band_r;
495     base = base + x_zero_band_i * x_zero_band_i;
496     mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base));
497     x_zero_band_r *= mag_scaling_fac;
498     x_zero_band_i *= mag_scaling_fac;
499     for (k = 0; k < 2; k++) {
500       base = 1e-17;
501       base = base + vec_y_r[k] * vec_y_r[k];
502       base = base + vec_y_i[k] * vec_y_i[k];
503       mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base));
504       vec_y_r[k] *= mag_scaling_fac;
505       vec_y_i[k] *= mag_scaling_fac;
506     }
507 
508     temp_r = x_zero_band_r;
509     temp_i = x_zero_band_i;
510     for (idx = 0; idx < mid_trans_fac - 1; idx++) {
511       FLOAT32 tmp = x_zero_band_r;
512       x_zero_band_r = x_zero_band_r * temp_r - x_zero_band_i * temp_i;
513       x_zero_band_i = tmp * temp_i + x_zero_band_i * temp_r;
514     }
515 
516     for (k = 0; k < 2; k++) {
517       temp_r = vec_y_r[k];
518       temp_i = vec_y_i[k];
519       for (idx = 0; idx < max_trans_fac - 1; idx++) {
520         FLOAT32 tmp = vec_y_r[k];
521         vec_y_r[k] = vec_y_r[k] * temp_r - vec_y_i[k] * temp_i;
522         vec_y_i[k] = tmp * temp_i + vec_y_i[k] * temp_r;
523       }
524     }
525 
526     for (k = 0; k < 2; k++) {
527       vec_o_r[k] = vec_y_r[k] * x_zero_band_r - vec_y_i[k] * x_zero_band_i;
528       vec_o_i[k] = vec_y_r[k] * x_zero_band_i + vec_y_i[k] * x_zero_band_r;
529     }
530 
531     {
532       FLOAT32 cos_theta =
533           ixheaacd_hbe_x_prod_cos_table_trans_3[(pitch_in_bins_idx << 1) + 0];
534       FLOAT32 sin_theta =
535           ixheaacd_hbe_x_prod_cos_table_trans_3[(pitch_in_bins_idx << 1) + 1];
536       if (d2 < d1) {
537         sin_theta = -sin_theta;
538       }
539       temp_r = vec_o_r[0];
540       temp_i = vec_o_i[0];
541       vec_o_r[0] = (FLOAT32)(cos_theta * temp_r - sin_theta * temp_i);
542       vec_o_i[0] = (FLOAT32)(cos_theta * temp_i + sin_theta * temp_r);
543     }
544 
545     for (k = 0; k < 2; k++) {
546       ptr_hbe_txposer->qmf_out_buf[qmf_col_idx * 2 + (k + HBE_ZERO_BAND_IDX -
547                                                       1)][2 * qmf_band_idx] +=
548           (FLOAT32)(mag_cmplx_gain * vec_o_r[k]);
549       ptr_hbe_txposer
550           ->qmf_out_buf[qmf_col_idx * 2 + (k + HBE_ZERO_BAND_IDX - 1)]
551                        [2 * qmf_band_idx + 1] +=
552           (FLOAT32)(mag_cmplx_gain * vec_o_i[k]);
553     }
554   }
555 }
556 
ixheaacd_hbe_xprod_proc_4(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_band_idx,WORD32 qmf_col_idx,FLOAT32 p,WORD32 pitch_in_bins_idx)557 VOID ixheaacd_hbe_xprod_proc_4(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
558                                WORD32 qmf_band_idx, WORD32 qmf_col_idx,
559                                FLOAT32 p, WORD32 pitch_in_bins_idx) {
560   WORD32 k;
561   WORD32 inp_band_idx = qmf_band_idx >> 1;
562   WORD32 tr, n1, n2, max_trans_fac, max_n1, max_n2;
563 
564   FLOAT64 temp_fac;
565   FLOAT32 max_mag_value, mag_zero_band, mag_n1_band, mag_n2_band, temp;
566   FLOAT32 temp_r, temp_i;
567   FLOAT32 mag_cmplx_gain = 2.0f;
568 
569   FLOAT32 *qmf_in_buf_ri =
570       ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + HBE_ZERO_BAND_IDX];
571 
572   mag_zero_band =
573       qmf_in_buf_ri[2 * inp_band_idx] * qmf_in_buf_ri[2 * inp_band_idx] +
574       qmf_in_buf_ri[2 * inp_band_idx + 1] * qmf_in_buf_ri[2 * inp_band_idx + 1];
575 
576   max_mag_value = 0;
577   max_n1 = max_n2 = max_trans_fac = 0;
578 
579   for (tr = 1; tr < 4; tr++) {
580     temp_fac = (2.0 * qmf_band_idx + 1 - tr * p) * 0.25;
581     n1 = ((WORD32)(temp_fac)) << 1;
582     n2 = ((WORD32)(temp_fac + p)) << 1;
583 
584     mag_n1_band = qmf_in_buf_ri[n1] * qmf_in_buf_ri[n1] +
585                   qmf_in_buf_ri[n1 + 1] * qmf_in_buf_ri[n1 + 1];
586     mag_n2_band = qmf_in_buf_ri[n2] * qmf_in_buf_ri[n2] +
587                   qmf_in_buf_ri[n2 + 1] * qmf_in_buf_ri[n2 + 1];
588 
589     temp = min(mag_n1_band, mag_n2_band);
590 
591     if (temp > max_mag_value) {
592       max_mag_value = temp;
593       max_trans_fac = tr;
594       max_n1 = n1;
595       max_n2 = n2;
596     }
597   }
598   if (max_mag_value > mag_zero_band && max_n1 >= 0 &&
599       max_n2 < TWICE_QMF_SYNTH_CHANNELS_NUM) {
600     FLOAT32 vec_y_r[2], vec_y_i[2], vec_o_r[2], vec_o_i[2];
601     FLOAT32 d1, d2;
602     WORD32 mid_trans_fac, idx;
603     FLOAT32 x_zero_band_r;
604     FLOAT32 x_zero_band_i;
605     FLOAT64 base = 1e-17;
606     FLOAT32 mag_scaling_fac = 0.0f;
607 
608     x_zero_band_r = 0;
609     x_zero_band_i = 0;
610     mid_trans_fac = 4 - max_trans_fac;
611 
612     if (max_trans_fac == 1) {
613       d1 = 0;
614       d2 = 2;
615       x_zero_band_r = qmf_in_buf_ri[max_n1];
616       x_zero_band_i = qmf_in_buf_ri[max_n1 + 1];
617       for (k = 0; k < 2; k++) {
618         vec_y_r[k] =
619             ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + HBE_ZERO_BAND_IDX +
620                                         2 * (k - 1)][max_n2];
621         vec_y_i[k] =
622             ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + HBE_ZERO_BAND_IDX +
623                                         2 * (k - 1)][max_n2 + 1];
624       }
625     } else if (max_trans_fac == 2) {
626       d1 = 0;
627       d2 = 1;
628       x_zero_band_r = qmf_in_buf_ri[max_n1];
629       x_zero_band_i = qmf_in_buf_ri[max_n1 + 1];
630       for (k = 0; k < 2; k++) {
631         vec_y_r[k] =
632             ptr_hbe_txposer
633                 ->qmf_in_buf[qmf_col_idx + HBE_ZERO_BAND_IDX + (k - 1)][max_n2];
634         vec_y_i[k] =
635             ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + HBE_ZERO_BAND_IDX +
636                                         (k - 1)][max_n2 + 1];
637       }
638     } else {
639       d1 = 2;
640       d2 = 0;
641       mid_trans_fac = max_trans_fac;
642       max_trans_fac = 4 - max_trans_fac;
643       x_zero_band_r = qmf_in_buf_ri[max_n2];
644       x_zero_band_i = qmf_in_buf_ri[max_n2 + 1];
645       for (k = 0; k < 2; k++) {
646         vec_y_r[k] =
647             ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + HBE_ZERO_BAND_IDX +
648                                         2 * (k - 1)][max_n1];
649         vec_y_i[k] =
650             ptr_hbe_txposer->qmf_in_buf[qmf_col_idx + HBE_ZERO_BAND_IDX +
651                                         2 * (k - 1)][max_n1 + 1];
652       }
653     }
654 
655     base = 1e-17;
656     base = base + x_zero_band_r * x_zero_band_r;
657     base = base + x_zero_band_i * x_zero_band_i;
658     {
659       temp = (FLOAT32)sqrt(sqrt(base));
660       mag_scaling_fac = temp * (FLOAT32)(sqrt(temp));
661       mag_scaling_fac = 1 / mag_scaling_fac;
662     }
663 
664     x_zero_band_r *= mag_scaling_fac;
665     x_zero_band_i *= mag_scaling_fac;
666     for (k = 0; k < 2; k++) {
667       base = 1e-17;
668       base = base + vec_y_r[k] * vec_y_r[k];
669       base = base + vec_y_i[k] * vec_y_i[k];
670       {
671         temp = (FLOAT32)sqrt(sqrt(base));
672         mag_scaling_fac = temp * (FLOAT32)(sqrt(temp));
673 
674         mag_scaling_fac = 1 / mag_scaling_fac;
675       }
676       vec_y_r[k] *= mag_scaling_fac;
677       vec_y_i[k] *= mag_scaling_fac;
678     }
679 
680     temp_r = x_zero_band_r;
681     temp_i = x_zero_band_i;
682     for (idx = 0; idx < mid_trans_fac - 1; idx++) {
683       FLOAT32 tmp = x_zero_band_r;
684       x_zero_band_r = x_zero_band_r * temp_r - x_zero_band_i * temp_i;
685       x_zero_band_i = tmp * temp_i + x_zero_band_i * temp_r;
686     }
687 
688     for (k = 0; k < 2; k++) {
689       temp_r = vec_y_r[k];
690       temp_i = vec_y_i[k];
691       for (idx = 0; idx < max_trans_fac - 1; idx++) {
692         FLOAT32 tmp = vec_y_r[k];
693         vec_y_r[k] = vec_y_r[k] * temp_r - vec_y_i[k] * temp_i;
694         vec_y_i[k] = tmp * temp_i + vec_y_i[k] * temp_r;
695       }
696     }
697 
698     for (k = 0; k < 2; k++) {
699       vec_o_r[k] = vec_y_r[k] * x_zero_band_r - vec_y_i[k] * x_zero_band_i;
700       vec_o_i[k] = vec_y_r[k] * x_zero_band_i + vec_y_i[k] * x_zero_band_r;
701     }
702 
703     {
704       FLOAT32 cos_theta;
705       FLOAT32 sin_theta;
706 
707       if (d2 == 1) {
708         cos_theta =
709             ixheaacd_hbe_x_prod_cos_table_trans_4_1[(pitch_in_bins_idx << 1) +
710                                                     0];
711         sin_theta =
712             ixheaacd_hbe_x_prod_cos_table_trans_4_1[(pitch_in_bins_idx << 1) +
713                                                     1];
714       } else {
715         cos_theta =
716             ixheaacd_hbe_x_prod_cos_table_trans_4[(pitch_in_bins_idx << 1) + 0];
717         sin_theta =
718             ixheaacd_hbe_x_prod_cos_table_trans_4[(pitch_in_bins_idx << 1) + 1];
719         if (d2 < d1) {
720           sin_theta = -sin_theta;
721         }
722       }
723       temp_r = vec_o_r[0];
724       temp_i = vec_o_i[0];
725       vec_o_r[0] = (FLOAT32)(cos_theta * temp_r - sin_theta * temp_i);
726       vec_o_i[0] = (FLOAT32)(cos_theta * temp_i + sin_theta * temp_r);
727     }
728 
729     for (k = 0; k < 2; k++) {
730       ptr_hbe_txposer->qmf_out_buf[qmf_col_idx * 2 + (k + HBE_ZERO_BAND_IDX -
731                                                       1)][2 * qmf_band_idx] +=
732           (FLOAT32)(mag_cmplx_gain * vec_o_r[k]);
733       ptr_hbe_txposer
734           ->qmf_out_buf[qmf_col_idx * 2 + (k + HBE_ZERO_BAND_IDX - 1)]
735                        [2 * qmf_band_idx + 1] +=
736           (FLOAT32)(mag_cmplx_gain * vec_o_i[k]);
737     }
738   }
739 }
740 
ixheaacd_hbe_post_anal_prod2(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_voc_columns,WORD32 qmf_band_idx)741 VOID ixheaacd_hbe_post_anal_prod2(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
742                                   WORD32 qmf_voc_columns, WORD32 qmf_band_idx) {
743   WORD32 i;
744   FLOAT32 *norm_ptr = &ptr_hbe_txposer->norm_qmf_in_buf[1][2 * qmf_band_idx];
745   FLOAT32 *out_ptr = &ptr_hbe_txposer->qmf_out_buf[1][2 * qmf_band_idx];
746   FLOAT32 *x_norm_ptr =
747       &ptr_hbe_txposer->norm_qmf_in_buf[HBE_ZERO_BAND_IDX][2 * qmf_band_idx];
748 
749   ixheaacd_norm_qmf_in_buf_2(ptr_hbe_txposer, qmf_band_idx);
750 
751   for (; qmf_band_idx < ptr_hbe_txposer->x_over_qmf[1]; qmf_band_idx++) {
752     for (i = 0; i < qmf_voc_columns; i++) {
753       WORD32 k;
754       FLOAT32 x_zero_band_r, x_zero_band_i;
755 
756       x_zero_band_r = *x_norm_ptr++;
757       x_zero_band_i = *x_norm_ptr++;
758 
759       for (k = 0; k < HBE_OPER_BLK_LEN_2; k++) {
760         register FLOAT32 tmp_r, tmp_i;
761         tmp_r = *norm_ptr++;
762         tmp_i = *norm_ptr++;
763 
764         *out_ptr++ +=
765             ((tmp_r * x_zero_band_r - tmp_i * x_zero_band_i) * 0.3333333f);
766 
767         *out_ptr++ +=
768             ((tmp_r * x_zero_band_i + tmp_i * x_zero_band_r) * 0.3333333f);
769 
770         norm_ptr += 126;
771         out_ptr += 126;
772       }
773 
774       norm_ptr -= 128 * 9;
775       out_ptr -= 128 * 8;
776       x_norm_ptr += 126;
777     }
778     out_ptr -= (128 * 2 * qmf_voc_columns) - 2;
779     norm_ptr -= (128 * qmf_voc_columns) - 2;
780     x_norm_ptr -= (128 * qmf_voc_columns) - 2;
781   }
782 }
783 
ixheaacd_hbe_post_anal_prod3(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_voc_columns,WORD32 qmf_band_idx)784 VOID ixheaacd_hbe_post_anal_prod3(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
785                                   WORD32 qmf_voc_columns, WORD32 qmf_band_idx) {
786   WORD32 i, inp_band_idx, rem;
787 
788   FLOAT32 *out_buf = &ptr_hbe_txposer->qmf_out_buf[2][2 * qmf_band_idx];
789 
790   for (; qmf_band_idx < ptr_hbe_txposer->x_over_qmf[2]; qmf_band_idx++) {
791     FLOAT32 temp_r, temp_i;
792     FLOAT32 temp_r1, temp_i1;
793     const FLOAT32 *ptr_sel, *ptr_sel1;
794 
795     inp_band_idx = (2 * qmf_band_idx) / 3;
796     ptr_sel = &ixheaacd_sel_case[(inp_band_idx + 1) & 3][0];
797     ptr_sel1 = &ixheaacd_sel_case[((inp_band_idx + 1) & 3) + 1][0];
798     rem = 2 * qmf_band_idx - 3 * inp_band_idx;
799 
800     if (rem == 0 || rem == 1) {
801       FLOAT32 *in_buf = &ptr_hbe_txposer->qmf_in_buf[0][2 * inp_band_idx];
802 
803       for (i = 0; i < qmf_voc_columns; i += 1) {
804         WORD32 k;
805         FLOAT32 vec_x[2 * HBE_OPER_WIN_LEN];
806         FLOAT32 *ptr_vec_x = &vec_x[0];
807         FLOAT32 x_zero_band_r, x_zero_band_i;
808 
809         FLOAT32 mag_scaling_fac;
810 
811         for (k = 0; k < (HBE_OPER_BLK_LEN_3); k += 2) {
812           FLOAT64 base1;
813           FLOAT64 base = 1e-17;
814 
815           temp_r = in_buf[0];
816           temp_i = in_buf[1];
817 
818           in_buf += 256;
819 
820           base1 = base + temp_r * temp_r;
821           base1 = base1 + temp_i * temp_i;
822 
823           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
824 
825           ptr_vec_x[0] = temp_r * mag_scaling_fac;
826           ptr_vec_x[1] = temp_i * mag_scaling_fac;
827 
828           temp_r = in_buf[0];
829           temp_i = in_buf[1];
830 
831           in_buf -= 128;
832 
833           temp_r1 = ptr_sel[0] * temp_r + ptr_sel[1] * temp_i;
834           temp_i1 = ptr_sel[2] * temp_r + ptr_sel[3] * temp_i;
835 
836           temp_r = in_buf[0];
837           temp_i = in_buf[1];
838 
839           temp_r1 += ptr_sel[4] * temp_r + ptr_sel[5] * temp_i;
840           temp_i1 += ptr_sel[6] * temp_r + ptr_sel[7] * temp_i;
841 
842           temp_r1 *= 0.3984033437f;
843           temp_i1 *= 0.3984033437f;
844 
845           base1 = base + temp_r1 * temp_r1;
846           base1 = base1 + temp_i1 * temp_i1;
847           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
848 
849           ptr_vec_x[2] = temp_r1 * mag_scaling_fac;
850           ptr_vec_x[3] = temp_i1 * mag_scaling_fac;
851 
852           ptr_vec_x += 4;
853           in_buf += 256;
854         }
855         ptr_vec_x = &vec_x[0];
856         temp_r = vec_x[2 * (HBE_ZERO_BAND_IDX - 2)];
857         temp_i = vec_x[(2 * (HBE_ZERO_BAND_IDX - 2)) + 1];
858 
859         x_zero_band_r = temp_r * temp_r - temp_i * temp_i;
860         x_zero_band_i = temp_r * temp_i + temp_i * temp_r;
861 
862         for (k = 0; k < (HBE_OPER_BLK_LEN_3); k++) {
863           temp_r = ptr_vec_x[0] * x_zero_band_r - ptr_vec_x[1] * x_zero_band_i;
864           temp_i = ptr_vec_x[0] * x_zero_band_i + ptr_vec_x[1] * x_zero_band_r;
865 
866           out_buf[0] += (temp_r * 0.4714045f);
867           out_buf[1] += (temp_i * 0.4714045f);
868 
869           ptr_vec_x += 2;
870           out_buf += 128;
871         }
872 
873         in_buf -= 128 * 11;
874         out_buf -= 128 * 6;
875       }
876     } else {
877       FLOAT32 *in_buf = &ptr_hbe_txposer->qmf_in_buf[0][2 * inp_band_idx];
878       FLOAT32 *in_buf1 =
879           &ptr_hbe_txposer->qmf_in_buf[0][2 * (inp_band_idx + 1)];
880 
881       for (i = 0; i < qmf_voc_columns; i++) {
882         WORD32 k;
883         FLOAT32 vec_x[2 * HBE_OPER_WIN_LEN];
884         FLOAT32 vec_x_cap[2 * HBE_OPER_WIN_LEN];
885 
886         FLOAT32 x_zero_band_r, x_zero_band_i;
887         FLOAT32 *ptr_vec_x = &vec_x[0];
888         FLOAT32 *ptr_vec_x_cap = &vec_x_cap[0];
889 
890         FLOAT32 mag_scaling_fac;
891 
892         for (k = 0; k < (HBE_OPER_BLK_LEN_3); k += 2) {
893           FLOAT32 tmp_vr, tmp_vi;
894           FLOAT32 tmp_cr, tmp_ci;
895           FLOAT64 base1;
896           FLOAT64 base = 1e-17;
897 
898           temp_r1 = in_buf[0];
899           temp_i1 = in_buf[1];
900           temp_r = in_buf1[0];
901           temp_i = in_buf1[1];
902 
903           base1 = base + temp_r * temp_r;
904           base1 = base1 + temp_i * temp_i;
905 
906           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
907 
908           ptr_vec_x[0] = temp_r * mag_scaling_fac;
909           ptr_vec_x[1] = temp_i * mag_scaling_fac;
910 
911           base1 = base + temp_r1 * temp_r1;
912           base1 = base1 + temp_i1 * temp_i1;
913 
914           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
915 
916           ptr_vec_x_cap[0] = temp_r1 * mag_scaling_fac;
917           ptr_vec_x_cap[1] = temp_i1 * mag_scaling_fac;
918 
919           in_buf += 256;
920 
921           temp_r = in_buf[0];
922           temp_i = in_buf[1];
923 
924           temp_r1 = ptr_sel[0] * temp_r + ptr_sel[1] * temp_i;
925           temp_i1 = ptr_sel[2] * temp_r + ptr_sel[3] * temp_i;
926 
927           in_buf -= 128;
928 
929           temp_r = in_buf[0];
930           temp_i = in_buf[1];
931 
932           tmp_cr = temp_r1 + ptr_sel[4] * temp_r + ptr_sel[5] * temp_i;
933           tmp_ci = temp_i1 + ptr_sel[6] * temp_r + ptr_sel[7] * temp_i;
934 
935           in_buf1 += 256;
936 
937           temp_r = in_buf1[0];
938           temp_i = in_buf1[1];
939 
940           temp_r1 = ptr_sel1[0] * temp_r + ptr_sel1[1] * temp_i;
941           temp_i1 = ptr_sel1[2] * temp_r + ptr_sel1[3] * temp_i;
942 
943           in_buf1 -= 128;
944 
945           temp_r = in_buf1[0];
946           temp_i = in_buf1[1];
947 
948           tmp_vr = temp_r1 + ptr_sel1[4] * temp_r + ptr_sel1[5] * temp_i;
949           tmp_vi = temp_i1 + ptr_sel1[6] * temp_r + ptr_sel1[7] * temp_i;
950 
951           tmp_cr *= 0.3984033437f;
952           tmp_ci *= 0.3984033437f;
953 
954           tmp_vr *= 0.3984033437f;
955           tmp_vi *= 0.3984033437f;
956 
957           base1 = base + tmp_vr * tmp_vr;
958           base1 = base1 + tmp_vi * tmp_vi;
959 
960           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
961 
962           ptr_vec_x[2] = tmp_vr * mag_scaling_fac;
963           ptr_vec_x[3] = tmp_vi * mag_scaling_fac;
964 
965           base1 = base + tmp_cr * tmp_cr;
966           base1 = base1 + tmp_ci * tmp_ci;
967 
968           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
969 
970           ptr_vec_x_cap[2] = tmp_cr * mag_scaling_fac;
971           ptr_vec_x_cap[3] = tmp_ci * mag_scaling_fac;
972 
973           in_buf += 256;
974           in_buf1 += 256;
975           ptr_vec_x += 4;
976           ptr_vec_x_cap += 4;
977         }
978         ptr_vec_x = &vec_x[0];
979         ptr_vec_x_cap = &vec_x_cap[0];
980 
981         temp_r = vec_x_cap[2 * (HBE_ZERO_BAND_IDX - 2)];
982         temp_i = vec_x_cap[2 * (HBE_ZERO_BAND_IDX - 2) + 1];
983         temp_r1 = vec_x[2 * (HBE_ZERO_BAND_IDX - 2)];
984         temp_i1 = vec_x[2 * (HBE_ZERO_BAND_IDX - 2) + 1];
985 
986         x_zero_band_r = temp_r * temp_r - temp_i * temp_i;
987         x_zero_band_i = temp_r * temp_i + temp_i * temp_r;
988 
989         temp_r = temp_r1 * temp_r1 - temp_i1 * temp_i1;
990         temp_i = temp_r1 * temp_i1 + temp_i1 * temp_r1;
991 
992         for (k = 0; k < (HBE_OPER_BLK_LEN_3); k++) {
993           temp_r1 = ptr_vec_x[0] * x_zero_band_r - ptr_vec_x[1] * x_zero_band_i;
994           temp_i1 = ptr_vec_x[0] * x_zero_band_i + ptr_vec_x[1] * x_zero_band_r;
995 
996           temp_r1 += ptr_vec_x_cap[0] * temp_r - ptr_vec_x_cap[1] * temp_i;
997           temp_i1 += ptr_vec_x_cap[0] * temp_i + ptr_vec_x_cap[1] * temp_r;
998 
999           out_buf[0] += (temp_r1 * 0.23570225f);
1000           out_buf[1] += (temp_i1 * 0.23570225f);
1001 
1002           out_buf += 128;
1003           ptr_vec_x += 2;
1004           ptr_vec_x_cap += 2;
1005         }
1006 
1007         in_buf -= 128 * 11;
1008         in_buf1 -= 128 * 11;
1009         out_buf -= 128 * 6;
1010       }
1011     }
1012 
1013     out_buf -= (256 * qmf_voc_columns) - 2;
1014   }
1015 }
1016 
ixheaacd_hbe_post_anal_prod4(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_voc_columns,WORD32 qmf_band_idx)1017 VOID ixheaacd_hbe_post_anal_prod4(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
1018                                   WORD32 qmf_voc_columns, WORD32 qmf_band_idx) {
1019   WORD32 i, inp_band_idx;
1020   FLOAT32 *out_ptr = &ptr_hbe_txposer->qmf_out_buf[3][2 * qmf_band_idx];
1021 
1022   ixheaacd_norm_qmf_in_buf_4(ptr_hbe_txposer, ((qmf_band_idx >> 1) - 1));
1023 
1024   for (; qmf_band_idx < ptr_hbe_txposer->x_over_qmf[3]; qmf_band_idx++) {
1025     WORD32 ip_idx;
1026     FLOAT32 temp, temp_r, temp_i;
1027     FLOAT32 *norm_ptr, *x_norm_ptr;
1028     inp_band_idx = qmf_band_idx >> 1;
1029     ip_idx = (qmf_band_idx & 1) ? (inp_band_idx + 1) : (inp_band_idx - 1);
1030 
1031     norm_ptr = &ptr_hbe_txposer->norm_qmf_in_buf[0][2 * ip_idx];
1032     x_norm_ptr =
1033         &ptr_hbe_txposer->norm_qmf_in_buf[HBE_ZERO_BAND_IDX][2 * inp_band_idx];
1034 
1035     for (i = 0; i < qmf_voc_columns; i++) {
1036       WORD32 k;
1037       FLOAT32 x_zero_band_r, x_zero_band_i;
1038 
1039       temp_r = x_zero_band_r = *x_norm_ptr++;
1040       temp_i = x_zero_band_i = *x_norm_ptr++;
1041 
1042       temp = x_zero_band_r * x_zero_band_r - x_zero_band_i * x_zero_band_i;
1043       x_zero_band_i =
1044           x_zero_band_r * x_zero_band_i + x_zero_band_i * x_zero_band_r;
1045 
1046       x_zero_band_r = temp_r * temp - temp_i * x_zero_band_i;
1047       x_zero_band_i = temp_r * x_zero_band_i + temp_i * temp;
1048 
1049       for (k = 0; k < HBE_OPER_BLK_LEN_4; k++) {
1050         temp = *norm_ptr++;
1051         temp_i = *norm_ptr++;
1052 
1053         temp_r = temp * x_zero_band_r - temp_i * x_zero_band_i;
1054         temp_i = temp * x_zero_band_i + temp_i * x_zero_band_r;
1055 
1056         *out_ptr++ += (temp_r * 0.6666667f);
1057         *out_ptr++ += (temp_i * 0.6666667f);
1058 
1059         norm_ptr += 254;
1060         out_ptr += 126;
1061       }
1062 
1063       norm_ptr -= 128 * 11;
1064       out_ptr -= 128 * 4;
1065       x_norm_ptr += 126;
1066     }
1067 
1068     out_ptr -= (128 * 2 * qmf_voc_columns) - 2;
1069   }
1070 }
1071 
ixheaacd_hbe_post_anal_xprod2(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_voc_columns,WORD32 qmf_band_idx,FLOAT32 p,FLOAT32 * cos_sin_theta)1072 VOID ixheaacd_hbe_post_anal_xprod2(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
1073                                    WORD32 qmf_voc_columns, WORD32 qmf_band_idx,
1074                                    FLOAT32 p, FLOAT32 *cos_sin_theta) {
1075   WORD32 i;
1076   FLOAT32 *norm_ptr = &ptr_hbe_txposer->norm_qmf_in_buf[1][2 * qmf_band_idx];
1077   FLOAT32 *out_ptr = &ptr_hbe_txposer->qmf_out_buf[1][2 * qmf_band_idx];
1078   FLOAT32 *x_norm_ptr =
1079       &ptr_hbe_txposer->norm_qmf_in_buf[HBE_ZERO_BAND_IDX][2 * qmf_band_idx];
1080 
1081   ixheaacd_norm_qmf_in_buf_2(ptr_hbe_txposer, qmf_band_idx);
1082 
1083   for (; qmf_band_idx < ptr_hbe_txposer->x_over_qmf[1]; qmf_band_idx++) {
1084     WORD32 n1, n2;
1085     FLOAT64 temp_fac;
1086     FLOAT32 mag_cmplx_gain = 1.666666667f;
1087     temp_fac = (2.0 * qmf_band_idx + 1 - p) * 0.5;
1088     n1 = ((WORD32)(temp_fac)) << 1;
1089     n2 = ((WORD32)(temp_fac + p)) << 1;
1090 
1091     for (i = 0; i < qmf_voc_columns; i++) {
1092       WORD32 k;
1093       FLOAT32 x_zero_band_r, x_zero_band_i;
1094 
1095       x_zero_band_r = *x_norm_ptr++;
1096       x_zero_band_i = *x_norm_ptr++;
1097 
1098       for (k = 1; k < (HBE_OPER_BLK_LEN_2 + 1); k++) {
1099         register FLOAT32 tmp_r, tmp_i;
1100         tmp_r = *norm_ptr++;
1101         tmp_i = *norm_ptr++;
1102 
1103         *out_ptr++ +=
1104             ((tmp_r * x_zero_band_r - tmp_i * x_zero_band_i) * 0.3333333f);
1105 
1106         *out_ptr++ +=
1107             ((tmp_r * x_zero_band_i + tmp_i * x_zero_band_r) * 0.3333333f);
1108 
1109         norm_ptr += 126;
1110         out_ptr += 126;
1111       }
1112       norm_ptr -= 128 * 9;
1113       out_ptr -= 128 * 8;
1114       x_norm_ptr += 126;
1115 
1116       {
1117         WORD32 max_trans_fac, max_n1, max_n2;
1118         FLOAT32 max_mag_value;
1119         FLOAT32 mag_zero_band, mag_n1_band, mag_n2_band, temp;
1120 
1121         FLOAT32 *qmf_in_buf_ri =
1122             ptr_hbe_txposer->qmf_in_buf[i + HBE_ZERO_BAND_IDX];
1123 
1124         mag_zero_band =
1125             qmf_in_buf_ri[2 * qmf_band_idx] * qmf_in_buf_ri[2 * qmf_band_idx] +
1126             qmf_in_buf_ri[2 * qmf_band_idx + 1] *
1127                 qmf_in_buf_ri[2 * qmf_band_idx + 1];
1128 
1129         mag_n1_band = qmf_in_buf_ri[n1] * qmf_in_buf_ri[n1] +
1130                       qmf_in_buf_ri[n1 + 1] * qmf_in_buf_ri[n1 + 1];
1131         mag_n2_band = qmf_in_buf_ri[n2] * qmf_in_buf_ri[n2] +
1132                       qmf_in_buf_ri[n2 + 1] * qmf_in_buf_ri[n2 + 1];
1133 
1134         temp = min(mag_n1_band, mag_n2_band);
1135 
1136         max_mag_value = 0;
1137         max_trans_fac = 0;
1138         max_n1 = 0;
1139         max_n2 = 0;
1140 
1141         if (temp > 0) {
1142           max_mag_value = temp;
1143           max_trans_fac = 1;
1144           max_n1 = n1;
1145           max_n2 = n2;
1146         }
1147 
1148         if (max_mag_value > mag_zero_band && max_n1 >= 0 &&
1149             max_n2 < TWICE_QMF_SYNTH_CHANNELS_NUM) {
1150           FLOAT32 vec_y_r[2], vec_y_i[2];
1151           FLOAT32 temp_r, temp_i, tmp_r1;
1152           WORD32 mid_trans_fac, idx;
1153           FLOAT64 base;
1154           WORD32 k;
1155           FLOAT32 mag_scaling_fac = 0.0f;
1156           FLOAT32 x_zero_band_r = 0;
1157           FLOAT32 x_zero_band_i = 0;
1158 
1159           mid_trans_fac = 2 - max_trans_fac;
1160 
1161           x_zero_band_r = qmf_in_buf_ri[max_n1];
1162           x_zero_band_i = qmf_in_buf_ri[max_n1 + 1];
1163           base = 1e-17;
1164           base = base + x_zero_band_r * x_zero_band_r;
1165           base = base + x_zero_band_i * x_zero_band_i;
1166 
1167           mag_scaling_fac = (FLOAT32)(1.0f / base);
1168           mag_scaling_fac = (FLOAT32)sqrt(sqrt(mag_scaling_fac));
1169 
1170           x_zero_band_r *= mag_scaling_fac;
1171           x_zero_band_i *= mag_scaling_fac;
1172 
1173           temp_r = x_zero_band_r;
1174           temp_i = x_zero_band_i;
1175           for (idx = 0; idx < mid_trans_fac - 1; idx++) {
1176             FLOAT32 tmp = x_zero_band_r;
1177             x_zero_band_r = x_zero_band_r * temp_r - x_zero_band_i * temp_i;
1178             x_zero_band_i = tmp * temp_i + x_zero_band_i * temp_r;
1179           }
1180 
1181           for (k = 0; k < 2; k++) {
1182             temp_r = ptr_hbe_txposer
1183                          ->qmf_in_buf[i + HBE_ZERO_BAND_IDX - 1 + k][max_n2];
1184             temp_i =
1185                 ptr_hbe_txposer
1186                     ->qmf_in_buf[i + HBE_ZERO_BAND_IDX - 1 + k][max_n2 + 1];
1187 
1188             base = 1e-17;
1189             base = base + temp_r * temp_r;
1190             base = base + temp_i * temp_i;
1191 
1192             mag_scaling_fac = (FLOAT32)(1.0f / base);
1193             mag_scaling_fac = (FLOAT32)sqrt(sqrt(mag_scaling_fac));
1194 
1195             temp_r *= mag_scaling_fac;
1196             temp_i *= mag_scaling_fac;
1197 
1198             vec_y_r[k] = temp_r;
1199             vec_y_i[k] = temp_i;
1200           }
1201 
1202           temp_r = vec_y_r[0] * x_zero_band_r - vec_y_i[0] * x_zero_band_i;
1203           temp_i = vec_y_r[0] * x_zero_band_i + vec_y_i[0] * x_zero_band_r;
1204 
1205           tmp_r1 =
1206               (FLOAT32)(cos_sin_theta[0] * temp_r - cos_sin_theta[1] * temp_i);
1207           temp_i =
1208               (FLOAT32)(cos_sin_theta[0] * temp_i + cos_sin_theta[1] * temp_r);
1209 
1210           ptr_hbe_txposer->qmf_out_buf[i * 2 + (HBE_ZERO_BAND_IDX - 1)]
1211                                       [2 * qmf_band_idx] +=
1212               (FLOAT32)(mag_cmplx_gain * tmp_r1);
1213 
1214           ptr_hbe_txposer->qmf_out_buf[i * 2 + (HBE_ZERO_BAND_IDX - 1)]
1215                                       [2 * qmf_band_idx + 1] +=
1216               (FLOAT32)(mag_cmplx_gain * temp_i);
1217 
1218           temp_r = vec_y_r[1] * x_zero_band_r - vec_y_i[1] * x_zero_band_i;
1219           temp_i = vec_y_r[1] * x_zero_band_i + vec_y_i[1] * x_zero_band_r;
1220 
1221           ptr_hbe_txposer->qmf_out_buf[i * 2 + (1 + HBE_ZERO_BAND_IDX - 1)]
1222                                       [2 * qmf_band_idx] +=
1223               (FLOAT32)(mag_cmplx_gain * temp_r);
1224 
1225           ptr_hbe_txposer->qmf_out_buf[i * 2 + (1 + HBE_ZERO_BAND_IDX - 1)]
1226                                       [2 * qmf_band_idx + 1] +=
1227               (FLOAT32)(mag_cmplx_gain * temp_i);
1228         }
1229       }
1230     }
1231 
1232     out_ptr -= (128 * 2 * qmf_voc_columns) - 2;
1233     norm_ptr -= (128 * qmf_voc_columns) - 2;
1234     x_norm_ptr -= (128 * qmf_voc_columns) - 2;
1235   }
1236 }
1237 
ixheaacd_hbe_post_anal_xprod3(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_voc_columns,WORD32 qmf_band_idx,FLOAT32 p,WORD32 pitch_in_bins_idx)1238 VOID ixheaacd_hbe_post_anal_xprod3(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
1239                                    WORD32 qmf_voc_columns, WORD32 qmf_band_idx,
1240                                    FLOAT32 p, WORD32 pitch_in_bins_idx) {
1241   WORD32 i, inp_band_idx, rem;
1242 
1243   FLOAT32 *out_buf = &ptr_hbe_txposer->qmf_out_buf[2][2 * qmf_band_idx];
1244 
1245   for (; qmf_band_idx < ptr_hbe_txposer->x_over_qmf[2]; qmf_band_idx++) {
1246     FLOAT32 temp_r, temp_i;
1247     FLOAT32 temp_r1, temp_i1;
1248     const FLOAT32 *ptr_sel, *ptr_sel1;
1249 
1250     inp_band_idx = (2 * qmf_band_idx) / 3;
1251     ptr_sel = &ixheaacd_sel_case[(inp_band_idx + 1) & 3][0];
1252     ptr_sel1 = &ixheaacd_sel_case[((inp_band_idx + 1) & 3) + 1][0];
1253     rem = 2 * qmf_band_idx - 3 * inp_band_idx;
1254 
1255     if (rem == 0 || rem == 1) {
1256       FLOAT32 *in_buf = &ptr_hbe_txposer->qmf_in_buf[0][2 * inp_band_idx];
1257 
1258       for (i = 0; i < qmf_voc_columns; i += 1) {
1259         WORD32 k;
1260         FLOAT32 vec_x[2 * HBE_OPER_WIN_LEN];
1261         FLOAT32 *ptr_vec_x = &vec_x[0];
1262         FLOAT32 x_zero_band_r, x_zero_band_i;
1263 
1264         FLOAT32 mag_scaling_fac;
1265 
1266         for (k = 0; k < (HBE_OPER_BLK_LEN_3); k += 2) {
1267           FLOAT64 base1;
1268           FLOAT64 base = 1e-17;
1269 
1270           temp_r = in_buf[0];
1271           temp_i = in_buf[1];
1272 
1273           in_buf += 256;
1274 
1275           base1 = base + temp_r * temp_r;
1276           base1 = base1 + temp_i * temp_i;
1277 
1278           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
1279 
1280           ptr_vec_x[0] = temp_r * mag_scaling_fac;
1281           ptr_vec_x[1] = temp_i * mag_scaling_fac;
1282 
1283           temp_r = in_buf[0];
1284           temp_i = in_buf[1];
1285 
1286           in_buf -= 128;
1287 
1288           temp_r1 = ptr_sel[0] * temp_r + ptr_sel[1] * temp_i;
1289           temp_i1 = ptr_sel[2] * temp_r + ptr_sel[3] * temp_i;
1290 
1291           temp_r = in_buf[0];
1292           temp_i = in_buf[1];
1293 
1294           temp_r1 += ptr_sel[4] * temp_r + ptr_sel[5] * temp_i;
1295           temp_i1 += ptr_sel[6] * temp_r + ptr_sel[7] * temp_i;
1296 
1297           temp_r1 *= 0.3984033437f;
1298           temp_i1 *= 0.3984033437f;
1299 
1300           base1 = base + temp_r1 * temp_r1;
1301           base1 = base1 + temp_i1 * temp_i1;
1302           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
1303 
1304           ptr_vec_x[2] = temp_r1 * mag_scaling_fac;
1305           ptr_vec_x[3] = temp_i1 * mag_scaling_fac;
1306 
1307           ptr_vec_x += 4;
1308           in_buf += 256;
1309         }
1310         ptr_vec_x = &vec_x[0];
1311         temp_r = vec_x[2 * (HBE_ZERO_BAND_IDX - 2)];
1312         temp_i = vec_x[(2 * (HBE_ZERO_BAND_IDX - 2)) + 1];
1313 
1314         x_zero_band_r = temp_r * temp_r - temp_i * temp_i;
1315         x_zero_band_i = temp_r * temp_i + temp_i * temp_r;
1316 
1317         for (k = 0; k < (HBE_OPER_BLK_LEN_3); k++) {
1318           temp_r = ptr_vec_x[0] * x_zero_band_r - ptr_vec_x[1] * x_zero_band_i;
1319           temp_i = ptr_vec_x[0] * x_zero_band_i + ptr_vec_x[1] * x_zero_band_r;
1320 
1321           out_buf[0] += (temp_r * 0.4714045f);
1322           out_buf[1] += (temp_i * 0.4714045f);
1323 
1324           ptr_vec_x += 2;
1325           out_buf += 128;
1326         }
1327 
1328         ixheaacd_hbe_xprod_proc_3(ptr_hbe_txposer, qmf_band_idx, i, p,
1329                                   pitch_in_bins_idx);
1330 
1331         in_buf -= 128 * 11;
1332         out_buf -= 128 * 6;
1333       }
1334     } else {
1335       FLOAT32 *in_buf = &ptr_hbe_txposer->qmf_in_buf[0][2 * inp_band_idx];
1336       FLOAT32 *in_buf1 =
1337           &ptr_hbe_txposer->qmf_in_buf[0][2 * (inp_band_idx + 1)];
1338 
1339       for (i = 0; i < qmf_voc_columns; i++) {
1340         WORD32 k;
1341         FLOAT32 vec_x[2 * HBE_OPER_WIN_LEN];
1342         FLOAT32 vec_x_cap[2 * HBE_OPER_WIN_LEN];
1343 
1344         FLOAT32 x_zero_band_r, x_zero_band_i;
1345         FLOAT32 *ptr_vec_x = &vec_x[0];
1346         FLOAT32 *ptr_vec_x_cap = &vec_x_cap[0];
1347 
1348         FLOAT32 mag_scaling_fac;
1349 
1350         for (k = 0; k < (HBE_OPER_BLK_LEN_3); k += 2) {
1351           FLOAT32 tmp_vr, tmp_vi;
1352           FLOAT32 tmp_cr, tmp_ci;
1353           FLOAT64 base1;
1354           FLOAT64 base = 1e-17;
1355 
1356           temp_r1 = in_buf[0];
1357           temp_i1 = in_buf[1];
1358           temp_r = in_buf1[0];
1359           temp_i = in_buf1[1];
1360 
1361           base1 = base + temp_r * temp_r;
1362           base1 = base1 + temp_i * temp_i;
1363 
1364           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
1365 
1366           ptr_vec_x[0] = temp_r * mag_scaling_fac;
1367           ptr_vec_x[1] = temp_i * mag_scaling_fac;
1368 
1369           base1 = base + temp_r1 * temp_r1;
1370           base1 = base1 + temp_i1 * temp_i1;
1371 
1372           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
1373 
1374           ptr_vec_x_cap[0] = temp_r1 * mag_scaling_fac;
1375           ptr_vec_x_cap[1] = temp_i1 * mag_scaling_fac;
1376 
1377           in_buf += 256;
1378 
1379           temp_r = in_buf[0];
1380           temp_i = in_buf[1];
1381 
1382           temp_r1 = ptr_sel[0] * temp_r + ptr_sel[1] * temp_i;
1383           temp_i1 = ptr_sel[2] * temp_r + ptr_sel[3] * temp_i;
1384 
1385           in_buf -= 128;
1386 
1387           temp_r = in_buf[0];
1388           temp_i = in_buf[1];
1389 
1390           tmp_cr = temp_r1 + ptr_sel[4] * temp_r + ptr_sel[5] * temp_i;
1391           tmp_ci = temp_i1 + ptr_sel[6] * temp_r + ptr_sel[7] * temp_i;
1392 
1393           in_buf1 += 256;
1394 
1395           temp_r = in_buf1[0];
1396           temp_i = in_buf1[1];
1397 
1398           temp_r1 = ptr_sel1[0] * temp_r + ptr_sel1[1] * temp_i;
1399           temp_i1 = ptr_sel1[2] * temp_r + ptr_sel1[3] * temp_i;
1400 
1401           in_buf1 -= 128;
1402 
1403           temp_r = in_buf1[0];
1404           temp_i = in_buf1[1];
1405 
1406           tmp_vr = temp_r1 + ptr_sel1[4] * temp_r + ptr_sel1[5] * temp_i;
1407           tmp_vi = temp_i1 + ptr_sel1[6] * temp_r + ptr_sel1[7] * temp_i;
1408 
1409           tmp_cr *= 0.3984033437f;
1410           tmp_ci *= 0.3984033437f;
1411 
1412           tmp_vr *= 0.3984033437f;
1413           tmp_vi *= 0.3984033437f;
1414 
1415           base1 = base + tmp_vr * tmp_vr;
1416           base1 = base1 + tmp_vi * tmp_vi;
1417 
1418           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
1419 
1420           ptr_vec_x[2] = tmp_vr * mag_scaling_fac;
1421           ptr_vec_x[3] = tmp_vi * mag_scaling_fac;
1422 
1423           base1 = base + tmp_cr * tmp_cr;
1424           base1 = base1 + tmp_ci * tmp_ci;
1425 
1426           mag_scaling_fac = (FLOAT32)(ixheaacd_cbrt_calc((FLOAT32)base1));
1427 
1428           ptr_vec_x_cap[2] = tmp_cr * mag_scaling_fac;
1429           ptr_vec_x_cap[3] = tmp_ci * mag_scaling_fac;
1430 
1431           in_buf += 256;
1432           in_buf1 += 256;
1433           ptr_vec_x += 4;
1434           ptr_vec_x_cap += 4;
1435         }
1436         ptr_vec_x = &vec_x[0];
1437         ptr_vec_x_cap = &vec_x_cap[0];
1438 
1439         temp_r = vec_x_cap[2 * (HBE_ZERO_BAND_IDX - 2)];
1440         temp_i = vec_x_cap[2 * (HBE_ZERO_BAND_IDX - 2) + 1];
1441         temp_r1 = vec_x[2 * (HBE_ZERO_BAND_IDX - 2)];
1442         temp_i1 = vec_x[2 * (HBE_ZERO_BAND_IDX - 2) + 1];
1443 
1444         x_zero_band_r = temp_r * temp_r - temp_i * temp_i;
1445         x_zero_band_i = temp_r * temp_i + temp_i * temp_r;
1446 
1447         temp_r = temp_r1 * temp_r1 - temp_i1 * temp_i1;
1448         temp_i = temp_r1 * temp_i1 + temp_i1 * temp_r1;
1449 
1450         for (k = 0; k < (HBE_OPER_BLK_LEN_3); k++) {
1451           temp_r1 = ptr_vec_x[0] * x_zero_band_r - ptr_vec_x[1] * x_zero_band_i;
1452           temp_i1 = ptr_vec_x[0] * x_zero_band_i + ptr_vec_x[1] * x_zero_band_r;
1453 
1454           temp_r1 += ptr_vec_x_cap[0] * temp_r - ptr_vec_x_cap[1] * temp_i;
1455           temp_i1 += ptr_vec_x_cap[0] * temp_i + ptr_vec_x_cap[1] * temp_r;
1456 
1457           out_buf[0] += (temp_r1 * 0.23570225f);
1458           out_buf[1] += (temp_i1 * 0.23570225f);
1459 
1460           out_buf += 128;
1461           ptr_vec_x += 2;
1462           ptr_vec_x_cap += 2;
1463         }
1464 
1465         ixheaacd_hbe_xprod_proc_3(ptr_hbe_txposer, qmf_band_idx, i, p,
1466                                   pitch_in_bins_idx);
1467 
1468         in_buf -= 128 * 11;
1469         in_buf1 -= 128 * 11;
1470         out_buf -= 128 * 6;
1471       }
1472     }
1473 
1474     out_buf -= (256 * qmf_voc_columns) - 2;
1475   }
1476 }
1477 
ixheaacd_hbe_post_anal_xprod4(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 qmf_voc_columns,WORD32 qmf_band_idx,FLOAT32 p,WORD32 pitch_in_bins_idx)1478 VOID ixheaacd_hbe_post_anal_xprod4(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
1479                                    WORD32 qmf_voc_columns, WORD32 qmf_band_idx,
1480                                    FLOAT32 p, WORD32 pitch_in_bins_idx) {
1481   WORD32 i, inp_band_idx;
1482   FLOAT32 *out_ptr = &ptr_hbe_txposer->qmf_out_buf[3][2 * qmf_band_idx];
1483 
1484   ixheaacd_norm_qmf_in_buf_4(ptr_hbe_txposer, ((qmf_band_idx >> 1) - 1));
1485 
1486   for (; qmf_band_idx < ptr_hbe_txposer->x_over_qmf[3]; qmf_band_idx++) {
1487     WORD32 ip_idx;
1488     FLOAT32 temp, temp_r, temp_i;
1489     FLOAT32 *norm_ptr, *x_norm_ptr;
1490     inp_band_idx = qmf_band_idx >> 1;
1491     ip_idx = (qmf_band_idx & 1) ? (inp_band_idx + 1) : (inp_band_idx - 1);
1492 
1493     norm_ptr = &ptr_hbe_txposer->norm_qmf_in_buf[0][2 * ip_idx];
1494     x_norm_ptr =
1495         &ptr_hbe_txposer->norm_qmf_in_buf[HBE_ZERO_BAND_IDX][2 * inp_band_idx];
1496 
1497     for (i = 0; i < qmf_voc_columns; i++) {
1498       WORD32 k;
1499       FLOAT32 x_zero_band_r, x_zero_band_i;
1500 
1501       temp_r = x_zero_band_r = *x_norm_ptr++;
1502       temp_i = x_zero_band_i = *x_norm_ptr++;
1503 
1504       temp = x_zero_band_r * x_zero_band_r - x_zero_band_i * x_zero_band_i;
1505       x_zero_band_i =
1506           x_zero_band_r * x_zero_band_i + x_zero_band_i * x_zero_band_r;
1507 
1508       x_zero_band_r = temp_r * temp - temp_i * x_zero_band_i;
1509       x_zero_band_i = temp_r * x_zero_band_i + temp_i * temp;
1510 
1511       for (k = 0; k < HBE_OPER_BLK_LEN_4; k++) {
1512         temp = *norm_ptr++;
1513         temp_i = *norm_ptr++;
1514 
1515         temp_r = temp * x_zero_band_r - temp_i * x_zero_band_i;
1516         temp_i = temp * x_zero_band_i + temp_i * x_zero_band_r;
1517 
1518         *out_ptr++ += (temp_r * 0.6666667f);
1519         *out_ptr++ += (temp_i * 0.6666667f);
1520 
1521         norm_ptr += 254;
1522         out_ptr += 126;
1523       }
1524 
1525       norm_ptr -= 128 * 11;
1526       out_ptr -= 128 * 4;
1527       x_norm_ptr += 126;
1528 
1529       ixheaacd_hbe_xprod_proc_4(ptr_hbe_txposer, qmf_band_idx, i, p,
1530                                 pitch_in_bins_idx);
1531     }
1532 
1533     out_ptr -= (128 * 2 * qmf_voc_columns) - 2;
1534   }
1535 }
1536 
ixheaacd_hbe_post_anal_process(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 pitch_in_bins,WORD32 sbr_upsamp_4_flg)1537 IA_ERRORCODE ixheaacd_hbe_post_anal_process(
1538     ia_esbr_hbe_txposer_struct *ptr_hbe_txposer, WORD32 pitch_in_bins,
1539     WORD32 sbr_upsamp_4_flg) {
1540   FLOAT32 p;
1541   WORD32 trans_fac;
1542   WORD32 qmf_voc_columns = ptr_hbe_txposer->no_bins / 2;
1543   FLOAT32 cos_sin_theta[2];
1544 
1545   p = (sbr_upsamp_4_flg) ? (FLOAT32)(pitch_in_bins * 0.04166666666666)
1546                          : (FLOAT32)(pitch_in_bins * 0.08333333333333);
1547 
1548   if (p < SBR_CONST_PMIN) {
1549     trans_fac = 2;
1550     if (trans_fac <= ptr_hbe_txposer->max_stretch)
1551       ixheaacd_hbe_post_anal_prod2(ptr_hbe_txposer, qmf_voc_columns,
1552                                    ptr_hbe_txposer->x_over_qmf[0]);
1553 
1554     trans_fac = 3;
1555     if (trans_fac <= ptr_hbe_txposer->max_stretch)
1556       ixheaacd_hbe_post_anal_prod3(ptr_hbe_txposer, qmf_voc_columns,
1557                                    ptr_hbe_txposer->x_over_qmf[1]);
1558 
1559     trans_fac = 4;
1560     if (trans_fac <= ptr_hbe_txposer->max_stretch) {
1561       if (ptr_hbe_txposer->x_over_qmf[2] <= 1) return IA_FATAL_ERROR;
1562       ixheaacd_hbe_post_anal_prod4(ptr_hbe_txposer, qmf_voc_columns,
1563                                    ptr_hbe_txposer->x_over_qmf[2]);
1564     }
1565 
1566   } else {
1567     trans_fac = 2;
1568     if (trans_fac <= ptr_hbe_txposer->max_stretch) {
1569       cos_sin_theta[0] = ixheaacd_hbe_x_prod_cos_table_trans_2
1570           [((pitch_in_bins + sbr_upsamp_4_flg * 128) << 1) + 0];
1571       cos_sin_theta[1] = ixheaacd_hbe_x_prod_cos_table_trans_2
1572           [((pitch_in_bins + sbr_upsamp_4_flg * 128) << 1) + 1];
1573 
1574       ixheaacd_hbe_post_anal_xprod2(ptr_hbe_txposer, qmf_voc_columns,
1575                                     ptr_hbe_txposer->x_over_qmf[0], p,
1576                                     cos_sin_theta);
1577     }
1578 
1579     trans_fac = 3;
1580     if (trans_fac <= ptr_hbe_txposer->max_stretch)
1581       ixheaacd_hbe_post_anal_xprod3(ptr_hbe_txposer, qmf_voc_columns,
1582                                     ptr_hbe_txposer->x_over_qmf[1], p,
1583                                     (pitch_in_bins + sbr_upsamp_4_flg * 128));
1584 
1585     trans_fac = 4;
1586     if (trans_fac <= ptr_hbe_txposer->max_stretch) {
1587       if (ptr_hbe_txposer->x_over_qmf[2] <= 1) return IA_FATAL_ERROR;
1588       ixheaacd_hbe_post_anal_xprod4(ptr_hbe_txposer, qmf_voc_columns,
1589                                     ptr_hbe_txposer->x_over_qmf[2], p,
1590                                     (pitch_in_bins + sbr_upsamp_4_flg * 128));
1591     }
1592   }
1593   return IA_NO_ERROR;
1594 }
1595