/src/libxaac/decoder/ixheaacd_ext_ch_ele.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 <stdio.h> |
21 | | #include <string.h> |
22 | | #include <stdlib.h> |
23 | | #include <setjmp.h> |
24 | | |
25 | | #include "ixheaac_type_def.h" |
26 | | |
27 | | #include "ixheaacd_cnst.h" |
28 | | |
29 | | #include "ixheaacd_bitbuffer.h" |
30 | | |
31 | | #include "ixheaacd_interface.h" |
32 | | #include "ixheaacd_acelp_info.h" |
33 | | |
34 | | #include "ixheaacd_tns_usac.h" |
35 | | #include "ixheaacd_acelp_info.h" |
36 | | |
37 | | #include "ixheaacd_sbrdecsettings.h" |
38 | | #include "ixheaacd_info.h" |
39 | | #include "ixheaacd_sbr_common.h" |
40 | | #include "ixheaacd_drc_data_struct.h" |
41 | | #include "ixheaacd_drc_dec.h" |
42 | | |
43 | | #include "ixheaacd_sbrdecoder.h" |
44 | | #include "ixheaacd_mps_polyphase.h" |
45 | | #include "ixheaac_sbr_const.h" |
46 | | |
47 | | #include "ixheaacd_ec_defines.h" |
48 | | #include "ixheaacd_ec_rom.h" |
49 | | #include "ixheaacd_ec_struct_def.h" |
50 | | #include "ixheaacd_main.h" |
51 | | #include "ixheaacd_arith_dec.h" |
52 | | #include "ixheaacd_tns_usac.h" |
53 | | |
54 | | #include "ixheaacd_bit_extract.h" |
55 | | |
56 | | #include "ixheaac_constants.h" |
57 | | #include "ixheaac_basic_ops32.h" |
58 | | #include "ixheaac_basic_ops40.h" |
59 | | |
60 | | #include "ixheaacd_func_def.h" |
61 | | |
62 | | #include "ixheaacd_defines.h" |
63 | | #include "ixheaacd_windows.h" |
64 | | |
65 | | #include "ixheaacd_vec_baisc_ops.h" |
66 | | #include "ixheaacd_config.h" |
67 | | #include "ixheaacd_defines.h" |
68 | | #include "ixheaacd_aac_rom.h" |
69 | | #include "ixheaacd_pulsedata.h" |
70 | | #include "ixheaacd_pns.h" |
71 | | #include "ixheaacd_channelinfo.h" |
72 | | #include "ixheaacd_ec.h" |
73 | | #include "ixheaacd_error_codes.h" |
74 | | |
75 | | const WORD16 ixheaacd_mdst_fcoeff_long_sin[] = {0, 0, -16384, 0, 16384, 0, 0}; |
76 | | const WORD16 ixheaacd_mdst_fcoeff_long_kbd[] = {-2998, 0, -19052, 0, |
77 | | 19052, 0, 2998}; |
78 | | const WORD16 ixheaacd_mdst_fcoeff_long_sin_kbd[] = {-1499, -1876, -17718, 0, |
79 | | 17718, 1876, 1499}; |
80 | | const WORD16 ixheaacd_mdst_fcoeff_long_kbd_sin[] = {-1499, 1876, -17718, 0, |
81 | | 17718, -1876, 1499}; |
82 | | |
83 | | const WORD16 *const ixheaacd_mdst_fcoeff_longshort_curr[2][2] = { |
84 | | {ixheaacd_mdst_fcoeff_long_sin, ixheaacd_mdst_fcoeff_long_sin_kbd}, |
85 | | {ixheaacd_mdst_fcoeff_long_kbd_sin, ixheaacd_mdst_fcoeff_long_kbd}}; |
86 | | |
87 | | const WORD16 ixheaacd_mdst_fcoeff_start_sin[] = {-3364, -3401, -18584, 0, |
88 | | 18584, 3401, 3364}; |
89 | | const WORD16 ixheaacd_mdst_fcoeff_start_kbd[] = {-4932, -1572, -19942, 0, |
90 | | 19942, 1572, 4932}; |
91 | | const WORD16 ixheaacd_mdst_fcoeff_start_sin_kbd[] = {-3433, -3447, -18608, 0, |
92 | | 18608, 3447, 3433}; |
93 | | const WORD16 ixheaacd_mdst_fcoeff_start_kbd_sin[] = {-4863, -1525, -19918, 0, |
94 | | 19918, 1525, 4863}; |
95 | | |
96 | | const WORD16 *const ixheaacd_mdst_fcoeff_start_curr[2][2] = { |
97 | | {ixheaacd_mdst_fcoeff_start_sin, ixheaacd_mdst_fcoeff_start_sin_kbd}, |
98 | | {ixheaacd_mdst_fcoeff_start_kbd_sin, ixheaacd_mdst_fcoeff_start_kbd}}; |
99 | | |
100 | | const WORD16 ixheaacd_mdst_fcoeff_stop_sin[] = {-3364, 3401, -18584, 0, |
101 | | 18584, -3401, 3364}; |
102 | | const WORD16 ixheaacd_mdst_fcoeff_stop_kbd[] = {-4932, 1572, -19942, 0, |
103 | | 19942, -1572, 4932}; |
104 | | const WORD16 ixheaacd_mdst_fcoeff_stop_sin_kbd[] = {-4863, 1525, -19918, 0, |
105 | | 19918, -1525, 4863}; |
106 | | const WORD16 ixheaacd_mdst_fcoeff_stop_kbd_sin[] = {-3433, 3447, -18608, 0, |
107 | | 18608, -3447, 3433}; |
108 | | |
109 | | const WORD16 *const ixheaacd_mdst_fcoeff_stop_cur[2][2] = { |
110 | | {ixheaacd_mdst_fcoeff_stop_sin, ixheaacd_mdst_fcoeff_stop_sin_kbd}, |
111 | | {ixheaacd_mdst_fcoeff_stop_kbd_sin, ixheaacd_mdst_fcoeff_stop_kbd}}; |
112 | | |
113 | | const WORD16 ixheaacd_mdst_fcoeff_stopstart_sin[] = {-6728, 0, -20785, 0, |
114 | | 20785, 0, 6728}; |
115 | | const WORD16 ixheaacd_mdst_fcoeff_stopstart_kbd[] = {-6866, -0, -20831, 0, |
116 | | 20831, 0, 6866}; |
117 | | const WORD16 ixheaacd_mdst_fcoeff_stopstart_sin_kbd[] = {-6797, -46, -20808, 0, |
118 | | 20808, 46, 6797}; |
119 | | const WORD16 ixheaacd_mdst_fcoeff_stopstart_kbd_sin[] = {-6797, 46, -20808, 0, |
120 | | 20808, 46, 6797}; |
121 | | |
122 | | const WORD16 *const ixheaacd_mdst_fcoeff_stopstart_cur[2][2] = { |
123 | | {ixheaacd_mdst_fcoeff_stopstart_sin, |
124 | | ixheaacd_mdst_fcoeff_stopstart_sin_kbd}, |
125 | | {ixheaacd_mdst_fcoeff_stopstart_kbd_sin, |
126 | | ixheaacd_mdst_fcoeff_stopstart_kbd}}; |
127 | | |
128 | | const WORD16 ixheaacd_mdst_fcoeff_l_s_start_left_sin[] = { |
129 | | -0, 3477, 8192, 10430, 8192, 3477, -0}; |
130 | | const WORD16 ixheaacd_mdst_fcoeff_l_s_start_left_kbd[] = { |
131 | | 1950, 4054, 6114, 6982, 6114, 4054, 1950}; |
132 | | |
133 | | const WORD16 ixheaacd_mdst_fcoeff_stop_stopstart_left_sin[] = { |
134 | | 1262, 1285, 1299, 1304, 1299, 1285, 1262}; |
135 | | const WORD16 ixheaacd_mdst_fcoeff_stop_stopstart_left_kbd[] = { |
136 | | 857, 866, 871, 873, 871, 866, 857}; |
137 | | |
138 | | const WORD16 *const ixheaacd_mdst_fcoeff_l_s_start_left_prev[2] = { |
139 | | ixheaacd_mdst_fcoeff_l_s_start_left_sin, |
140 | | ixheaacd_mdst_fcoeff_l_s_start_left_kbd}; |
141 | | const WORD16 *const ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[2] = { |
142 | | ixheaacd_mdst_fcoeff_stop_stopstart_left_sin, |
143 | | ixheaacd_mdst_fcoeff_stop_stopstart_left_kbd}; |
144 | | |
145 | | #define ONE_BY_TWO_POW_14 0.00006103515625 |
146 | 521M | #define ONE_BY_TWO_POW_15 0.000030517578125 |
147 | | |
148 | | void ixheaacd_usac_cplx_save_prev(ia_sfb_info_struct *info, WORD32 *l_spec, |
149 | | WORD32 *r_spec, WORD32 *l_spec_prev, |
150 | 101k | WORD32 *r_spec_prev) { |
151 | 101k | WORD32 ixheaacd_drc_offset; |
152 | | |
153 | 101k | ixheaacd_drc_offset = info->samp_per_bk - info->bins_per_sbk; |
154 | | |
155 | 101k | memcpy(l_spec_prev + ixheaacd_drc_offset, l_spec + ixheaacd_drc_offset, |
156 | 101k | sizeof(WORD32) * info->bins_per_sbk); |
157 | 101k | memcpy(r_spec_prev + ixheaacd_drc_offset, r_spec + ixheaacd_drc_offset, |
158 | 101k | sizeof(WORD32) * info->bins_per_sbk); |
159 | 101k | } |
160 | | |
161 | | static VOID ixheaacd_cplx_pred_data( |
162 | | ia_usac_data_struct *usac_data, |
163 | | ia_usac_tmp_core_coder_struct *pstr_core_coder, WORD32 num_window_groups, |
164 | 15.9k | ia_bit_buf_struct *it_bit_buff) { |
165 | 15.9k | ia_huff_code_book_struct *ptr_huff_code_book = &ixheaacd_book; |
166 | 15.9k | const ia_huff_code_word_struct *ptr_huff_code_word = |
167 | 15.9k | ptr_huff_code_book->pstr_huff_code_word; |
168 | 15.9k | WORD32 cplx_pred_all; |
169 | 15.9k | WORD32 delta_code_time; |
170 | 15.9k | WORD32 g, sfb; |
171 | 15.9k | WORD32 dpcm_alpha, last_alpha_q_re, last_alpha_q_im; |
172 | 15.9k | UWORD8 max_sfb_ste = pstr_core_coder->max_sfb_ste; |
173 | | |
174 | 15.9k | WORD32(*alpha_q_re)[SFB_NUM_MAX] = usac_data->alpha_q_re; |
175 | 15.9k | WORD32(*alpha_q_im)[SFB_NUM_MAX] = usac_data->alpha_q_im; |
176 | 15.9k | WORD32 *alpha_q_re_prev = usac_data->alpha_q_re_prev; |
177 | 15.9k | WORD32 *alpha_q_im_prev = usac_data->alpha_q_im_prev; |
178 | 15.9k | UWORD8(*cplx_pred_used)[SFB_NUM_MAX] = usac_data->cplx_pred_used; |
179 | | |
180 | 15.9k | cplx_pred_all = ixheaacd_read_bits_buf(it_bit_buff, 1); |
181 | | |
182 | 15.9k | if (cplx_pred_all == 0) { |
183 | 64.0k | for (g = 0; g < num_window_groups; g++) { |
184 | 157k | for (sfb = 0; sfb < max_sfb_ste; sfb += SFB_PER_PRED_BAND) { |
185 | 104k | cplx_pred_used[g][sfb] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
186 | | |
187 | 104k | if (sfb + 1 < max_sfb_ste) |
188 | 50.7k | cplx_pred_used[g][sfb + 1] = cplx_pred_used[g][sfb]; |
189 | 104k | } |
190 | 7.21M | for (sfb = max_sfb_ste; sfb < SFB_NUM_MAX; sfb++) |
191 | 7.15M | cplx_pred_used[g][sfb] = 0; |
192 | 53.7k | } |
193 | 10.2k | } else { |
194 | 16.7k | for (g = 0; g < num_window_groups; g++) { |
195 | 105k | for (sfb = 0; sfb < max_sfb_ste; sfb++) cplx_pred_used[g][sfb] = 1; |
196 | | |
197 | 1.43M | for (sfb = max_sfb_ste; sfb < SFB_NUM_MAX; sfb++) |
198 | 1.41M | cplx_pred_used[g][sfb] = 0; |
199 | 11.1k | } |
200 | 5.61k | } |
201 | | |
202 | 15.9k | pstr_core_coder->pred_dir = ixheaacd_read_bits_buf(it_bit_buff, 1); |
203 | | |
204 | 15.9k | pstr_core_coder->complex_coef = ixheaacd_read_bits_buf(it_bit_buff, 1); |
205 | | |
206 | 15.9k | if (pstr_core_coder->complex_coef) { |
207 | 8.08k | if (usac_data->usac_independency_flg) |
208 | 7.19k | pstr_core_coder->use_prev_frame = 0; |
209 | 887 | else |
210 | 887 | pstr_core_coder->use_prev_frame = ixheaacd_read_bits_buf(it_bit_buff, 1); |
211 | 8.08k | } |
212 | | |
213 | 15.9k | if (usac_data->usac_independency_flg) |
214 | 8.47k | delta_code_time = 0; |
215 | 7.43k | else |
216 | 7.43k | delta_code_time = ixheaacd_read_bits_buf(it_bit_buff, 1); |
217 | | |
218 | 80.8k | for (g = 0; g < num_window_groups; g++) { |
219 | 220k | for (sfb = 0; sfb < max_sfb_ste; sfb += SFB_PER_PRED_BAND) { |
220 | 155k | if (delta_code_time == 1) { |
221 | 4.13k | last_alpha_q_re = alpha_q_re_prev[sfb]; |
222 | 4.13k | last_alpha_q_im = alpha_q_im_prev[sfb]; |
223 | 151k | } else { |
224 | 151k | if (sfb > 0) { |
225 | 89.5k | last_alpha_q_re = alpha_q_re[g][sfb - 1]; |
226 | 89.5k | last_alpha_q_im = alpha_q_im[g][sfb - 1]; |
227 | 89.5k | } else { |
228 | 62.1k | last_alpha_q_re = last_alpha_q_im = 0; |
229 | 62.1k | } |
230 | 151k | } |
231 | | |
232 | 155k | if (cplx_pred_used[g][sfb] == 1) { |
233 | 102k | dpcm_alpha = |
234 | 102k | -ixheaacd_huff_codeword(ptr_huff_code_word, 0, it_bit_buff) + 60; |
235 | 102k | alpha_q_re[g][sfb] = dpcm_alpha + last_alpha_q_re; |
236 | | |
237 | 102k | if (pstr_core_coder->complex_coef) { |
238 | 74.1k | dpcm_alpha = |
239 | 74.1k | -ixheaacd_huff_codeword(ptr_huff_code_word, 0, it_bit_buff) + 60; |
240 | 74.1k | alpha_q_im[g][sfb] = dpcm_alpha + last_alpha_q_im; |
241 | 74.1k | } else { |
242 | 28.7k | alpha_q_im[g][sfb] = 0; |
243 | 28.7k | } |
244 | 102k | } else { |
245 | 52.9k | alpha_q_re[g][sfb] = 0; |
246 | 52.9k | alpha_q_im[g][sfb] = 0; |
247 | 52.9k | } |
248 | | |
249 | 155k | if ((sfb + 1) < max_sfb_ste) { |
250 | 93.4k | alpha_q_re[g][sfb + 1] = alpha_q_re[g][sfb]; |
251 | 93.4k | alpha_q_im[g][sfb + 1] = alpha_q_im[g][sfb]; |
252 | 93.4k | } |
253 | | |
254 | 155k | alpha_q_re_prev[sfb] = alpha_q_re[g][sfb]; |
255 | 155k | alpha_q_im_prev[sfb] = alpha_q_im[g][sfb]; |
256 | 155k | } |
257 | 8.64M | for (sfb = max_sfb_ste; sfb < SFB_NUM_MAX; sfb++) { |
258 | 8.57M | alpha_q_re[g][sfb] = 0; |
259 | 8.57M | alpha_q_im[g][sfb] = 0; |
260 | 8.57M | alpha_q_re_prev[sfb] = 0; |
261 | 8.57M | alpha_q_im_prev[sfb] = 0; |
262 | 8.57M | } |
263 | 64.9k | } |
264 | | |
265 | 15.9k | return; |
266 | 15.9k | } |
267 | | |
268 | | static WORD32 ixheaacd_read_ms_mask( |
269 | | ia_usac_data_struct *usac_data, |
270 | | ia_usac_tmp_core_coder_struct *pstr_core_coder, |
271 | 41.4k | ia_bit_buf_struct *it_bit_buff, WORD32 chn) { |
272 | 41.4k | WORD32 g, sfb; |
273 | 41.4k | WORD32 ms_mask_present; |
274 | | |
275 | 41.4k | UWORD8 *sfb_group = usac_data->group_dis[chn]; |
276 | 41.4k | UWORD8 max_sfb = pstr_core_coder->max_sfb_ste; |
277 | 41.4k | UWORD8 *ms_used = usac_data->ms_used[chn]; |
278 | 41.4k | ia_sfb_info_struct *info = usac_data->pstr_sfb_info[chn]; |
279 | | |
280 | 41.4k | ms_mask_present = ixheaacd_read_bits_buf(it_bit_buff, 2); |
281 | | |
282 | 41.4k | switch (ms_mask_present) { |
283 | 13.7k | case 0: |
284 | | |
285 | 13.7k | break; |
286 | | |
287 | 757 | case 1: |
288 | 3.88k | for (g = 0; g < info->max_win_len; g = *sfb_group++) { |
289 | 25.5k | for (sfb = 0; sfb < max_sfb; sfb++) { |
290 | 22.4k | *ms_used = ixheaacd_read_bits_buf(it_bit_buff, 1); |
291 | 22.4k | ms_used++; |
292 | 22.4k | } |
293 | 30.0k | for (; sfb < info->sfb_per_sbk; sfb++) { |
294 | 26.9k | *ms_used = 0; |
295 | 26.9k | ms_used++; |
296 | 26.9k | } |
297 | 3.12k | } |
298 | | |
299 | 757 | break; |
300 | 11.0k | case 2: |
301 | 23.4k | for (g = 0; g < info->max_win_len; g = *sfb_group++) |
302 | 495k | for (sfb = 0; sfb < info->sfb_per_sbk; sfb++) *ms_used++ = 1; |
303 | 11.0k | break; |
304 | | |
305 | 15.9k | case 3: |
306 | | |
307 | 15.9k | ixheaacd_cplx_pred_data(usac_data, pstr_core_coder, info->num_groups, |
308 | 15.9k | it_bit_buff); |
309 | 15.9k | return 3; |
310 | 41.4k | } |
311 | | |
312 | 3.49M | for (sfb = 0; sfb < SFB_NUM_MAX; sfb++) { |
313 | 3.47M | usac_data->alpha_q_re_prev[sfb] = 0; |
314 | 3.47M | usac_data->alpha_q_im_prev[sfb] = 0; |
315 | 3.47M | } |
316 | 25.5k | return ms_mask_present; |
317 | 41.4k | } |
318 | | |
319 | | VOID ixheaacd_ms_stereo(ia_usac_data_struct *usac_data, WORD32 *r_spec, |
320 | 11.6k | WORD32 *l_spec, WORD32 chn, WORD32 nband) { |
321 | 11.6k | WORD32 temp_r, temp_l; |
322 | 11.6k | WORD32 sfb, k, grp, grp_len; |
323 | 11.6k | ia_sfb_info_struct *ptr_sfb_info = usac_data->pstr_sfb_info[chn]; |
324 | 11.6k | UWORD8 *ms_used = usac_data->ms_used[chn]; |
325 | 11.6k | WORD32 ixheaacd_drc_offset = 0; |
326 | | |
327 | 27.1k | for (grp = 0; grp < ptr_sfb_info->num_groups; grp++) { |
328 | 34.3k | for (grp_len = 0; grp_len < ptr_sfb_info->group_len[grp]; grp_len++) { |
329 | 18.9k | ixheaacd_drc_offset = 0; |
330 | 109k | for (sfb = 0; sfb < nband; sfb++) { |
331 | 90.4k | ixheaacd_drc_offset += ptr_sfb_info->sfb_width[sfb]; |
332 | 90.4k | if (ms_used[sfb]) { |
333 | 906k | for (k = 0; k < ptr_sfb_info->sfb_width[sfb]; k++) { |
334 | 835k | temp_r = *r_spec; |
335 | 835k | temp_l = *l_spec; |
336 | 835k | *l_spec = ixheaac_add32_sat(temp_r, temp_l); |
337 | 835k | *r_spec = ixheaac_sub32_sat(temp_l, temp_r); |
338 | 835k | r_spec++; |
339 | 835k | l_spec++; |
340 | 835k | } |
341 | 71.0k | } else { |
342 | 19.4k | r_spec += ptr_sfb_info->sfb_width[sfb]; |
343 | 19.4k | l_spec += ptr_sfb_info->sfb_width[sfb]; |
344 | 19.4k | } |
345 | 90.4k | } |
346 | | |
347 | 18.9k | l_spec = l_spec + ptr_sfb_info->bins_per_sbk - ixheaacd_drc_offset; |
348 | 18.9k | r_spec = r_spec + ptr_sfb_info->bins_per_sbk - ixheaacd_drc_offset; |
349 | 18.9k | } |
350 | | |
351 | 15.4k | ms_used += ptr_sfb_info->sfb_per_sbk; |
352 | 15.4k | } |
353 | 11.6k | } |
354 | | |
355 | | static VOID ixheaacd_filter_and_add(const WORD32 *in, const WORD32 length, |
356 | | const WORD16 *filter, WORD32 *out, |
357 | | const WORD32 factor_even, |
358 | 109k | const WORD32 factor_odd) { |
359 | 109k | WORD32 i; |
360 | 109k | WORD64 sum; |
361 | | |
362 | 109k | sum = ixheaac_mult32x32in64(in[2], filter[0]); |
363 | 109k | sum = ixheaac_mac32x32in64(sum, in[1], filter[1]); |
364 | 109k | sum = ixheaac_mac32x32in64(sum, in[0], filter[2]); |
365 | 109k | sum = ixheaac_mac32x32in64_n(sum, &in[0], &filter[3], 4); |
366 | 109k | *out = ixheaac_add32_sat( |
367 | 109k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); |
368 | 109k | out++; |
369 | | |
370 | 109k | sum = ixheaac_mult32x32in64(in[1], filter[0]); |
371 | 109k | sum = ixheaac_mac32x32in64(sum, in[0], filter[1]); |
372 | 109k | sum = ixheaac_mac32x32in64_n(sum, &in[0], &filter[2], 5); |
373 | 109k | *out = ixheaac_add32_sat( |
374 | 109k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); |
375 | 109k | out++; |
376 | | |
377 | 109k | sum = ixheaac_mult32x32in64(in[0], filter[0]); |
378 | 109k | sum = ixheaac_mac32x32in64_n(sum, &in[0], &filter[1], 6); |
379 | 109k | *out = ixheaac_add32_sat( |
380 | 109k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); |
381 | 109k | out++; |
382 | | |
383 | 7.11M | for (i = 3; i < length - 4; i += 2) { |
384 | 7.00M | sum = 0; |
385 | 7.00M | sum = ixheaac_mac32x32in64_7(&in[i - 3], filter); |
386 | 7.00M | *out = ixheaac_add32_sat( |
387 | 7.00M | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); |
388 | 7.00M | out++; |
389 | | |
390 | 7.00M | sum = 0; |
391 | 7.00M | sum = ixheaac_mac32x32in64_7(&in[i - 2], filter); |
392 | 7.00M | *out = ixheaac_add32_sat( |
393 | 7.00M | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); |
394 | 7.00M | out++; |
395 | 7.00M | } |
396 | 109k | i = length - 3; |
397 | 109k | sum = 0; |
398 | 109k | sum = ixheaac_mac32x32in64_n(sum, &in[i - 3], filter, 6); |
399 | 109k | sum = ixheaac_mac32x32in64(sum, in[i + 2], filter[6]); |
400 | 109k | *out = ixheaac_add32_sat( |
401 | 109k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); |
402 | | |
403 | 109k | out++; |
404 | 109k | i = length - 2; |
405 | 109k | sum = 0; |
406 | 109k | sum = ixheaac_mac32x32in64_n(sum, &in[i - 3], filter, 5); |
407 | 109k | sum = ixheaac_mac32x32in64(sum, in[i + 1], filter[5]); |
408 | 109k | sum = ixheaac_mac32x32in64(sum, in[i], filter[6]); |
409 | | |
410 | 109k | *out = ixheaac_add32_sat( |
411 | 109k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); |
412 | 109k | out++; |
413 | | |
414 | 109k | i = length - 1; |
415 | 109k | sum = 0; |
416 | 109k | sum = ixheaac_mac32x32in64_n(sum, &in[i - 3], filter, 4); |
417 | 109k | sum = ixheaac_mac32x32in64(sum, in[i], filter[4]); |
418 | 109k | sum = ixheaac_mac32x32in64(sum, in[i - 1], filter[5]); |
419 | 109k | sum = ixheaac_mac32x32in64(sum, in[i - 2], filter[6]); |
420 | | |
421 | 109k | *out = ixheaac_add32_sat( |
422 | 109k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); |
423 | 109k | } |
424 | | |
425 | | static VOID ixheaacd_estimate_dmx_im(const WORD32 *dmx_re, |
426 | | const WORD32 *dmx_re_prev, WORD32 *dmx_im, |
427 | | ia_sfb_info_struct *pstr_sfb_info, |
428 | | WORD32 window, const WORD32 w_shape, |
429 | 7.86k | const WORD32 prev_w_shape) { |
430 | 7.86k | WORD32 i; |
431 | 7.86k | const WORD16 *mdst_fcoeff_curr, *mdst_fcoeff_prev; |
432 | | |
433 | 7.86k | switch (window) { |
434 | 117 | case ONLY_LONG_SEQUENCE: |
435 | 7.36k | case EIGHT_SHORT_SEQUENCE: |
436 | 7.36k | mdst_fcoeff_curr = |
437 | 7.36k | ixheaacd_mdst_fcoeff_longshort_curr[prev_w_shape][w_shape]; |
438 | 7.36k | mdst_fcoeff_prev = ixheaacd_mdst_fcoeff_l_s_start_left_prev[prev_w_shape]; |
439 | 7.36k | break; |
440 | 25 | case LONG_START_SEQUENCE: |
441 | 25 | mdst_fcoeff_curr = ixheaacd_mdst_fcoeff_start_curr[prev_w_shape][w_shape]; |
442 | 25 | mdst_fcoeff_prev = ixheaacd_mdst_fcoeff_l_s_start_left_prev[prev_w_shape]; |
443 | 25 | break; |
444 | 329 | case LONG_STOP_SEQUENCE: |
445 | 329 | mdst_fcoeff_curr = ixheaacd_mdst_fcoeff_stop_cur[prev_w_shape][w_shape]; |
446 | 329 | mdst_fcoeff_prev = |
447 | 329 | ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[prev_w_shape]; |
448 | 329 | break; |
449 | 145 | case STOP_START_SEQUENCE: |
450 | 145 | mdst_fcoeff_curr = |
451 | 145 | ixheaacd_mdst_fcoeff_stopstart_cur[prev_w_shape][w_shape]; |
452 | 145 | mdst_fcoeff_prev = |
453 | 145 | ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[prev_w_shape]; |
454 | 145 | break; |
455 | 0 | default: |
456 | 0 | mdst_fcoeff_curr = |
457 | 0 | ixheaacd_mdst_fcoeff_stopstart_cur[prev_w_shape][w_shape]; |
458 | 0 | mdst_fcoeff_prev = |
459 | 0 | ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[prev_w_shape]; |
460 | 0 | break; |
461 | 7.86k | } |
462 | | |
463 | 66.4k | for (i = 0; i < pstr_sfb_info->max_win_len; i++) { |
464 | 58.6k | ixheaacd_filter_and_add(dmx_re, pstr_sfb_info->bins_per_sbk, |
465 | 58.6k | mdst_fcoeff_curr, dmx_im, 1, 1); |
466 | | |
467 | 58.6k | if (dmx_re_prev) |
468 | 51.1k | ixheaacd_filter_and_add(dmx_re_prev, pstr_sfb_info->bins_per_sbk, |
469 | 51.1k | mdst_fcoeff_prev, dmx_im, -1, 1); |
470 | | |
471 | 58.6k | dmx_re_prev = dmx_re; |
472 | 58.6k | dmx_re += pstr_sfb_info->bins_per_sbk; |
473 | 58.6k | dmx_im += pstr_sfb_info->bins_per_sbk; |
474 | 58.6k | } |
475 | 7.86k | return; |
476 | 7.86k | } |
477 | | |
478 | | static VOID ixheaacd_cplx_pred_upmixing( |
479 | | ia_usac_data_struct *usac_data, WORD32 *l_spec, WORD32 *r_spec, |
480 | 15.6k | ia_usac_tmp_core_coder_struct *pstr_core_coder, WORD32 chn) { |
481 | 15.6k | ia_sfb_info_struct *pstr_sfb_info = usac_data->pstr_sfb_info[chn]; |
482 | 15.6k | WORD32 *dmx_re = &usac_data->scratch_buffer[0]; |
483 | 15.6k | WORD32 *dmx_im = &usac_data->x_ac_dec[0]; |
484 | | |
485 | 15.6k | WORD32 grp, sfb, grp_len, i = 0, k; |
486 | 15.6k | WORD32 *dmx_re_prev = usac_data->dmx_re_prev; |
487 | 15.6k | WORD32(*alpha_q_re)[SFB_NUM_MAX] = usac_data->alpha_q_re; |
488 | 15.6k | WORD32(*alpha_q_im)[SFB_NUM_MAX] = usac_data->alpha_q_im; |
489 | | |
490 | 15.6k | UWORD8(*cplx_pred_used)[SFB_NUM_MAX] = usac_data->cplx_pred_used; |
491 | | |
492 | 15.6k | WORD32 alpha_q_re_temp; |
493 | 15.6k | WORD32 alpha_q_im_temp; |
494 | 15.6k | WORD32 factor = 1; |
495 | | |
496 | 15.6k | if (pstr_core_coder->pred_dir) factor = -1; |
497 | | |
498 | 79.7k | for (grp = 0; grp < pstr_sfb_info->num_groups; grp++) { |
499 | 184k | for (grp_len = 0; grp_len < pstr_sfb_info->group_len[grp]; grp_len++) { |
500 | 1.93M | for (sfb = 0; sfb < pstr_sfb_info->sfb_per_sbk; sfb++) { |
501 | 1.81M | if (cplx_pred_used[grp][sfb] == 1) { |
502 | 656k | memcpy(&dmx_re[i], &l_spec[i], |
503 | 656k | pstr_sfb_info->sfb_width[sfb] * sizeof(WORD32)); |
504 | 656k | i += pstr_sfb_info->sfb_width[sfb]; |
505 | 656k | } |
506 | | |
507 | 1.16M | else { |
508 | 12.0M | for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) { |
509 | 10.8M | dmx_re[i] = (WORD32)( |
510 | 10.8M | ((WORD64)l_spec[i] + ((WORD64)factor * (WORD64)r_spec[i])) >> |
511 | 10.8M | 1); |
512 | 10.8M | } |
513 | 1.16M | } |
514 | 1.81M | } |
515 | 119k | } |
516 | 64.1k | } |
517 | | |
518 | 15.6k | memset(dmx_im, 0, sizeof(WORD32) * BLOCK_LEN_LONG); |
519 | | |
520 | 15.6k | if (pstr_core_coder->complex_coef) { |
521 | 7.86k | WORD32 *p_dmx_re_prev = |
522 | 7.86k | pstr_core_coder->use_prev_frame ? dmx_re_prev : NULL; |
523 | 7.86k | ixheaacd_estimate_dmx_im(dmx_re, p_dmx_re_prev, dmx_im, pstr_sfb_info, |
524 | 7.86k | usac_data->window_sequence[chn], |
525 | 7.86k | usac_data->window_shape[chn], |
526 | 7.86k | usac_data->window_shape_prev[chn]); |
527 | | |
528 | 27.3k | for (grp = 0, i = 0; grp < pstr_sfb_info->num_groups; grp++) { |
529 | 78.0k | for (grp_len = 0; grp_len < pstr_sfb_info->group_len[grp]; grp_len++) { |
530 | 954k | for (sfb = 0; sfb < pstr_sfb_info->sfb_per_sbk; sfb++) { |
531 | 895k | alpha_q_re_temp = ixheaac_sat64_32(ixheaac_mult32x32in64(alpha_q_re[grp][sfb], 1677722)); |
532 | 895k | alpha_q_im_temp = ixheaac_sat64_32(ixheaac_mult32x32in64(alpha_q_im[grp][sfb], 1677722)); |
533 | 895k | if (cplx_pred_used[grp][sfb]) { |
534 | 5.30M | for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) { |
535 | 4.71M | WORD32 mid_side = ixheaac_sub32_sat( |
536 | 4.71M | ixheaac_sub32_sat(r_spec[i], |
537 | 4.71M | (WORD32)((WORD64)ixheaac_mult32x32in64( |
538 | 4.71M | alpha_q_re_temp, l_spec[i]) >> |
539 | 4.71M | 24)), |
540 | 4.71M | (WORD32)((WORD64)ixheaac_mult32x32in64(alpha_q_im_temp, |
541 | 4.71M | dmx_im[i]) >> |
542 | 4.71M | 24)); |
543 | 4.71M | r_spec[i] = ixheaac_sat64_32((WORD64)factor) * |
544 | 4.71M | (WORD64)(ixheaac_sub32_sat(l_spec[i], mid_side)); |
545 | 4.71M | l_spec[i] = ixheaac_add32_sat(l_spec[i], mid_side); |
546 | 4.71M | } |
547 | 590k | } else { |
548 | 305k | i += pstr_sfb_info->sfb_width[sfb]; |
549 | 305k | } |
550 | 895k | } |
551 | 58.6k | } |
552 | 19.4k | } |
553 | 7.86k | } else { |
554 | 52.4k | for (grp = 0, i = 0; grp < pstr_sfb_info->num_groups; grp++) { |
555 | 106k | for (grp_len = 0; grp_len < pstr_sfb_info->group_len[grp]; grp_len++) { |
556 | 983k | for (sfb = 0; sfb < pstr_sfb_info->sfb_per_sbk; sfb++) { |
557 | 922k | alpha_q_re_temp = ixheaac_sat64_32(ixheaac_mult32x32in64(alpha_q_re[grp][sfb], 1677722)); |
558 | 922k | if (cplx_pred_used[grp][sfb]) { |
559 | 461k | for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) { |
560 | 394k | WORD32 mid_side = ixheaac_sub32_sat( |
561 | 394k | r_spec[i], (WORD32)((WORD64)ixheaac_mult32x32in64( |
562 | 394k | alpha_q_re_temp, l_spec[i]) >> |
563 | 394k | 24)); |
564 | | |
565 | 394k | r_spec[i] = ixheaac_sat64_32((WORD64)factor) * |
566 | 394k | (WORD64)(ixheaac_sub32_sat(l_spec[i], mid_side)); |
567 | 394k | l_spec[i] = ixheaac_add32_sat(l_spec[i], mid_side); |
568 | 394k | } |
569 | 855k | } else { |
570 | 855k | i += pstr_sfb_info->sfb_width[sfb]; |
571 | 855k | } |
572 | 922k | } |
573 | 61.3k | } |
574 | 44.6k | } |
575 | 7.75k | } |
576 | | |
577 | 15.6k | return; |
578 | 15.6k | } |
579 | | |
580 | | static VOID ixheaacd_cplx_prev_mdct_dmx(ia_sfb_info_struct *pstr_sfb_info, |
581 | | WORD32 *l_spec, WORD32 *r_spec, |
582 | 101k | WORD32 *dmx_re_prev, WORD32 pred_dir) { |
583 | 101k | WORD32 offs, i; |
584 | 101k | WORD32 factor = 1; |
585 | 101k | if (pred_dir) factor = -1; |
586 | | |
587 | 101k | offs = pstr_sfb_info->samp_per_bk - pstr_sfb_info->bins_per_sbk; |
588 | | |
589 | 71.3M | for (i = 0; i < pstr_sfb_info->bins_per_sbk; i++) |
590 | 71.2M | dmx_re_prev[i] = (WORD32)(((WORD64)l_spec[i + offs] + |
591 | 71.2M | ((WORD64)factor * (WORD64)r_spec[i + offs])) >> |
592 | 71.2M | 1); |
593 | 101k | } |
594 | | |
595 | | WORD32 ixheaacd_ics_info(ia_usac_data_struct *usac_data, WORD32 chn, |
596 | | UWORD8 *max_sfb, ia_bit_buf_struct *it_bit_buff, |
597 | | WORD32 window_sequence_last |
598 | | |
599 | | ) |
600 | | |
601 | 304k | { |
602 | 304k | WORD32 win; |
603 | 304k | WORD32 mask = 0x40; |
604 | | |
605 | 304k | UWORD8 *scf_group_ptr = usac_data->group_dis[chn]; |
606 | | |
607 | 304k | win = ixheaacd_read_bits_buf(it_bit_buff, 2); |
608 | | |
609 | 304k | win = usac_data->window_sequence[chn] = |
610 | 304k | ixheaacd_win_seq_select(win, window_sequence_last); |
611 | 304k | if (win == -1) return -1; |
612 | | |
613 | 304k | usac_data->pstr_sfb_info[chn] = |
614 | 304k | usac_data->pstr_usac_winmap[usac_data->window_sequence[chn]]; |
615 | | |
616 | 304k | usac_data->window_shape[chn] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
617 | | |
618 | 304k | if (usac_data->pstr_usac_winmap[win]->islong) { |
619 | 237k | *max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 6); |
620 | 237k | *scf_group_ptr = 1; |
621 | 237k | } else { |
622 | 66.6k | WORD32 i, scale_factor_grouping; |
623 | | |
624 | 66.6k | *max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 4); |
625 | | |
626 | 66.6k | scale_factor_grouping = ixheaacd_read_bits_buf(it_bit_buff, 7); |
627 | | |
628 | 533k | for (i = 1; i < 8; i++) { |
629 | 466k | if (!(scale_factor_grouping & mask)) *scf_group_ptr++ = i; |
630 | | |
631 | 466k | mask = mask >> 1; |
632 | 466k | } |
633 | 66.6k | *scf_group_ptr++ = i; |
634 | | |
635 | 66.6k | ixheaacd_calc_grp_offset(usac_data->pstr_usac_winmap[win], |
636 | 66.6k | &usac_data->group_dis[chn][0]); |
637 | 66.6k | } |
638 | | |
639 | 304k | if (*max_sfb > usac_data->pstr_sfb_info[chn]->sfb_per_sbk) { |
640 | 554 | *max_sfb = usac_data->pstr_sfb_info[chn]->sfb_per_sbk; |
641 | 554 | return -1; |
642 | 554 | } |
643 | | |
644 | 303k | return 0; |
645 | 304k | } |
646 | | |
647 | | WORD32 ixheaacd_core_coder_data(WORD32 id, ia_usac_data_struct *usac_data, |
648 | | WORD32 elem_idx, WORD32 chan_offset, |
649 | | ia_bit_buf_struct *it_bit_buff, |
650 | 299k | WORD32 nr_core_coder_channels) { |
651 | 299k | WORD32 err_code = 0; |
652 | 299k | WORD32 k = 0, ch = 0, chn = 0, left = 0, right = 0; |
653 | | |
654 | 299k | ia_usac_tmp_core_coder_struct str_tmp_core_coder = {0}; |
655 | 299k | ia_usac_tmp_core_coder_struct *pstr_core_coder = &str_tmp_core_coder; |
656 | 299k | ia_td_frame_data_struct td_frame; |
657 | 299k | jmp_buf local; |
658 | | |
659 | 299k | if (usac_data->ec_flag) { |
660 | 0 | err_code = setjmp(local); |
661 | 0 | it_bit_buff->xaac_jmp_buf = &local; |
662 | 0 | } |
663 | 299k | if (err_code == 0 && |
664 | 299k | ((usac_data->ec_flag == 0) || (usac_data->frame_ok == 1 && usac_data->ec_flag == 1))) { |
665 | 299k | memset(&td_frame, 0, sizeof(td_frame)); |
666 | 299k | pstr_core_coder->tns_on_lr = 0; |
667 | 299k | pstr_core_coder->pred_dir = 0; |
668 | 299k | if (id != ID_USAC_LFE) { |
669 | 738k | for (ch = 0; ch < nr_core_coder_channels; ch++) |
670 | 439k | pstr_core_coder->core_mode[ch] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
671 | 298k | } else { |
672 | 2.24k | for (ch = 0; ch < nr_core_coder_channels; ch++) pstr_core_coder->core_mode[ch] = 0; |
673 | 1.12k | } |
674 | | |
675 | 299k | if (nr_core_coder_channels == 2 && pstr_core_coder->core_mode[0] == 0 && |
676 | 299k | pstr_core_coder->core_mode[1] == 0) { |
677 | 102k | pstr_core_coder->tns_active = ixheaacd_read_bits_buf(it_bit_buff, 1); |
678 | 102k | pstr_core_coder->common_window = ixheaacd_read_bits_buf(it_bit_buff, 1); |
679 | | |
680 | 102k | if (pstr_core_coder->common_window) { |
681 | 41.4k | left = chan_offset; |
682 | 41.4k | right = chan_offset + 1; |
683 | | |
684 | 41.4k | err_code = ixheaacd_ics_info(usac_data, left, &pstr_core_coder->max_sfb[left], |
685 | 41.4k | it_bit_buff, usac_data->window_sequence_last[left]); |
686 | | |
687 | 41.4k | if (err_code == -1) { |
688 | 17 | if (usac_data->ec_flag) { |
689 | 0 | memcpy(usac_data->max_sfb, pstr_core_coder->max_sfb, |
690 | 0 | sizeof(pstr_core_coder->max_sfb)); |
691 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
692 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
693 | 17 | } else { |
694 | 17 | return err_code; |
695 | 17 | } |
696 | 17 | } |
697 | | |
698 | 41.4k | pstr_core_coder->common_max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 1); |
699 | | |
700 | 41.4k | if (pstr_core_coder->common_max_sfb == 0) { |
701 | 14.9k | if (usac_data->window_sequence[left] == EIGHT_SHORT_SEQUENCE) |
702 | 13.4k | pstr_core_coder->max_sfb[right] = ixheaacd_read_bits_buf(it_bit_buff, 4); |
703 | 1.56k | else |
704 | 1.56k | pstr_core_coder->max_sfb[right] = ixheaacd_read_bits_buf(it_bit_buff, 6); |
705 | 26.4k | } else { |
706 | 26.4k | pstr_core_coder->max_sfb[right] = pstr_core_coder->max_sfb[left]; |
707 | 26.4k | } |
708 | | |
709 | 41.4k | pstr_core_coder->max_sfb_ste = |
710 | 41.4k | max(pstr_core_coder->max_sfb[left], pstr_core_coder->max_sfb[right]); |
711 | | |
712 | 41.4k | usac_data->window_sequence[right] = usac_data->window_sequence[left]; |
713 | 41.4k | usac_data->window_shape[right] = usac_data->window_shape[left]; |
714 | 41.4k | memcpy(&usac_data->group_dis[right][0], &usac_data->group_dis[left][0], 8); |
715 | 41.4k | usac_data->pstr_sfb_info[right] = usac_data->pstr_sfb_info[left]; |
716 | 41.4k | if (pstr_core_coder->max_sfb[right] > usac_data->pstr_sfb_info[right]->sfb_per_sbk) |
717 | 346 | pstr_core_coder->max_sfb[right] = usac_data->pstr_sfb_info[right]->sfb_per_sbk; |
718 | | |
719 | 41.4k | pstr_core_coder->ms_mask_present[0] = |
720 | 41.4k | ixheaacd_read_ms_mask(usac_data, pstr_core_coder, it_bit_buff, left); |
721 | 61.0k | } else { |
722 | 61.0k | left = chan_offset; |
723 | 61.0k | right = chan_offset + 1; |
724 | | |
725 | 61.0k | pstr_core_coder->ms_mask_present[0] = 0; |
726 | 61.0k | pstr_core_coder->ms_mask_present[1] = 0; |
727 | | |
728 | 8.35M | for (k = 0; k < SFB_NUM_MAX; k++) { |
729 | 8.29M | usac_data->alpha_q_re_prev[k] = 0; |
730 | 8.29M | usac_data->alpha_q_im_prev[k] = 0; |
731 | 8.29M | } |
732 | 61.0k | } |
733 | | |
734 | 102k | if (usac_data->tw_mdct[elem_idx] == 1) { |
735 | 0 | pstr_core_coder->common_tw = ixheaacd_read_bits_buf(it_bit_buff, 1); |
736 | |
|
737 | 0 | if (pstr_core_coder->common_tw == 1) { |
738 | 0 | usac_data->tw_data_present[left] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
739 | 0 | usac_data->tw_data_present[right] = usac_data->tw_data_present[left]; |
740 | 0 | if (usac_data->tw_data_present[left]) { |
741 | 0 | for (k = 0; k < NUM_TW_NODES; k++) { |
742 | 0 | usac_data->tw_ratio[left][k] = ixheaacd_read_bits_buf(it_bit_buff, 3); |
743 | 0 | usac_data->tw_ratio[right][k] = usac_data->tw_ratio[left][k]; |
744 | 0 | } |
745 | 0 | } |
746 | 0 | } |
747 | 0 | } |
748 | | |
749 | 102k | if (pstr_core_coder->tns_active) { |
750 | 21.3k | if (pstr_core_coder->common_window) { |
751 | 18.4k | pstr_core_coder->common_tns = ixheaacd_read_bits_buf(it_bit_buff, 1); |
752 | | |
753 | 18.4k | } else { |
754 | 2.90k | pstr_core_coder->common_tns = 0; |
755 | 2.90k | } |
756 | | |
757 | 21.3k | pstr_core_coder->tns_on_lr = ixheaacd_read_bits_buf(it_bit_buff, 1); |
758 | | |
759 | 21.3k | if (pstr_core_coder->common_tns) { |
760 | 4.08k | ixheaacd_read_tns_u(usac_data->pstr_sfb_info[0], &usac_data->pstr_tns[left][0], |
761 | 4.08k | it_bit_buff); |
762 | 4.08k | memcpy(&usac_data->pstr_tns[right][0], &usac_data->pstr_tns[left][0], |
763 | 4.08k | sizeof(ia_tns_frame_info_struct)); |
764 | | |
765 | 4.08k | pstr_core_coder->tns_data_present[0] = 2; |
766 | 4.08k | pstr_core_coder->tns_data_present[1] = 2; |
767 | 17.2k | } else { |
768 | 17.2k | pstr_core_coder->tns_present_both = ixheaacd_read_bits_buf(it_bit_buff, 1); |
769 | | |
770 | 17.2k | if (pstr_core_coder->tns_present_both) { |
771 | 12.4k | pstr_core_coder->tns_data_present[0] = 1; |
772 | 12.4k | pstr_core_coder->tns_data_present[1] = 1; |
773 | 12.4k | } else { |
774 | 4.76k | pstr_core_coder->tns_data_present[1] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
775 | 4.76k | pstr_core_coder->tns_data_present[0] = 1 - pstr_core_coder->tns_data_present[1]; |
776 | 4.76k | } |
777 | 17.2k | } |
778 | 81.1k | } else { |
779 | 81.1k | pstr_core_coder->common_tns = 0; |
780 | 81.1k | pstr_core_coder->tns_data_present[0] = 0; |
781 | 81.1k | pstr_core_coder->tns_data_present[1] = 0; |
782 | 81.1k | } |
783 | | |
784 | 197k | } else { |
785 | 197k | pstr_core_coder->common_window = 0; |
786 | 197k | pstr_core_coder->common_tw = 0; |
787 | 197k | left = chan_offset; |
788 | 197k | right = chan_offset; |
789 | 197k | if (nr_core_coder_channels == 2) right = chan_offset + 1; |
790 | 197k | } |
791 | | |
792 | 739k | for (ch = 0, chn = chan_offset; ch < nr_core_coder_channels; ch++, chn++) { |
793 | 440k | if (pstr_core_coder->core_mode[chn] == CORE_MODE_LPD && |
794 | 440k | usac_data->td_frame_prev[chn] == CORE_MODE_FD && usac_data->ec_flag) { |
795 | 0 | memcpy(usac_data->coef_fix[chn], usac_data->str_error_concealment[chn].spectral_coeff, |
796 | 0 | sizeof(usac_data->str_error_concealment[chn].spectral_coeff)); |
797 | 0 | memcpy(usac_data->spec_scale[chn], usac_data->str_error_concealment[chn].q_spec_coeff, |
798 | 0 | sizeof(usac_data->spec_scale[chn])); |
799 | 0 | err_code = ixheaacd_fd_frm_dec(usac_data, chn); |
800 | 0 | if (err_code == -1) return err_code; |
801 | 0 | for (k = 0; k < usac_data->ccfl; k++) { |
802 | 0 | usac_data->time_sample_vector[chn][k] = (FLOAT32)( |
803 | 0 | (FLOAT32)usac_data->output_data_ptr[chn][k] * (FLOAT32)(ONE_BY_TWO_POW_15)); |
804 | 0 | } |
805 | 0 | memcpy(usac_data->time_sample_vector_prev[chn], usac_data->time_sample_vector[chn], |
806 | 0 | usac_data->ccfl * sizeof(usac_data->time_sample_vector_prev[chn][0])); |
807 | |
|
808 | 0 | usac_data->window_sequence[ch] = usac_data->str_error_concealment[ch].win_seq; |
809 | 0 | usac_data->window_shape[ch] = usac_data->str_error_concealment[ch].win_shape; |
810 | 0 | usac_data->window_shape_prev[ch] = usac_data->window_shape[ch]; |
811 | 0 | usac_data->window_sequence_last[ch] = usac_data->window_sequence[ch]; |
812 | 0 | } |
813 | 440k | if (pstr_core_coder->core_mode[ch] == 1) { |
814 | 94.7k | err_code = ixheaacd_tw_buff_update(usac_data, chn, usac_data->str_tddec[chn]); |
815 | 94.7k | if (err_code == -1) return err_code; |
816 | | |
817 | 94.7k | if (!usac_data->td_frame_prev[chn]) { |
818 | 23.3k | ixheaacd_fix2flt_data(usac_data, usac_data->str_tddec[chn], chn); |
819 | 23.3k | } |
820 | | |
821 | 89.1M | for (k = 0; k < usac_data->ccfl; k++) { |
822 | 89.0M | usac_data->time_sample_vector[chn][k] = (FLOAT32)( |
823 | 89.0M | (FLOAT32)usac_data->output_data_ptr[chn][k] * (FLOAT32)(ONE_BY_TWO_POW_15)); |
824 | 89.0M | } |
825 | 94.7k | usac_data->present_chan = chn; |
826 | 94.7k | err_code = ixheaacd_lpd_channel_stream(usac_data, &td_frame, it_bit_buff, |
827 | 94.7k | usac_data->time_sample_vector[chn]); |
828 | 94.7k | if (err_code == -1) return err_code; |
829 | 94.7k | if (usac_data->ec_flag) { |
830 | 0 | it_bit_buff->xaac_jmp_buf = &local; |
831 | 0 | } |
832 | 94.7k | if (usac_data->ec_flag && usac_data->frame_ok) { |
833 | 0 | memcpy(&usac_data->td_frame_data_prev[chn], &td_frame, sizeof(td_frame)); |
834 | 0 | usac_data->core_mode = CORE_MODE_LPD; |
835 | 0 | } |
836 | 88.2M | for (k = 0; k < usac_data->ccfl; k++) { |
837 | 88.1M | usac_data->output_data_ptr[chn][k] = |
838 | 88.1M | (WORD32)(usac_data->time_sample_vector[chn][k] * (FLOAT32)((WORD64)1 << 15)); |
839 | 88.1M | } |
840 | | |
841 | 94.7k | usac_data->window_shape[chn] = WIN_SEL_0; |
842 | | |
843 | 94.7k | ixheaacd_td_frm_dec(usac_data, chn, td_frame.mod[0]); |
844 | | |
845 | 94.7k | usac_data->window_shape_prev[chn] = usac_data->window_shape[chn]; |
846 | 94.7k | usac_data->window_sequence_last[chn] = EIGHT_SHORT_SEQUENCE; |
847 | | |
848 | 345k | } else { |
849 | 345k | memset(usac_data->coef_fix[chn], 0, LN2 * sizeof(*usac_data->coef_fix[0])); |
850 | | |
851 | 345k | if (usac_data->str_tddec[chn] && usac_data->td_frame_prev[chn]) { |
852 | 20.0k | if (usac_data->ec_flag) { |
853 | 0 | memcpy(usac_data->time_sample_vector[chn], usac_data->time_sample_vector_prev[chn], |
854 | 0 | usac_data->ccfl * sizeof(usac_data->time_sample_vector[chn][0])); |
855 | 0 | } |
856 | 20.0k | ixheaacd_lpd_dec_update(usac_data->str_tddec[chn], usac_data, chn); |
857 | 20.0k | } |
858 | | |
859 | 345k | if (id != ID_USAC_LFE) { |
860 | 344k | if ((nr_core_coder_channels == 1) || |
861 | 344k | (pstr_core_coder->core_mode[0] != pstr_core_coder->core_mode[1])) |
862 | 139k | pstr_core_coder->tns_data_present[ch] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
863 | 344k | } |
864 | | |
865 | 345k | err_code = ixheaacd_fd_channel_stream( |
866 | 345k | usac_data, pstr_core_coder, &pstr_core_coder->max_sfb[ch], |
867 | 345k | usac_data->window_sequence_last[chn], chn, usac_data->noise_filling_config[elem_idx], |
868 | 345k | ch, it_bit_buff); |
869 | 345k | if (err_code == -1) return err_code; |
870 | 345k | } |
871 | 440k | } |
872 | | |
873 | 299k | if (pstr_core_coder->core_mode[0] == CORE_MODE_FD && |
874 | 299k | pstr_core_coder->core_mode[1] == CORE_MODE_FD && nr_core_coder_channels == 2) { |
875 | 101k | ixheaacd_cplx_prev_mdct_dmx(usac_data->pstr_sfb_info[left], usac_data->coef_save[left], |
876 | 101k | usac_data->coef_save[right], usac_data->dmx_re_prev, |
877 | 101k | pstr_core_coder->pred_dir); |
878 | 101k | } |
879 | | |
880 | 299k | if (pstr_core_coder->tns_on_lr == 0 && (id != ID_USAC_LFE)) { |
881 | 682k | for (ch = 0, chn = left; chn <= right; ch++, chn++) { |
882 | 402k | if (pstr_core_coder->core_mode[ch] == CORE_MODE_FD) { |
883 | 309k | err_code = ixheaacd_tns_apply(usac_data, usac_data->coef_fix[chn], |
884 | 309k | pstr_core_coder->max_sfb[ch], |
885 | 309k | usac_data->pstr_sfb_info[chn], usac_data->pstr_tns[chn]); |
886 | 309k | if (err_code) return err_code; |
887 | 309k | } |
888 | 402k | } |
889 | 279k | } |
890 | | |
891 | 299k | if (nr_core_coder_channels == 2 && pstr_core_coder->core_mode[0] == 0 && |
892 | 299k | pstr_core_coder->core_mode[1] == 0) { |
893 | 101k | if (pstr_core_coder->ms_mask_present[0] == 3) { |
894 | 15.6k | ixheaacd_cplx_pred_upmixing(usac_data, usac_data->coef_fix[left], |
895 | 15.6k | usac_data->coef_fix[right], pstr_core_coder, left); |
896 | | |
897 | 85.8k | } else if (pstr_core_coder->ms_mask_present[0] > 0) { |
898 | 11.6k | ixheaacd_ms_stereo(usac_data, usac_data->coef_fix[right], usac_data->coef_fix[left], left, |
899 | 11.6k | pstr_core_coder->max_sfb[right] > pstr_core_coder->max_sfb[left] |
900 | 11.6k | ? pstr_core_coder->max_sfb[right] |
901 | 11.6k | : pstr_core_coder->max_sfb[left]); |
902 | 11.6k | } |
903 | | |
904 | 101k | if (pstr_core_coder->tns_on_lr) { |
905 | 48.8k | for (ch = 0, chn = left; chn <= right; ch++, chn++) { |
906 | 32.5k | if (pstr_core_coder->core_mode[ch] == CORE_MODE_FD) { |
907 | 32.5k | err_code = ixheaacd_tns_apply( |
908 | 32.5k | usac_data, usac_data->coef_fix[chn], pstr_core_coder->max_sfb[ch], |
909 | 32.5k | usac_data->pstr_sfb_info[chn], usac_data->pstr_tns[chn]); |
910 | 32.5k | if (err_code) return err_code; |
911 | 32.5k | } |
912 | 32.5k | } |
913 | 16.2k | } |
914 | | |
915 | 101k | ixheaacd_usac_cplx_save_prev(usac_data->pstr_sfb_info[left], usac_data->coef_fix[left], |
916 | 101k | usac_data->coef_fix[right], usac_data->coef_save[left], |
917 | 101k | usac_data->coef_save[right]); |
918 | 101k | } |
919 | 299k | if (usac_data->ec_flag) { |
920 | 0 | for (chn = left; chn <= right; chn++) { |
921 | 0 | if (pstr_core_coder->core_mode[chn] == CORE_MODE_FD && |
922 | 0 | usac_data->td_frame_prev[chn] == CORE_MODE_LPD) { |
923 | 0 | memcpy(usac_data->str_error_concealment[chn].spectral_coeff, usac_data->coef_fix[chn], |
924 | 0 | sizeof(usac_data->str_error_concealment[chn].spectral_coeff)); |
925 | 0 | memcpy(usac_data->str_error_concealment[chn].q_spec_coeff, usac_data->spec_scale[chn], |
926 | 0 | sizeof(usac_data->spec_scale[chn])); |
927 | 0 | usac_data->str_error_concealment[chn].win_seq = usac_data->window_sequence[chn]; |
928 | 0 | usac_data->str_error_concealment[chn].win_shape = usac_data->window_shape[chn]; |
929 | 0 | usac_data->str_error_concealment[chn].win_shape_prev = |
930 | 0 | usac_data->window_shape_prev[chn]; |
931 | 0 | usac_data->str_error_concealment[chn].td_frame_prev = usac_data->td_frame_prev[chn]; |
932 | 0 | usac_data->str_error_concealment[chn].fac_data_present = |
933 | 0 | usac_data->fac_data_present[chn]; |
934 | 0 | } |
935 | 0 | } |
936 | 0 | if (usac_data->frame_ok && usac_data->ec_flag) { |
937 | 0 | memcpy(usac_data->max_sfb, pstr_core_coder->max_sfb, sizeof(pstr_core_coder->max_sfb)); |
938 | 0 | } |
939 | 0 | } |
940 | 299k | } else { |
941 | 0 | left = chan_offset; |
942 | 0 | right = chan_offset; |
943 | 0 | if (nr_core_coder_channels == 2) right = chan_offset + 1; |
944 | 0 | if (usac_data->ec_flag == 1) { |
945 | 0 | WORD32 err = 0; |
946 | 0 | usac_data->frame_ok = 0; |
947 | 0 | for (ch = left; ch <= right; ch++) { |
948 | 0 | if (usac_data->td_frame_prev[ch] == CORE_MODE_LPD) { |
949 | 0 | usac_data->fac_data_present[ch] = 0; |
950 | 0 | usac_data->str_error_concealment[ch].pstr_ec_scratch = |
951 | 0 | (ia_ec_scratch_str *)&usac_data->str_error_concealment[ch].str_ec_scratch; |
952 | 0 | usac_data->core_mode = usac_data->td_frame_prev[ch]; |
953 | 0 | usac_data->present_chan = ch; |
954 | 0 | ixheaacd_usac_apply_ec(usac_data, NULL, ch); |
955 | 0 | err = ixheaacd_lpd_dec(usac_data, usac_data->str_tddec[ch], |
956 | 0 | &usac_data->td_frame_data_prev[ch], |
957 | 0 | usac_data->time_sample_vector[ch], usac_data->first_lpd_flag, 0, |
958 | 0 | usac_data->bpf_control_info); |
959 | |
|
960 | 0 | if (err) return err; |
961 | | |
962 | 0 | for (k = 0; k < usac_data->ccfl; k++) { |
963 | 0 | usac_data->output_data_ptr[ch][k] = |
964 | 0 | (WORD32)(usac_data->time_sample_vector[ch][k] * (FLOAT32)((WORD64)1 << 15)); |
965 | 0 | } |
966 | |
|
967 | 0 | usac_data->window_shape[ch] = WIN_SEL_0; |
968 | 0 | usac_data->window_shape_prev[ch] = usac_data->window_shape[ch]; |
969 | 0 | usac_data->window_sequence_last[ch] = EIGHT_SHORT_SEQUENCE; |
970 | 0 | } else { |
971 | 0 | pstr_core_coder->core_mode[ch] = CORE_MODE_FD; |
972 | 0 | } |
973 | 0 | } |
974 | 0 | } |
975 | 0 | } |
976 | | |
977 | 735k | for (ch = left; ch <= right; ch++) { |
978 | 436k | FLOAT32 *ptr_scratch = |
979 | 436k | (FLOAT32 *)usac_data->str_error_concealment[ch].str_ec_scratch.spec_coeff; |
980 | 436k | if ((pstr_core_coder->core_mode[ch] != CORE_MODE_LPD && |
981 | 436k | usac_data->td_frame_prev[ch] != CORE_MODE_LPD && usac_data->ec_flag) || |
982 | 436k | (pstr_core_coder->core_mode[ch] == CORE_MODE_FD && usac_data->ec_flag == 0)) { |
983 | 370k | if (usac_data->tw_mdct[elem_idx]) { |
984 | 0 | err_code = -1; |
985 | 0 | return err_code; |
986 | |
|
987 | 370k | } else { |
988 | 370k | if (usac_data->frame_ok == 0) { |
989 | 0 | usac_data->fac_data_present[ch] = 0; |
990 | 0 | } |
991 | 370k | err_code = ixheaacd_fd_frm_dec(usac_data, ch); |
992 | 370k | if (err_code == -1) return err_code; |
993 | 370k | if (usac_data->ec_flag) { |
994 | 0 | if (usac_data->str_error_concealment[ch].fade_idx < MAX_FADE_FRAMES) { |
995 | 0 | FLOAT32 fade_fac = (FLOAT32)(ONE_BY_TWO_POW_15)*ia_ec_fade_factors |
996 | 0 | [usac_data->str_error_concealment[ch].fade_idx]; |
997 | 0 | for (k = 0; k < usac_data->ccfl; k++) { |
998 | 0 | usac_data->time_sample_vector[ch][k] = |
999 | 0 | (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] * fade_fac); |
1000 | 0 | } |
1001 | 0 | } else { |
1002 | 0 | memset(&usac_data->time_sample_vector[ch][0], 0, |
1003 | 0 | usac_data->ccfl * sizeof(usac_data->time_sample_vector[ch][0])); |
1004 | 0 | } |
1005 | 370k | } else { |
1006 | 371M | for (k = 0; k < usac_data->ccfl; k++) { |
1007 | 371M | usac_data->time_sample_vector[ch][k] = |
1008 | 371M | (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] * |
1009 | 371M | (FLOAT32)(ONE_BY_TWO_POW_15)); |
1010 | 371M | } |
1011 | 370k | } |
1012 | 370k | } |
1013 | 370k | usac_data->window_shape_prev[ch] = usac_data->window_shape[ch]; |
1014 | 370k | usac_data->window_sequence_last[ch] = usac_data->window_sequence[ch]; |
1015 | 370k | } else { |
1016 | 65.3k | if (usac_data->ec_flag) { |
1017 | 0 | usac_data->str_error_concealment[ch].prev_frame_ok[0] = |
1018 | 0 | usac_data->str_error_concealment[ch].prev_frame_ok[1]; |
1019 | 0 | usac_data->str_error_concealment[ch].prev_frame_ok[1] = usac_data->frame_ok; |
1020 | |
|
1021 | 0 | if (usac_data->str_error_concealment[ch].fade_idx < MAX_FADE_FRAMES) { |
1022 | 0 | FLOAT32 fade_fac = |
1023 | 0 | (FLOAT32)(ONE_BY_TWO_POW_15)*ia_ec_fade_factors[usac_data->str_error_concealment[ch] |
1024 | 0 | .fade_idx]; |
1025 | 0 | for (k = 0; k < usac_data->ccfl; k++) { |
1026 | 0 | usac_data->time_sample_vector[ch][k] = |
1027 | 0 | (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] * fade_fac); |
1028 | 0 | } |
1029 | 0 | } else { |
1030 | 0 | memset(&usac_data->time_sample_vector[ch][0], 0, |
1031 | 0 | usac_data->ccfl * sizeof(usac_data->time_sample_vector[ch][0])); |
1032 | 0 | } |
1033 | |
|
1034 | 0 | memcpy(ptr_scratch, usac_data->time_sample_vector[ch], |
1035 | 0 | usac_data->ccfl * sizeof(ptr_scratch[0])); |
1036 | 0 | memcpy(usac_data->time_sample_vector[ch], usac_data->time_sample_vector_prev[ch], |
1037 | 0 | usac_data->ccfl * sizeof(usac_data->time_sample_vector[ch][0])); |
1038 | 0 | memcpy(usac_data->time_sample_vector_prev[ch], ptr_scratch, |
1039 | 0 | usac_data->ccfl * sizeof(ptr_scratch[0])); |
1040 | 65.3k | } else { |
1041 | 61.1M | for (k = 0; k < usac_data->ccfl; k++) { |
1042 | 61.1M | usac_data->time_sample_vector[ch][k] = |
1043 | 61.1M | (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] * |
1044 | 61.1M | (FLOAT32)(ONE_BY_TWO_POW_15)); |
1045 | 61.1M | } |
1046 | 65.3k | } |
1047 | 65.3k | } |
1048 | 436k | if (usac_data->ec_flag) { |
1049 | 0 | usac_data->window_sequence[ch] = usac_data->str_error_concealment[ch].win_seq; |
1050 | 0 | usac_data->window_shape[ch] = usac_data->str_error_concealment[ch].win_shape; |
1051 | 0 | if (usac_data->first_frame == 0) { |
1052 | 0 | usac_data->window_shape_prev[ch] = usac_data->window_shape[ch]; |
1053 | 0 | usac_data->window_sequence_last[ch] = usac_data->window_sequence[ch]; |
1054 | 0 | } |
1055 | 0 | } |
1056 | 436k | } |
1057 | 299k | if (usac_data->ec_flag) { |
1058 | 0 | usac_data->first_frame = 0; |
1059 | 0 | if (usac_data->frame_ok == 1) { |
1060 | 0 | for (ch = 0, chn = left; chn <= right; chn++, ch++) |
1061 | 0 | usac_data->td_frame_prev[chn] = pstr_core_coder->core_mode[ch]; |
1062 | 0 | } |
1063 | 299k | } else { |
1064 | 735k | for (ch = 0, chn = left; chn <= right; chn++, ch++) |
1065 | 436k | usac_data->td_frame_prev[chn] = pstr_core_coder->core_mode[ch]; |
1066 | 299k | } |
1067 | | |
1068 | 299k | return 0; |
1069 | 299k | } |