/src/libxaac/decoder/ixheaacd_env_calc.c
Line | Count | Source (jump to first uncovered line) |
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 "ixheaacd_sbr_common.h" |
21 | | #include "ixheaac_type_def.h" |
22 | | |
23 | | #include "ixheaac_constants.h" |
24 | | #include "ixheaac_basic_ops32.h" |
25 | | #include "ixheaac_basic_ops16.h" |
26 | | #include "ixheaac_basic_ops40.h" |
27 | | #include "ixheaac_basic_ops.h" |
28 | | |
29 | | #include "ixheaacd_intrinsics.h" |
30 | | #include "ixheaacd_bitbuffer.h" |
31 | | #include "ixheaacd_sbrdecsettings.h" |
32 | | #include "ixheaacd_defines.h" |
33 | | |
34 | | #include "ixheaacd_pns.h" |
35 | | |
36 | | #include "ixheaacd_aac_rom.h" |
37 | | #include "ixheaacd_pulsedata.h" |
38 | | #include "ixheaacd_drc_data_struct.h" |
39 | | |
40 | | #include "ixheaacd_lt_predict.h" |
41 | | |
42 | | #include "ixheaacd_cnst.h" |
43 | | #include "ixheaacd_ec_defines.h" |
44 | | #include "ixheaacd_ec_struct_def.h" |
45 | | #include "ixheaacd_channelinfo.h" |
46 | | #include "ixheaacd_drc_dec.h" |
47 | | |
48 | | #include "ixheaacd_sbrdecoder.h" |
49 | | #include "ixheaacd_sbr_scale.h" |
50 | | #include "ixheaacd_lpp_tran.h" |
51 | | |
52 | | #include "ixheaacd_env_extr_part.h" |
53 | | #include "ixheaacd_sbr_rom.h" |
54 | | #include "ixheaacd_hybrid.h" |
55 | | #include "ixheaacd_ps_dec.h" |
56 | | #include "ixheaacd_env_extr.h" |
57 | | |
58 | | #include "ixheaac_sbr_const.h" |
59 | | #include "ixheaacd_common_rom.h" |
60 | | #include "ixheaacd_freq_sca.h" |
61 | | |
62 | | #include "ixheaacd_basic_funcs.h" |
63 | | #include "ixheaacd_env_extr.h" |
64 | | |
65 | | #include "ixheaacd_env_calc.h" |
66 | | #include "ixheaac_basic_op.h" |
67 | | |
68 | | #include "ixheaacd_qmf_dec.h" |
69 | | |
70 | | #include "ixheaacd_pvc_dec.h" |
71 | | #include "ixheaacd_sbr_dec.h" |
72 | | #include "ixheaacd_function_selector.h" |
73 | | |
74 | | #include "ixheaacd_audioobjtypes.h" |
75 | | |
76 | 0 | #define FACTOR 0x010b0000 * 2 |
77 | | |
78 | | static VOID ixheaacd_alias_reduction(WORD16 *deg_patched, WORD16 *nrg_gain, |
79 | | WORD16 *nrg_est, WORD8 *alias_red_buf, |
80 | | WORD32 num_sub_bands, |
81 | 0 | ixheaacd_misc_tables *pstr_common_tables) { |
82 | 0 | WORD32 group, grouping, i, num_groups, k; |
83 | 0 | WORD16 f_group_vec[MAX_FREQ_COEFFS], *ptr_f_group_vec; |
84 | |
|
85 | 0 | grouping = 0; |
86 | 0 | i = 0; |
87 | |
|
88 | 0 | for (k = 0; k < num_sub_bands - 1; k++) { |
89 | 0 | if ((deg_patched[k + 1] != 0) && alias_red_buf[k]) { |
90 | 0 | if (grouping == 0) { |
91 | 0 | f_group_vec[i] = k; |
92 | 0 | grouping = 1; |
93 | 0 | i++; |
94 | 0 | } else { |
95 | 0 | if ((f_group_vec[i - 1] + 3) == k) { |
96 | 0 | f_group_vec[i] = (k + 1); |
97 | 0 | grouping = 0; |
98 | 0 | i++; |
99 | 0 | } |
100 | 0 | } |
101 | 0 | } else { |
102 | 0 | if (grouping) { |
103 | 0 | grouping = 0; |
104 | 0 | f_group_vec[i] = k; |
105 | |
|
106 | 0 | if (alias_red_buf[k]) f_group_vec[i] = k + 1; |
107 | |
|
108 | 0 | i++; |
109 | 0 | } |
110 | 0 | } |
111 | 0 | } |
112 | |
|
113 | 0 | if (grouping) { |
114 | 0 | f_group_vec[i] = num_sub_bands; |
115 | 0 | i++; |
116 | 0 | } |
117 | 0 | num_groups = (i >> 1); |
118 | |
|
119 | 0 | ptr_f_group_vec = f_group_vec; |
120 | |
|
121 | 0 | for (group = num_groups; group != 0; group--) { |
122 | 0 | WORD16 nrg_amp_mant; |
123 | 0 | WORD16 nrg_amp_exp; |
124 | 0 | WORD16 nrgMod_m; |
125 | 0 | WORD16 nrgMod_e; |
126 | 0 | WORD16 grp_gain_mant; |
127 | 0 | WORD16 grp_gain_exp; |
128 | 0 | WORD16 compensation_m; |
129 | 0 | WORD16 compensation_e; |
130 | 0 | WORD32 nrg_mod_mant; |
131 | 0 | WORD32 nrg_mod_exp; |
132 | |
|
133 | 0 | WORD32 start_grp = *ptr_f_group_vec++; |
134 | 0 | WORD32 stop_grp = *ptr_f_group_vec++; |
135 | |
|
136 | 0 | ixheaacd_avggain_calc(nrg_est, nrg_gain, start_grp, stop_grp, &nrg_amp_mant, |
137 | 0 | &nrg_amp_exp, &grp_gain_mant, &grp_gain_exp, |
138 | 0 | pstr_common_tables, 1); |
139 | |
|
140 | 0 | nrg_mod_mant = 0; |
141 | 0 | nrg_mod_exp = 0; |
142 | 0 | { |
143 | 0 | WORD16 *ptr_nrg_gain_mant = &nrg_gain[2 * start_grp]; |
144 | |
|
145 | 0 | for (k = start_grp; k < stop_grp; k++) { |
146 | 0 | WORD32 tmp_mant, tmp_gain_mant, gain_m; |
147 | 0 | WORD32 tmp_e, tmp_gain_exp; |
148 | 0 | WORD16 one_minus_alpha, alpha = deg_patched[k]; |
149 | |
|
150 | 0 | if (k < (num_sub_bands - 1)) { |
151 | 0 | alpha = ixheaac_max16(deg_patched[k + 1], alpha); |
152 | 0 | } |
153 | 0 | gain_m = (alpha * grp_gain_mant); |
154 | 0 | one_minus_alpha = 0x7fff - alpha; |
155 | |
|
156 | 0 | tmp_gain_mant = *ptr_nrg_gain_mant; |
157 | 0 | tmp_gain_exp = *(ptr_nrg_gain_mant + 1); |
158 | |
|
159 | 0 | { |
160 | 0 | WORD32 exp_diff; |
161 | |
|
162 | 0 | tmp_gain_mant = (one_minus_alpha * tmp_gain_mant) >> 15; |
163 | |
|
164 | 0 | exp_diff = (grp_gain_exp - tmp_gain_exp); |
165 | |
|
166 | 0 | if (exp_diff >= 0) { |
167 | 0 | tmp_gain_exp = grp_gain_exp; |
168 | 0 | tmp_gain_mant = ixheaac_shr32(tmp_gain_mant, exp_diff); |
169 | |
|
170 | 0 | tmp_gain_mant = (gain_m >> 15) + tmp_gain_mant; |
171 | |
|
172 | 0 | } else { |
173 | 0 | tmp_gain_mant = |
174 | 0 | (ixheaac_shr32(gain_m, (15 - exp_diff))) + tmp_gain_mant; |
175 | 0 | } |
176 | 0 | } |
177 | 0 | *ptr_nrg_gain_mant++ = tmp_gain_mant; |
178 | 0 | *ptr_nrg_gain_mant++ = tmp_gain_exp; |
179 | |
|
180 | 0 | tmp_mant = (tmp_gain_mant * (nrg_est[2 * k])) >> 16; |
181 | 0 | tmp_e = (tmp_gain_exp + (nrg_est[2 * k + 1]) + 1); |
182 | |
|
183 | 0 | { |
184 | 0 | WORD32 exp_diff; |
185 | 0 | exp_diff = tmp_e - nrg_mod_exp; |
186 | 0 | if (exp_diff >= 0) { |
187 | 0 | nrg_mod_mant = tmp_mant + (ixheaac_shr32(nrg_mod_mant, exp_diff)); |
188 | 0 | nrg_mod_exp = tmp_e; |
189 | 0 | } else { |
190 | 0 | exp_diff = -exp_diff; |
191 | 0 | nrg_mod_mant = (ixheaac_shr32(tmp_mant, exp_diff)) + nrg_mod_mant; |
192 | 0 | } |
193 | 0 | } |
194 | 0 | } |
195 | 0 | } |
196 | |
|
197 | 0 | { |
198 | 0 | WORD32 norm_val; |
199 | 0 | norm_val = 16 - ixheaac_pnorm32(nrg_mod_mant); |
200 | 0 | if (norm_val > 0) { |
201 | 0 | nrg_mod_mant >>= norm_val; |
202 | 0 | nrg_mod_exp += norm_val; |
203 | 0 | } |
204 | 0 | } |
205 | |
|
206 | 0 | nrgMod_m = (WORD16)nrg_mod_mant; |
207 | 0 | nrgMod_e = (WORD16)nrg_mod_exp; |
208 | |
|
209 | 0 | compensation_e = ixheaacd_fix_mant_div(nrg_amp_mant, nrgMod_m, |
210 | 0 | &compensation_m, pstr_common_tables); |
211 | 0 | compensation_e += nrg_amp_exp - nrgMod_e + 1 + 1; |
212 | |
|
213 | 0 | { |
214 | 0 | WORD16 *ptr_nrg_gain_mant = &nrg_gain[2 * start_grp]; |
215 | |
|
216 | 0 | for (k = stop_grp - start_grp; k != 0; k--) { |
217 | 0 | WORD16 temp1, temp2; |
218 | 0 | temp1 = *ptr_nrg_gain_mant; |
219 | 0 | temp2 = *(ptr_nrg_gain_mant + 1); |
220 | 0 | temp1 = (temp1 * compensation_m) >> 16; |
221 | 0 | temp2 = (temp2 + compensation_e); |
222 | 0 | *ptr_nrg_gain_mant++ = temp1; |
223 | 0 | *ptr_nrg_gain_mant++ = temp2; |
224 | 0 | } |
225 | 0 | } |
226 | 0 | } |
227 | 0 | } |
228 | | |
229 | | VOID ixheaacd_noiselimiting(ia_freq_band_data_struct *pstr_freq_band_data, |
230 | | WORD32 skip_bands, WORD16 *ptr_enrg_orig, |
231 | | WORD16 *nrg_est, WORD16 *nrg_gain, |
232 | | WORD16 *noise_level_mant, WORD16 *nrg_sine, |
233 | | WORD16 *ptr_limit_gain_table, FLAG noise_absc_flag, |
234 | 69.0k | ixheaacd_misc_tables *pstr_common_tables) { |
235 | 69.0k | WORD32 c, k; |
236 | 69.0k | WORD32 temp_val; |
237 | 69.0k | WORD16 limit_gain_mant = *ptr_limit_gain_table++; |
238 | 69.0k | WORD16 limit_gain_exp = *ptr_limit_gain_table; |
239 | 261k | for (c = 0; c < pstr_freq_band_data->num_lf_bands; c++) { |
240 | 192k | WORD16 max_gain_mant; |
241 | 192k | WORD16 sum_orig_mant, sum_orig_exp; |
242 | 192k | WORD16 max_gain_exp; |
243 | 192k | WORD32 max_temp; |
244 | 192k | WORD32 start_band = 0; |
245 | 192k | WORD32 stop_band = 0; |
246 | | |
247 | 192k | if ((pstr_freq_band_data->freq_band_tbl_lim[c] > skip_bands)) { |
248 | 123k | start_band = (pstr_freq_band_data->freq_band_tbl_lim[c] - skip_bands); |
249 | 123k | } |
250 | | |
251 | 192k | if ((pstr_freq_band_data->freq_band_tbl_lim[c + 1] > skip_bands)) { |
252 | 192k | stop_band = (pstr_freq_band_data->freq_band_tbl_lim[c + 1] - skip_bands); |
253 | 192k | } |
254 | | |
255 | 192k | if ((start_band < stop_band)) { |
256 | 192k | ixheaacd_avggain_calc(ptr_enrg_orig, nrg_est, start_band, stop_band, |
257 | 192k | &sum_orig_mant, &sum_orig_exp, &max_gain_mant, |
258 | 192k | &max_gain_exp, pstr_common_tables, 0); |
259 | | |
260 | 192k | max_temp = ixheaac_mult16x16in32_shl(max_gain_mant, limit_gain_mant); |
261 | 192k | max_gain_exp = (max_gain_exp + limit_gain_exp); |
262 | | |
263 | 192k | temp_val = ixheaac_norm32(max_temp); |
264 | | |
265 | 192k | max_gain_exp = (WORD16)(max_gain_exp - temp_val); |
266 | 192k | max_gain_mant = (WORD16)((max_temp << temp_val) >> 16); |
267 | | |
268 | 192k | if ((max_gain_exp >= MAX_GAIN_EXP)) { |
269 | 44.5k | max_gain_mant = 0x3000; |
270 | 44.5k | max_gain_exp = MAX_GAIN_EXP; |
271 | 44.5k | } |
272 | | |
273 | 192k | { |
274 | 192k | WORD16 *ptr_nrg_gain = &nrg_gain[2 * start_band]; |
275 | 192k | WORD16 *p_noise_level = &noise_level_mant[2 * start_band]; |
276 | | |
277 | 1.73M | for (k = stop_band - start_band; k != 0; k--) { |
278 | 1.53M | WORD16 noise_amp_mant; |
279 | 1.53M | WORD16 noise_amp_exp; |
280 | | |
281 | 1.53M | WORD16 t_gain_mant = *(ptr_nrg_gain); |
282 | 1.53M | WORD16 t_gain_exp = *(ptr_nrg_gain + 1); |
283 | | |
284 | 1.53M | if (((t_gain_exp > max_gain_exp)) || |
285 | 1.53M | ((t_gain_exp == max_gain_exp) && (t_gain_mant > max_gain_mant))) { |
286 | 207k | noise_amp_exp = |
287 | 207k | ixheaacd_fix_mant_div(max_gain_mant, t_gain_mant, |
288 | 207k | &noise_amp_mant, pstr_common_tables); |
289 | 207k | noise_amp_exp += (max_gain_exp - t_gain_exp) + 1; |
290 | | |
291 | 207k | *p_noise_level = ixheaac_extract16h(ixheaac_shl32_dir_sat_limit( |
292 | 207k | ixheaac_mult16x16in32_shl(*p_noise_level, noise_amp_mant), |
293 | 207k | noise_amp_exp)); |
294 | | |
295 | 207k | *ptr_nrg_gain = max_gain_mant; |
296 | 207k | *(ptr_nrg_gain + 1) = max_gain_exp; |
297 | 207k | } |
298 | 1.53M | ptr_nrg_gain += 2; |
299 | 1.53M | p_noise_level += 2; |
300 | 1.53M | } |
301 | 192k | } |
302 | | |
303 | 192k | { |
304 | 192k | WORD16 boost_gain_mant; |
305 | 192k | WORD16 boost_gain_exp; |
306 | 192k | WORD16 accu_m; |
307 | 192k | WORD16 accu_e; |
308 | 192k | WORD32 accu_m_t; |
309 | 192k | WORD32 accu_e_t; |
310 | 192k | WORD16 *ptr_nrg_gain = &nrg_gain[2 * start_band]; |
311 | 192k | WORD16 *ptr_enrg_est_buf = &nrg_est[2 * start_band]; |
312 | 192k | WORD16 *p_noise_level = &noise_level_mant[2 * start_band]; |
313 | 192k | WORD16 *p_nrg_sine = &nrg_sine[2 * start_band]; |
314 | | |
315 | 192k | accu_m_t = 0; |
316 | 192k | accu_e_t = 0; |
317 | | |
318 | 1.73M | for (k = stop_band - start_band; k != 0; k--) { |
319 | 1.53M | WORD32 tmp_mant, tmp_e; |
320 | | |
321 | 1.53M | tmp_mant = *ptr_nrg_gain++; |
322 | 1.53M | tmp_e = *ptr_nrg_gain++; |
323 | 1.53M | tmp_mant = (tmp_mant * (*ptr_enrg_est_buf++)); |
324 | 1.53M | tmp_e = (tmp_e + (*ptr_enrg_est_buf++)); |
325 | 1.53M | tmp_mant = tmp_mant >> 15; |
326 | 1.53M | { |
327 | 1.53M | WORD32 exp_diff; |
328 | 1.53M | exp_diff = tmp_e - accu_e_t; |
329 | 1.53M | if (exp_diff >= 0) { |
330 | 668k | accu_m_t = tmp_mant + ixheaac_shr32(accu_m_t, exp_diff); |
331 | 668k | accu_e_t = tmp_e; |
332 | 871k | } else { |
333 | 871k | exp_diff = -exp_diff; |
334 | 871k | accu_m_t = ixheaac_shr32(tmp_mant, exp_diff) + accu_m_t; |
335 | 871k | } |
336 | 1.53M | } |
337 | | |
338 | 1.53M | if (p_nrg_sine[0] != 0) { |
339 | 43.3k | WORD32 exp_diff = p_nrg_sine[1] - accu_e_t; |
340 | 43.3k | if (exp_diff >= 0) { |
341 | 12.1k | accu_m_t = p_nrg_sine[0] + ixheaac_shr32(accu_m_t, exp_diff); |
342 | 12.1k | accu_e_t = p_nrg_sine[1]; |
343 | 31.2k | } else { |
344 | 31.2k | exp_diff = -exp_diff; |
345 | 31.2k | accu_m_t = accu_m_t + ixheaac_shr32(p_nrg_sine[0], exp_diff); |
346 | 31.2k | } |
347 | | |
348 | 1.49M | } else { |
349 | 1.49M | if (noise_absc_flag == 0) { |
350 | 1.36M | WORD32 exp_diff = p_noise_level[1] - accu_e_t; |
351 | 1.36M | if (exp_diff >= 0) { |
352 | 592k | accu_m_t = |
353 | 592k | p_noise_level[0] + ixheaac_shr32(accu_m_t, exp_diff); |
354 | 592k | accu_e_t = p_noise_level[1]; |
355 | 772k | } else { |
356 | 772k | exp_diff = -exp_diff; |
357 | 772k | accu_m_t = |
358 | 772k | accu_m_t + ixheaac_shr32(p_noise_level[0], exp_diff); |
359 | 772k | } |
360 | 1.36M | } |
361 | 1.49M | } |
362 | 1.53M | p_noise_level += 2; |
363 | 1.53M | p_nrg_sine += 2; |
364 | 1.53M | } |
365 | | |
366 | 192k | { |
367 | 192k | WORD32 norm_val; |
368 | 192k | norm_val = 16 - ixheaac_norm32(accu_m_t); |
369 | 192k | if (norm_val > 0) { |
370 | 96.5k | accu_m_t >>= norm_val; |
371 | 96.5k | accu_e_t += norm_val; |
372 | 96.5k | } |
373 | 192k | } |
374 | | |
375 | 192k | accu_m = (WORD16)accu_m_t; |
376 | 192k | accu_e = (WORD16)accu_e_t; |
377 | | |
378 | 192k | boost_gain_exp = ixheaacd_fix_mant_div( |
379 | 192k | sum_orig_mant, accu_m, &boost_gain_mant, pstr_common_tables); |
380 | | |
381 | 192k | boost_gain_exp += (sum_orig_exp - accu_e) + 1; |
382 | | |
383 | 192k | if ((boost_gain_exp > 2) || |
384 | 192k | ((boost_gain_exp == 2) && (boost_gain_mant > 0x5061))) { |
385 | 37.2k | boost_gain_mant = 0x5061; |
386 | 37.2k | boost_gain_exp = 2; |
387 | 37.2k | } |
388 | | |
389 | 192k | ptr_nrg_gain = &nrg_gain[2 * start_band]; |
390 | 192k | p_noise_level = &noise_level_mant[2 * start_band]; |
391 | 192k | p_nrg_sine = &nrg_sine[2 * start_band]; |
392 | | |
393 | 1.73M | for (k = stop_band - start_band; k != 0; k--) { |
394 | 1.53M | WORD16 temp1, temp2, temp3; |
395 | | |
396 | 1.53M | temp1 = *ptr_nrg_gain; |
397 | 1.53M | temp2 = *p_nrg_sine; |
398 | 1.53M | temp3 = *p_noise_level; |
399 | | |
400 | 1.53M | temp1 = ixheaac_mult16_shl(temp1, boost_gain_mant); |
401 | 1.53M | temp2 = ixheaac_mult16_shl(temp2, boost_gain_mant); |
402 | 1.53M | temp3 = ixheaac_mult16_shl(temp3, boost_gain_mant); |
403 | 1.53M | *ptr_nrg_gain++ = temp1; |
404 | 1.53M | *p_nrg_sine++ = temp2; |
405 | 1.53M | *p_noise_level++ = temp3; |
406 | | |
407 | 1.53M | temp1 = *ptr_nrg_gain; |
408 | 1.53M | temp2 = *p_nrg_sine; |
409 | 1.53M | temp3 = *p_noise_level; |
410 | | |
411 | 1.53M | temp1 = (temp1 + boost_gain_exp); |
412 | 1.53M | temp2 = (temp2 + boost_gain_exp); |
413 | 1.53M | temp3 = (temp3 + boost_gain_exp); |
414 | 1.53M | *ptr_nrg_gain++ = (temp1); |
415 | 1.53M | *p_nrg_sine++ = (temp2); |
416 | 1.53M | *p_noise_level++ = (temp3); |
417 | 1.53M | } |
418 | 192k | } |
419 | 192k | } |
420 | 192k | } |
421 | 69.0k | } |
422 | | |
423 | | VOID ixheaacd_conv_ergtoamplitudelp_dec(WORD32 bands, WORD16 noise_e, |
424 | | WORD16 *nrg_sine, WORD16 *nrg_gain, |
425 | | WORD16 *noise_level_mant, |
426 | 0 | WORD16 *sqrt_table) { |
427 | 0 | WORD32 k; |
428 | 0 | for (k = 0; k < bands; k++) { |
429 | 0 | WORD32 shift; |
430 | 0 | ixheaacd_fix_mant_exp_sqrt(&nrg_sine[2 * k], sqrt_table); |
431 | 0 | ixheaacd_fix_mant_exp_sqrt(&nrg_gain[2 * k], sqrt_table); |
432 | 0 | ixheaacd_fix_mant_exp_sqrt(&noise_level_mant[2 * k], sqrt_table); |
433 | |
|
434 | 0 | shift = (noise_e - noise_level_mant[2 * k + 1]); |
435 | |
|
436 | 0 | shift = (shift - 4); |
437 | 0 | if (shift > 0) |
438 | 0 | noise_level_mant[2 * k] = (noise_level_mant[2 * k] >> shift); |
439 | 0 | else |
440 | 0 | noise_level_mant[2 * k] = (noise_level_mant[2 * k] << -shift); |
441 | |
|
442 | 0 | shift = (nrg_sine[2 * k + 1] - noise_e); |
443 | 0 | if (shift > 0) |
444 | 0 | nrg_sine[2 * k] = ixheaac_shl16_sat(nrg_sine[2 * k], (WORD16)shift); |
445 | 0 | else |
446 | 0 | nrg_sine[2 * k] = ixheaac_shr16(nrg_sine[2 * k], (WORD16)-shift); |
447 | 0 | } |
448 | 0 | } |
449 | | |
450 | | VOID ixheaacd_conv_ergtoamplitude_dec(WORD32 bands, WORD16 noise_e, |
451 | | WORD16 *nrg_sine, WORD16 *nrg_gain, |
452 | | WORD16 *noise_level_mant, |
453 | 69.0k | WORD16 *sqrt_table) { |
454 | 69.0k | WORD32 k; |
455 | 1.62M | for (k = 0; k < bands; k++) { |
456 | 1.55M | WORD32 shift; |
457 | | |
458 | 1.55M | ixheaacd_fix_mant_exp_sqrt(&nrg_sine[2 * k], sqrt_table); |
459 | 1.55M | ixheaacd_fix_mant_exp_sqrt(&nrg_gain[2 * k], sqrt_table); |
460 | 1.55M | ixheaacd_fix_mant_exp_sqrt(&noise_level_mant[2 * k], sqrt_table); |
461 | | |
462 | 1.55M | shift = (noise_e - noise_level_mant[2 * k + 1]); |
463 | | |
464 | 1.55M | shift = (shift - 4); |
465 | 1.55M | if (shift > 0) { |
466 | 1.55M | if (shift > 31) { |
467 | 12.3k | shift = 31; |
468 | 12.3k | } |
469 | 1.55M | noise_level_mant[2 * k] = (noise_level_mant[2 * k] >> shift); |
470 | 1.55M | } else { |
471 | 3.17k | if (shift < -31) { |
472 | 0 | shift = -31; |
473 | 0 | } |
474 | 3.17k | noise_level_mant[2 * k] = (noise_level_mant[2 * k] << -shift); |
475 | 3.17k | } |
476 | 1.55M | } |
477 | 69.0k | } |
478 | | |
479 | | static PLATFORM_INLINE VOID ixheaacd_adapt_noise_gain_calc( |
480 | | ia_sbr_calc_env_struct *ptr_sbr_calc_env, WORD32 noise_e, |
481 | | WORD32 num_sub_bands, WORD32 skip_bands, WORD16 *nrg_gain, |
482 | | WORD16 *noise_level_mant, WORD16 *nrg_sine, WORD32 start_pos, |
483 | | WORD32 end_pos, WORD32 input_e, WORD32 adj_e, WORD32 final_e, |
484 | | WORD32 sub_band_start, WORD32 lb_scale, FLAG noise_absc_flag, |
485 | | WORD32 smooth_length, WORD32 **anal_buf_real_mant, |
486 | | WORD32 **anal_buf_imag_mant, WORD32 low_pow_flag, |
487 | 69.0k | ia_sbr_tables_struct *ptr_sbr_tables, WORD16 max_cols) { |
488 | 69.0k | WORD32 l, k; |
489 | 69.0k | WORD32 scale_change; |
490 | 69.0k | WORD32 bands = num_sub_bands - skip_bands; |
491 | 69.0k | WORD16 *ptr_filt_buf; |
492 | 69.0k | WORD16 *ptr_filt_buf_noise; |
493 | 69.0k | WORD16 *ptr_gain = &nrg_gain[0]; |
494 | | |
495 | 69.0k | if (ptr_sbr_calc_env->start_up) { |
496 | 21.6k | WORD16 *ptr_noise = noise_level_mant; |
497 | 21.6k | ptr_sbr_calc_env->start_up = 0; |
498 | | |
499 | 21.6k | ptr_sbr_calc_env->filt_buf_noise_e = noise_e; |
500 | 21.6k | ptr_filt_buf = &ptr_sbr_calc_env->filt_buf_me[skip_bands * 2]; |
501 | 21.6k | ptr_filt_buf_noise = &ptr_sbr_calc_env->filt_buf_noise_m[skip_bands]; |
502 | | |
503 | 529k | for (k = bands; k != 0; k--) { |
504 | 508k | WORD16 temp1 = *ptr_gain++; |
505 | 508k | WORD16 temp2 = *ptr_gain++; |
506 | 508k | WORD16 temp3 = *ptr_noise; |
507 | 508k | ptr_noise += 2; |
508 | | |
509 | 508k | *ptr_filt_buf++ = temp1; |
510 | 508k | *ptr_filt_buf++ = temp2; |
511 | 508k | *ptr_filt_buf_noise++ = temp3; |
512 | 508k | } |
513 | 47.3k | } else { |
514 | 47.3k | ixheaacd_equalize_filt_buff_exp( |
515 | 47.3k | &ptr_sbr_calc_env->filt_buf_me[2 * skip_bands], nrg_gain, bands); |
516 | 47.3k | } |
517 | | |
518 | 874k | for (l = start_pos; l < end_pos; l++) { |
519 | | |
520 | 805k | if (max_cols != 30) { |
521 | 415k | if ((l < MAX_COLS)) { |
522 | 415k | scale_change = (adj_e - input_e); |
523 | 415k | } else { |
524 | 0 | scale_change = (final_e - input_e); |
525 | |
|
526 | 0 | if (((l == MAX_COLS)) && ((start_pos < MAX_COLS))) { |
527 | 0 | WORD32 diff = final_e - noise_e; |
528 | 0 | noise_e = final_e; |
529 | 0 | ixheaacd_noise_level_rescaling(noise_level_mant, diff, bands, 2); |
530 | 0 | } |
531 | 0 | } |
532 | 415k | } else { |
533 | 389k | if ((l < max_cols)) { |
534 | 389k | scale_change = (adj_e - input_e); |
535 | 389k | } else { |
536 | 0 | scale_change = (final_e - input_e); |
537 | |
|
538 | 0 | if (((l == max_cols)) && ((start_pos < max_cols))) { |
539 | 0 | WORD32 diff = final_e - noise_e; |
540 | 0 | noise_e = final_e; |
541 | 0 | ixheaacd_noise_level_rescaling(noise_level_mant, diff, bands, 2); |
542 | 0 | } |
543 | 0 | } |
544 | 389k | } |
545 | | |
546 | 805k | ixheaacd_noise_level_rescaling(ptr_sbr_calc_env->filt_buf_noise_m, |
547 | 805k | ptr_sbr_calc_env->filt_buf_noise_e - noise_e, |
548 | 805k | num_sub_bands, 1); |
549 | | |
550 | 805k | ptr_sbr_calc_env->filt_buf_noise_e = noise_e; |
551 | | |
552 | 805k | { |
553 | 805k | WORD32 *anal_buf_real_m_l; |
554 | 805k | anal_buf_real_m_l = anal_buf_real_mant[l]; |
555 | | |
556 | 805k | if (low_pow_flag) { |
557 | 0 | WORD32 index = ptr_sbr_calc_env->ph_index; |
558 | 0 | WORD32 harm_index = ptr_sbr_calc_env->harm_index; |
559 | 0 | WORD32 freq_inv_flag = (sub_band_start & 1); |
560 | 0 | WORD32 *ptr_real_buf = &anal_buf_real_m_l[sub_band_start]; |
561 | |
|
562 | 0 | const WORD32 *ptr_rand_ph = &ptr_sbr_tables->sbr_rand_ph[index + 1]; |
563 | |
|
564 | 0 | ptr_sbr_calc_env->ph_index = |
565 | 0 | (WORD16)((index + num_sub_bands) & (SBR_NF_NO_RANDOM_VAL - 1)); |
566 | 0 | ptr_sbr_calc_env->harm_index = (WORD16)(((harm_index + 1)) & 3); |
567 | |
|
568 | 0 | if (!(harm_index & 0x1)) { |
569 | 0 | (*ixheaacd_harm_idx_zerotwolp)( |
570 | 0 | ptr_real_buf, nrg_gain, scale_change, nrg_sine, ptr_rand_ph, |
571 | 0 | noise_level_mant, num_sub_bands, noise_absc_flag, harm_index); |
572 | 0 | } else { |
573 | 0 | WORD32 noise = (noise_e - 16) - lb_scale; |
574 | |
|
575 | 0 | freq_inv_flag = (!freq_inv_flag); |
576 | 0 | freq_inv_flag = (freq_inv_flag << 1) - 1; |
577 | |
|
578 | 0 | if (harm_index == 3) freq_inv_flag = -freq_inv_flag; |
579 | |
|
580 | 0 | ixheaacd_harm_idx_onethreelp(ptr_real_buf, nrg_gain, scale_change, |
581 | 0 | nrg_sine, ptr_rand_ph, noise_level_mant, |
582 | 0 | num_sub_bands, noise_absc_flag, |
583 | 0 | freq_inv_flag, noise, sub_band_start); |
584 | 0 | } |
585 | |
|
586 | 805k | } else { |
587 | 805k | WORD16 smooth_ratio; |
588 | 805k | WORD32 *anal_buf_imag_m_l; |
589 | 805k | anal_buf_imag_m_l = anal_buf_imag_mant[l]; |
590 | | |
591 | 805k | if (((l - start_pos) < smooth_length)) { |
592 | 74.1k | smooth_ratio = ptr_sbr_tables->env_calc_tables_ptr |
593 | 74.1k | ->sbr_smooth_filter[(l - start_pos)]; |
594 | 730k | } else { |
595 | 730k | smooth_ratio = 0; |
596 | 730k | } |
597 | | |
598 | 805k | ixheaacd_adj_timeslot( |
599 | 805k | &anal_buf_real_m_l[sub_band_start], |
600 | 805k | &anal_buf_imag_m_l[sub_band_start], |
601 | 805k | &ptr_sbr_calc_env->filt_buf_me[2 * skip_bands], |
602 | 805k | &ptr_sbr_calc_env->filt_buf_noise_m[skip_bands], nrg_gain, |
603 | 805k | noise_level_mant, nrg_sine, (WORD16)(noise_e - 16), |
604 | 805k | &ptr_sbr_calc_env->harm_index, (WORD16)sub_band_start, |
605 | 805k | (WORD16)(bands), (WORD16)scale_change, smooth_ratio, |
606 | 805k | noise_absc_flag, &ptr_sbr_calc_env->ph_index, ptr_sbr_tables); |
607 | 805k | } |
608 | 805k | } |
609 | 805k | } |
610 | | |
611 | 69.0k | ixheaacd_filt_buf_update(ptr_sbr_calc_env->filt_buf_me + 2 * skip_bands, |
612 | 69.0k | ptr_sbr_calc_env->filt_buf_noise_m + skip_bands, |
613 | 69.0k | nrg_gain, noise_level_mant, bands); |
614 | 69.0k | } |
615 | | |
616 | | VOID ixheaacd_calc_subband_gains(ia_freq_band_data_struct *pstr_freq_band_data, |
617 | | ia_sbr_frame_info_data_struct *ptr_frame_data, |
618 | | WORD32 freq_res, WORD16 *ptr_noise_floor, |
619 | | WORD32 num_sf_bands, WORD32 mvalue, WORD32 env, |
620 | | WORD8 *sine_mapped_matrix, |
621 | | WORD8 *alias_red_buf, WORD16 *ptr_enrg_orig, |
622 | | WORD16 *nrg_sine, WORD16 *nrg_est, |
623 | | WORD16 *nrg_gain, WORD16 *noise_level_mant, |
624 | | FLAG noise_absc_flag, |
625 | 69.0k | ixheaacd_misc_tables *pstr_common_tables) { |
626 | 69.0k | WORD16 *ptr_freq_band_tbl = pstr_freq_band_data->freq_band_table[freq_res]; |
627 | 69.0k | WORD32 ui_noise = pstr_freq_band_data->freq_band_tbl_noise[1]; |
628 | 69.0k | WORD32 nb_idx = 0; |
629 | 69.0k | WORD16 tmp_noise_mant; |
630 | 69.0k | WORD16 tmp_noise_exp; |
631 | 69.0k | WORD8 *ptr_sine_mapped = sine_mapped_matrix; |
632 | 69.0k | WORD32 sub_band_start = pstr_freq_band_data->sub_band_start; |
633 | 69.0k | WORD32 skip_bands = (ptr_frame_data->max_qmf_subband_aac - sub_band_start); |
634 | 69.0k | WORD8 *ptr_sine_mapped_1 = &sine_mapped_matrix[skip_bands]; |
635 | 69.0k | WORD32 k, c = 0, j; |
636 | | |
637 | 69.0k | WORD16 *ptr_env_sf_arr = &ptr_frame_data->int_env_sf_arr[mvalue]; |
638 | 69.0k | WORD8 *ptr_alias_red_buf = |
639 | 69.0k | &alias_red_buf[ptr_freq_band_tbl[0] - sub_band_start]; |
640 | | |
641 | 69.0k | tmp_noise_mant = (WORD16)(ptr_noise_floor[nb_idx] & MASK_M); |
642 | 69.0k | tmp_noise_exp = |
643 | 69.0k | (WORD16)(ptr_noise_floor[nb_idx] & MASK_FOR_EXP) - NOISE_EXP_OFFSET; |
644 | | |
645 | 747k | for (j = 0; j < num_sf_bands; j++) { |
646 | 678k | WORD8 sine_present_flag; |
647 | 678k | WORD16 tmp_nrg_ref_exp, tmp_nrg_ref_mant; |
648 | 678k | WORD16 li = *ptr_freq_band_tbl++; |
649 | 678k | WORD16 ui = *ptr_freq_band_tbl; |
650 | 678k | WORD16 env_sf_val = *ptr_env_sf_arr++; |
651 | | |
652 | 678k | tmp_nrg_ref_exp = |
653 | 678k | (WORD16)((env_sf_val & (WORD16)MASK_FOR_EXP) - NRG_EXP_OFFSET); |
654 | 678k | tmp_nrg_ref_mant = (WORD16)(env_sf_val & MASK_M); |
655 | | |
656 | 678k | sine_present_flag = 0; |
657 | 2.23M | for (k = li; k < ui; k++) { |
658 | 1.55M | if ((env >= *ptr_sine_mapped++)) sine_present_flag = 1; |
659 | 1.55M | } |
660 | 2.23M | for (k = li; k < ui; k++) { |
661 | 1.55M | *ptr_alias_red_buf++ = !sine_present_flag; |
662 | | |
663 | 1.55M | if ((k >= ui_noise)) { |
664 | 71.4k | nb_idx++; |
665 | 71.4k | ui_noise = pstr_freq_band_data->freq_band_tbl_noise[nb_idx + 1]; |
666 | 71.4k | tmp_noise_mant = (WORD16)(ptr_noise_floor[nb_idx] & MASK_M); |
667 | 71.4k | tmp_noise_exp = |
668 | 71.4k | (WORD16)(ptr_noise_floor[nb_idx] & MASK_FOR_EXP) - NOISE_EXP_OFFSET; |
669 | 71.4k | } |
670 | | |
671 | 1.55M | if ((k >= ptr_frame_data->max_qmf_subband_aac)) { |
672 | 1.55M | ptr_enrg_orig[2 * c] = tmp_nrg_ref_mant; |
673 | 1.55M | ptr_enrg_orig[2 * c + 1] = tmp_nrg_ref_exp; |
674 | 1.55M | nrg_sine[2 * c] = 0; |
675 | 1.55M | nrg_sine[2 * c + 1] = 0; |
676 | | |
677 | 1.55M | ixheaacd_subbandgain_calc( |
678 | 1.55M | tmp_nrg_ref_mant, tmp_noise_mant, nrg_est[2 * c], |
679 | 1.55M | nrg_est[2 * c + 1], tmp_noise_exp, tmp_nrg_ref_exp, |
680 | 1.55M | sine_present_flag, |
681 | 1.55M | (env >= ptr_sine_mapped_1[c]) ? (FLAG)1 : (FLAG)0, noise_absc_flag, |
682 | 1.55M | &nrg_gain[2 * c], &noise_level_mant[2 * c], &nrg_sine[2 * c], |
683 | 1.55M | pstr_common_tables); |
684 | 1.55M | c++; |
685 | 1.55M | } |
686 | 1.55M | } |
687 | 678k | } |
688 | 69.0k | } |
689 | | |
690 | 51.9k | #define ALIGN_SIZE64(x) ((((x) + 7) >> 3) << 3) |
691 | | |
692 | | IA_ERRORCODE ixheaacd_calc_sbrenvelope( |
693 | | ia_sbr_scale_fact_struct *ptr_sbr_scale_fac, |
694 | | ia_sbr_calc_env_struct *ptr_sbr_calc_env, |
695 | | ia_sbr_header_data_struct *ptr_header_data, |
696 | | ia_sbr_frame_info_data_struct *ptr_frame_data, |
697 | | ia_sbr_prev_frame_data_struct *ptr_frame_data_prev, |
698 | | WORD32 **anal_buf_real_mant, WORD32 **anal_buf_imag_mant, |
699 | | WORD16 *deg_patched, FLAG low_pow_flag, |
700 | | ia_sbr_tables_struct *ptr_sbr_tables, |
701 | | ixheaacd_misc_tables *pstr_common_tables, WORD32 *ptr_qmf_matrix, |
702 | 51.9k | WORD32 audio_object_type) { |
703 | 51.9k | WORD32 i, j, m; |
704 | 51.9k | WORD32 noise_floor_idx; |
705 | 51.9k | WORD32 start_pos, end_pos; |
706 | 51.9k | WORD32 freq_res; |
707 | 51.9k | WORD32 num_env = ptr_frame_data->str_frame_info_details.num_env; |
708 | 51.9k | WORD16 *ptr_border_vec = ptr_frame_data->str_frame_info_details.border_vec; |
709 | 51.9k | IA_ERRORCODE err_code = IA_NO_ERROR; |
710 | 51.9k | WORD16 *ptr_noise_floor; |
711 | 51.9k | ia_freq_band_data_struct *pstr_freq_band_data = |
712 | 51.9k | ptr_header_data->pstr_freq_band_data; |
713 | | |
714 | 51.9k | FLAG noise_absc_flag; |
715 | 51.9k | WORD32 smooth_length; |
716 | | |
717 | 51.9k | const WORD16 *num_sf_bands = pstr_freq_band_data->num_sf_bands; |
718 | 51.9k | const WORD32 num_nf_bands = pstr_freq_band_data->num_nf_bands; |
719 | | |
720 | 51.9k | WORD32 sub_band_start = pstr_freq_band_data->sub_band_start; |
721 | 51.9k | WORD32 sub_band_end = pstr_freq_band_data->sub_band_end; |
722 | | |
723 | 51.9k | WORD16 num_timeslots = ptr_header_data->num_time_slots; |
724 | 51.9k | WORD16 max_cols = ptr_header_data->num_time_slots * 2; |
725 | | |
726 | 51.9k | WORD32 num_sub_bands; |
727 | 51.9k | WORD32 skip_bands; |
728 | 51.9k | WORD32 bands; |
729 | | |
730 | 51.9k | WORD num_cols; |
731 | 51.9k | WORD32 first_start; |
732 | | |
733 | 51.9k | WORD16 *ptr_sbr_lim_gain; |
734 | 51.9k | WORD32 max_sfb_nrg_exp; |
735 | | |
736 | 51.9k | WORD16 *ptr_enrg_orig; |
737 | | |
738 | 51.9k | WORD32 input_e; |
739 | 51.9k | WORD32 ov_adj_e; |
740 | 51.9k | WORD32 adj_e; |
741 | 51.9k | WORD32 output_e; |
742 | 51.9k | WORD32 final_e; |
743 | 51.9k | WORD16 noise_e; |
744 | 51.9k | WORD16 lb_scale; |
745 | | |
746 | 51.9k | WORD16 nrg_est[2 * MAX_FREQ_COEFFS]; |
747 | | |
748 | 51.9k | WORD16 nrg_gain[2 * MAX_FREQ_COEFFS]; |
749 | 51.9k | WORD16 noise_level_mant[2 * MAX_FREQ_COEFFS]; |
750 | 51.9k | WORD16 nrg_sine[2 * MAX_FREQ_COEFFS]; |
751 | | |
752 | 51.9k | WORD8 sine_mapped_matrix[MAX_FREQ_COEFFS]; |
753 | 51.9k | WORD8 alias_red_buf[64]; |
754 | | |
755 | 51.9k | ptr_noise_floor = ptr_frame_data->int_noise_floor; |
756 | | |
757 | 51.9k | ptr_enrg_orig = |
758 | 51.9k | (WORD16 *)((WORD8 *)ptr_frame_data + |
759 | 51.9k | ALIGN_SIZE64(sizeof(ia_sbr_frame_info_data_struct))); |
760 | | |
761 | 51.9k | num_env = ptr_frame_data->str_frame_info_details.num_env; |
762 | 51.9k | ptr_border_vec = ptr_frame_data->str_frame_info_details.border_vec; |
763 | 51.9k | num_sub_bands = (sub_band_end - sub_band_start); |
764 | 51.9k | skip_bands = (ptr_frame_data->max_qmf_subband_aac - sub_band_start); |
765 | | |
766 | 51.9k | ixheaacd_map_sineflags( |
767 | 51.9k | pstr_freq_band_data->freq_band_table[HIGH], |
768 | 51.9k | pstr_freq_band_data->num_sf_bands[HIGH], ptr_frame_data->add_harmonics, |
769 | 51.9k | ptr_sbr_calc_env->harm_flags_prev, |
770 | 51.9k | ptr_frame_data->str_frame_info_details.transient_env, sine_mapped_matrix); |
771 | | |
772 | 51.9k | adj_e = 0; |
773 | 51.9k | { |
774 | 51.9k | WORD16 max_noise; |
775 | 51.9k | WORD32 first_band; |
776 | | |
777 | 51.9k | if (ptr_frame_data_prev->max_qmf_subband_aac > |
778 | 51.9k | ptr_frame_data->max_qmf_subband_aac) |
779 | 5.77k | first_band = (ptr_frame_data_prev->max_qmf_subband_aac - sub_band_start); |
780 | 46.1k | else |
781 | 46.1k | first_band = (ptr_frame_data->max_qmf_subband_aac - sub_band_start); |
782 | | |
783 | 51.9k | max_noise = 0; |
784 | 1.17M | for (i = first_band; i < num_sub_bands; i++) { |
785 | 1.12M | if (ptr_sbr_calc_env->filt_buf_noise_m[i] > max_noise) { |
786 | 80.2k | max_noise = ptr_sbr_calc_env->filt_buf_noise_m[i]; |
787 | 80.2k | } |
788 | 1.12M | } |
789 | 51.9k | adj_e = ((ptr_sbr_calc_env->filt_buf_noise_e - ixheaac_norm32(max_noise)) - |
790 | 51.9k | 16); |
791 | 51.9k | } |
792 | | |
793 | 51.9k | final_e = 0; |
794 | 51.9k | { |
795 | 51.9k | WORD16 *ptr_env_sf_buf = ptr_frame_data->int_env_sf_arr; |
796 | 120k | for (i = 0; i < num_env; i++) { |
797 | 69.0k | WORD32 temp_val; |
798 | | |
799 | 69.0k | max_sfb_nrg_exp = NRG_EXP_OFFSET - SHORT_BITS; |
800 | | |
801 | 69.0k | freq_res = ptr_frame_data->str_frame_info_details.freq_res[i]; |
802 | | |
803 | 747k | for (j = 0; j < num_sf_bands[freq_res]; j++) { |
804 | 678k | temp_val = ((*ptr_env_sf_buf++ & MASK_FOR_EXP)); |
805 | | |
806 | 678k | if ((temp_val > max_sfb_nrg_exp)) { |
807 | 105k | max_sfb_nrg_exp = temp_val; |
808 | 105k | } |
809 | 678k | } |
810 | | |
811 | 69.0k | max_sfb_nrg_exp = (max_sfb_nrg_exp - NRG_EXP_OFFSET); |
812 | | |
813 | 69.0k | temp_val = ((max_sfb_nrg_exp + 13) >> 1); |
814 | | |
815 | 69.0k | if (num_timeslots != 15) { |
816 | 34.0k | if ((ptr_border_vec[i] < SBR_TIME_SLOTS)) { |
817 | 34.0k | if ((temp_val > adj_e)) { |
818 | 28.4k | adj_e = (WORD16)temp_val; |
819 | 28.4k | } |
820 | 34.0k | } |
821 | | |
822 | 34.0k | if ((ptr_border_vec[i + 1] > SBR_TIME_SLOTS)) { |
823 | 0 | if ((temp_val > final_e)) { |
824 | 0 | final_e = (WORD16)temp_val; |
825 | 0 | } |
826 | 0 | } |
827 | 35.0k | } else { |
828 | 35.0k | if ((ptr_border_vec[i] < num_timeslots)) { |
829 | 35.0k | if ((temp_val > adj_e)) { |
830 | 28.0k | adj_e = (WORD16)temp_val; |
831 | 28.0k | } |
832 | 35.0k | } |
833 | | |
834 | 35.0k | if ((ptr_border_vec[i + 1] > num_timeslots)) { |
835 | 0 | if ((temp_val > final_e)) { |
836 | 0 | final_e = (WORD16)temp_val; |
837 | 0 | } |
838 | 0 | } |
839 | 35.0k | } |
840 | 69.0k | } |
841 | 51.9k | } |
842 | | |
843 | 51.9k | m = 0; |
844 | 51.9k | noise_floor_idx = 0; |
845 | | |
846 | 120k | for (i = 0; i < num_env; i++) { |
847 | 69.0k | if (audio_object_type == AOT_ER_AAC_ELD || |
848 | 69.0k | audio_object_type == AOT_ER_AAC_LD) { |
849 | 69.0k | start_pos = ptr_border_vec[i]; |
850 | 69.0k | end_pos = ptr_border_vec[i + 1]; |
851 | 69.0k | } else { |
852 | 0 | start_pos = SBR_TIME_STEP * ptr_border_vec[i]; |
853 | 0 | end_pos = SBR_TIME_STEP * ptr_border_vec[i + 1]; |
854 | 0 | } |
855 | 69.0k | if ((start_pos >= MAX_ENV_COLS) || (end_pos > MAX_ENV_COLS)) |
856 | 0 | return IA_FATAL_ERROR; |
857 | 69.0k | freq_res = ptr_frame_data->str_frame_info_details.freq_res[i]; |
858 | | |
859 | 69.0k | if (noise_floor_idx >= MAX_NOISE_ENVELOPES) return IA_FATAL_ERROR; |
860 | | |
861 | 69.0k | if (ptr_border_vec[i] == |
862 | 69.0k | ptr_frame_data->str_frame_info_details |
863 | 69.0k | .noise_border_vec[noise_floor_idx + 1]) { |
864 | 10.5k | ptr_noise_floor += num_nf_bands; |
865 | 10.5k | noise_floor_idx++; |
866 | 10.5k | } |
867 | | |
868 | 69.0k | if ((i == ptr_frame_data->str_frame_info_details.transient_env) || |
869 | 69.0k | (i == ptr_sbr_calc_env->tansient_env_prev)) { |
870 | 6.34k | noise_absc_flag = 1; |
871 | 6.34k | smooth_length = 0; |
872 | 62.7k | } else { |
873 | 62.7k | noise_absc_flag = 0; |
874 | 62.7k | smooth_length = ((1 - ptr_header_data->smoothing_mode) << 2); |
875 | 62.7k | } |
876 | | |
877 | 69.0k | input_e = 15 - ptr_sbr_scale_fac->hb_scale; |
878 | | |
879 | 69.0k | if (ptr_header_data->interpol_freq) { |
880 | 53.5k | (*ixheaacd_enery_calc_per_subband)( |
881 | 53.5k | start_pos, end_pos, ptr_frame_data->max_qmf_subband_aac, sub_band_end, |
882 | 53.5k | input_e, nrg_est, low_pow_flag, ptr_sbr_tables, ptr_qmf_matrix); |
883 | 53.5k | } else { |
884 | 15.5k | ixheaacd_enery_calc_persfb( |
885 | 15.5k | anal_buf_real_mant, anal_buf_imag_mant, num_sf_bands[freq_res], |
886 | 15.5k | pstr_freq_band_data->freq_band_table[freq_res], start_pos, end_pos, |
887 | 15.5k | ptr_frame_data->max_qmf_subband_aac, input_e, nrg_est, low_pow_flag, |
888 | 15.5k | ptr_sbr_tables); |
889 | 15.5k | } |
890 | | |
891 | 69.0k | if (pstr_freq_band_data->freq_band_table[freq_res][0] < pstr_freq_band_data->sub_band_start) { |
892 | 0 | pstr_freq_band_data->sub_band_start = pstr_freq_band_data->freq_band_table[freq_res][0]; |
893 | 0 | return IA_FATAL_ERROR; |
894 | 0 | } |
895 | | |
896 | 69.0k | ixheaacd_calc_subband_gains( |
897 | 69.0k | pstr_freq_band_data, ptr_frame_data, freq_res, ptr_noise_floor, |
898 | 69.0k | num_sf_bands[freq_res], m, i, sine_mapped_matrix, alias_red_buf, |
899 | 69.0k | ptr_enrg_orig, nrg_sine, nrg_est, nrg_gain, noise_level_mant, |
900 | 69.0k | noise_absc_flag, pstr_common_tables); |
901 | | |
902 | 69.0k | m += num_sf_bands[freq_res]; |
903 | | |
904 | 69.0k | ptr_sbr_lim_gain = |
905 | 69.0k | &ptr_sbr_tables->env_calc_tables_ptr |
906 | 69.0k | ->sbr_lim_gains_m[2 * ptr_header_data->limiter_gains]; |
907 | 69.0k | ixheaacd_noiselimiting(pstr_freq_band_data, skip_bands, ptr_enrg_orig, |
908 | 69.0k | nrg_est, nrg_gain, noise_level_mant, nrg_sine, |
909 | 69.0k | ptr_sbr_lim_gain, noise_absc_flag, |
910 | 69.0k | pstr_common_tables); |
911 | | |
912 | 69.0k | if (low_pow_flag) { |
913 | 0 | ixheaacd_alias_reduction(deg_patched + sub_band_start, nrg_gain, nrg_est, |
914 | 0 | alias_red_buf, num_sub_bands, |
915 | 0 | pstr_common_tables); |
916 | 0 | } |
917 | | |
918 | 69.0k | if (max_cols != 30) { |
919 | 34.0k | if ((start_pos < MAX_COLS)) { |
920 | 34.0k | noise_e = adj_e; |
921 | 34.0k | } else { |
922 | 0 | noise_e = final_e; |
923 | 0 | } |
924 | 35.0k | } else { |
925 | 35.0k | if ((start_pos < max_cols)) { |
926 | 35.0k | noise_e = adj_e; |
927 | 35.0k | } else { |
928 | 0 | noise_e = final_e; |
929 | 0 | } |
930 | 35.0k | } |
931 | | |
932 | 69.0k | bands = num_sub_bands - skip_bands; |
933 | | |
934 | 69.0k | if (low_pow_flag) { |
935 | 0 | (*ixheaacd_conv_ergtoamplitudelp)( |
936 | 0 | bands, noise_e, nrg_sine, nrg_gain, noise_level_mant, |
937 | 0 | (WORD16 *)pstr_common_tables->sqrt_table); |
938 | 0 | } else |
939 | | |
940 | 69.0k | { |
941 | 69.0k | (*ixheaacd_conv_ergtoamplitude)(bands, noise_e, nrg_sine, nrg_gain, |
942 | 69.0k | noise_level_mant, |
943 | 69.0k | (WORD16 *)pstr_common_tables->sqrt_table); |
944 | 69.0k | } |
945 | | |
946 | 69.0k | lb_scale = ixheaac_sub16(15, ptr_sbr_scale_fac->lb_scale); |
947 | | |
948 | 69.0k | ixheaacd_adapt_noise_gain_calc( |
949 | 69.0k | ptr_sbr_calc_env, noise_e, num_sub_bands, skip_bands, nrg_gain, |
950 | 69.0k | noise_level_mant, nrg_sine, start_pos, end_pos, input_e, adj_e, final_e, |
951 | 69.0k | ptr_frame_data->max_qmf_subband_aac, lb_scale, noise_absc_flag, |
952 | 69.0k | smooth_length, anal_buf_real_mant, anal_buf_imag_mant, low_pow_flag, |
953 | 69.0k | ptr_sbr_tables, max_cols); |
954 | 69.0k | } |
955 | | |
956 | 51.9k | first_start = ptr_border_vec[0] * SBR_TIME_STEP; |
957 | 51.9k | { |
958 | 51.9k | WORD32 ov_reserve, reserve; |
959 | | |
960 | 51.9k | ov_reserve = reserve = 0; |
961 | | |
962 | 51.9k | if (audio_object_type != AOT_ER_AAC_ELD) { |
963 | 0 | if (ptr_header_data->channel_mode == PS_STEREO) { |
964 | 0 | ov_reserve = (*ixheaacd_ixheaacd_expsubbandsamples)( |
965 | 0 | anal_buf_real_mant, anal_buf_imag_mant, |
966 | 0 | ptr_frame_data->max_qmf_subband_aac, sub_band_end, 0, first_start, |
967 | 0 | low_pow_flag); |
968 | |
|
969 | 0 | if (max_cols != 30) { |
970 | 0 | reserve = (*ixheaacd_ixheaacd_expsubbandsamples)( |
971 | 0 | anal_buf_real_mant, anal_buf_imag_mant, |
972 | 0 | ptr_frame_data->max_qmf_subband_aac, sub_band_end, first_start, |
973 | 0 | MAX_COLS, low_pow_flag); |
974 | 0 | } else { |
975 | 0 | reserve = (*ixheaacd_ixheaacd_expsubbandsamples)( |
976 | 0 | anal_buf_real_mant, anal_buf_imag_mant, |
977 | 0 | ptr_frame_data->max_qmf_subband_aac, sub_band_end, first_start, |
978 | 0 | max_cols, low_pow_flag); |
979 | 0 | } |
980 | 0 | } |
981 | 0 | } |
982 | | |
983 | 51.9k | output_e = 0; |
984 | | |
985 | 51.9k | ov_adj_e = 15 - ptr_sbr_scale_fac->ov_hb_scale; |
986 | | |
987 | 51.9k | if (((ov_adj_e - ov_reserve) > (adj_e - reserve))) |
988 | 28 | output_e = (ov_adj_e - ov_reserve); |
989 | 51.9k | else |
990 | 51.9k | output_e = (adj_e - reserve); |
991 | | |
992 | 51.9k | (*ixheaacd_adjust_scale)(anal_buf_real_mant, anal_buf_imag_mant, |
993 | 51.9k | ptr_frame_data->max_qmf_subband_aac, sub_band_end, |
994 | 51.9k | 0, first_start, (ov_adj_e - output_e), |
995 | 51.9k | low_pow_flag); |
996 | | |
997 | 51.9k | num_cols = (ptr_header_data->num_time_slots * ptr_header_data->time_step); |
998 | | |
999 | 51.9k | (*ixheaacd_adjust_scale)(anal_buf_real_mant, anal_buf_imag_mant, |
1000 | 51.9k | ptr_frame_data->max_qmf_subband_aac, sub_band_end, |
1001 | 51.9k | first_start, num_cols, (adj_e - output_e), |
1002 | 51.9k | low_pow_flag); |
1003 | 51.9k | } |
1004 | | |
1005 | 51.9k | ptr_sbr_scale_fac->hb_scale = (WORD16)(15 - output_e); |
1006 | | |
1007 | 51.9k | ptr_sbr_scale_fac->ov_hb_scale = (WORD16)(15 - final_e); |
1008 | | |
1009 | 51.9k | if (ptr_frame_data->str_frame_info_details.transient_env == num_env) { |
1010 | 0 | ptr_sbr_calc_env->tansient_env_prev = 0; |
1011 | 51.9k | } else { |
1012 | 51.9k | ptr_sbr_calc_env->tansient_env_prev = -1; |
1013 | 51.9k | } |
1014 | 51.9k | return err_code; |
1015 | 51.9k | } |
1016 | | |
1017 | | VOID ixheaacd_equalize_filt_buff_exp(WORD16 *ptr_filt_buf, WORD16 *nrg_gain, |
1018 | 47.3k | WORD32 subbands) { |
1019 | 47.3k | WORD32 band; |
1020 | 47.3k | WORD32 diff; |
1021 | 47.3k | WORD32 gain_m, gain_e; |
1022 | 47.3k | WORD32 filt_buf_mant, filt_buf_exp; |
1023 | | |
1024 | 1.09M | for (band = subbands - 1; band >= 0; band--) { |
1025 | 1.04M | filt_buf_exp = *(ptr_filt_buf + 1); |
1026 | 1.04M | gain_e = *(nrg_gain + 1); |
1027 | 1.04M | filt_buf_mant = *ptr_filt_buf; |
1028 | 1.04M | gain_m = *nrg_gain; |
1029 | 1.04M | diff = (gain_e - filt_buf_exp); |
1030 | | |
1031 | 1.04M | if (diff >= 0) { |
1032 | 549k | *(ptr_filt_buf + 1) = (WORD16)(gain_e); |
1033 | | |
1034 | 549k | *ptr_filt_buf = (WORD16)(*ptr_filt_buf >> diff); |
1035 | 549k | } else { |
1036 | 498k | WORD32 reserve; |
1037 | 498k | reserve = (ixheaac_norm32(filt_buf_mant) - 16); |
1038 | | |
1039 | 498k | if ((diff + reserve) >= 0) { |
1040 | 164k | *ptr_filt_buf = (WORD16)(filt_buf_mant << -diff); |
1041 | 164k | *(ptr_filt_buf + 1) = (WORD16)(filt_buf_exp + diff); |
1042 | 333k | } else { |
1043 | 333k | WORD32 shift; |
1044 | | |
1045 | 333k | *ptr_filt_buf = (WORD16)(filt_buf_mant << reserve); |
1046 | | |
1047 | 333k | *(ptr_filt_buf + 1) = (WORD16)(filt_buf_exp - reserve); |
1048 | | |
1049 | 333k | shift = -(reserve + diff); |
1050 | | |
1051 | 333k | *nrg_gain = (WORD16)(gain_m >> shift); |
1052 | 333k | *(nrg_gain + 1) = (WORD16)(*(nrg_gain + 1) + shift); |
1053 | 333k | } |
1054 | 498k | } |
1055 | 1.04M | nrg_gain += 2; |
1056 | 1.04M | ptr_filt_buf += 2; |
1057 | 1.04M | } |
1058 | 47.3k | } |
1059 | | |
1060 | | VOID ixheaacd_filt_buf_update(WORD16 *ptr_filt_buf, |
1061 | | WORD16 *ptr_filt_buf_noise, |
1062 | | WORD16 *nrg_gain, |
1063 | | WORD16 *noise_level_mant, |
1064 | 69.0k | WORD32 num_sub_bands) { |
1065 | 69.0k | WORD32 k; |
1066 | 69.0k | WORD32 temp1, temp2; |
1067 | | |
1068 | 1.62M | for (k = num_sub_bands - 1; k >= 0; k--) { |
1069 | 1.55M | temp1 = *nrg_gain; |
1070 | 1.55M | nrg_gain += 2; |
1071 | 1.55M | temp2 = *noise_level_mant; |
1072 | 1.55M | noise_level_mant += 2; |
1073 | | |
1074 | 1.55M | *ptr_filt_buf = temp1; |
1075 | 1.55M | ptr_filt_buf += 2; |
1076 | 1.55M | *ptr_filt_buf_noise++ = temp2; |
1077 | 1.55M | } |
1078 | 69.0k | } |
1079 | | |
1080 | | VOID ixheaacd_noise_level_rescaling(WORD16 *noise_level_mant, WORD32 diff, |
1081 | | WORD32 num_sub_bands, |
1082 | 805k | WORD32 ixheaacd_drc_offset) { |
1083 | 805k | WORD32 k; |
1084 | | |
1085 | 805k | if (diff > 0) { |
1086 | 138k | for (k = num_sub_bands - 1; k >= 0; k--) { |
1087 | 132k | *noise_level_mant = *noise_level_mant >> diff; |
1088 | 132k | noise_level_mant += ixheaacd_drc_offset; |
1089 | 132k | } |
1090 | 798k | } else if (diff < 0) { |
1091 | 4.37k | diff = -diff; |
1092 | 100k | for (k = num_sub_bands - 1; k >= 0; k--) { |
1093 | 96.3k | *noise_level_mant = *noise_level_mant << diff; |
1094 | 96.3k | noise_level_mant += ixheaacd_drc_offset; |
1095 | 96.3k | } |
1096 | 4.37k | } |
1097 | 805k | } |
1098 | | |
1099 | | VOID ixheaacd_adjust_scale_dec(WORD32 **re, WORD32 **im, WORD32 sub_band_start, |
1100 | | WORD32 sub_band_end, WORD32 start_pos, |
1101 | | WORD32 next_pos, WORD32 shift, |
1102 | 408k | FLAG low_pow_flag) { |
1103 | 408k | WORD32 k, l; |
1104 | | |
1105 | 408k | if (shift != 0) { |
1106 | 299k | WORD32 num_sub_bands = (sub_band_end - sub_band_start); |
1107 | | |
1108 | 299k | shift = ixheaac_min32(shift, 31); |
1109 | 299k | shift = ixheaac_max32(shift, -31); |
1110 | | |
1111 | 299k | if (low_pow_flag) { |
1112 | 0 | if (shift > 0) { |
1113 | 0 | for (l = start_pos; l < next_pos; l++) { |
1114 | 0 | WORD32 *ptr = re[l] + sub_band_start; |
1115 | 0 | for (k = num_sub_bands - 1; k >= 0; k--) { |
1116 | 0 | *ptr = (*ptr << shift); |
1117 | 0 | ptr++; |
1118 | 0 | } |
1119 | 0 | } |
1120 | 0 | } else { |
1121 | 0 | shift = -shift; |
1122 | 0 | for (l = start_pos; l < next_pos; l++) { |
1123 | 0 | WORD32 *ptr = re[l] + sub_band_start; |
1124 | 0 | for (k = num_sub_bands - 1; k >= 0; k--) { |
1125 | 0 | *ptr = (*ptr >> shift); |
1126 | 0 | ptr++; |
1127 | 0 | } |
1128 | 0 | } |
1129 | 0 | } |
1130 | 299k | } else { |
1131 | 299k | if (shift > 0) { |
1132 | 982k | for (l = start_pos; l < next_pos; l++) { |
1133 | 896k | WORD32 *ptr = re[l] + sub_band_start; |
1134 | 896k | WORD32 *pti = im[l] + sub_band_start; |
1135 | 19.8M | for (k = num_sub_bands; k > 0; k--) { |
1136 | 18.9M | *ptr = (*ptr << shift); |
1137 | 18.9M | *pti = (*pti << shift); |
1138 | 18.9M | pti++; |
1139 | 18.9M | ptr++; |
1140 | 18.9M | } |
1141 | 896k | } |
1142 | 213k | } else { |
1143 | 213k | shift = -shift; |
1144 | 1.97M | for (l = start_pos; l < next_pos; l++) { |
1145 | 1.75M | WORD32 *ptr = re[l] + sub_band_start; |
1146 | 1.75M | WORD32 *pti = im[l] + sub_band_start; |
1147 | 40.0M | for (k = num_sub_bands; k > 0; k--) { |
1148 | 38.3M | *ptr = (*ptr >> shift); |
1149 | 38.3M | *pti = (*pti >> shift); |
1150 | 38.3M | ptr++; |
1151 | 38.3M | pti++; |
1152 | 38.3M | } |
1153 | 1.75M | } |
1154 | 213k | } |
1155 | 299k | } |
1156 | 299k | } |
1157 | 408k | } |
1158 | | |
1159 | | WORD16 ixheaacd_expsubbandsamples_dec(WORD32 **re, WORD32 **im, |
1160 | | WORD32 sub_band_start, |
1161 | | WORD32 sub_band_end, WORD32 start_pos, |
1162 | 297k | WORD32 next_pos, FLAG low_pow_flag) { |
1163 | 297k | WORD32 l, k; |
1164 | 297k | WORD16 max_shift; |
1165 | | |
1166 | 297k | WORD32 value; |
1167 | 297k | WORD32 max_abs; |
1168 | 297k | WORD32 num_sub_bands; |
1169 | | |
1170 | 297k | WORD32 *ptr_real; |
1171 | 297k | WORD32 *ptr_imag; |
1172 | | |
1173 | 297k | max_abs = 1; |
1174 | 297k | num_sub_bands = (sub_band_end - sub_band_start); |
1175 | | |
1176 | 297k | if (low_pow_flag) { |
1177 | 0 | for (l = start_pos; l < next_pos; l++) { |
1178 | 0 | WORD32 temp_real; |
1179 | 0 | ptr_real = re[l] + sub_band_start; |
1180 | 0 | temp_real = *ptr_real++; |
1181 | 0 | for (k = num_sub_bands; k > 0; k--) { |
1182 | 0 | value = ixheaac_abs32_nrm(temp_real); |
1183 | 0 | max_abs |= value; |
1184 | 0 | temp_real = *ptr_real++; |
1185 | 0 | } |
1186 | 0 | } |
1187 | 0 | max_shift = ixheaac_pnorm32(max_abs); |
1188 | 297k | } else { |
1189 | 3.38M | for (l = start_pos; l < next_pos; l++) { |
1190 | 3.08M | ptr_real = re[l] + sub_band_start; |
1191 | 3.08M | ptr_imag = im[l] + sub_band_start; |
1192 | | |
1193 | 28.1M | for (k = num_sub_bands; k > 0; k--) { |
1194 | 25.0M | WORD32 temp_real = *ptr_real++; |
1195 | 25.0M | WORD32 tempIm = *ptr_imag++; |
1196 | | |
1197 | 25.0M | temp_real = ixheaac_abs32_nrm(temp_real); |
1198 | 25.0M | max_abs |= temp_real; |
1199 | 25.0M | tempIm = ixheaac_abs32_nrm(tempIm); |
1200 | 25.0M | max_abs |= tempIm; |
1201 | 25.0M | } |
1202 | 3.08M | } |
1203 | 297k | max_shift = ixheaac_pnorm32(max_abs); |
1204 | 297k | } |
1205 | | |
1206 | 297k | return max_shift; |
1207 | 297k | } |
1208 | | |
1209 | 226k | #define SHIFT_BEFORE_SQUARE 4 |
1210 | | |
1211 | | VOID ixheaacd_enery_calc_per_subband_dec(WORD32 start_pos, WORD32 next_pos, |
1212 | | WORD32 sub_band_start, |
1213 | | WORD32 sub_band_end, WORD32 frame_exp, |
1214 | | WORD16 *nrg_est, FLAG low_pow_flag, |
1215 | | ia_sbr_tables_struct *ptr_sbr_tables, |
1216 | 53.5k | WORD32 *ptr_qmf_matrix) { |
1217 | 53.5k | WORD16 temp; |
1218 | 53.5k | WORD16 inv_width; |
1219 | 53.5k | WORD16 sum_m; |
1220 | 53.5k | WORD32 accu; |
1221 | 53.5k | WORD32 k, l; |
1222 | 53.5k | WORD32 pre_shift_val; |
1223 | 53.5k | WORD32 shift; |
1224 | 53.5k | WORD32 *p_real; |
1225 | 53.5k | WORD32 max_shift_gap = SHIFT_BEFORE_SQUARE; |
1226 | 53.5k | WORD32 extra_shift = 0; |
1227 | 53.5k | WORD32 num_cols = next_pos - start_pos; |
1228 | | |
1229 | 53.5k | if (low_pow_flag) { |
1230 | 0 | max_shift_gap -= 1; |
1231 | 0 | p_real = ptr_qmf_matrix + sub_band_start + (start_pos << 6); |
1232 | 0 | extra_shift++; |
1233 | 53.5k | } else { |
1234 | 53.5k | p_real = ptr_qmf_matrix + sub_band_start + (start_pos << 7); |
1235 | 53.5k | num_cols = num_cols << 1; |
1236 | 53.5k | } |
1237 | 53.5k | inv_width = ptr_sbr_tables->env_calc_tables_ptr |
1238 | 53.5k | ->sbr_inv_int_table[(next_pos - start_pos)]; |
1239 | 53.5k | frame_exp = (frame_exp << 1); |
1240 | | |
1241 | 53.5k | { |
1242 | 53.5k | WORD32 *ptr; |
1243 | 1.24M | for (k = sub_band_start; k < sub_band_end; k++) { |
1244 | 1.18M | WORD32 max_val = 1; |
1245 | | |
1246 | 1.18M | ptr = p_real; |
1247 | | |
1248 | 15.0M | for (l = num_cols; l != 0; l -= 2) { |
1249 | 13.9M | WORD32 value = ixheaac_abs32_nrm(*ptr); |
1250 | 13.9M | ptr += 64; |
1251 | 13.9M | max_val = ixheaac_max32(value, max_val); |
1252 | 13.9M | value = ixheaac_abs32_nrm(*ptr); |
1253 | 13.9M | ptr += 64; |
1254 | 13.9M | max_val = ixheaac_max32(value, max_val); |
1255 | 13.9M | } |
1256 | 1.18M | pre_shift_val = (ixheaac_pnorm32(max_val) - max_shift_gap); |
1257 | | |
1258 | 1.18M | accu = 0L; |
1259 | 1.18M | shift = 16 - pre_shift_val; |
1260 | 1.18M | ptr = p_real; |
1261 | | |
1262 | 1.18M | if (shift > 0) |
1263 | 11.4M | for (l = num_cols; l != 0; l -= 2) { |
1264 | 10.6M | temp = (WORD16)((*(ptr) >> shift)); |
1265 | 10.6M | ptr += 64; |
1266 | 10.6M | accu += (temp * temp); |
1267 | 10.6M | temp = (WORD16)((*(ptr) >> shift)); |
1268 | 10.6M | ptr += 64; |
1269 | 10.6M | accu += (temp * temp); |
1270 | 10.6M | } |
1271 | 369k | else |
1272 | 3.63M | for (l = num_cols; l != 0; l -= 2) { |
1273 | 3.26M | temp = (WORD16)((*(ptr) << (-shift))); |
1274 | 3.26M | ptr += 64; |
1275 | 3.26M | accu += (temp * temp); |
1276 | 3.26M | temp = (WORD16)((*(ptr) << (-shift))); |
1277 | 3.26M | ptr += 64; |
1278 | 3.26M | accu += (temp * temp); |
1279 | 3.26M | } |
1280 | | |
1281 | 1.18M | if (accu != 0L) { |
1282 | 822k | shift = -(ixheaac_pnorm32(accu)); |
1283 | 822k | sum_m = (WORD16)(ixheaac_shr32_dir_sat_limit(accu, (16 + shift))); |
1284 | 822k | *nrg_est++ = ixheaac_mult16_shl_sat(sum_m, inv_width); |
1285 | 822k | shift = (shift - (pre_shift_val << 1)); |
1286 | 822k | shift += extra_shift; |
1287 | 822k | *nrg_est++ = (WORD16)(frame_exp + shift + 1); |
1288 | 822k | } else { |
1289 | 367k | *nrg_est++ = 0; |
1290 | 367k | *nrg_est++ = 0; |
1291 | 367k | } |
1292 | | |
1293 | 1.18M | p_real++; |
1294 | 1.18M | } |
1295 | 53.5k | } |
1296 | 53.5k | } |
1297 | | |
1298 | | VOID ixheaacd_enery_calc_persfb(WORD32 **anal_buf_real, WORD32 **anal_buf_imag, |
1299 | | WORD32 num_sf_bands, WORD16 *freq_band_table, |
1300 | | WORD32 start_pos, WORD32 next_pos, |
1301 | | WORD32 max_qmf_subband_aac, WORD32 frame_exp, |
1302 | | WORD16 *nrg_est, FLAG low_pow_flag, |
1303 | 15.5k | ia_sbr_tables_struct *ptr_sbr_tables) { |
1304 | 15.5k | WORD16 inv_width; |
1305 | 15.5k | WORD32 pre_shift_val; |
1306 | 15.5k | WORD32 shift; |
1307 | 15.5k | WORD32 sum_e; |
1308 | 15.5k | WORD16 sum_m; |
1309 | | |
1310 | 15.5k | WORD32 j, k, l; |
1311 | 15.5k | WORD32 li, ui; |
1312 | 15.5k | WORD32 accu_line; |
1313 | 15.5k | WORD32 accumulate; |
1314 | 15.5k | WORD32 extra_shift = 10; |
1315 | | |
1316 | 15.5k | inv_width = ptr_sbr_tables->env_calc_tables_ptr |
1317 | 15.5k | ->sbr_inv_int_table[(next_pos - start_pos)]; |
1318 | | |
1319 | 15.5k | frame_exp = (frame_exp << 1); |
1320 | | |
1321 | 15.5k | if (low_pow_flag) extra_shift++; |
1322 | | |
1323 | 188k | for (j = 0; j < num_sf_bands; j++) { |
1324 | 172k | li = freq_band_table[j]; |
1325 | | |
1326 | 172k | if ((li >= max_qmf_subband_aac)) { |
1327 | 172k | ui = freq_band_table[j + 1]; |
1328 | | |
1329 | 172k | pre_shift_val = (*ixheaacd_ixheaacd_expsubbandsamples)( |
1330 | 172k | anal_buf_real, anal_buf_imag, li, ui, start_pos, next_pos, |
1331 | 172k | low_pow_flag); |
1332 | | |
1333 | 172k | pre_shift_val = (pre_shift_val - SHIFT_BEFORE_SQUARE); |
1334 | | |
1335 | 172k | accumulate = 0; |
1336 | | |
1337 | 539k | for (k = li; k < ui; k++) { |
1338 | 366k | WORD32 pre_shift1 = (16 - pre_shift_val); |
1339 | 366k | accu_line = 0L; |
1340 | 366k | pre_shift1 = min(pre_shift1, 31); |
1341 | 366k | { |
1342 | 366k | WORD32 *ptr = &anal_buf_real[start_pos][k]; |
1343 | 366k | WORD32 inc = !low_pow_flag; |
1344 | 8.92M | for (l = (next_pos - start_pos) << inc; l != 0; l--) { |
1345 | 8.55M | WORD16 temp; |
1346 | 8.55M | temp = ixheaac_extract16l(ixheaac_shr32_dir(*ptr, pre_shift1)); |
1347 | 8.55M | ptr += 64; |
1348 | 8.55M | accu_line = ixheaac_mac16x16in32_sat(accu_line, temp, temp); |
1349 | 8.55M | } |
1350 | 366k | } |
1351 | 366k | accumulate = |
1352 | 366k | ixheaac_add32_sat(accumulate, ixheaac_shr32(accu_line, 9)); |
1353 | 366k | } |
1354 | | |
1355 | 172k | shift = ixheaac_pnorm32(accumulate); |
1356 | | |
1357 | 172k | sum_m = ixheaac_extract16l( |
1358 | 172k | ixheaac_shr32_dir_sat_limit(accumulate, (16 - shift))); |
1359 | | |
1360 | 172k | if (sum_m == 0) { |
1361 | 50.4k | sum_e = 0; |
1362 | 122k | } else { |
1363 | 122k | sum_m = ixheaac_mult16_shl_sat(sum_m, inv_width); |
1364 | | |
1365 | 122k | sum_m = ixheaac_mult16_shl_sat( |
1366 | 122k | sum_m, |
1367 | 122k | ptr_sbr_tables->env_calc_tables_ptr->sbr_inv_int_table[ui - li]); |
1368 | | |
1369 | 122k | sum_e = ((frame_exp + extra_shift) - shift); |
1370 | | |
1371 | 122k | sum_e = (sum_e - (pre_shift_val << 1)); |
1372 | 122k | } |
1373 | | |
1374 | 539k | for (k = li; k < ui; k++) { |
1375 | 366k | *nrg_est++ = sum_m; |
1376 | 366k | *nrg_est++ = (WORD16)sum_e; |
1377 | 366k | } |
1378 | 172k | } |
1379 | 172k | } |
1380 | 15.5k | } |
1381 | | |
1382 | | VOID ixheaacd_subbandgain_calc(WORD16 e_orig_mant_matrix, WORD16 tmp_noise_mant, |
1383 | | WORD16 nrg_est_mant, WORD16 nrg_est_exp, |
1384 | | WORD16 tmp_noise_exp, WORD16 nrg_ref_exp, |
1385 | | FLAG sine_present_flag, FLAG sine_mapped_matrix, |
1386 | | FLAG noise_absc_flag, WORD16 *ptr_nrg_gain_mant, |
1387 | | WORD16 *ptr_noise_floor_mant, |
1388 | | WORD16 *ptr_nrg_sine_m, |
1389 | 1.55M | ixheaacd_misc_tables *pstr_common_tables) { |
1390 | 1.55M | WORD16 var1_mant; |
1391 | 1.55M | WORD16 var1_exp; |
1392 | 1.55M | WORD16 var2_mant; |
1393 | 1.55M | WORD16 var2_exp; |
1394 | 1.55M | WORD16 var3_mant; |
1395 | 1.55M | WORD16 var3_exp; |
1396 | 1.55M | WORD32 temp; |
1397 | | |
1398 | 1.55M | if (nrg_est_mant == 0) { |
1399 | 488k | nrg_est_mant = 0x4000; |
1400 | 488k | nrg_est_exp = 1; |
1401 | 488k | } |
1402 | | |
1403 | 1.55M | var1_mant = ixheaac_mult16_shl_sat(e_orig_mant_matrix, tmp_noise_mant); |
1404 | 1.55M | var1_exp = (nrg_ref_exp + tmp_noise_exp); |
1405 | | |
1406 | 1.55M | { |
1407 | 1.55M | WORD32 accu, exp_diff; |
1408 | | |
1409 | 1.55M | exp_diff = tmp_noise_exp - 1; |
1410 | | |
1411 | 1.55M | if (exp_diff >= 0) { |
1412 | 911k | accu = tmp_noise_mant + ixheaac_shr32(0x4000, exp_diff); |
1413 | 911k | var2_exp = tmp_noise_exp; |
1414 | 911k | } else { |
1415 | 644k | exp_diff = -exp_diff; |
1416 | 644k | accu = ixheaac_shr32((WORD32)tmp_noise_mant, exp_diff) + 0x4000; |
1417 | 644k | var2_exp = 1; |
1418 | 644k | } |
1419 | 1.55M | if (ixheaac_abs32(accu) >= 0x8000) { |
1420 | 20.9k | accu = accu >> 1; |
1421 | 20.9k | var2_exp++; |
1422 | 20.9k | } |
1423 | 1.55M | var2_mant = (WORD16)(accu); |
1424 | 1.55M | } |
1425 | | |
1426 | 1.55M | temp = ixheaacd_fix_mant_div(var1_mant, var2_mant, ptr_noise_floor_mant, |
1427 | 1.55M | pstr_common_tables); |
1428 | 1.55M | *(ptr_noise_floor_mant + 1) = temp + (var1_exp - var2_exp) + 1; |
1429 | | |
1430 | 1.55M | if (sine_present_flag || !noise_absc_flag) { |
1431 | 1.43M | var3_mant = ixheaac_mult16_shl_sat(var2_mant, nrg_est_mant); |
1432 | 1.43M | var3_exp = (var2_exp + nrg_est_exp); |
1433 | 1.43M | } else { |
1434 | 119k | var3_mant = nrg_est_mant; |
1435 | 119k | var3_exp = nrg_est_exp; |
1436 | 119k | } |
1437 | | |
1438 | 1.55M | if (sine_present_flag == 0) { |
1439 | 1.45M | var1_mant = e_orig_mant_matrix; |
1440 | 1.45M | var1_exp = nrg_ref_exp; |
1441 | 1.45M | } |
1442 | | |
1443 | 1.55M | temp = ixheaacd_fix_mant_div(var1_mant, var3_mant, ptr_nrg_gain_mant, |
1444 | 1.55M | pstr_common_tables); |
1445 | 1.55M | *(ptr_nrg_gain_mant + 1) = temp + (var1_exp - var3_exp) + 1; |
1446 | | |
1447 | 1.55M | if (sine_present_flag && sine_mapped_matrix) { |
1448 | 43.6k | temp = ixheaacd_fix_mant_div(e_orig_mant_matrix, var2_mant, ptr_nrg_sine_m, |
1449 | 43.6k | pstr_common_tables); |
1450 | 43.6k | *(ptr_nrg_sine_m + 1) = temp + (nrg_ref_exp - var2_exp) + 1; |
1451 | 43.6k | } |
1452 | 1.55M | } |
1453 | | |
1454 | | VOID ixheaacd_avggain_calc(WORD16 *ptr_enrg_orig, WORD16 *nrg_est, |
1455 | | WORD32 sub_band_start, WORD32 sub_band_end, |
1456 | | WORD16 *ptr_enrg_orig_mant, WORD16 *ptr_sum_ref_exp, |
1457 | | WORD16 *ptr_avg_gain_mant, WORD16 *ptr_avg_gain_exp, |
1458 | | ixheaacd_misc_tables *pstr_common_tables, |
1459 | 192k | WORD32 flag) { |
1460 | 192k | WORD16 sum_orig_mant; |
1461 | 192k | WORD16 sum_orig_exp; |
1462 | 192k | WORD16 sum_est_mant; |
1463 | 192k | WORD16 sum_est_exp; |
1464 | | |
1465 | 192k | WORD32 accu_sum_orig_mant; |
1466 | 192k | WORD32 accu_sum_orig_exp; |
1467 | 192k | WORD32 accu_sum_est_mant; |
1468 | 192k | WORD32 accu_sum_est_exp; |
1469 | | |
1470 | 192k | WORD32 k, temp; |
1471 | 192k | WORD16 *ptr_enrg_orig_buf; |
1472 | 192k | WORD16 *ptr_enrg_est_buf; |
1473 | | |
1474 | 192k | { |
1475 | 192k | accu_sum_orig_mant = 0; |
1476 | 192k | accu_sum_orig_exp = 0; |
1477 | | |
1478 | 192k | accu_sum_est_mant = 0; |
1479 | 192k | accu_sum_est_exp = 0; |
1480 | 192k | } |
1481 | | |
1482 | 192k | ptr_enrg_orig_buf = &ptr_enrg_orig[sub_band_start << 1]; |
1483 | 192k | ptr_enrg_est_buf = &nrg_est[sub_band_start << 1]; |
1484 | | |
1485 | 1.73M | for (k = sub_band_end - sub_band_start; k != 0; k--) { |
1486 | 1.53M | WORD16 tmp_mant, tmp_e; |
1487 | 1.53M | WORD16 tmp2_m, tmp2_e; |
1488 | | |
1489 | 1.53M | tmp_mant = *ptr_enrg_orig_buf++; |
1490 | 1.53M | tmp_e = *ptr_enrg_orig_buf++; |
1491 | 1.53M | tmp2_m = *ptr_enrg_est_buf++; |
1492 | 1.53M | tmp2_e = *ptr_enrg_est_buf++; |
1493 | 1.53M | { |
1494 | 1.53M | WORD32 exp_diff; |
1495 | 1.53M | exp_diff = tmp_e - accu_sum_orig_exp; |
1496 | 1.53M | if (exp_diff >= 0) { |
1497 | 1.20M | accu_sum_orig_mant = |
1498 | 1.20M | tmp_mant + ixheaac_shr32(accu_sum_orig_mant, exp_diff); |
1499 | 1.20M | accu_sum_orig_exp = tmp_e; |
1500 | 1.20M | } else { |
1501 | 331k | exp_diff = -exp_diff; |
1502 | 331k | accu_sum_orig_mant = |
1503 | 331k | ixheaac_shr32(tmp_mant, exp_diff) + accu_sum_orig_mant; |
1504 | 331k | } |
1505 | 1.53M | } |
1506 | 1.53M | if (flag) { |
1507 | 0 | tmp_mant = (tmp_mant * tmp2_m) >> 16; |
1508 | 0 | tmp_e = (tmp_e + tmp2_e + 1); |
1509 | |
|
1510 | 1.53M | } else { |
1511 | 1.53M | tmp_mant = tmp2_m; |
1512 | 1.53M | tmp_e = tmp2_e; |
1513 | 1.53M | } |
1514 | | |
1515 | 1.53M | { |
1516 | 1.53M | WORD32 exp_diff; |
1517 | 1.53M | exp_diff = tmp_e - accu_sum_est_exp; |
1518 | 1.53M | if (exp_diff >= 0) { |
1519 | 1.13M | accu_sum_est_mant = |
1520 | 1.13M | tmp_mant + ixheaac_shr32(accu_sum_est_mant, exp_diff); |
1521 | 1.13M | accu_sum_est_exp = tmp_e; |
1522 | 1.13M | } else { |
1523 | 407k | exp_diff = -exp_diff; |
1524 | 407k | accu_sum_est_mant = |
1525 | 407k | ixheaac_shr32(tmp_mant, exp_diff) + accu_sum_est_mant; |
1526 | 407k | } |
1527 | 1.53M | } |
1528 | 1.53M | } |
1529 | 192k | { |
1530 | 192k | WORD32 norm_val; |
1531 | 192k | norm_val = 16 - ixheaac_pnorm32(accu_sum_orig_mant); |
1532 | 192k | if (norm_val > 0) { |
1533 | 176k | accu_sum_orig_mant >>= norm_val; |
1534 | 176k | accu_sum_orig_exp += norm_val; |
1535 | 176k | } |
1536 | 192k | norm_val = 16 - ixheaac_pnorm32(accu_sum_est_mant); |
1537 | 192k | if (norm_val > 0) { |
1538 | 2.65k | accu_sum_est_mant >>= norm_val; |
1539 | 2.65k | accu_sum_est_exp += norm_val; |
1540 | 2.65k | } |
1541 | 192k | } |
1542 | | |
1543 | 192k | if (!flag) { |
1544 | 192k | sum_orig_mant = (WORD16)accu_sum_orig_mant; |
1545 | 192k | sum_orig_exp = (WORD16)accu_sum_orig_exp; |
1546 | 192k | sum_est_mant = (WORD16)accu_sum_est_mant; |
1547 | 192k | sum_est_exp = (WORD16)accu_sum_est_exp; |
1548 | 192k | } else { |
1549 | 0 | sum_est_mant = (WORD16)accu_sum_orig_mant; |
1550 | 0 | sum_est_exp = (WORD16)accu_sum_orig_exp; |
1551 | 0 | sum_orig_mant = (WORD16)accu_sum_est_mant; |
1552 | 0 | sum_orig_exp = (WORD16)accu_sum_est_exp; |
1553 | 0 | } |
1554 | | |
1555 | 192k | { |
1556 | 192k | temp = ixheaacd_fix_mant_div(sum_orig_mant, sum_est_mant, ptr_avg_gain_mant, |
1557 | 192k | pstr_common_tables); |
1558 | 192k | *ptr_avg_gain_exp = temp + (sum_orig_exp - sum_est_exp) + 1; |
1559 | 192k | *ptr_enrg_orig_mant = sum_orig_mant; |
1560 | 192k | *ptr_sum_ref_exp = sum_orig_exp; |
1561 | 192k | } |
1562 | 192k | } |
1563 | | |
1564 | | VOID ixheaacd_harm_idx_zerotwolp_dec(WORD32 *ptr_real_buf, WORD16 *ptr_gain_buf, |
1565 | | WORD32 scale_change, |
1566 | | WORD16 *ptr_sine_level_buf, |
1567 | | const WORD32 *ptr_rand_ph, |
1568 | | WORD16 *noise_level_mant, |
1569 | | WORD32 num_sub_bands, FLAG noise_absc_flag, |
1570 | 0 | WORD32 harm_index) { |
1571 | 0 | WORD32 shift, k; |
1572 | 0 | WORD32 signal_real; |
1573 | 0 | WORD32 sine_level; |
1574 | |
|
1575 | 0 | scale_change = scale_change - 1; |
1576 | 0 | if (!noise_absc_flag) { |
1577 | 0 | for (k = 0; k < num_sub_bands; k++) { |
1578 | 0 | signal_real = ixheaac_mult32x16in32(*ptr_real_buf, *ptr_gain_buf++); |
1579 | 0 | shift = (*ptr_gain_buf++ - scale_change); |
1580 | |
|
1581 | 0 | if (shift > 0) |
1582 | 0 | signal_real = (signal_real << shift); |
1583 | 0 | else |
1584 | 0 | signal_real = (signal_real >> -(shift)); |
1585 | |
|
1586 | 0 | sine_level = (ptr_sine_level_buf[2 * k] << 16); |
1587 | |
|
1588 | 0 | if (sine_level == 0) { |
1589 | 0 | *ptr_real_buf++ = ixheaac_mac16x16in32_shl_sat( |
1590 | 0 | signal_real, ixheaac_extract16h(ptr_rand_ph[k]), |
1591 | 0 | noise_level_mant[2 * k]); |
1592 | 0 | } else if (harm_index == 0) |
1593 | 0 | *ptr_real_buf++ = ixheaac_add32_sat(signal_real, sine_level); |
1594 | 0 | else |
1595 | 0 | *ptr_real_buf++ = ixheaac_sub32_sat(signal_real, sine_level); |
1596 | 0 | } |
1597 | 0 | } else { |
1598 | 0 | for (k = 0; k < num_sub_bands; k++) { |
1599 | 0 | signal_real = ixheaac_mult32x16in32(*ptr_real_buf, *ptr_gain_buf++); |
1600 | 0 | shift = (*ptr_gain_buf++ - scale_change); |
1601 | |
|
1602 | 0 | if (shift > 0) |
1603 | 0 | signal_real = (signal_real << shift); |
1604 | 0 | else |
1605 | 0 | signal_real = (signal_real >> -(shift)); |
1606 | |
|
1607 | 0 | sine_level = (ptr_sine_level_buf[2 * k] << 16); |
1608 | |
|
1609 | 0 | if (harm_index == 0) |
1610 | 0 | *ptr_real_buf++ = ixheaac_add32_sat(signal_real, sine_level); |
1611 | 0 | else |
1612 | 0 | *ptr_real_buf++ = ixheaac_sub32_sat(signal_real, sine_level); |
1613 | 0 | } |
1614 | 0 | } |
1615 | 0 | } |
1616 | | |
1617 | | VOID ixheaacd_harm_idx_onethreelp( |
1618 | | WORD32 *ptr_real_buf, WORD16 *ptr_gain_buf, WORD32 scale_change, |
1619 | | WORD16 *ptr_sine_level_buf, const WORD32 *ptr_rand_ph, |
1620 | | WORD16 *noise_level_mant, WORD32 num_sub_bands, FLAG noise_absc_flag, |
1621 | 0 | WORD32 freq_inv_flag, WORD32 noise_e, WORD32 sub_band_start) { |
1622 | 0 | WORD32 shift, k = 0; |
1623 | 0 | WORD32 signal_real, temp_mult, temp_mult2; |
1624 | 0 | WORD16 sine_level, sine_level_prev, sine_level_next; |
1625 | 0 | WORD32 tone_count = 0; |
1626 | 0 | WORD16 tmp; |
1627 | |
|
1628 | 0 | scale_change = scale_change - 1; |
1629 | |
|
1630 | 0 | signal_real = ixheaac_mult32x16in32(*ptr_real_buf, *ptr_gain_buf++); |
1631 | 0 | shift = (*ptr_gain_buf++ - scale_change); |
1632 | |
|
1633 | 0 | if (shift > 0) |
1634 | 0 | signal_real = (signal_real << shift); |
1635 | 0 | else |
1636 | 0 | signal_real = (signal_real >> -(shift)); |
1637 | |
|
1638 | 0 | sine_level = ((ptr_sine_level_buf[2 * 0])); |
1639 | |
|
1640 | 0 | if (num_sub_bands > 1) { |
1641 | 0 | sine_level_next = ((ptr_sine_level_buf[2 * 1])); |
1642 | 0 | } else { |
1643 | 0 | sine_level_next = 0; |
1644 | 0 | } |
1645 | |
|
1646 | 0 | if (ptr_sine_level_buf[2 * 0] != 0) { |
1647 | 0 | tone_count++; |
1648 | 0 | } else { |
1649 | 0 | if (!noise_absc_flag) { |
1650 | 0 | signal_real = ixheaac_mac16x16in32_shl_sat( |
1651 | 0 | signal_real, ixheaac_extract16h(ptr_rand_ph[k]), *noise_level_mant); |
1652 | 0 | } |
1653 | 0 | } |
1654 | |
|
1655 | 0 | noise_level_mant += 2; |
1656 | 0 | temp_mult2 = ixheaac_mult32x16in32(FACTOR, sine_level_next); |
1657 | 0 | temp_mult = ixheaac_mult32x16in32(FACTOR, sine_level); |
1658 | 0 | tmp = noise_e; |
1659 | |
|
1660 | 0 | if (tmp > 0) { |
1661 | 0 | temp_mult = ixheaac_shl32(temp_mult, tmp); |
1662 | 0 | } else { |
1663 | 0 | temp_mult = ixheaac_shr32(temp_mult, -tmp); |
1664 | 0 | } |
1665 | |
|
1666 | 0 | if (freq_inv_flag < 0) { |
1667 | 0 | *(ptr_real_buf - 1) = ixheaac_add32_sat(*(ptr_real_buf - 1), temp_mult); |
1668 | 0 | signal_real = ixheaac_sub32_sat(signal_real, temp_mult2); |
1669 | 0 | } else { |
1670 | 0 | *(ptr_real_buf - 1) = ixheaac_sub32_sat(*(ptr_real_buf - 1), temp_mult); |
1671 | 0 | signal_real = ixheaac_add32_sat(signal_real, temp_mult2); |
1672 | 0 | } |
1673 | 0 | *ptr_real_buf++ = signal_real; |
1674 | |
|
1675 | 0 | num_sub_bands = num_sub_bands - 1; |
1676 | 0 | for (k = 1; k < num_sub_bands; k++) { |
1677 | 0 | WORD16 gain_m = *ptr_gain_buf++; |
1678 | 0 | WORD16 gain_e = *ptr_gain_buf++; |
1679 | 0 | WORD32 q_real = *ptr_real_buf; |
1680 | |
|
1681 | 0 | signal_real = ixheaac_mult32x16in32(q_real, gain_m); |
1682 | |
|
1683 | 0 | if ((shift = (gain_e - scale_change)) >= 0) |
1684 | 0 | signal_real = (signal_real << shift); |
1685 | 0 | else |
1686 | 0 | signal_real = (signal_real >> -(shift)); |
1687 | |
|
1688 | 0 | sine_level_prev = sine_level; |
1689 | 0 | sine_level = sine_level_next; |
1690 | 0 | if (sine_level != 0) { |
1691 | 0 | tone_count++; |
1692 | 0 | } |
1693 | 0 | sine_level_next = (ptr_sine_level_buf[2 * (k + 1)]); |
1694 | |
|
1695 | 0 | if ((!noise_absc_flag) && (sine_level == 0)) { |
1696 | 0 | signal_real = ixheaac_mac16x16in32_shl_sat( |
1697 | 0 | signal_real, ixheaac_extract16h(ptr_rand_ph[k]), *noise_level_mant); |
1698 | 0 | } |
1699 | 0 | noise_level_mant += 2; |
1700 | |
|
1701 | 0 | if (tone_count <= 16) { |
1702 | 0 | WORD32 temp_mult; |
1703 | 0 | WORD32 add_sine = ixheaac_mult32x16in32( |
1704 | 0 | FACTOR, ixheaac_sub16(sine_level_prev, sine_level_next)); |
1705 | 0 | temp_mult = add_sine * freq_inv_flag; |
1706 | 0 | signal_real = ixheaac_add32_sat(signal_real, temp_mult); |
1707 | 0 | } |
1708 | 0 | *ptr_real_buf++ = signal_real; |
1709 | 0 | freq_inv_flag = -(freq_inv_flag); |
1710 | 0 | } |
1711 | |
|
1712 | 0 | freq_inv_flag = (freq_inv_flag + 1) >> 1; |
1713 | |
|
1714 | 0 | if (num_sub_bands > 0) { |
1715 | 0 | WORD32 temp_mult_sine; |
1716 | 0 | signal_real = ixheaac_mult32x16in32(*ptr_real_buf, *ptr_gain_buf++); |
1717 | 0 | shift = (*ptr_gain_buf - scale_change); |
1718 | |
|
1719 | 0 | if (shift > 0) |
1720 | 0 | signal_real = (signal_real << shift); |
1721 | 0 | else |
1722 | 0 | signal_real = (signal_real >> -(shift)); |
1723 | |
|
1724 | 0 | temp_mult_sine = ixheaac_mult32x16in32(FACTOR, sine_level); |
1725 | 0 | sine_level = sine_level_next; |
1726 | |
|
1727 | 0 | if (sine_level != 0) { |
1728 | 0 | tone_count++; |
1729 | 0 | } else { |
1730 | 0 | if (!noise_absc_flag) { |
1731 | 0 | signal_real = ixheaac_mac16x16in32_shl_sat( |
1732 | 0 | signal_real, ixheaac_extract16h(ptr_rand_ph[k]), |
1733 | 0 | *noise_level_mant); |
1734 | 0 | } |
1735 | 0 | } |
1736 | |
|
1737 | 0 | if (tone_count <= 16) { |
1738 | 0 | temp_mult2 = ixheaac_mult32x16in32(FACTOR, sine_level); |
1739 | |
|
1740 | 0 | if (freq_inv_flag) { |
1741 | 0 | *ptr_real_buf++ = ixheaac_add32_sat(signal_real, temp_mult_sine); |
1742 | |
|
1743 | 0 | if ((k + sub_band_start) < 62) { |
1744 | 0 | *ptr_real_buf = ixheaac_sub32_sat(*ptr_real_buf, temp_mult2); |
1745 | 0 | } |
1746 | 0 | } else { |
1747 | 0 | *ptr_real_buf++ = ixheaac_sub32_sat(signal_real, temp_mult_sine); |
1748 | |
|
1749 | 0 | if ((k + sub_band_start) < 62) { |
1750 | 0 | *ptr_real_buf = ixheaac_add32_sat(*ptr_real_buf, temp_mult2); |
1751 | 0 | } |
1752 | 0 | } |
1753 | 0 | } else { |
1754 | 0 | *ptr_real_buf = signal_real; |
1755 | 0 | } |
1756 | 0 | } |
1757 | 0 | } |
1758 | | |
1759 | | VOID ixheaacd_harm_idx_zerotwo(FLAG noise_absc_flag, WORD16 num_sub_bands, |
1760 | | WORD32 *ptr_real_buf, WORD32 *ptr_imag, |
1761 | | WORD16 *smoothed_gain, WORD16 *smoothed_noise, |
1762 | | WORD32 factor, WORD16 *ptr_gain_buf, |
1763 | | WORD16 scale_change, const WORD32 *ptr_rand_ph, |
1764 | | WORD16 *ptr_sine_level_buf, WORD16 noise_e, |
1765 | 403k | WORD32 harm_index) { |
1766 | 403k | WORD32 k; |
1767 | 403k | WORD32 signal_real, sig_imag; |
1768 | 403k | WORD32 shift; |
1769 | 403k | WORD32 sine_level; |
1770 | 403k | ptr_gain_buf++; |
1771 | | |
1772 | 9.51M | for (k = 0; k < num_sub_bands; k++) { |
1773 | 9.11M | signal_real = ixheaac_mult32x16in32(*ptr_real_buf, smoothed_gain[0]); |
1774 | 9.11M | sig_imag = ixheaac_mult32x16in32(*ptr_imag, smoothed_gain[0]); |
1775 | | |
1776 | 9.11M | shift = ixheaac_sub16(*ptr_gain_buf, scale_change); |
1777 | 9.11M | ptr_gain_buf += 2; |
1778 | | |
1779 | 9.11M | if (shift > 0) { |
1780 | 1.90M | signal_real = ixheaac_shl32(signal_real, shift); |
1781 | 1.90M | sig_imag = ixheaac_shl32(sig_imag, shift); |
1782 | 7.21M | } else { |
1783 | 7.21M | shift = -shift; |
1784 | 7.21M | signal_real = ixheaac_shr32(signal_real, shift); |
1785 | 7.21M | sig_imag = ixheaac_shr32(sig_imag, shift); |
1786 | 7.21M | } |
1787 | | |
1788 | 9.11M | ptr_rand_ph++; |
1789 | | |
1790 | 9.11M | if (*ptr_sine_level_buf != 0) { |
1791 | 166k | WORD32 tmp = ixheaac_sub16(ptr_sine_level_buf[1], noise_e); |
1792 | | |
1793 | 166k | if (tmp > 0) |
1794 | 153k | sine_level = ixheaac_shl32(ptr_sine_level_buf[0], tmp); |
1795 | 12.6k | else |
1796 | 12.6k | sine_level = ixheaac_shr32(ptr_sine_level_buf[0], tmp); |
1797 | | |
1798 | 166k | if (harm_index == 0) |
1799 | 81.6k | *ptr_real_buf = ixheaac_add32_sat(signal_real, sine_level); |
1800 | 84.5k | else |
1801 | 84.5k | *ptr_real_buf = ixheaac_sub32_sat(signal_real, sine_level); |
1802 | | |
1803 | 166k | *ptr_imag = sig_imag; |
1804 | 8.94M | } else { |
1805 | 8.94M | if (!noise_absc_flag) { |
1806 | 8.71M | WORD32 random = *ptr_rand_ph; |
1807 | 8.71M | WORD16 noise = smoothed_noise[0]; |
1808 | | |
1809 | 8.71M | *ptr_real_buf = ixheaac_mac16x16in32_shl_sat( |
1810 | 8.71M | signal_real, ixheaac_extract16h(random), noise); |
1811 | 8.71M | *ptr_imag = ixheaac_mac16x16in32_shl_sat( |
1812 | 8.71M | sig_imag, ixheaac_extract16l(random), noise); |
1813 | 8.71M | } else { |
1814 | 231k | *ptr_real_buf = signal_real; |
1815 | 231k | *ptr_imag = sig_imag; |
1816 | 231k | } |
1817 | 8.94M | } |
1818 | | |
1819 | 9.11M | smoothed_noise += factor; |
1820 | 9.11M | smoothed_gain += 2; |
1821 | 9.11M | ptr_sine_level_buf += 2; |
1822 | 9.11M | ptr_real_buf++; |
1823 | 9.11M | ptr_imag++; |
1824 | 9.11M | } |
1825 | 403k | } |
1826 | | |
1827 | | VOID ixheaacd_harm_idx_onethree(FLAG noise_absc_flag, WORD16 num_sub_bands, |
1828 | | WORD32 *ptr_real_buf, WORD32 *ptr_imag, |
1829 | | WORD16 *smoothed_gain, WORD16 *smoothed_noise, |
1830 | | WORD32 factor, WORD16 *ptr_gain_buf, |
1831 | | WORD16 scale_change, const WORD32 *ptr_rand_ph, |
1832 | | WORD16 *ptr_sine_level_buf, WORD16 noise_e, |
1833 | 401k | WORD32 freq_inv_flag, WORD32 harm_index) { |
1834 | 401k | WORD32 k; |
1835 | 401k | WORD32 signal_real, sig_imag; |
1836 | 401k | WORD32 shift; |
1837 | 401k | WORD32 sine_level; |
1838 | | |
1839 | 401k | ptr_gain_buf++; |
1840 | | |
1841 | 401k | if (harm_index == 1) freq_inv_flag = !freq_inv_flag; |
1842 | | |
1843 | 9.46M | for (k = 0; k < num_sub_bands; k++) { |
1844 | 9.06M | signal_real = ixheaac_mult32x16in32(*ptr_real_buf, smoothed_gain[0]); |
1845 | 9.06M | sig_imag = ixheaac_mult32x16in32(*ptr_imag, smoothed_gain[0]); |
1846 | | |
1847 | 9.06M | shift = ixheaac_sub16(*ptr_gain_buf, scale_change); |
1848 | 9.06M | ptr_gain_buf += 2; |
1849 | | |
1850 | 9.06M | if (shift > 0) { |
1851 | 1.90M | signal_real = ixheaac_shl32(signal_real, shift); |
1852 | 1.90M | sig_imag = ixheaac_shl32(sig_imag, shift); |
1853 | 7.15M | } else { |
1854 | 7.15M | shift = -shift; |
1855 | 7.15M | signal_real = ixheaac_shr32(signal_real, shift); |
1856 | 7.15M | sig_imag = ixheaac_shr32(sig_imag, shift); |
1857 | 7.15M | } |
1858 | | |
1859 | 9.06M | ptr_rand_ph++; |
1860 | | |
1861 | 9.06M | if (*ptr_sine_level_buf != 0) { |
1862 | 166k | WORD32 tmp = ixheaac_sub16(ptr_sine_level_buf[1], noise_e); |
1863 | | |
1864 | 166k | if (tmp > 0) |
1865 | 153k | sine_level = ixheaac_shl32(ptr_sine_level_buf[0], tmp); |
1866 | 12.9k | else |
1867 | 12.9k | sine_level = ixheaac_shr32(ptr_sine_level_buf[0], -tmp); |
1868 | | |
1869 | 166k | *ptr_real_buf = signal_real; |
1870 | | |
1871 | 166k | if (freq_inv_flag) { |
1872 | 84.2k | *ptr_imag = ixheaac_add32_sat(sig_imag, sine_level); |
1873 | 84.2k | } else { |
1874 | 82.5k | *ptr_imag = ixheaac_sub32_sat(sig_imag, sine_level); |
1875 | 82.5k | } |
1876 | | |
1877 | 8.89M | } else { |
1878 | 8.89M | if (!noise_absc_flag) { |
1879 | 8.65M | WORD32 random = *ptr_rand_ph; |
1880 | 8.65M | WORD16 noise = smoothed_noise[0]; |
1881 | | |
1882 | 8.65M | *ptr_real_buf = ixheaac_mac16x16in32_shl_sat( |
1883 | 8.65M | signal_real, ixheaac_extract16h(random), noise); |
1884 | 8.65M | *ptr_imag = ixheaac_mac16x16in32_shl_sat( |
1885 | 8.65M | sig_imag, ixheaac_extract16l(random), noise); |
1886 | 8.65M | } else { |
1887 | 239k | *ptr_real_buf = signal_real; |
1888 | 239k | *ptr_imag = sig_imag; |
1889 | 239k | } |
1890 | 8.89M | } |
1891 | | |
1892 | 9.06M | freq_inv_flag = (!freq_inv_flag); |
1893 | 9.06M | smoothed_gain += 2; |
1894 | 9.06M | smoothed_noise += factor; |
1895 | 9.06M | ptr_sine_level_buf += 2; |
1896 | 9.06M | ptr_real_buf++; |
1897 | 9.06M | ptr_imag++; |
1898 | 9.06M | } |
1899 | 401k | } |