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