/src/libxaac/decoder/ixheaacd_sbrdec_lpfuncs.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * * |
3 | | * Copyright (C) 2018 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | #include <string.h> |
21 | | #include <math.h> |
22 | | #include "ixheaacd_sbr_common.h" |
23 | | #include "ixheaac_type_def.h" |
24 | | |
25 | | #include "ixheaac_constants.h" |
26 | | #include "ixheaac_basic_ops32.h" |
27 | | #include "ixheaac_basic_ops16.h" |
28 | | #include "ixheaac_basic_ops40.h" |
29 | | #include "ixheaac_basic_ops.h" |
30 | | #include "ixheaacd_defines.h" |
31 | | |
32 | | #include "ixheaacd_intrinsics.h" |
33 | | #include "ixheaac_sbr_const.h" |
34 | | #include "ixheaac_basic_op.h" |
35 | | #include "ixheaacd_defines.h" |
36 | | #include "ixheaacd_bitbuffer.h" |
37 | | #include "ixheaacd_pns.h" |
38 | | |
39 | | #include "ixheaacd_aac_rom.h" |
40 | | #include "ixheaacd_pulsedata.h" |
41 | | |
42 | | #include "ixheaacd_drc_data_struct.h" |
43 | | #include "ixheaacd_lt_predict.h" |
44 | | #include "ixheaacd_cnst.h" |
45 | | #include "ixheaacd_ec_defines.h" |
46 | | #include "ixheaacd_ec_struct_def.h" |
47 | | #include "ixheaacd_channelinfo.h" |
48 | | #include "ixheaacd_drc_dec.h" |
49 | | |
50 | | #include "ixheaacd_sbrdecoder.h" |
51 | | |
52 | | #include "ixheaacd_sbrdecsettings.h" |
53 | | #include "ixheaacd_sbr_scale.h" |
54 | | #include "ixheaacd_lpp_tran.h" |
55 | | #include "ixheaacd_env_extr_part.h" |
56 | | #include "ixheaacd_sbr_rom.h" |
57 | | #include "ixheaacd_hybrid.h" |
58 | | #include "ixheaacd_ps_dec.h" |
59 | | #include "ixheaacd_ps_bitdec.h" |
60 | | #include "ixheaacd_env_extr.h" |
61 | | #include "ixheaacd_common_rom.h" |
62 | | #include "ixheaacd_freq_sca.h" |
63 | | |
64 | | #include "ixheaacd_qmf_dec.h" |
65 | | |
66 | | #include "ixheaacd_env_calc.h" |
67 | | |
68 | | #include "ixheaacd_pvc_dec.h" |
69 | | #include "ixheaacd_sbr_dec.h" |
70 | | #include "ixheaacd_env_dec.h" |
71 | | #include "ixheaacd_basic_funcs.h" |
72 | | #include "ixheaacd_sbr_crc.h" |
73 | | #include "ixheaacd_function_selector.h" |
74 | | |
75 | | #include "ixheaacd_audioobjtypes.h" |
76 | | #include "ixheaacd_error_codes.h" |
77 | | |
78 | | #define ALIGN_SIZE64(x) ((((x) + 7) >> 3) << 3) |
79 | | |
80 | | static const FLOAT32 ixheaacd_new_bw_table[4][4] = { |
81 | | {0.00f, 0.60f, 0.90f, 0.98f}, |
82 | | {0.60f, 0.75f, 0.90f, 0.98f}, |
83 | | {0.00f, 0.75f, 0.90f, 0.98f}, |
84 | | {0.00f, 0.75f, 0.90f, 0.98f}}; |
85 | | static const WORD32 ixheaacd_inew_bw_table[4][4] = { |
86 | | {0x00000000, 0x4ccccccd, 0x73333333, 0x7d70a3d7}, |
87 | | {0x4ccccccd, 0x60000000, 0x73333333, 0x7d70a3d7}, |
88 | | {0x00000000, 0x60000000, 0x73333333, 0x7d70a3d7}, |
89 | | {0x00000000, 0x60000000, 0x73333333, 0x7d70a3d7}}; |
90 | | |
91 | 120k | VOID ixheaacd_reset_sbrenvelope_calc(ia_sbr_calc_env_struct *h_cal_env) { |
92 | 120k | h_cal_env->ph_index = 0; |
93 | 120k | h_cal_env->filt_buf_noise_e = 0; |
94 | 120k | h_cal_env->start_up = 1; |
95 | 120k | } |
96 | | |
97 | | VOID ixheaacd_derive_lim_band_tbl( |
98 | | ia_sbr_header_data_struct *ptr_header_data, |
99 | | const ia_patch_param_struct *p_str_patch_param, WORD16 num_patches, |
100 | 23.9k | ixheaacd_misc_tables *pstr_common_tables) { |
101 | 23.9k | WORD32 i, k, k_1; |
102 | 23.9k | WORD32 nr_lim, patch_border_k, patch_border_k_1, temp_nr_lim; |
103 | | |
104 | 23.9k | WORD16 lim_table[MAX_FREQ_COEFFS / 2 + MAX_NUM_PATCHES + 1]; |
105 | 23.9k | WORD16 patch_borders[MAX_NUM_PATCHES + 1]; |
106 | 23.9k | WORD16 kx, k2; |
107 | 23.9k | WORD16 temp, lim_bands, num_octaves; |
108 | | |
109 | 23.9k | WORD16 *f_lim_tbl = ptr_header_data->pstr_freq_band_data->freq_band_tbl_lim; |
110 | 23.9k | WORD16 *num_lf_bands = &ptr_header_data->pstr_freq_band_data->num_lf_bands; |
111 | 23.9k | WORD16 *f_low_tbl = |
112 | 23.9k | ptr_header_data->pstr_freq_band_data->freq_band_table[LOW]; |
113 | 23.9k | WORD16 num_low_bnd = ptr_header_data->pstr_freq_band_data->num_sf_bands[LOW]; |
114 | 23.9k | WORD16 limiter_bands = ptr_header_data->limiter_bands; |
115 | | |
116 | 23.9k | WORD16 sub_band_start = f_low_tbl[0]; |
117 | 23.9k | WORD16 sub_band_end = f_low_tbl[num_low_bnd]; |
118 | 23.9k | const WORD16 limbnd_per_oct[4] = {(WORD16)0x2000, (WORD16)0x2666, (WORD16)0x4000, |
119 | 23.9k | (WORD16)0x6000}; |
120 | | |
121 | 23.9k | if (limiter_bands == 0) { |
122 | 2.92k | f_lim_tbl[0] = 0; |
123 | 2.92k | f_lim_tbl[1] = sub_band_end - sub_band_start; |
124 | 2.92k | nr_lim = 1; |
125 | 21.0k | } else { |
126 | 72.1k | for (k = 0; k < num_patches; k++) { |
127 | 51.1k | patch_borders[k] = p_str_patch_param[k].guard_start_band - sub_band_start; |
128 | 51.1k | } |
129 | 21.0k | patch_borders[k] = sub_band_end - sub_band_start; |
130 | | |
131 | 165k | for (k = 0; k <= num_low_bnd; k++) { |
132 | 144k | lim_table[k] = f_low_tbl[k] - sub_band_start; |
133 | 144k | } |
134 | 51.7k | for (k = 1; k < num_patches; k++) { |
135 | 30.6k | lim_table[num_low_bnd + k] = patch_borders[k]; |
136 | 30.6k | } |
137 | | |
138 | 21.0k | temp_nr_lim = nr_lim = (num_low_bnd + num_patches) - 1; |
139 | 21.0k | ixheaacd_aac_shellsort(lim_table, (temp_nr_lim + 1)); |
140 | | |
141 | 21.0k | k = 1; |
142 | 21.0k | k_1 = 0; |
143 | | |
144 | 21.0k | lim_bands = limbnd_per_oct[limiter_bands]; |
145 | | |
146 | 174k | while ((k - temp_nr_lim) <= 0) { |
147 | 153k | k2 = lim_table[k] + sub_band_start; |
148 | 153k | kx = lim_table[k_1] + sub_band_start; |
149 | | |
150 | 153k | num_octaves = pstr_common_tables->log_dual_is_table[k2]; |
151 | 153k | num_octaves -= pstr_common_tables->log_dual_is_table[kx]; |
152 | | |
153 | 153k | temp = (WORD16)(((WORD32)lim_bands * (WORD32)num_octaves) >> 15); |
154 | | |
155 | 153k | if (temp < 0x01f6) { |
156 | 95.5k | if (lim_table[k_1] == lim_table[k]) { |
157 | 12.2k | lim_table[k] = sub_band_end; |
158 | 12.2k | nr_lim = nr_lim - 1; |
159 | 12.2k | k = (k + 1); |
160 | 12.2k | continue; |
161 | 12.2k | } |
162 | 83.3k | patch_border_k_1 = patch_border_k = 0; |
163 | | |
164 | 406k | for (i = 0; i <= num_patches; i++) { |
165 | 323k | if (lim_table[k] == patch_borders[i]) { |
166 | 29.2k | patch_border_k = 1; |
167 | 29.2k | } |
168 | 323k | if (lim_table[k_1] == patch_borders[i]) { |
169 | 49.7k | patch_border_k_1 = 1; |
170 | 49.7k | } |
171 | 323k | } |
172 | 83.3k | if (!patch_border_k) { |
173 | 54.1k | lim_table[k] = sub_band_end; |
174 | 54.1k | nr_lim = nr_lim - 1; |
175 | 54.1k | k = (k + 1); |
176 | 54.1k | continue; |
177 | 54.1k | } |
178 | | |
179 | 29.2k | if (!patch_border_k_1) { |
180 | 17.9k | lim_table[k_1] = sub_band_end; |
181 | 17.9k | nr_lim = nr_lim - 1; |
182 | 17.9k | } |
183 | 29.2k | } |
184 | 86.8k | k_1 = k; |
185 | 86.8k | k = (k + 1); |
186 | 86.8k | } |
187 | 21.0k | ixheaacd_aac_shellsort(lim_table, (temp_nr_lim + 1)); |
188 | | |
189 | 21.0k | memcpy(f_lim_tbl, lim_table, sizeof(WORD16) * (nr_lim + 1)); |
190 | 21.0k | } |
191 | 23.9k | *num_lf_bands = nr_lim; |
192 | | |
193 | 23.9k | return; |
194 | 23.9k | } |
195 | | |
196 | | VOID ixheaacd_lean_sbrconcealment( |
197 | | ia_sbr_header_data_struct *ptr_header_data, |
198 | | ia_sbr_frame_info_data_struct *ptr_sbr_data, |
199 | 42.9k | ia_sbr_prev_frame_data_struct *ptr_prev_data) { |
200 | 42.9k | WORD32 target; |
201 | 42.9k | WORD32 step; |
202 | 42.9k | WORD32 i; |
203 | | |
204 | 42.9k | WORD16 cur_start_pos; |
205 | 42.9k | WORD16 cur_stop_pos; |
206 | | |
207 | 42.9k | ptr_sbr_data->amp_res = ptr_prev_data->amp_res; |
208 | 42.9k | ptr_sbr_data->coupling_mode = ptr_prev_data->coupling_mode; |
209 | 42.9k | ptr_sbr_data->max_qmf_subband_aac = ptr_prev_data->max_qmf_subband_aac; |
210 | | |
211 | 42.9k | memcpy(ptr_sbr_data->sbr_invf_mode, ptr_prev_data->sbr_invf_mode, |
212 | 42.9k | sizeof(WORD32) * MAX_INVF_BANDS); |
213 | | |
214 | 42.9k | ptr_sbr_data->str_frame_info_details.num_env = 1; |
215 | | |
216 | 42.9k | cur_start_pos = ptr_prev_data->end_position - ptr_header_data->num_time_slots; |
217 | 42.9k | cur_stop_pos = ptr_header_data->num_time_slots; |
218 | | |
219 | 42.9k | ptr_sbr_data->str_frame_info_details.border_vec[0] = cur_start_pos; |
220 | 42.9k | ptr_sbr_data->str_frame_info_details.border_vec[1] = cur_stop_pos; |
221 | | |
222 | 42.9k | ptr_sbr_data->str_frame_info_details.noise_border_vec[0] = cur_start_pos; |
223 | 42.9k | ptr_sbr_data->str_frame_info_details.noise_border_vec[1] = cur_stop_pos; |
224 | 42.9k | ; |
225 | | |
226 | 42.9k | ptr_sbr_data->str_frame_info_details.freq_res[0] = 1; |
227 | 42.9k | ptr_sbr_data->str_frame_info_details.transient_env = -1; |
228 | 42.9k | ptr_sbr_data->str_frame_info_details.num_noise_env = 1; |
229 | | |
230 | 42.9k | ptr_sbr_data->num_env_sfac = |
231 | 42.9k | ptr_header_data->pstr_freq_band_data->num_sf_bands[1]; |
232 | | |
233 | 42.9k | ptr_sbr_data->del_cod_dir_arr[0] = DTDF_DIR_TIME; |
234 | | |
235 | 42.9k | if (ptr_sbr_data->coupling_mode == COUPLING_BAL) { |
236 | 3.61k | target = SBR_ENERGY_PAN_OFFSET; |
237 | 39.3k | } else { |
238 | 39.3k | target = 0; |
239 | 39.3k | } |
240 | | |
241 | 42.9k | step = 1; |
242 | | |
243 | 42.9k | if (ptr_header_data->amp_res - SBR_AMPLITUDE_RESOLUTION_1_5 == 0) { |
244 | 27.0k | target = (target << 1); |
245 | 27.0k | step = (step << 1); |
246 | 27.0k | } |
247 | | |
248 | 507k | for (i = 0; i < ptr_sbr_data->num_env_sfac; i++) { |
249 | 464k | if (ptr_prev_data->sfb_nrg_prev[i] > target) |
250 | 265k | ptr_sbr_data->int_env_sf_arr[i] = -(step); |
251 | 199k | else |
252 | 199k | ptr_sbr_data->int_env_sf_arr[i] = step; |
253 | 464k | } |
254 | | |
255 | 42.9k | ptr_sbr_data->del_cod_dir_noise_arr[0] = DTDF_DIR_TIME; |
256 | | |
257 | 42.9k | memset(ptr_sbr_data->int_noise_floor, 0, |
258 | 42.9k | sizeof(ptr_sbr_data->int_noise_floor)); |
259 | | |
260 | 42.9k | memset(ptr_sbr_data->add_harmonics, 0, sizeof(FLAG) * MAX_FREQ_COEFFS); |
261 | 42.9k | } |
262 | | |
263 | | static WORD16 ixheaacd_find_closest_entry(WORD32 goal_sb, WORD16 *f_master_tbl, |
264 | | WORD16 num_mf_bands, |
265 | 476k | WORD16 direction) { |
266 | 476k | WORD32 index; |
267 | | |
268 | 476k | if (goal_sb <= f_master_tbl[0]) return f_master_tbl[0]; |
269 | | |
270 | 476k | if (goal_sb >= f_master_tbl[num_mf_bands]) return f_master_tbl[num_mf_bands]; |
271 | | |
272 | 438k | if (direction) { |
273 | 1.24k | index = 0; |
274 | 8.08k | while (f_master_tbl[index] < goal_sb) { |
275 | 6.83k | index++; |
276 | 6.83k | } |
277 | 437k | } else { |
278 | 437k | index = num_mf_bands; |
279 | 2.87M | while (f_master_tbl[index] > goal_sb) { |
280 | 2.43M | index--; |
281 | 2.43M | } |
282 | 437k | } |
283 | | |
284 | 438k | return f_master_tbl[index]; |
285 | 476k | } |
286 | | |
287 | | WORD32 ixheaacd_reset_hf_generator(ia_sbr_hf_generator_struct *ptr_hf_gen_str, |
288 | | ia_sbr_header_data_struct *ptr_header_data, |
289 | 23.9k | WORD audio_object_type) { |
290 | 23.9k | WORD32 patch, sb; |
291 | 23.9k | WORD32 temp; |
292 | 23.9k | WORD16 *ptr_noise_freq_tbl; |
293 | 23.9k | WORD32 num_nf_bands; |
294 | | |
295 | 23.9k | ia_transposer_settings_struct *pstr_transposer_settings = |
296 | 23.9k | ptr_hf_gen_str->pstr_settings; |
297 | 23.9k | ia_patch_param_struct *p_str_patch_param = |
298 | 23.9k | pstr_transposer_settings->str_patch_param; |
299 | | |
300 | 23.9k | WORD32 sub_band_start = ptr_header_data->pstr_freq_band_data->sub_band_start; |
301 | 23.9k | WORD16 *f_master_tbl = ptr_header_data->pstr_freq_band_data->f_master_tbl; |
302 | 23.9k | WORD16 num_mf_bands = ptr_header_data->pstr_freq_band_data->num_mf_bands; |
303 | 23.9k | WORD16 usb = ptr_header_data->pstr_freq_band_data->sub_band_end; |
304 | | |
305 | 23.9k | WORD32 src_start_band; |
306 | 23.9k | WORD32 patch_stride; |
307 | 23.9k | WORD32 num_bands_in_patch; |
308 | | |
309 | 23.9k | WORD32 lsb = f_master_tbl[0]; |
310 | 23.9k | WORD16 xover_offset = sub_band_start - lsb; |
311 | | |
312 | 23.9k | WORD16 goal_sb, flag_break_1 = 0; |
313 | 23.9k | WORD32 fs = ptr_header_data->out_sampling_freq; |
314 | | |
315 | 23.9k | if (lsb < (SHIFT_START_SB + 4)) { |
316 | 0 | return (1); |
317 | 0 | } |
318 | 23.9k | switch (fs) { |
319 | 3.31k | case 16000: |
320 | 3.66k | case 22050: |
321 | 3.76k | case 24000: |
322 | 20.4k | case 32000: |
323 | 20.4k | goal_sb = 64; |
324 | 20.4k | break; |
325 | 103 | case 44100: |
326 | 103 | goal_sb = 46; |
327 | 103 | break; |
328 | 85 | case 48000: |
329 | 85 | goal_sb = 43; |
330 | 85 | break; |
331 | 112 | case 64000: |
332 | 112 | goal_sb = 32; |
333 | 112 | break; |
334 | 708 | case 88200: |
335 | 708 | goal_sb = 23; |
336 | 708 | break; |
337 | 1.68k | case 96000: |
338 | 1.68k | goal_sb = 21; |
339 | 1.68k | break; |
340 | 822 | default: |
341 | 822 | return (0); |
342 | 23.9k | } |
343 | | |
344 | 23.1k | goal_sb = ixheaacd_find_closest_entry(goal_sb, f_master_tbl, num_mf_bands, 1); |
345 | 23.1k | if (audio_object_type != AOT_ER_AAC_ELD && |
346 | 842 | audio_object_type != AOT_ER_AAC_LD) { |
347 | 842 | if (ixheaac_abs16_sat((WORD16)(goal_sb - usb)) < 4) { |
348 | 673 | goal_sb = usb; |
349 | 673 | } |
350 | 842 | } |
351 | | |
352 | 23.1k | src_start_band = SHIFT_START_SB + xover_offset; |
353 | 23.1k | sb = (lsb + xover_offset); |
354 | | |
355 | 23.1k | patch = 0; |
356 | | |
357 | 23.1k | if ((goal_sb < sb) && (lsb > src_start_band)) { |
358 | 12 | return -1; |
359 | 12 | } |
360 | | |
361 | 83.8k | while (((sb - usb) < 0) && (patch < MAX_NUM_PATCHES)) { |
362 | 60.7k | ia_patch_param_struct *ptr_loc_patch_param = &p_str_patch_param[patch]; |
363 | 60.7k | WORD16 abs_sb, flag_break = 0; |
364 | 60.7k | ptr_loc_patch_param->guard_start_band = sb; |
365 | 60.7k | sb = (sb + GUARDBANDS); |
366 | 60.7k | ptr_loc_patch_param->dst_start_band = sb; |
367 | | |
368 | 60.7k | num_bands_in_patch = (goal_sb - sb); |
369 | 60.7k | if ((num_bands_in_patch <= 0) && |
370 | 33 | ((num_bands_in_patch - (lsb - src_start_band)) < 0)) { |
371 | 19 | flag_break = 1; |
372 | 19 | } |
373 | 60.7k | if ((num_bands_in_patch - (lsb - src_start_band)) >= 0) { |
374 | 38.7k | patch_stride = sb - src_start_band; |
375 | 38.7k | patch_stride = (WORD16)(patch_stride & ~1); |
376 | 38.7k | num_bands_in_patch = (lsb - (sb - patch_stride)); |
377 | 38.7k | num_bands_in_patch = ixheaacd_find_closest_entry( |
378 | 38.7k | sb + num_bands_in_patch, f_master_tbl, num_mf_bands, 0); |
379 | 38.7k | num_bands_in_patch -= sb; |
380 | 38.7k | } |
381 | | |
382 | 60.7k | patch_stride = ((num_bands_in_patch + sb) - lsb); |
383 | 60.7k | patch_stride = (WORD16)((patch_stride + 1) & ~1); |
384 | | |
385 | 60.7k | if (num_bands_in_patch > 0) { |
386 | 59.8k | ptr_loc_patch_param->src_start_band = (sb - patch_stride); |
387 | 59.8k | ptr_loc_patch_param->dst_end_band = patch_stride; |
388 | 59.8k | ptr_loc_patch_param->num_bands_in_patch = num_bands_in_patch; |
389 | 59.8k | ptr_loc_patch_param->src_end_band = |
390 | 59.8k | (ptr_loc_patch_param->src_start_band + num_bands_in_patch); |
391 | | |
392 | 59.8k | sb = (sb + ptr_loc_patch_param->num_bands_in_patch); |
393 | 59.8k | patch++; |
394 | 59.8k | } |
395 | | |
396 | 60.7k | src_start_band = SHIFT_START_SB; |
397 | 60.7k | abs_sb = ixheaac_abs16_sat((WORD16)((sb - goal_sb))) - 3; |
398 | | |
399 | 60.7k | if (num_bands_in_patch <= 0 && flag_break_1 == 1) { |
400 | 0 | break; |
401 | 0 | } |
402 | | |
403 | 60.7k | if (abs_sb < 0) { |
404 | 24.6k | goal_sb = usb; |
405 | 36.0k | } else { |
406 | 36.0k | if (flag_break == 1) break; |
407 | 36.0k | } |
408 | | |
409 | 60.7k | if (num_bands_in_patch <= 0) { |
410 | 868 | flag_break_1 = 1; |
411 | 59.8k | } else { |
412 | 59.8k | flag_break_1 = 0; |
413 | 59.8k | } |
414 | 60.7k | } |
415 | | |
416 | 23.1k | patch--; |
417 | | |
418 | 23.1k | if ((patch > 0) && (p_str_patch_param[patch].num_bands_in_patch < 3)) { |
419 | 1.48k | patch--; |
420 | 1.48k | sb = p_str_patch_param[patch].dst_start_band + |
421 | 1.48k | p_str_patch_param[patch].num_bands_in_patch; |
422 | 1.48k | } |
423 | | |
424 | 23.1k | if (patch >= MAX_NUM_PATCHES) { |
425 | 0 | return -1; |
426 | 0 | } |
427 | | |
428 | 23.1k | pstr_transposer_settings->num_patches = patch + 1; |
429 | | |
430 | 23.1k | temp = 0; |
431 | | |
432 | 81.5k | for (patch = 0; patch < pstr_transposer_settings->num_patches; patch++) { |
433 | 58.3k | sb = ixheaac_min32(sb, p_str_patch_param[patch].src_start_band); |
434 | 58.3k | temp = ixheaac_max32(temp, p_str_patch_param[patch].src_end_band); |
435 | 58.3k | } |
436 | | |
437 | 23.1k | if (sb > temp) return IA_FATAL_ERROR; |
438 | | |
439 | 23.1k | pstr_transposer_settings->start_patch = sb; |
440 | 23.1k | pstr_transposer_settings->stop_patch = temp; |
441 | | |
442 | 23.1k | ptr_noise_freq_tbl = |
443 | 23.1k | ptr_header_data->pstr_freq_band_data->freq_band_tbl_noise; |
444 | 23.1k | num_nf_bands = ptr_header_data->pstr_freq_band_data->num_nf_bands; |
445 | | |
446 | 23.1k | memcpy(&pstr_transposer_settings->bw_borders[0], &ptr_noise_freq_tbl[1], |
447 | 23.1k | sizeof(WORD16) * num_nf_bands); |
448 | | |
449 | 23.1k | memset(ptr_hf_gen_str->bw_array_prev, 0, sizeof(WORD32) * MAX_NUM_PATCHES); |
450 | | |
451 | 23.1k | return 0; |
452 | 23.1k | } |
453 | | VOID ixheaacd_rescale_x_overlap( |
454 | | ia_sbr_dec_struct *ptr_sbr_dec, ia_sbr_header_data_struct *ptr_header_data, |
455 | | ia_sbr_frame_info_data_struct *ptr_frame_data, |
456 | | ia_sbr_prev_frame_data_struct *ptr_frame_data_prev, |
457 | | WORD32 **pp_overlap_buffer_real, WORD32 **pp_overlap_buffer_imag, |
458 | 62.8k | FLAG low_pow_flag) { |
459 | 62.8k | WORD32 k, l; |
460 | 62.8k | WORD32 start_band, end_band; |
461 | 62.8k | WORD32 target_lsb, target_usb; |
462 | 62.8k | WORD32 source_scale, target_scale, delta_scale, reserve; |
463 | | |
464 | 62.8k | WORD32 old_lsb = ptr_frame_data_prev->max_qmf_subband_aac; |
465 | 62.8k | WORD32 start_slot = |
466 | 62.8k | (ptr_header_data->time_step * |
467 | 62.8k | (ptr_frame_data_prev->end_position - ptr_header_data->num_time_slots)); |
468 | 62.8k | WORD32 new_lsb = ptr_frame_data->max_qmf_subband_aac; |
469 | | |
470 | 62.8k | ptr_sbr_dec->str_codec_qmf_bank.usb = new_lsb; |
471 | 62.8k | ptr_sbr_dec->str_synthesis_qmf_bank.lsb = new_lsb; |
472 | | |
473 | 62.8k | start_band = ixheaac_min32(old_lsb, new_lsb); |
474 | 62.8k | end_band = ixheaac_max32(old_lsb, new_lsb); |
475 | | |
476 | 62.8k | if (new_lsb != old_lsb && old_lsb > 0) { |
477 | 72.3k | for (l = start_slot; l < 6; l++) { |
478 | 287k | for (k = old_lsb; k < new_lsb; k++) { |
479 | 225k | pp_overlap_buffer_real[l][k] = 0L; |
480 | | |
481 | 225k | if (!low_pow_flag) { |
482 | 225k | pp_overlap_buffer_imag[l][k] = 0L; |
483 | 225k | } |
484 | 225k | } |
485 | 62.0k | } |
486 | | |
487 | 10.3k | if (new_lsb > old_lsb) { |
488 | 4.99k | source_scale = ptr_sbr_dec->str_sbr_scale_fact.ov_hb_scale; |
489 | 4.99k | target_scale = ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale; |
490 | 4.99k | target_lsb = 0; |
491 | 4.99k | target_usb = old_lsb; |
492 | 5.34k | } else { |
493 | 5.34k | source_scale = ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale; |
494 | 5.34k | target_scale = ptr_sbr_dec->str_sbr_scale_fact.ov_hb_scale; |
495 | 5.34k | target_lsb = old_lsb; |
496 | 5.34k | target_usb = ptr_sbr_dec->str_synthesis_qmf_bank.usb; |
497 | 5.34k | } |
498 | | |
499 | 10.3k | reserve = (*ixheaacd_ixheaacd_expsubbandsamples)( |
500 | 10.3k | pp_overlap_buffer_real, pp_overlap_buffer_imag, start_band, end_band, 0, |
501 | 10.3k | start_slot, low_pow_flag); |
502 | | |
503 | 10.3k | (*ixheaacd_adjust_scale)(pp_overlap_buffer_real, pp_overlap_buffer_imag, |
504 | 10.3k | start_band, end_band, 0, start_slot, reserve, |
505 | 10.3k | low_pow_flag); |
506 | | |
507 | 10.3k | source_scale += reserve; |
508 | | |
509 | 10.3k | delta_scale = (target_scale - source_scale); |
510 | | |
511 | 10.3k | if (delta_scale > 0) { |
512 | 63 | delta_scale = -(delta_scale); |
513 | 63 | start_band = target_lsb; |
514 | 63 | end_band = target_usb; |
515 | | |
516 | 63 | if (new_lsb > old_lsb) { |
517 | 0 | ptr_sbr_dec->str_sbr_scale_fact.ov_lb_scale = source_scale; |
518 | 63 | } else { |
519 | 63 | ptr_sbr_dec->str_sbr_scale_fact.ov_hb_scale = source_scale; |
520 | 63 | } |
521 | 63 | } |
522 | | |
523 | 10.3k | (*ixheaacd_adjust_scale)(pp_overlap_buffer_real, pp_overlap_buffer_imag, |
524 | 10.3k | start_band, end_band, 0, start_slot, delta_scale, |
525 | 10.3k | low_pow_flag); |
526 | 10.3k | } |
527 | 62.8k | } |
528 | | |
529 | | VOID ixheaacd_map_sineflags(WORD16 *freq_band_table, WORD16 num_sf_bands, |
530 | | FLAG *add_harmonics, WORD8 *harm_flags_prev, |
531 | | WORD16 transient_env, WORD8 *sine_mapped) |
532 | | |
533 | 57.4k | { |
534 | 57.4k | WORD32 qmfband2, li, ui, i; |
535 | 57.4k | WORD32 low_subband_sec; |
536 | 57.4k | WORD32 oldflags; |
537 | | |
538 | 57.4k | low_subband_sec = (freq_band_table[0] << 1); |
539 | | |
540 | 57.4k | memset(sine_mapped, MAX_ENVELOPES, sizeof(WORD8) * MAX_FREQ_COEFFS); |
541 | | |
542 | 690k | for (i = (num_sf_bands - 1); i >= 0; i--) { |
543 | 633k | oldflags = *harm_flags_prev; |
544 | 633k | *harm_flags_prev++ = add_harmonics[i]; |
545 | | |
546 | 633k | if (add_harmonics[i]) { |
547 | 26.2k | li = freq_band_table[i]; |
548 | | |
549 | 26.2k | ui = freq_band_table[i + 1]; |
550 | | |
551 | 26.2k | qmfband2 = ((ui + li) - low_subband_sec) >> 1; |
552 | | |
553 | 26.2k | if (oldflags) |
554 | 3.44k | sine_mapped[qmfband2] = 0; |
555 | 22.7k | else |
556 | 22.7k | sine_mapped[qmfband2] = (WORD8)transient_env; |
557 | 26.2k | } |
558 | 633k | } |
559 | 57.4k | } |
560 | | |
561 | 3.70k | VOID ixheaacd_map_34_params_to_20(WORD16 *params) { |
562 | 3.70k | params[0] = ixheaacd_divideby3(params[0] + params[0] + params[1]); |
563 | 3.70k | params[1] = ixheaacd_divideby3(params[1] + params[2] + params[2]); |
564 | 3.70k | params[2] = ixheaacd_divideby3(params[3] + params[3] + params[4]); |
565 | 3.70k | params[3] = ixheaacd_divideby3(params[4] + params[5] + params[5]); |
566 | 3.70k | params[4] = ixheaacd_divideby2(params[6] + params[7]); |
567 | 3.70k | params[5] = ixheaacd_divideby2(params[8] + params[9]); |
568 | 3.70k | params[6] = params[10]; |
569 | 3.70k | params[7] = params[11]; |
570 | 3.70k | params[8] = ixheaacd_divideby2(params[12] + params[13]); |
571 | 3.70k | params[9] = ixheaacd_divideby2(params[14] + params[15]); |
572 | 3.70k | params[10] = params[16]; |
573 | 3.70k | params[11] = params[17]; |
574 | 3.70k | params[12] = params[18]; |
575 | 3.70k | params[13] = params[19]; |
576 | 3.70k | params[14] = ixheaacd_divideby2(params[20] + params[21]); |
577 | 3.70k | params[15] = ixheaacd_divideby2(params[22] + params[23]); |
578 | 3.70k | params[16] = ixheaacd_divideby2(params[24] + params[25]); |
579 | 3.70k | params[17] = ixheaacd_divideby2(params[26] + params[27]); |
580 | 3.70k | params[18] = ixheaacd_divideby2( |
581 | 3.70k | ixheaacd_divideby2(params[28] + params[29] + params[30] + params[31])); |
582 | 3.70k | params[19] = ixheaacd_divideby2(params[32] + params[33]); |
583 | 3.70k | } |
584 | | |
585 | | extern const WORD16 ixheaacd_num_bands[3]; |
586 | | |
587 | | IA_ERRORCODE ixheaacd_read_ps_data(ia_ps_dec_struct *ptr_ps_dec, ia_bit_buf_struct *it_bit_buff, |
588 | | WORD16 num_bits_left, ia_ps_tables_struct *ps_tables_ptr) |
589 | 4.37k | { |
590 | 4.37k | WORD b, e, temp; |
591 | 4.37k | const WORD16 num_env_tab[4] = {0, 1, 2, 4}; |
592 | 4.37k | WORD cnt_bits; |
593 | 4.37k | ia_huffman_data_type huffman_table, huffman_df_table, huffman_dt_table; |
594 | 4.37k | FLAG enable_ps_header; |
595 | | |
596 | 4.37k | if (!ptr_ps_dec) { |
597 | 0 | return 0; |
598 | 0 | } |
599 | | |
600 | 4.37k | cnt_bits = it_bit_buff->cnt_bits; |
601 | | |
602 | 4.37k | enable_ps_header = ixheaacd_read_bits_buf(it_bit_buff, 1); |
603 | | |
604 | 4.37k | if (enable_ps_header) { |
605 | 837 | ptr_ps_dec->enable_iid = ixheaacd_read_bits_buf(it_bit_buff, 1); |
606 | 837 | if (ptr_ps_dec->enable_iid) { |
607 | 617 | ptr_ps_dec->iid_mode = ixheaacd_read_bits_buf(it_bit_buff, 3); |
608 | 617 | } |
609 | | |
610 | 837 | if (ptr_ps_dec->iid_mode > 2) { |
611 | 444 | ptr_ps_dec->iid_quant = 1; |
612 | 444 | ptr_ps_dec->iid_mode -= 3; |
613 | 444 | } else { |
614 | 393 | ptr_ps_dec->iid_quant = 0; |
615 | 393 | } |
616 | | |
617 | 837 | ptr_ps_dec->enable_icc = ixheaacd_read_bits_buf(it_bit_buff, 1); |
618 | 837 | if (ptr_ps_dec->enable_icc) { |
619 | 508 | ptr_ps_dec->icc_mode = ixheaacd_read_bits_buf(it_bit_buff, 3); |
620 | 508 | } |
621 | | |
622 | 837 | ptr_ps_dec->enable_ext = ixheaacd_read_bits_buf(it_bit_buff, 1); |
623 | | |
624 | 837 | if (ptr_ps_dec->icc_mode > 2) { |
625 | 471 | ptr_ps_dec->icc_mode -= 3; |
626 | 471 | ptr_ps_dec->use_pca_rot_flg = 1; |
627 | 471 | } else { |
628 | 366 | ptr_ps_dec->use_pca_rot_flg = 0; |
629 | 366 | } |
630 | 837 | ptr_ps_dec->freq_res_ipd = ptr_ps_dec->iid_mode; |
631 | 837 | if (ptr_ps_dec->freq_res_ipd > 2) { |
632 | 3 | return IA_FATAL_ERROR; |
633 | 3 | } |
634 | 837 | } |
635 | | |
636 | 4.37k | ptr_ps_dec->use_34_st_bands = 0; |
637 | 4.37k | ptr_ps_dec->use_pca_rot_flg = 0; |
638 | | |
639 | 4.37k | if ((ptr_ps_dec->enable_iid && ptr_ps_dec->iid_mode > 2) || |
640 | 4.37k | (ptr_ps_dec->enable_icc && ptr_ps_dec->icc_mode > 2)) { |
641 | 1.07k | ptr_ps_dec->ps_data_present = 0; |
642 | | |
643 | 1.07k | num_bits_left -= (cnt_bits - it_bit_buff->cnt_bits); |
644 | | |
645 | 4.49k | while (num_bits_left > 8) { |
646 | 3.41k | ixheaacd_read_bits_buf(it_bit_buff, 8); |
647 | 3.41k | num_bits_left -= 8; |
648 | 3.41k | } |
649 | 1.07k | if (num_bits_left >= 0) { |
650 | 974 | ixheaacd_read_bits_buf(it_bit_buff, num_bits_left); |
651 | 974 | } |
652 | | |
653 | 1.07k | return (cnt_bits - it_bit_buff->cnt_bits); |
654 | 1.07k | } |
655 | | |
656 | 3.30k | ptr_ps_dec->frame_class = (FLAG)ixheaacd_read_bits_buf(it_bit_buff, 1); |
657 | | |
658 | 3.30k | temp = ixheaacd_read_bits_buf(it_bit_buff, 2); |
659 | | |
660 | 3.30k | if (ptr_ps_dec->frame_class == 0) { |
661 | 2.67k | ptr_ps_dec->num_env = num_env_tab[temp]; |
662 | 2.67k | } else { |
663 | 626 | ptr_ps_dec->num_env = (((1 + temp) << 8) >> 8); |
664 | | |
665 | 2.52k | for (e = 1; e < ptr_ps_dec->num_env + 1; e++) { |
666 | 1.90k | ptr_ps_dec->border_position[e] = |
667 | 1.90k | (((ixheaacd_read_bits_buf(it_bit_buff, 5) + 1) << 8) >> 8); |
668 | 1.90k | } |
669 | 626 | } |
670 | | |
671 | 3.30k | if (ptr_ps_dec->enable_iid) { |
672 | 905 | if (ptr_ps_dec->iid_quant) { |
673 | 644 | huffman_df_table = (ia_huffman_data_type)&ps_tables_ptr->huff_iid_df_fine; |
674 | 644 | huffman_dt_table = (ia_huffman_data_type)&ps_tables_ptr->huff_iid_dt_fine; |
675 | 644 | } else { |
676 | 261 | huffman_df_table = (ia_huffman_data_type)&ps_tables_ptr->huff_iid_df; |
677 | 261 | huffman_dt_table = (ia_huffman_data_type)&ps_tables_ptr->huff_iid_dt; |
678 | 261 | } |
679 | | |
680 | 2.65k | for (e = 0; e < ptr_ps_dec->num_env; e++) { |
681 | 1.75k | ptr_ps_dec->iid_dt[e] = (FLAG)ixheaacd_read_bits_buf(it_bit_buff, 1); |
682 | | |
683 | 1.75k | if (ptr_ps_dec->iid_dt[e]) { |
684 | 1.01k | huffman_table = huffman_dt_table; |
685 | 1.01k | } else { |
686 | 741 | huffman_table = huffman_df_table; |
687 | 741 | } |
688 | | |
689 | 47.3k | for (b = 0; b < ixheaacd_num_bands[ptr_ps_dec->iid_mode]; b++) { |
690 | 45.5k | ptr_ps_dec->iid_par_table[e][b] = |
691 | 45.5k | ixheaacd_ssc_huff_dec(huffman_table, it_bit_buff); |
692 | 45.5k | } |
693 | 1.75k | } |
694 | 905 | } |
695 | | |
696 | 3.30k | if (ptr_ps_dec->enable_icc) { |
697 | 651 | huffman_df_table = (ia_huffman_data_type)&ps_tables_ptr->huff_icc_df; |
698 | 651 | huffman_dt_table = (ia_huffman_data_type)&ps_tables_ptr->huff_icc_dt; |
699 | | |
700 | 2.28k | for (e = 0; e < ptr_ps_dec->num_env; e++) { |
701 | 1.63k | ptr_ps_dec->icc_dt[e] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
702 | | |
703 | 1.63k | if (ptr_ps_dec->icc_dt[e]) { |
704 | 675 | huffman_table = huffman_dt_table; |
705 | 963 | } else { |
706 | 963 | huffman_table = huffman_df_table; |
707 | 963 | } |
708 | | |
709 | 21.6k | for (b = 0; b < ixheaacd_num_bands[ptr_ps_dec->icc_mode]; b++) { |
710 | 19.9k | ptr_ps_dec->icc_par_table[e][b] = ixheaacd_ssc_huff_dec(huffman_table, it_bit_buff); |
711 | 19.9k | } |
712 | 1.63k | } |
713 | 651 | } |
714 | | |
715 | 3.30k | if (ptr_ps_dec->enable_ext) { |
716 | 423 | WORD32 cnt; |
717 | 423 | if (it_bit_buff->cnt_bits < 4) |
718 | 5 | cnt = ixheaacd_read_bits_buf(it_bit_buff, it_bit_buff->cnt_bits); |
719 | 418 | else |
720 | 418 | cnt = ixheaacd_read_bits_buf(it_bit_buff, 4); |
721 | | |
722 | 423 | if (cnt == 15) { |
723 | 34 | cnt += ixheaacd_read_bits_buf(it_bit_buff, 8); |
724 | 34 | } |
725 | 8.87k | while (cnt--) { |
726 | 8.45k | ixheaacd_read_bits_buf(it_bit_buff, 8); |
727 | 8.45k | } |
728 | 423 | } |
729 | | |
730 | 3.30k | ptr_ps_dec->ps_data_present = 1; |
731 | | |
732 | 3.30k | return (cnt_bits - it_bit_buff->cnt_bits); |
733 | 4.37k | } |
734 | | |
735 | | VOID ixheaacd_invfilt_level_emphasis(ia_sbr_hf_generator_struct *ptr_hf_gen_str, |
736 | | WORD32 num_if_bands, WORD32 *inv_filt_mode, |
737 | | WORD32 *inv_filt_mode_prev, |
738 | 57.4k | WORD32 *bw_array) { |
739 | 57.4k | WORD32 i; |
740 | 57.4k | WORD32 accu; |
741 | 57.4k | WORD16 w1, w2; |
742 | | |
743 | 187k | for (i = 0; i < num_if_bands; i++) { |
744 | 130k | bw_array[i] = |
745 | 130k | ixheaacd_inew_bw_table[inv_filt_mode_prev[i]][inv_filt_mode[i]]; |
746 | | |
747 | 130k | if (bw_array[i] < ptr_hf_gen_str->bw_array_prev[i]) { |
748 | 13.4k | w1 = 0x6000; |
749 | 13.4k | w2 = 0x2000; |
750 | 116k | } else { |
751 | 116k | w1 = 0x7400; |
752 | 116k | w2 = 0x0c00; |
753 | 116k | } |
754 | 130k | accu = ixheaac_add32( |
755 | 130k | ixheaac_mult32x16in32_shl(bw_array[i], w1), |
756 | 130k | ixheaac_mult32x16in32_shl(ptr_hf_gen_str->bw_array_prev[i], w2)); |
757 | | |
758 | 130k | if (accu < 0x02000000) { |
759 | 85.0k | accu = 0; |
760 | 85.0k | } |
761 | | |
762 | 130k | if (accu >= 0x7f800000) { |
763 | 0 | accu = 0x7f800000; |
764 | 0 | } |
765 | 130k | bw_array[i] = accu; |
766 | 130k | } |
767 | 57.4k | } |
768 | | |
769 | | typedef struct { |
770 | | FLOAT32 phi_0_1_real; |
771 | | FLOAT32 phi_0_1_imag; |
772 | | FLOAT32 phi_0_2_real; |
773 | | FLOAT32 phi_0_2_imag; |
774 | | FLOAT32 phi_1_1; |
775 | | FLOAT32 phi_1_2_real; |
776 | | FLOAT32 phi_1_2_imag; |
777 | | FLOAT32 phi_2_2; |
778 | | FLOAT32 det; |
779 | | } ia_auto_corr_ele_struct; |
780 | | |
781 | | static VOID ixheaacd_esbr_calc_co_variance( |
782 | | ia_auto_corr_ele_struct *pstr_auto_corr, FLOAT32 vec_x_real[][64], |
783 | 5.89M | FLOAT32 vec_x_imag[][64], WORD32 bd, WORD32 len) { |
784 | 5.89M | WORD32 j, jminus1, jminus2; |
785 | | |
786 | 5.89M | memset(pstr_auto_corr, 0, sizeof(ia_auto_corr_ele_struct)); |
787 | | |
788 | 232M | for (j = 0; j < len; j++) { |
789 | 226M | jminus1 = j - 1; |
790 | 226M | jminus2 = jminus1 - 1; |
791 | | |
792 | 226M | pstr_auto_corr->phi_0_1_real += |
793 | 226M | vec_x_real[j][bd] * vec_x_real[jminus1][bd] + |
794 | 226M | vec_x_imag[j][bd] * vec_x_imag[jminus1][bd]; |
795 | | |
796 | 226M | pstr_auto_corr->phi_0_1_imag += |
797 | 226M | vec_x_imag[j][bd] * vec_x_real[jminus1][bd] - |
798 | 226M | vec_x_real[j][bd] * vec_x_imag[jminus1][bd]; |
799 | | |
800 | 226M | pstr_auto_corr->phi_0_2_real += |
801 | 226M | vec_x_real[j][bd] * vec_x_real[jminus2][bd] + |
802 | 226M | vec_x_imag[j][bd] * vec_x_imag[jminus2][bd]; |
803 | | |
804 | 226M | pstr_auto_corr->phi_0_2_imag += |
805 | 226M | vec_x_imag[j][bd] * vec_x_real[jminus2][bd] - |
806 | 226M | vec_x_real[j][bd] * vec_x_imag[jminus2][bd]; |
807 | | |
808 | 226M | pstr_auto_corr->phi_1_1 += |
809 | 226M | vec_x_real[jminus1][bd] * vec_x_real[jminus1][bd] + |
810 | 226M | vec_x_imag[jminus1][bd] * vec_x_imag[jminus1][bd]; |
811 | | |
812 | 226M | pstr_auto_corr->phi_1_2_real += |
813 | 226M | vec_x_real[jminus1][bd] * vec_x_real[jminus2][bd] + |
814 | 226M | vec_x_imag[jminus1][bd] * vec_x_imag[jminus2][bd]; |
815 | | |
816 | 226M | pstr_auto_corr->phi_1_2_imag += |
817 | 226M | vec_x_imag[jminus1][bd] * vec_x_real[jminus2][bd] - |
818 | 226M | vec_x_real[jminus1][bd] * vec_x_imag[jminus2][bd]; |
819 | | |
820 | 226M | pstr_auto_corr->phi_2_2 += |
821 | 226M | vec_x_real[jminus2][bd] * vec_x_real[jminus2][bd] + |
822 | 226M | vec_x_imag[jminus2][bd] * vec_x_imag[jminus2][bd]; |
823 | 226M | } |
824 | | |
825 | 5.89M | pstr_auto_corr->det = |
826 | 5.89M | pstr_auto_corr->phi_1_1 * pstr_auto_corr->phi_2_2 - |
827 | 5.89M | (pstr_auto_corr->phi_1_2_real * pstr_auto_corr->phi_1_2_real + |
828 | 5.89M | pstr_auto_corr->phi_1_2_imag * pstr_auto_corr->phi_1_2_imag) * |
829 | 5.89M | SBR_HF_RELAXATION_PARAM; |
830 | 5.89M | } |
831 | | |
832 | | static void ixheaacd_esbr_chirp_fac_calc(WORD32 *inv_filt_mode, |
833 | | WORD32 *inv_filt_mode_prev, |
834 | | WORD32 num_if_bands, FLOAT32 *bw_array, |
835 | 329k | FLOAT32 *bw_array_prev) { |
836 | 329k | WORD32 i; |
837 | | |
838 | 1.21M | for (i = 0; i < num_if_bands; i++) { |
839 | 887k | bw_array[i] = |
840 | 887k | ixheaacd_new_bw_table[inv_filt_mode_prev[i]][inv_filt_mode[i]]; |
841 | | |
842 | 887k | if (bw_array[i] < bw_array_prev[i]) |
843 | 246k | bw_array[i] = 0.75000f * bw_array[i] + 0.25000f * bw_array_prev[i]; |
844 | 641k | else |
845 | 641k | bw_array[i] = 0.90625f * bw_array[i] + 0.09375f * bw_array_prev[i]; |
846 | | |
847 | 887k | if (bw_array[i] < 0.015625) bw_array[i] = 0; |
848 | 887k | } |
849 | 329k | } |
850 | | |
851 | | static void ixheaacd_gausssolve(WORD32 n, FLOAT32 a[][MAXDEG + 1], FLOAT32 b[], |
852 | 27.0k | FLOAT32 y[]) { |
853 | 27.0k | WORD32 i, j, k, imax; |
854 | 27.0k | FLOAT32 v; |
855 | | |
856 | 135k | for (i = 0; i < n; i++) { |
857 | 108k | imax = i; |
858 | 270k | for (k = i + 1; k < n; k++) { |
859 | 162k | if (fabs(a[k][i]) > fabs(a[imax][i])) { |
860 | 5.17k | imax = k; |
861 | 5.17k | } |
862 | 162k | } |
863 | 108k | if (imax != i) { |
864 | 5.15k | v = b[imax]; |
865 | 5.15k | b[imax] = b[i]; |
866 | 5.15k | b[i] = v; |
867 | 15.4k | for (j = i; j < n; j++) { |
868 | 10.3k | v = a[imax][j]; |
869 | 10.3k | a[imax][j] = a[i][j]; |
870 | 10.3k | a[i][j] = v; |
871 | 10.3k | } |
872 | 5.15k | } |
873 | | |
874 | 108k | v = a[i][i]; |
875 | | |
876 | 108k | b[i] /= v; |
877 | 378k | for (j = i; j < n; j++) { |
878 | 270k | a[i][j] /= v; |
879 | 270k | } |
880 | | |
881 | 270k | for (k = i + 1; k < n; k++) { |
882 | 162k | v = a[k][i]; |
883 | 162k | b[k] -= v * b[i]; |
884 | 540k | for (j = i + 1; j < n; j++) { |
885 | 378k | a[k][j] -= v * a[i][j]; |
886 | 378k | } |
887 | 162k | } |
888 | 108k | } |
889 | | |
890 | 135k | for (i = n - 1; i >= 0; i--) { |
891 | 108k | y[i] = b[i]; |
892 | 270k | for (j = i + 1; j < n; j++) { |
893 | 162k | y[i] -= a[i][j] * y[j]; |
894 | 162k | } |
895 | 108k | } |
896 | 27.0k | } |
897 | | |
898 | 27.0k | void ixheaacd_polyfit(WORD32 n, FLOAT32 y[], FLOAT32 p[]) { |
899 | 27.0k | WORD32 i, j, k; |
900 | 27.0k | FLOAT32 a[MAXDEG + 1][MAXDEG + 1]; |
901 | 27.0k | FLOAT32 b[MAXDEG + 1]; |
902 | 27.0k | FLOAT32 v[2 * MAXDEG + 1]; |
903 | | |
904 | 135k | for (i = 0; i <= MAXDEG; i++) { |
905 | 108k | b[i] = 0.0f; |
906 | 540k | for (j = 0; j <= MAXDEG; j++) { |
907 | 432k | a[i][j] = 0.0f; |
908 | 432k | } |
909 | 108k | } |
910 | | |
911 | 468k | for (k = 0; k < n; k++) { |
912 | 441k | v[0] = 1.0; |
913 | 3.09M | for (i = 1; i <= 2 * MAXDEG; i++) { |
914 | 2.65M | v[i] = k * v[i - 1]; |
915 | 2.65M | } |
916 | | |
917 | 2.20M | for (i = 0; i <= MAXDEG; i++) { |
918 | 1.76M | b[i] += v[MAXDEG - i] * y[k]; |
919 | 8.83M | for (j = 0; j <= MAXDEG; j++) { |
920 | 7.07M | a[i][j] += v[2 * MAXDEG - i - j]; |
921 | 7.07M | } |
922 | 1.76M | } |
923 | 441k | } |
924 | | |
925 | 27.0k | ixheaacd_gausssolve(MAXDEG + 1, a, b, p); |
926 | 27.0k | } |
927 | | |
928 | | VOID ixheaacd_pre_processing(FLOAT32 ptr_src_buf_real[][64], |
929 | | FLOAT32 ptr_src_buf_imag[][64], |
930 | | FLOAT32 gain_vector[], WORD32 num_bands, |
931 | 27.0k | WORD32 start_sample, WORD32 end_sample) { |
932 | 27.0k | WORD32 k, i; |
933 | 27.0k | FLOAT32 poly_coeff[4]; |
934 | 27.0k | FLOAT32 mean_enrg = 0; |
935 | 27.0k | FLOAT32 low_env_slope[64]; |
936 | 27.0k | FLOAT32 low_env[64] = {0}; |
937 | 27.0k | FLOAT32 a0; |
938 | 27.0k | FLOAT32 a1; |
939 | 27.0k | FLOAT32 a2; |
940 | 27.0k | FLOAT32 a3; |
941 | | |
942 | 27.0k | if (num_bands != 0 && end_sample != start_sample) { |
943 | 463k | for (k = 0; k < num_bands; k++) { |
944 | 437k | FLOAT32 temp = 0; |
945 | 14.7M | for (i = start_sample; i < end_sample; i++) { |
946 | 14.2M | temp += ptr_src_buf_real[i][k] * ptr_src_buf_real[i][k] + |
947 | 14.2M | ptr_src_buf_imag[i][k] * ptr_src_buf_imag[i][k]; |
948 | 14.2M | } |
949 | 437k | temp /= (end_sample - start_sample); |
950 | 437k | low_env[k] = (FLOAT32)(10 * log10(temp + 1)); |
951 | 437k | mean_enrg = mean_enrg + low_env[k]; |
952 | 437k | } |
953 | 26.7k | mean_enrg /= num_bands; |
954 | 26.7k | } |
955 | | |
956 | 27.0k | ixheaacd_polyfit(num_bands, low_env, poly_coeff); |
957 | | |
958 | 27.0k | a0 = poly_coeff[0]; |
959 | 27.0k | a1 = poly_coeff[1]; |
960 | 27.0k | a2 = poly_coeff[2]; |
961 | 27.0k | a3 = poly_coeff[3]; |
962 | 468k | for (k = 0; k < num_bands; k++) { |
963 | 441k | FLOAT32 x_low_l = (FLOAT32)k; |
964 | 441k | FLOAT32 low_env_slope_l = a3; |
965 | 441k | low_env_slope_l = low_env_slope_l + a2 * x_low_l; |
966 | | |
967 | 441k | x_low_l = x_low_l * x_low_l; |
968 | 441k | low_env_slope_l = low_env_slope_l + a1 * x_low_l; |
969 | | |
970 | 441k | x_low_l = x_low_l * (FLOAT32)k; |
971 | 441k | low_env_slope_l = low_env_slope_l + a0 * x_low_l; |
972 | | |
973 | 441k | low_env_slope[k] = low_env_slope_l; |
974 | 441k | } |
975 | | |
976 | 468k | for (i = 0; i < num_bands; i++) { |
977 | 441k | gain_vector[i] = (FLOAT32)pow(10, (mean_enrg - low_env_slope[i]) / 20.0f); |
978 | 441k | } |
979 | 27.0k | } |
980 | | |
981 | | WORD32 ixheaacd_generate_hf(FLOAT32 ptr_src_buf_real[][64], FLOAT32 ptr_src_buf_imag[][64], |
982 | | FLOAT32 ptr_ph_vocod_buf_real[][64], |
983 | | FLOAT32 ptr_ph_vocod_buf_imag[][64], FLOAT32 ptr_dst_buf_real[][64], |
984 | | FLOAT32 ptr_dst_buf_imag[][64], |
985 | | ia_sbr_frame_info_data_struct *ptr_frame_data, |
986 | | ia_sbr_header_data_struct *ptr_header_data, WORD32 ldmps_present, |
987 | 329k | WORD32 time_slots, WORD32 ec_flag) { |
988 | 329k | WORD32 bw_index, i, k, k2, patch = 0; |
989 | 329k | WORD32 co_var_len; |
990 | 329k | WORD32 start_sample, end_sample, goal_sb; |
991 | 329k | WORD32 sb, source_start_band, patch_stride, num_bands_in_patch; |
992 | 329k | WORD32 hbe_flag = ptr_header_data->hbe_flag; |
993 | 329k | FLOAT32 a0r, a0i, a1r, a1i; |
994 | 329k | FLOAT32 bw_array[MAX_NUM_PATCHES] = {0}; |
995 | | |
996 | 329k | ia_auto_corr_ele_struct str_auto_corr; |
997 | | |
998 | 329k | WORD16 *ptr_invf_band_tbl = |
999 | 329k | &ptr_header_data->pstr_freq_band_data |
1000 | 329k | ->freq_band_tbl_noise[1]; // offest 1 used as base address of |
1001 | | // ptr_invf_band_tbl |
1002 | 329k | WORD32 num_if_bands = ptr_header_data->pstr_freq_band_data->num_nf_bands; |
1003 | 329k | WORD32 sub_band_start = ptr_header_data->pstr_freq_band_data->sub_band_start; |
1004 | 329k | WORD16 *f_master_tbl = ptr_header_data->pstr_freq_band_data->f_master_tbl; |
1005 | 329k | WORD32 num_mf_bands = ptr_header_data->pstr_freq_band_data->num_mf_bands; |
1006 | 329k | WORD32 *inv_filt_mode = ptr_frame_data->sbr_invf_mode; |
1007 | 329k | WORD32 *inv_filt_mode_prev = ptr_frame_data->sbr_invf_mode_prev; |
1008 | 329k | WORD32 sbr_patching_mode = ptr_frame_data->sbr_patching_mode; |
1009 | 329k | ia_frame_info_struct *p_frame_info = &ptr_frame_data->str_frame_info_details; |
1010 | 329k | WORD32 pre_proc_flag = ptr_header_data->pre_proc_flag; |
1011 | 329k | WORD32 is_usf_4 = ptr_header_data->is_usf_4; |
1012 | 329k | WORD32 fs = ptr_header_data->out_sampling_freq; |
1013 | 329k | WORD32 cov_count; |
1014 | 329k | WORD32 lsb = f_master_tbl[0]; |
1015 | 329k | WORD32 usb = f_master_tbl[num_mf_bands]; |
1016 | 329k | WORD32 xover_offset = sub_band_start - f_master_tbl[0]; |
1017 | | |
1018 | 329k | FLOAT32 bw = 0.0f; |
1019 | 329k | FLOAT32 fac = 0.0f; |
1020 | | |
1021 | 329k | FLOAT32 gain; |
1022 | 329k | FLOAT32 gain_vector[64]; |
1023 | | |
1024 | 329k | WORD32 slope_length = 0; |
1025 | 329k | WORD32 first_slot_offset = p_frame_info->border_vec[0]; |
1026 | 329k | WORD32 end_slot_offs = 0; |
1027 | | |
1028 | 329k | FLOAT32 *bw_array_prev = ptr_frame_data->bw_array_prev; |
1029 | | |
1030 | 329k | end_slot_offs = p_frame_info->border_vec[p_frame_info->num_env] - 16; |
1031 | | |
1032 | 329k | if (ldmps_present == 1) |
1033 | 5.35k | end_slot_offs = |
1034 | 5.35k | p_frame_info->border_vec[p_frame_info->num_env] - time_slots; |
1035 | | |
1036 | 329k | if (is_usf_4) { |
1037 | 23.1k | start_sample = first_slot_offset * 4; |
1038 | 23.1k | end_sample = 64 + end_slot_offs * 4; |
1039 | 23.1k | co_var_len = 76; |
1040 | 306k | } else { |
1041 | 306k | start_sample = first_slot_offset * 2; |
1042 | 306k | end_sample = 32 + end_slot_offs * 2; |
1043 | 306k | co_var_len = 38; |
1044 | 306k | } |
1045 | | |
1046 | 329k | if (ldmps_present == 1) { |
1047 | 5.35k | start_sample = 0; |
1048 | 5.35k | end_sample = time_slots; |
1049 | 5.35k | co_var_len = time_slots; |
1050 | 5.35k | } |
1051 | | |
1052 | 329k | if (pre_proc_flag) { |
1053 | 27.0k | ixheaacd_pre_processing(ptr_src_buf_real, ptr_src_buf_imag, gain_vector, |
1054 | 27.0k | f_master_tbl[0], start_sample, end_sample); |
1055 | 27.0k | } |
1056 | | |
1057 | 329k | ixheaacd_esbr_chirp_fac_calc(inv_filt_mode, inv_filt_mode_prev, num_if_bands, |
1058 | 329k | bw_array, bw_array_prev); |
1059 | | |
1060 | 11.5M | for (i = start_sample; i < end_sample; i++) { |
1061 | 11.1M | memset(ptr_dst_buf_real[i] + usb, 0, (64 - usb) * sizeof(FLOAT32)); |
1062 | 11.1M | memset(ptr_dst_buf_imag[i] + usb, 0, (64 - usb) * sizeof(FLOAT32)); |
1063 | 11.1M | } |
1064 | | |
1065 | 329k | if (sbr_patching_mode || !hbe_flag) { |
1066 | 197k | WORD32 flag_break = 0; |
1067 | 197k | FLOAT32 alpha_real[64][2] = {{0}}, alpha_imag[64][2] = {{0}}; |
1068 | 197k | if (ptr_frame_data->mps_sbr_flag) { |
1069 | 76.4k | cov_count = (f_master_tbl[0] < ptr_frame_data->cov_count) |
1070 | 76.4k | ? f_master_tbl[0] |
1071 | 76.4k | : ptr_frame_data->cov_count; |
1072 | 121k | } else { |
1073 | 121k | cov_count = f_master_tbl[0]; |
1074 | 121k | } |
1075 | | |
1076 | 3.24M | for (k = 1; k < cov_count; k++) { |
1077 | 3.05M | ixheaacd_esbr_calc_co_variance(&str_auto_corr, &ptr_src_buf_real[0], |
1078 | 3.05M | &ptr_src_buf_imag[0], k, co_var_len); |
1079 | 3.05M | if (str_auto_corr.det == 0.0f) { |
1080 | 1.49M | alpha_real[k][1] = alpha_imag[k][1] = 0; |
1081 | 1.55M | } else { |
1082 | 1.55M | fac = 1.0f / str_auto_corr.det; |
1083 | 1.55M | alpha_real[k][1] = |
1084 | 1.55M | (str_auto_corr.phi_0_1_real * str_auto_corr.phi_1_2_real - |
1085 | 1.55M | str_auto_corr.phi_0_1_imag * str_auto_corr.phi_1_2_imag - |
1086 | 1.55M | str_auto_corr.phi_0_2_real * str_auto_corr.phi_1_1) * |
1087 | 1.55M | fac; |
1088 | 1.55M | alpha_imag[k][1] = |
1089 | 1.55M | (str_auto_corr.phi_0_1_imag * str_auto_corr.phi_1_2_real + |
1090 | 1.55M | str_auto_corr.phi_0_1_real * str_auto_corr.phi_1_2_imag - |
1091 | 1.55M | str_auto_corr.phi_0_2_imag * str_auto_corr.phi_1_1) * |
1092 | 1.55M | fac; |
1093 | 1.55M | } |
1094 | | |
1095 | 3.05M | if (str_auto_corr.phi_1_1 == 0) { |
1096 | 1.49M | alpha_real[k][0] = alpha_imag[k][0] = 0; |
1097 | 1.55M | } else { |
1098 | 1.55M | fac = 1.0f / str_auto_corr.phi_1_1; |
1099 | 1.55M | alpha_real[k][0] = -(str_auto_corr.phi_0_1_real + |
1100 | 1.55M | alpha_real[k][1] * str_auto_corr.phi_1_2_real + |
1101 | 1.55M | alpha_imag[k][1] * str_auto_corr.phi_1_2_imag) * |
1102 | 1.55M | fac; |
1103 | 1.55M | alpha_imag[k][0] = -(str_auto_corr.phi_0_1_imag + |
1104 | 1.55M | alpha_imag[k][1] * str_auto_corr.phi_1_2_real - |
1105 | 1.55M | alpha_real[k][1] * str_auto_corr.phi_1_2_imag) * |
1106 | 1.55M | fac; |
1107 | 1.55M | } |
1108 | | |
1109 | 3.05M | if ((alpha_real[k][0] * alpha_real[k][0] + |
1110 | 3.05M | alpha_imag[k][0] * alpha_imag[k][0] >= |
1111 | 3.05M | 16.0f) || |
1112 | 3.04M | (alpha_real[k][1] * alpha_real[k][1] + |
1113 | 3.04M | alpha_imag[k][1] * alpha_imag[k][1] >= |
1114 | 3.04M | 16.0f)) { |
1115 | 8.68k | alpha_real[k][0] = 0.0f; |
1116 | 8.68k | alpha_imag[k][0] = 0.0f; |
1117 | 8.68k | alpha_real[k][1] = 0.0f; |
1118 | 8.68k | alpha_imag[k][1] = 0.0f; |
1119 | 8.68k | } |
1120 | 3.05M | } |
1121 | | |
1122 | 197k | goal_sb = (WORD32)(2.048e6f / fs + 0.5f); |
1123 | 197k | { |
1124 | 197k | WORD32 index; |
1125 | 197k | if (goal_sb < f_master_tbl[num_mf_bands]) { |
1126 | 152k | for (index = 0; (f_master_tbl[index] < goal_sb); index++) |
1127 | 134k | ; |
1128 | 18.1k | goal_sb = f_master_tbl[index]; |
1129 | 179k | } else { |
1130 | 179k | goal_sb = f_master_tbl[num_mf_bands]; |
1131 | 179k | } |
1132 | 197k | } |
1133 | | |
1134 | 197k | source_start_band = xover_offset + 1; |
1135 | 197k | sb = lsb + xover_offset; |
1136 | | |
1137 | 197k | patch = 0; |
1138 | 751k | while (sb < usb) { |
1139 | 610k | if (MAX_NUM_PATCHES <= patch) { |
1140 | 39 | if (ec_flag) { |
1141 | 0 | break; |
1142 | 39 | } else { |
1143 | 39 | return -1; |
1144 | 39 | } |
1145 | 39 | } |
1146 | 610k | ptr_frame_data->patch_param.start_subband[patch] = sb; |
1147 | 610k | num_bands_in_patch = goal_sb - sb; |
1148 | | |
1149 | 610k | if (num_bands_in_patch >= lsb - source_start_band) { |
1150 | 414k | patch_stride = sb - source_start_band; |
1151 | 414k | patch_stride = patch_stride & ~1; |
1152 | 414k | num_bands_in_patch = lsb - (sb - patch_stride); |
1153 | 414k | num_bands_in_patch = |
1154 | 414k | ixheaacd_find_closest_entry(sb + num_bands_in_patch, f_master_tbl, |
1155 | 414k | (WORD16)(num_mf_bands), 0) - |
1156 | 414k | (WORD32)(sb); |
1157 | 414k | } |
1158 | | |
1159 | 610k | patch_stride = num_bands_in_patch + sb - lsb; |
1160 | 610k | patch_stride = (patch_stride + 1) & ~1; |
1161 | | |
1162 | 610k | source_start_band = 1; |
1163 | | |
1164 | 610k | if (goal_sb - (sb + num_bands_in_patch) < 3) { |
1165 | 256k | goal_sb = usb; |
1166 | 256k | } |
1167 | | |
1168 | 610k | if ((num_bands_in_patch < 3) && (patch > 0) && |
1169 | 54.9k | (sb + num_bands_in_patch == usb)) { |
1170 | 1.73M | for (i = start_sample + slope_length; i < end_sample + slope_length; |
1171 | 1.67M | i++) { |
1172 | 5.03M | for (k2 = sb; k2 < sb + num_bands_in_patch; k2++) { |
1173 | 3.35M | ptr_dst_buf_real[i][k2] = 0.0f; |
1174 | 3.35M | ptr_dst_buf_imag[i][k2] = 0.0f; |
1175 | 3.35M | } |
1176 | 1.67M | } |
1177 | | |
1178 | 52.0k | break; |
1179 | 52.0k | } |
1180 | | |
1181 | 558k | if (num_bands_in_patch < 0 && flag_break == 1) { |
1182 | 4.28k | break; |
1183 | 4.28k | } |
1184 | | |
1185 | 553k | if (num_bands_in_patch < 0) { |
1186 | 14.7k | flag_break = 1; |
1187 | 14.7k | continue; |
1188 | 539k | } else { |
1189 | 539k | flag_break = 0; |
1190 | 539k | } |
1191 | | |
1192 | 5.60M | for (k2 = sb; k2 < sb + num_bands_in_patch; k2++) { |
1193 | 5.06M | k = k2 - patch_stride; |
1194 | 5.06M | bw_index = 0; |
1195 | 11.8M | while (k2 >= ptr_invf_band_tbl[bw_index]) { |
1196 | 6.77M | bw_index++; |
1197 | 6.77M | if (bw_index >= MAX_NOISE_COEFFS) { |
1198 | 0 | if (ec_flag) { |
1199 | 0 | bw_index = MAX_NOISE_COEFFS - 1; |
1200 | 0 | break; |
1201 | 0 | } else |
1202 | 0 | return -1; |
1203 | 0 | } |
1204 | 6.77M | } |
1205 | | |
1206 | 5.06M | if (bw_index >= MAX_NUM_PATCHES) { |
1207 | 0 | if (ec_flag) |
1208 | 0 | bw_index = MAX_NUM_PATCHES - 1; |
1209 | 0 | else |
1210 | 0 | return -1; |
1211 | 0 | } |
1212 | 5.06M | bw = bw_array[bw_index]; |
1213 | | |
1214 | 5.06M | a0r = bw * alpha_real[k][0]; |
1215 | 5.06M | a0i = bw * alpha_imag[k][0]; |
1216 | 5.06M | bw *= bw; |
1217 | 5.06M | a1r = bw * alpha_real[k][1]; |
1218 | 5.06M | a1i = bw * alpha_imag[k][1]; |
1219 | | |
1220 | 5.06M | if (pre_proc_flag) { |
1221 | 451k | gain = gain_vector[k]; |
1222 | 4.61M | } else { |
1223 | 4.61M | gain = 1.0f; |
1224 | 4.61M | } |
1225 | | |
1226 | 166M | for (i = start_sample + slope_length; i < end_sample + slope_length; |
1227 | 161M | i++) { |
1228 | 161M | ptr_dst_buf_real[i][k2] = ptr_src_buf_real[i][k] * gain; |
1229 | | |
1230 | 161M | ptr_dst_buf_imag[i][k2] = ptr_src_buf_imag[i][k] * gain; |
1231 | | |
1232 | 161M | if (bw > 0.0f) { |
1233 | 93.0M | ptr_dst_buf_real[i][k2] += (a0r * ptr_src_buf_real[i - 1][k] - |
1234 | 93.0M | a0i * ptr_src_buf_imag[i - 1][k] + |
1235 | 93.0M | a1r * ptr_src_buf_real[i - 2][k] - |
1236 | 93.0M | a1i * ptr_src_buf_imag[i - 2][k]) * |
1237 | 93.0M | gain; |
1238 | 93.0M | ptr_dst_buf_imag[i][k2] += (a0i * ptr_src_buf_real[i - 1][k] + |
1239 | 93.0M | a0r * ptr_src_buf_imag[i - 1][k] + |
1240 | 93.0M | a1i * ptr_src_buf_real[i - 2][k] + |
1241 | 93.0M | a1r * ptr_src_buf_imag[i - 2][k]) * |
1242 | 93.0M | gain; |
1243 | 93.0M | } |
1244 | 161M | } |
1245 | 5.06M | } |
1246 | 539k | sb += num_bands_in_patch; |
1247 | 539k | patch++; |
1248 | 539k | } |
1249 | 197k | } |
1250 | | |
1251 | 329k | if (NULL != ptr_ph_vocod_buf_real && NULL != ptr_ph_vocod_buf_imag) { |
1252 | 222k | if (hbe_flag && !sbr_patching_mode) { |
1253 | 101k | FLOAT32 alpha_real[2], alpha_imag[2]; |
1254 | | |
1255 | 101k | bw_index = 0, patch = 1; |
1256 | | |
1257 | 2.94M | for (k2 = sub_band_start; k2 < f_master_tbl[num_mf_bands]; k2++) { |
1258 | 2.84M | ixheaacd_esbr_calc_co_variance(&str_auto_corr, &ptr_ph_vocod_buf_real[0], |
1259 | 2.84M | &ptr_ph_vocod_buf_imag[0], k2, co_var_len); |
1260 | | |
1261 | 2.84M | if (str_auto_corr.det == 0.0f) { |
1262 | 1.45M | alpha_real[1] = alpha_imag[1] = 0; |
1263 | 1.45M | } else { |
1264 | 1.38M | fac = 1.0f / str_auto_corr.det; |
1265 | 1.38M | alpha_real[1] = (str_auto_corr.phi_0_1_real * str_auto_corr.phi_1_2_real - |
1266 | 1.38M | str_auto_corr.phi_0_1_imag * str_auto_corr.phi_1_2_imag - |
1267 | 1.38M | str_auto_corr.phi_0_2_real * str_auto_corr.phi_1_1) * |
1268 | 1.38M | fac; |
1269 | 1.38M | alpha_imag[1] = (str_auto_corr.phi_0_1_imag * str_auto_corr.phi_1_2_real + |
1270 | 1.38M | str_auto_corr.phi_0_1_real * str_auto_corr.phi_1_2_imag - |
1271 | 1.38M | str_auto_corr.phi_0_2_imag * str_auto_corr.phi_1_1) * |
1272 | 1.38M | fac; |
1273 | 1.38M | } |
1274 | | |
1275 | 2.84M | if (str_auto_corr.phi_1_1 == 0) { |
1276 | 1.45M | alpha_real[0] = alpha_imag[0] = 0; |
1277 | 1.45M | } else { |
1278 | 1.38M | fac = 1.0f / str_auto_corr.phi_1_1; |
1279 | 1.38M | alpha_real[0] = |
1280 | 1.38M | -(str_auto_corr.phi_0_1_real + alpha_real[1] * str_auto_corr.phi_1_2_real + |
1281 | 1.38M | alpha_imag[1] * str_auto_corr.phi_1_2_imag) * |
1282 | 1.38M | fac; |
1283 | 1.38M | alpha_imag[0] = |
1284 | 1.38M | -(str_auto_corr.phi_0_1_imag + alpha_imag[1] * str_auto_corr.phi_1_2_real - |
1285 | 1.38M | alpha_real[1] * str_auto_corr.phi_1_2_imag) * |
1286 | 1.38M | fac; |
1287 | 1.38M | } |
1288 | | |
1289 | 2.84M | if (alpha_real[0] * alpha_real[0] + alpha_imag[0] * alpha_imag[0] >= 16.0f || |
1290 | 2.82M | alpha_real[1] * alpha_real[1] + alpha_imag[1] * alpha_imag[1] >= 16.0f) { |
1291 | 53.7k | alpha_real[0] = 0.0f; |
1292 | 53.7k | alpha_imag[0] = 0.0f; |
1293 | 53.7k | alpha_real[1] = 0.0f; |
1294 | 53.7k | alpha_imag[1] = 0.0f; |
1295 | 53.7k | } |
1296 | | |
1297 | 3.08M | while (k2 >= ptr_invf_band_tbl[bw_index]) { |
1298 | 242k | bw_index++; |
1299 | 242k | if (bw_index >= MAX_NOISE_COEFFS) { |
1300 | 0 | if (ec_flag) { |
1301 | 0 | bw_index = MAX_NOISE_COEFFS - 1; |
1302 | 0 | break; |
1303 | 0 | } else |
1304 | 0 | return -1; |
1305 | 0 | } |
1306 | 242k | } |
1307 | | |
1308 | 2.84M | if (bw_index >= MAX_NUM_PATCHES) { |
1309 | 0 | if (ec_flag) |
1310 | 0 | bw_index = MAX_NUM_PATCHES - 1; |
1311 | 0 | else |
1312 | 0 | return -1; |
1313 | 0 | } |
1314 | 2.84M | bw = bw_array[bw_index]; |
1315 | | |
1316 | 2.84M | a0r = bw * alpha_real[0]; |
1317 | 2.84M | a0i = bw * alpha_imag[0]; |
1318 | 2.84M | bw *= bw; |
1319 | 2.84M | a1r = bw * alpha_real[1]; |
1320 | 2.84M | a1i = bw * alpha_imag[1]; |
1321 | | |
1322 | 2.84M | if (bw > 0.0f) { |
1323 | 52.3M | for (i = start_sample; i < end_sample; i++) { |
1324 | 50.8M | FLOAT32 real1, imag1, real2, imag2, realTarget, imag_target; |
1325 | | |
1326 | 50.8M | realTarget = ptr_ph_vocod_buf_real[i][k2]; |
1327 | 50.8M | imag_target = ptr_ph_vocod_buf_imag[i][k2]; |
1328 | 50.8M | real1 = ptr_ph_vocod_buf_real[i - 1][k2]; |
1329 | 50.8M | imag1 = ptr_ph_vocod_buf_imag[i - 1][k2]; |
1330 | 50.8M | real2 = ptr_ph_vocod_buf_real[i - 2][k2]; |
1331 | 50.8M | imag2 = ptr_ph_vocod_buf_imag[i - 2][k2]; |
1332 | 50.8M | realTarget += ((a0r * real1 - a0i * imag1) + (a1r * real2 - a1i * imag2)); |
1333 | 50.8M | imag_target += ((a0i * real1 + a0r * imag1) + (a1i * real2 + a1r * imag2)); |
1334 | | |
1335 | 50.8M | ptr_dst_buf_real[i][k2] = realTarget; |
1336 | 50.8M | ptr_dst_buf_imag[i][k2] = imag_target; |
1337 | 50.8M | } |
1338 | 1.55M | } else { |
1339 | 44.9M | for (i = start_sample; i < end_sample; i++) { |
1340 | 43.6M | ptr_dst_buf_real[i][k2] = ptr_ph_vocod_buf_real[i][k2]; |
1341 | 43.6M | ptr_dst_buf_imag[i][k2] = ptr_ph_vocod_buf_imag[i][k2]; |
1342 | 43.6M | } |
1343 | 1.28M | } |
1344 | 2.84M | } |
1345 | 101k | } |
1346 | 222k | } |
1347 | 329k | if ((MAX_NUM_PATCHES + 1) <= patch) { |
1348 | 0 | if (ec_flag) { |
1349 | 0 | patch = MAX_NUM_PATCHES; |
1350 | 0 | } else { |
1351 | 0 | return -1; |
1352 | 0 | } |
1353 | 0 | } |
1354 | 329k | ptr_frame_data->patch_param.num_patches = patch; |
1355 | 1.21M | for (i = 0; i < num_if_bands; i++) { |
1356 | 887k | bw_array_prev[i] = bw_array[i]; |
1357 | 887k | } |
1358 | 329k | return 0; |
1359 | 329k | } |