/src/libxaac/decoder/ixheaacd_ext_ch_ele.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * * |
3 | | * Copyright (C) 2018 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | #include <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 | 500M | #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.4k | ia_bit_buf_struct *it_bit_buff) { |
165 | 15.4k | ia_huff_code_book_struct *ptr_huff_code_book = &ixheaacd_book; |
166 | 15.4k | const ia_huff_code_word_struct *ptr_huff_code_word = |
167 | 15.4k | ptr_huff_code_book->pstr_huff_code_word; |
168 | 15.4k | WORD32 cplx_pred_all; |
169 | 15.4k | WORD32 delta_code_time; |
170 | 15.4k | WORD32 g, sfb; |
171 | 15.4k | WORD32 dpcm_alpha, last_alpha_q_re, last_alpha_q_im; |
172 | 15.4k | UWORD8 max_sfb_ste = pstr_core_coder->max_sfb_ste; |
173 | | |
174 | 15.4k | WORD32(*alpha_q_re)[SFB_NUM_MAX] = usac_data->alpha_q_re; |
175 | 15.4k | WORD32(*alpha_q_im)[SFB_NUM_MAX] = usac_data->alpha_q_im; |
176 | 15.4k | WORD32 *alpha_q_re_prev = usac_data->alpha_q_re_prev; |
177 | 15.4k | WORD32 *alpha_q_im_prev = usac_data->alpha_q_im_prev; |
178 | 15.4k | UWORD8(*cplx_pred_used)[SFB_NUM_MAX] = usac_data->cplx_pred_used; |
179 | | |
180 | 15.4k | cplx_pred_all = ixheaacd_read_bits_buf(it_bit_buff, 1); |
181 | | |
182 | 15.4k | if (cplx_pred_all == 0) { |
183 | 55.2k | for (g = 0; g < num_window_groups; g++) { |
184 | 135k | for (sfb = 0; sfb < max_sfb_ste; sfb += SFB_PER_PRED_BAND) { |
185 | 89.1k | cplx_pred_used[g][sfb] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
186 | | |
187 | 89.1k | if (sfb + 1 < max_sfb_ste) |
188 | 43.1k | cplx_pred_used[g][sfb + 1] = cplx_pred_used[g][sfb]; |
189 | 89.1k | } |
190 | 6.22M | for (sfb = max_sfb_ste; sfb < SFB_NUM_MAX; sfb++) |
191 | 6.18M | cplx_pred_used[g][sfb] = 0; |
192 | 46.4k | } |
193 | 8.85k | } else { |
194 | 18.1k | for (g = 0; g < num_window_groups; g++) { |
195 | 123k | for (sfb = 0; sfb < max_sfb_ste; sfb++) cplx_pred_used[g][sfb] = 1; |
196 | | |
197 | 1.47M | for (sfb = max_sfb_ste; sfb < SFB_NUM_MAX; sfb++) |
198 | 1.46M | cplx_pred_used[g][sfb] = 0; |
199 | 11.5k | } |
200 | 6.59k | } |
201 | | |
202 | 15.4k | pstr_core_coder->pred_dir = ixheaacd_read_bits_buf(it_bit_buff, 1); |
203 | | |
204 | 15.4k | pstr_core_coder->complex_coef = ixheaacd_read_bits_buf(it_bit_buff, 1); |
205 | | |
206 | 15.4k | if (pstr_core_coder->complex_coef) { |
207 | 8.35k | if (usac_data->usac_independency_flg) |
208 | 7.74k | pstr_core_coder->use_prev_frame = 0; |
209 | 608 | else |
210 | 608 | pstr_core_coder->use_prev_frame = ixheaacd_read_bits_buf(it_bit_buff, 1); |
211 | 8.35k | } |
212 | | |
213 | 15.4k | if (usac_data->usac_independency_flg) |
214 | 9.02k | delta_code_time = 0; |
215 | 6.42k | else |
216 | 6.42k | delta_code_time = ixheaacd_read_bits_buf(it_bit_buff, 1); |
217 | | |
218 | 73.4k | for (g = 0; g < num_window_groups; g++) { |
219 | 208k | for (sfb = 0; sfb < max_sfb_ste; sfb += SFB_PER_PRED_BAND) { |
220 | 150k | if (delta_code_time == 1) { |
221 | 2.86k | last_alpha_q_re = alpha_q_re_prev[sfb]; |
222 | 2.86k | last_alpha_q_im = alpha_q_im_prev[sfb]; |
223 | 147k | } else { |
224 | 147k | if (sfb > 0) { |
225 | 90.2k | last_alpha_q_re = alpha_q_re[g][sfb - 1]; |
226 | 90.2k | last_alpha_q_im = alpha_q_im[g][sfb - 1]; |
227 | 90.2k | } else { |
228 | 57.1k | last_alpha_q_re = last_alpha_q_im = 0; |
229 | 57.1k | } |
230 | 147k | } |
231 | | |
232 | 150k | if (cplx_pred_used[g][sfb] == 1) { |
233 | 104k | dpcm_alpha = |
234 | 104k | -ixheaacd_huff_codeword(ptr_huff_code_word, 0, it_bit_buff) + 60; |
235 | 104k | alpha_q_re[g][sfb] = dpcm_alpha + last_alpha_q_re; |
236 | | |
237 | 104k | if (pstr_core_coder->complex_coef) { |
238 | 76.4k | dpcm_alpha = |
239 | 76.4k | -ixheaacd_huff_codeword(ptr_huff_code_word, 0, it_bit_buff) + 60; |
240 | 76.4k | alpha_q_im[g][sfb] = dpcm_alpha + last_alpha_q_im; |
241 | 76.4k | } else { |
242 | 28.0k | alpha_q_im[g][sfb] = 0; |
243 | 28.0k | } |
244 | 104k | } else { |
245 | 45.8k | alpha_q_re[g][sfb] = 0; |
246 | 45.8k | alpha_q_im[g][sfb] = 0; |
247 | 45.8k | } |
248 | | |
249 | 150k | if ((sfb + 1) < max_sfb_ste) { |
250 | 93.7k | alpha_q_re[g][sfb + 1] = alpha_q_re[g][sfb]; |
251 | 93.7k | alpha_q_im[g][sfb + 1] = alpha_q_im[g][sfb]; |
252 | 93.7k | } |
253 | | |
254 | 150k | alpha_q_re_prev[sfb] = alpha_q_re[g][sfb]; |
255 | 150k | alpha_q_im_prev[sfb] = alpha_q_im[g][sfb]; |
256 | 150k | } |
257 | 7.70M | for (sfb = max_sfb_ste; sfb < SFB_NUM_MAX; sfb++) { |
258 | 7.64M | alpha_q_re[g][sfb] = 0; |
259 | 7.64M | alpha_q_im[g][sfb] = 0; |
260 | 7.64M | alpha_q_re_prev[sfb] = 0; |
261 | 7.64M | alpha_q_im_prev[sfb] = 0; |
262 | 7.64M | } |
263 | 58.0k | } |
264 | | |
265 | 15.4k | return; |
266 | 15.4k | } |
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 | 49.9k | ia_bit_buf_struct *it_bit_buff, WORD32 chn) { |
272 | 49.9k | WORD32 g, sfb; |
273 | 49.9k | WORD32 ms_mask_present; |
274 | | |
275 | 49.9k | UWORD8 *sfb_group = usac_data->group_dis[chn]; |
276 | 49.9k | UWORD8 max_sfb = pstr_core_coder->max_sfb_ste; |
277 | 49.9k | UWORD8 *ms_used = usac_data->ms_used[chn]; |
278 | 49.9k | ia_sfb_info_struct *info = usac_data->pstr_sfb_info[chn]; |
279 | | |
280 | 49.9k | ms_mask_present = ixheaacd_read_bits_buf(it_bit_buff, 2); |
281 | | |
282 | 49.9k | switch (ms_mask_present) { |
283 | 14.4k | case 0: |
284 | | |
285 | 14.4k | break; |
286 | | |
287 | 907 | case 1: |
288 | 4.75k | for (g = 0; g < info->max_win_len; g = *sfb_group++) { |
289 | 31.5k | for (sfb = 0; sfb < max_sfb; sfb++) { |
290 | 27.6k | *ms_used = ixheaacd_read_bits_buf(it_bit_buff, 1); |
291 | 27.6k | ms_used++; |
292 | 27.6k | } |
293 | 36.1k | for (; sfb < info->sfb_per_sbk; sfb++) { |
294 | 32.2k | *ms_used = 0; |
295 | 32.2k | ms_used++; |
296 | 32.2k | } |
297 | 3.84k | } |
298 | | |
299 | 907 | break; |
300 | 19.1k | case 2: |
301 | 40.2k | for (g = 0; g < info->max_win_len; g = *sfb_group++) |
302 | 848k | for (sfb = 0; sfb < info->sfb_per_sbk; sfb++) *ms_used++ = 1; |
303 | 19.1k | break; |
304 | | |
305 | 15.4k | case 3: |
306 | | |
307 | 15.4k | ixheaacd_cplx_pred_data(usac_data, pstr_core_coder, info->num_groups, |
308 | 15.4k | it_bit_buff); |
309 | 15.4k | return 3; |
310 | 49.9k | } |
311 | | |
312 | 4.72M | for (sfb = 0; sfb < SFB_NUM_MAX; sfb++) { |
313 | 4.69M | usac_data->alpha_q_re_prev[sfb] = 0; |
314 | 4.69M | usac_data->alpha_q_im_prev[sfb] = 0; |
315 | 4.69M | } |
316 | 34.5k | return ms_mask_present; |
317 | 49.9k | } |
318 | | |
319 | | VOID ixheaacd_ms_stereo(ia_usac_data_struct *usac_data, WORD32 *r_spec, |
320 | 20.0k | WORD32 *l_spec, WORD32 chn, WORD32 nband) { |
321 | 20.0k | WORD32 temp_r, temp_l; |
322 | 20.0k | WORD32 sfb, k, grp, grp_len; |
323 | 20.0k | ia_sfb_info_struct *ptr_sfb_info = usac_data->pstr_sfb_info[chn]; |
324 | 20.0k | UWORD8 *ms_used = usac_data->ms_used[chn]; |
325 | 20.0k | WORD32 ixheaacd_drc_offset = 0; |
326 | | |
327 | 44.8k | for (grp = 0; grp < ptr_sfb_info->num_groups; grp++) { |
328 | 53.7k | for (grp_len = 0; grp_len < ptr_sfb_info->group_len[grp]; grp_len++) { |
329 | 28.8k | ixheaacd_drc_offset = 0; |
330 | 144k | for (sfb = 0; sfb < nband; sfb++) { |
331 | 115k | ixheaacd_drc_offset += ptr_sfb_info->sfb_width[sfb]; |
332 | 115k | if (ms_used[sfb]) { |
333 | 1.14M | for (k = 0; k < ptr_sfb_info->sfb_width[sfb]; k++) { |
334 | 1.05M | temp_r = *r_spec; |
335 | 1.05M | temp_l = *l_spec; |
336 | 1.05M | *l_spec = ixheaac_add32_sat(temp_r, temp_l); |
337 | 1.05M | *r_spec = ixheaac_sub32_sat(temp_l, temp_r); |
338 | 1.05M | r_spec++; |
339 | 1.05M | l_spec++; |
340 | 1.05M | } |
341 | 91.1k | } else { |
342 | 24.5k | r_spec += ptr_sfb_info->sfb_width[sfb]; |
343 | 24.5k | l_spec += ptr_sfb_info->sfb_width[sfb]; |
344 | 24.5k | } |
345 | 115k | } |
346 | | |
347 | 28.8k | l_spec = l_spec + ptr_sfb_info->bins_per_sbk - ixheaacd_drc_offset; |
348 | 28.8k | r_spec = r_spec + ptr_sfb_info->bins_per_sbk - ixheaacd_drc_offset; |
349 | 28.8k | } |
350 | | |
351 | 24.8k | ms_used += ptr_sfb_info->sfb_per_sbk; |
352 | 24.8k | } |
353 | 20.0k | } |
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 | 115k | const WORD32 factor_odd) { |
359 | 115k | WORD32 i; |
360 | 115k | WORD64 sum; |
361 | | |
362 | 115k | sum = ixheaac_mult32x32in64(in[2], filter[0]); |
363 | 115k | sum = ixheaac_mac32x32in64(sum, in[1], filter[1]); |
364 | 115k | sum = ixheaac_mac32x32in64(sum, in[0], filter[2]); |
365 | 115k | sum = ixheaac_mac32x32in64_n(sum, &in[0], &filter[3], 4); |
366 | 115k | *out = ixheaac_add32_sat( |
367 | 115k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); |
368 | 115k | out++; |
369 | | |
370 | 115k | sum = ixheaac_mult32x32in64(in[1], filter[0]); |
371 | 115k | sum = ixheaac_mac32x32in64(sum, in[0], filter[1]); |
372 | 115k | sum = ixheaac_mac32x32in64_n(sum, &in[0], &filter[2], 5); |
373 | 115k | *out = ixheaac_add32_sat( |
374 | 115k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); |
375 | 115k | out++; |
376 | | |
377 | 115k | sum = ixheaac_mult32x32in64(in[0], filter[0]); |
378 | 115k | sum = ixheaac_mac32x32in64_n(sum, &in[0], &filter[1], 6); |
379 | 115k | *out = ixheaac_add32_sat( |
380 | 115k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); |
381 | 115k | out++; |
382 | | |
383 | 7.43M | for (i = 3; i < length - 4; i += 2) { |
384 | 7.31M | sum = 0; |
385 | 7.31M | sum = ixheaac_mac32x32in64_7(&in[i - 3], filter); |
386 | 7.31M | *out = ixheaac_add32_sat( |
387 | 7.31M | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); |
388 | 7.31M | out++; |
389 | | |
390 | 7.31M | sum = 0; |
391 | 7.31M | sum = ixheaac_mac32x32in64_7(&in[i - 2], filter); |
392 | 7.31M | *out = ixheaac_add32_sat( |
393 | 7.31M | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); |
394 | 7.31M | out++; |
395 | 7.31M | } |
396 | 115k | i = length - 3; |
397 | 115k | sum = 0; |
398 | 115k | sum = ixheaac_mac32x32in64_n(sum, &in[i - 3], filter, 6); |
399 | 115k | sum = ixheaac_mac32x32in64(sum, in[i + 2], filter[6]); |
400 | 115k | *out = ixheaac_add32_sat( |
401 | 115k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); |
402 | | |
403 | 115k | out++; |
404 | 115k | i = length - 2; |
405 | 115k | sum = 0; |
406 | 115k | sum = ixheaac_mac32x32in64_n(sum, &in[i - 3], filter, 5); |
407 | 115k | sum = ixheaac_mac32x32in64(sum, in[i + 1], filter[5]); |
408 | 115k | sum = ixheaac_mac32x32in64(sum, in[i], filter[6]); |
409 | | |
410 | 115k | *out = ixheaac_add32_sat( |
411 | 115k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); |
412 | 115k | out++; |
413 | | |
414 | 115k | i = length - 1; |
415 | 115k | sum = 0; |
416 | 115k | sum = ixheaac_mac32x32in64_n(sum, &in[i - 3], filter, 4); |
417 | 115k | sum = ixheaac_mac32x32in64(sum, in[i], filter[4]); |
418 | 115k | sum = ixheaac_mac32x32in64(sum, in[i - 1], filter[5]); |
419 | 115k | sum = ixheaac_mac32x32in64(sum, in[i - 2], filter[6]); |
420 | | |
421 | 115k | *out = ixheaac_add32_sat( |
422 | 115k | *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); |
423 | 115k | } |
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 | 8.17k | const WORD32 prev_w_shape) { |
430 | 8.17k | WORD32 i; |
431 | 8.17k | const WORD16 *mdst_fcoeff_curr, *mdst_fcoeff_prev; |
432 | | |
433 | 8.17k | switch (window) { |
434 | 115 | case ONLY_LONG_SEQUENCE: |
435 | 7.71k | case EIGHT_SHORT_SEQUENCE: |
436 | 7.71k | mdst_fcoeff_curr = |
437 | 7.71k | ixheaacd_mdst_fcoeff_longshort_curr[prev_w_shape][w_shape]; |
438 | 7.71k | mdst_fcoeff_prev = ixheaacd_mdst_fcoeff_l_s_start_left_prev[prev_w_shape]; |
439 | 7.71k | break; |
440 | 16 | case LONG_START_SEQUENCE: |
441 | 16 | mdst_fcoeff_curr = ixheaacd_mdst_fcoeff_start_curr[prev_w_shape][w_shape]; |
442 | 16 | mdst_fcoeff_prev = ixheaacd_mdst_fcoeff_l_s_start_left_prev[prev_w_shape]; |
443 | 16 | break; |
444 | 261 | case LONG_STOP_SEQUENCE: |
445 | 261 | mdst_fcoeff_curr = ixheaacd_mdst_fcoeff_stop_cur[prev_w_shape][w_shape]; |
446 | 261 | mdst_fcoeff_prev = |
447 | 261 | ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[prev_w_shape]; |
448 | 261 | break; |
449 | 186 | case STOP_START_SEQUENCE: |
450 | 186 | mdst_fcoeff_curr = |
451 | 186 | ixheaacd_mdst_fcoeff_stopstart_cur[prev_w_shape][w_shape]; |
452 | 186 | mdst_fcoeff_prev = |
453 | 186 | ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[prev_w_shape]; |
454 | 186 | 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 | 8.17k | } |
462 | | |
463 | 69.5k | for (i = 0; i < pstr_sfb_info->max_win_len; i++) { |
464 | 61.3k | ixheaacd_filter_and_add(dmx_re, pstr_sfb_info->bins_per_sbk, |
465 | 61.3k | mdst_fcoeff_curr, dmx_im, 1, 1); |
466 | | |
467 | 61.3k | if (dmx_re_prev) |
468 | 53.6k | ixheaacd_filter_and_add(dmx_re_prev, pstr_sfb_info->bins_per_sbk, |
469 | 53.6k | mdst_fcoeff_prev, dmx_im, -1, 1); |
470 | | |
471 | 61.3k | dmx_re_prev = dmx_re; |
472 | 61.3k | dmx_re += pstr_sfb_info->bins_per_sbk; |
473 | 61.3k | dmx_im += pstr_sfb_info->bins_per_sbk; |
474 | 61.3k | } |
475 | 8.17k | return; |
476 | 8.17k | } |
477 | | |
478 | | static VOID ixheaacd_cplx_pred_upmixing( |
479 | | ia_usac_data_struct *usac_data, WORD32 *l_spec, WORD32 *r_spec, |
480 | 15.2k | ia_usac_tmp_core_coder_struct *pstr_core_coder, WORD32 chn) { |
481 | 15.2k | ia_sfb_info_struct *pstr_sfb_info = usac_data->pstr_sfb_info[chn]; |
482 | 15.2k | WORD32 *dmx_re = &usac_data->scratch_buffer[0]; |
483 | 15.2k | WORD32 *dmx_im = &usac_data->x_ac_dec[0]; |
484 | | |
485 | 15.2k | WORD32 grp, sfb, grp_len, i = 0, k; |
486 | 15.2k | WORD32 *dmx_re_prev = usac_data->dmx_re_prev; |
487 | 15.2k | WORD32(*alpha_q_re)[SFB_NUM_MAX] = usac_data->alpha_q_re; |
488 | 15.2k | WORD32(*alpha_q_im)[SFB_NUM_MAX] = usac_data->alpha_q_im; |
489 | | |
490 | 15.2k | UWORD8(*cplx_pred_used)[SFB_NUM_MAX] = usac_data->cplx_pred_used; |
491 | | |
492 | 15.2k | WORD32 alpha_q_re_temp; |
493 | 15.2k | WORD32 alpha_q_im_temp; |
494 | 15.2k | WORD32 factor = 1; |
495 | | |
496 | 15.2k | if (pstr_core_coder->pred_dir) factor = -1; |
497 | | |
498 | 72.7k | for (grp = 0; grp < pstr_sfb_info->num_groups; grp++) { |
499 | 174k | for (grp_len = 0; grp_len < pstr_sfb_info->group_len[grp]; grp_len++) { |
500 | 1.89M | for (sfb = 0; sfb < pstr_sfb_info->sfb_per_sbk; sfb++) { |
501 | 1.77M | if (cplx_pred_used[grp][sfb] == 1) { |
502 | 770k | memcpy(&dmx_re[i], &l_spec[i], |
503 | 770k | pstr_sfb_info->sfb_width[sfb] * sizeof(WORD32)); |
504 | 770k | i += pstr_sfb_info->sfb_width[sfb]; |
505 | 770k | } |
506 | | |
507 | 1.00M | else { |
508 | 10.4M | for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) { |
509 | 9.46M | dmx_re[i] = (WORD32)( |
510 | 9.46M | ((WORD64)l_spec[i] + ((WORD64)factor * (WORD64)r_spec[i])) >> |
511 | 9.46M | 1); |
512 | 9.46M | } |
513 | 1.00M | } |
514 | 1.77M | } |
515 | 117k | } |
516 | 57.5k | } |
517 | | |
518 | 15.2k | memset(dmx_im, 0, sizeof(WORD32) * BLOCK_LEN_LONG); |
519 | | |
520 | 15.2k | if (pstr_core_coder->complex_coef) { |
521 | 8.17k | WORD32 *p_dmx_re_prev = |
522 | 8.17k | pstr_core_coder->use_prev_frame ? dmx_re_prev : NULL; |
523 | 8.17k | ixheaacd_estimate_dmx_im(dmx_re, p_dmx_re_prev, dmx_im, pstr_sfb_info, |
524 | 8.17k | usac_data->window_sequence[chn], |
525 | 8.17k | usac_data->window_shape[chn], |
526 | 8.17k | usac_data->window_shape_prev[chn]); |
527 | | |
528 | 25.6k | for (grp = 0, i = 0; grp < pstr_sfb_info->num_groups; grp++) { |
529 | 78.8k | for (grp_len = 0; grp_len < pstr_sfb_info->group_len[grp]; grp_len++) { |
530 | 996k | for (sfb = 0; sfb < pstr_sfb_info->sfb_per_sbk; sfb++) { |
531 | 935k | alpha_q_re_temp = ixheaac_sat64_32(ixheaac_mult32x32in64(alpha_q_re[grp][sfb], 1677722)); |
532 | 935k | alpha_q_im_temp = ixheaac_sat64_32(ixheaac_mult32x32in64(alpha_q_im[grp][sfb], 1677722)); |
533 | 935k | if (cplx_pred_used[grp][sfb]) { |
534 | 6.36M | for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) { |
535 | 5.66M | WORD32 mid_side = ixheaac_sub32_sat( |
536 | 5.66M | ixheaac_sub32_sat(r_spec[i], |
537 | 5.66M | (WORD32)((WORD64)ixheaac_mult32x32in64( |
538 | 5.66M | alpha_q_re_temp, l_spec[i]) >> |
539 | 5.66M | 24)), |
540 | 5.66M | (WORD32)((WORD64)ixheaac_mult32x32in64(alpha_q_im_temp, |
541 | 5.66M | dmx_im[i]) >> |
542 | 5.66M | 24)); |
543 | 5.66M | r_spec[i] = ixheaac_sat64_32((WORD64)factor) * |
544 | 5.66M | (WORD64)(ixheaac_sub32_sat(l_spec[i], mid_side)); |
545 | 5.66M | l_spec[i] = ixheaac_add32_sat(l_spec[i], mid_side); |
546 | 5.66M | } |
547 | 696k | } else { |
548 | 238k | i += pstr_sfb_info->sfb_width[sfb]; |
549 | 238k | } |
550 | 935k | } |
551 | 61.3k | } |
552 | 17.4k | } |
553 | 8.17k | } else { |
554 | 47.1k | for (grp = 0, i = 0; grp < pstr_sfb_info->num_groups; grp++) { |
555 | 95.7k | for (grp_len = 0; grp_len < pstr_sfb_info->group_len[grp]; grp_len++) { |
556 | 893k | for (sfb = 0; sfb < pstr_sfb_info->sfb_per_sbk; sfb++) { |
557 | 837k | alpha_q_re_temp = ixheaac_sat64_32(ixheaac_mult32x32in64(alpha_q_re[grp][sfb], 1677722)); |
558 | 837k | if (cplx_pred_used[grp][sfb]) { |
559 | 531k | for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) { |
560 | 457k | WORD32 mid_side = ixheaac_sub32_sat( |
561 | 457k | r_spec[i], (WORD32)((WORD64)ixheaac_mult32x32in64( |
562 | 457k | alpha_q_re_temp, l_spec[i]) >> |
563 | 457k | 24)); |
564 | | |
565 | 457k | r_spec[i] = ixheaac_sat64_32((WORD64)factor) * |
566 | 457k | (WORD64)(ixheaac_sub32_sat(l_spec[i], mid_side)); |
567 | 457k | l_spec[i] = ixheaac_add32_sat(l_spec[i], mid_side); |
568 | 457k | } |
569 | 764k | } else { |
570 | 764k | i += pstr_sfb_info->sfb_width[sfb]; |
571 | 764k | } |
572 | 837k | } |
573 | 55.6k | } |
574 | 40.1k | } |
575 | 7.05k | } |
576 | | |
577 | 15.2k | return; |
578 | 15.2k | } |
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 | 69.9M | for (i = 0; i < pstr_sfb_info->bins_per_sbk; i++) |
590 | 69.8M | dmx_re_prev[i] = (WORD32)(((WORD64)l_spec[i + offs] + |
591 | 69.8M | ((WORD64)factor * (WORD64)r_spec[i + offs])) >> |
592 | 69.8M | 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 | 284k | { |
602 | 284k | WORD32 win; |
603 | 284k | WORD32 mask = 0x40; |
604 | | |
605 | 284k | UWORD8 *scf_group_ptr = usac_data->group_dis[chn]; |
606 | | |
607 | 284k | win = ixheaacd_read_bits_buf(it_bit_buff, 2); |
608 | | |
609 | 284k | win = usac_data->window_sequence[chn] = |
610 | 284k | ixheaacd_win_seq_select(win, window_sequence_last); |
611 | 284k | if (win == -1) return -1; |
612 | | |
613 | 284k | usac_data->pstr_sfb_info[chn] = |
614 | 284k | usac_data->pstr_usac_winmap[usac_data->window_sequence[chn]]; |
615 | | |
616 | 284k | usac_data->window_shape[chn] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
617 | | |
618 | 284k | if (usac_data->pstr_usac_winmap[win]->islong) { |
619 | 207k | *max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 6); |
620 | 207k | *scf_group_ptr = 1; |
621 | 207k | } else { |
622 | 76.7k | WORD32 i, scale_factor_grouping; |
623 | | |
624 | 76.7k | *max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 4); |
625 | | |
626 | 76.7k | scale_factor_grouping = ixheaacd_read_bits_buf(it_bit_buff, 7); |
627 | | |
628 | 613k | for (i = 1; i < 8; i++) { |
629 | 536k | if (!(scale_factor_grouping & mask)) *scf_group_ptr++ = i; |
630 | | |
631 | 536k | mask = mask >> 1; |
632 | 536k | } |
633 | 76.7k | *scf_group_ptr++ = i; |
634 | | |
635 | 76.7k | ixheaacd_calc_grp_offset(usac_data->pstr_usac_winmap[win], |
636 | 76.7k | &usac_data->group_dis[chn][0]); |
637 | 76.7k | } |
638 | | |
639 | 284k | if (*max_sfb > usac_data->pstr_sfb_info[chn]->sfb_per_sbk) { |
640 | 514 | *max_sfb = usac_data->pstr_sfb_info[chn]->sfb_per_sbk; |
641 | 514 | return -1; |
642 | 514 | } |
643 | | |
644 | 283k | return 0; |
645 | 284k | } |
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 | 287k | WORD32 nr_core_coder_channels) { |
651 | 287k | WORD32 err_code = 0; |
652 | 287k | WORD32 k = 0, ch = 0, chn = 0, left = 0, right = 0; |
653 | | |
654 | 287k | ia_usac_tmp_core_coder_struct str_tmp_core_coder = {0}; |
655 | 287k | ia_usac_tmp_core_coder_struct *pstr_core_coder = &str_tmp_core_coder; |
656 | 287k | ia_td_frame_data_struct td_frame; |
657 | 287k | jmp_buf local; |
658 | | |
659 | 287k | if (usac_data->ec_flag) { |
660 | 0 | err_code = setjmp(local); |
661 | 0 | it_bit_buff->xaac_jmp_buf = &local; |
662 | 0 | } |
663 | 287k | if (err_code == 0 && |
664 | 287k | ((usac_data->ec_flag == 0) || (usac_data->frame_ok == 1 && usac_data->ec_flag == 1))) { |
665 | 287k | memset(&td_frame, 0, sizeof(td_frame)); |
666 | 287k | pstr_core_coder->tns_on_lr = 0; |
667 | 287k | pstr_core_coder->pred_dir = 0; |
668 | 287k | if (id != ID_USAC_LFE) { |
669 | 709k | for (ch = 0; ch < nr_core_coder_channels; ch++) |
670 | 423k | pstr_core_coder->core_mode[ch] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
671 | 285k | } else { |
672 | 3.72k | for (ch = 0; ch < nr_core_coder_channels; ch++) pstr_core_coder->core_mode[ch] = 0; |
673 | 1.86k | } |
674 | | |
675 | 287k | if (nr_core_coder_channels == 2 && pstr_core_coder->core_mode[0] == 0 && |
676 | 119k | 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 | 49.9k | left = chan_offset; |
682 | 49.9k | right = chan_offset + 1; |
683 | | |
684 | 49.9k | err_code = ixheaacd_ics_info(usac_data, left, &pstr_core_coder->max_sfb[left], |
685 | 49.9k | it_bit_buff, usac_data->window_sequence_last[left]); |
686 | | |
687 | 49.9k | if (err_code == -1) { |
688 | 24 | 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 | 24 | } else { |
694 | 24 | return err_code; |
695 | 24 | } |
696 | 24 | } |
697 | | |
698 | 49.9k | pstr_core_coder->common_max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 1); |
699 | | |
700 | 49.9k | if (pstr_core_coder->common_max_sfb == 0) { |
701 | 15.6k | if (usac_data->window_sequence[left] == EIGHT_SHORT_SEQUENCE) |
702 | 14.2k | pstr_core_coder->max_sfb[right] = ixheaacd_read_bits_buf(it_bit_buff, 4); |
703 | 1.44k | else |
704 | 1.44k | pstr_core_coder->max_sfb[right] = ixheaacd_read_bits_buf(it_bit_buff, 6); |
705 | 34.3k | } else { |
706 | 34.3k | pstr_core_coder->max_sfb[right] = pstr_core_coder->max_sfb[left]; |
707 | 34.3k | } |
708 | | |
709 | 49.9k | pstr_core_coder->max_sfb_ste = |
710 | 49.9k | max(pstr_core_coder->max_sfb[left], pstr_core_coder->max_sfb[right]); |
711 | | |
712 | 49.9k | usac_data->window_sequence[right] = usac_data->window_sequence[left]; |
713 | 49.9k | usac_data->window_shape[right] = usac_data->window_shape[left]; |
714 | 49.9k | memcpy(&usac_data->group_dis[right][0], &usac_data->group_dis[left][0], 8); |
715 | 49.9k | usac_data->pstr_sfb_info[right] = usac_data->pstr_sfb_info[left]; |
716 | 49.9k | if (pstr_core_coder->max_sfb[right] > usac_data->pstr_sfb_info[right]->sfb_per_sbk) |
717 | 226 | pstr_core_coder->max_sfb[right] = usac_data->pstr_sfb_info[right]->sfb_per_sbk; |
718 | | |
719 | 49.9k | pstr_core_coder->ms_mask_present[0] = |
720 | 49.9k | ixheaacd_read_ms_mask(usac_data, pstr_core_coder, it_bit_buff, left); |
721 | 52.7k | } else { |
722 | 52.7k | left = chan_offset; |
723 | 52.7k | right = chan_offset + 1; |
724 | | |
725 | 52.7k | pstr_core_coder->ms_mask_present[0] = 0; |
726 | 52.7k | pstr_core_coder->ms_mask_present[1] = 0; |
727 | | |
728 | 7.23M | for (k = 0; k < SFB_NUM_MAX; k++) { |
729 | 7.17M | usac_data->alpha_q_re_prev[k] = 0; |
730 | 7.17M | usac_data->alpha_q_im_prev[k] = 0; |
731 | 7.17M | } |
732 | 52.7k | } |
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 | 20.4k | if (pstr_core_coder->common_window) { |
751 | 18.0k | pstr_core_coder->common_tns = ixheaacd_read_bits_buf(it_bit_buff, 1); |
752 | | |
753 | 18.0k | } else { |
754 | 2.31k | pstr_core_coder->common_tns = 0; |
755 | 2.31k | } |
756 | | |
757 | 20.4k | pstr_core_coder->tns_on_lr = ixheaacd_read_bits_buf(it_bit_buff, 1); |
758 | | |
759 | 20.4k | if (pstr_core_coder->common_tns) { |
760 | 4.03k | ixheaacd_read_tns_u(usac_data->pstr_sfb_info[0], &usac_data->pstr_tns[left][0], |
761 | 4.03k | it_bit_buff); |
762 | 4.03k | memcpy(&usac_data->pstr_tns[right][0], &usac_data->pstr_tns[left][0], |
763 | 4.03k | sizeof(ia_tns_frame_info_struct)); |
764 | | |
765 | 4.03k | pstr_core_coder->tns_data_present[0] = 2; |
766 | 4.03k | pstr_core_coder->tns_data_present[1] = 2; |
767 | 16.3k | } else { |
768 | 16.3k | pstr_core_coder->tns_present_both = ixheaacd_read_bits_buf(it_bit_buff, 1); |
769 | | |
770 | 16.3k | if (pstr_core_coder->tns_present_both) { |
771 | 12.1k | pstr_core_coder->tns_data_present[0] = 1; |
772 | 12.1k | pstr_core_coder->tns_data_present[1] = 1; |
773 | 12.1k | } else { |
774 | 4.17k | pstr_core_coder->tns_data_present[1] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
775 | 4.17k | pstr_core_coder->tns_data_present[0] = 1 - pstr_core_coder->tns_data_present[1]; |
776 | 4.17k | } |
777 | 16.3k | } |
778 | 82.3k | } else { |
779 | 82.3k | pstr_core_coder->common_tns = 0; |
780 | 82.3k | pstr_core_coder->tns_data_present[0] = 0; |
781 | 82.3k | pstr_core_coder->tns_data_present[1] = 0; |
782 | 82.3k | } |
783 | | |
784 | 185k | } else { |
785 | 185k | pstr_core_coder->common_window = 0; |
786 | 185k | pstr_core_coder->common_tw = 0; |
787 | 185k | left = chan_offset; |
788 | 185k | right = chan_offset; |
789 | 185k | if (nr_core_coder_channels == 2) right = chan_offset + 1; |
790 | 185k | } |
791 | | |
792 | 711k | for (ch = 0, chn = chan_offset; ch < nr_core_coder_channels; ch++, chn++) { |
793 | 424k | if (pstr_core_coder->core_mode[chn] == CORE_MODE_LPD && |
794 | 61.7k | 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 | 424k | if (pstr_core_coder->core_mode[ch] == 1) { |
814 | 90.1k | err_code = ixheaacd_tw_buff_update(usac_data, chn, usac_data->str_tddec[chn]); |
815 | 90.1k | if (err_code == -1) return err_code; |
816 | | |
817 | 90.1k | if (!usac_data->td_frame_prev[chn]) { |
818 | 22.8k | ixheaacd_fix2flt_data(usac_data, usac_data->str_tddec[chn], chn); |
819 | 22.8k | } |
820 | | |
821 | 83.7M | for (k = 0; k < usac_data->ccfl; k++) { |
822 | 83.6M | usac_data->time_sample_vector[chn][k] = (FLOAT32)( |
823 | 83.6M | (FLOAT32)usac_data->output_data_ptr[chn][k] * (FLOAT32)(ONE_BY_TWO_POW_15)); |
824 | 83.6M | } |
825 | 90.1k | usac_data->present_chan = chn; |
826 | 90.1k | err_code = ixheaacd_lpd_channel_stream(usac_data, &td_frame, it_bit_buff, |
827 | 90.1k | usac_data->time_sample_vector[chn]); |
828 | 90.1k | if (err_code == -1) return err_code; |
829 | 90.1k | if (usac_data->ec_flag) { |
830 | 0 | it_bit_buff->xaac_jmp_buf = &local; |
831 | 0 | } |
832 | 90.1k | 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 | 82.9M | for (k = 0; k < usac_data->ccfl; k++) { |
837 | 82.8M | usac_data->output_data_ptr[chn][k] = |
838 | 82.8M | (WORD32)(usac_data->time_sample_vector[chn][k] * (FLOAT32)((WORD64)1 << 15)); |
839 | 82.8M | } |
840 | | |
841 | 90.1k | usac_data->window_shape[chn] = WIN_SEL_0; |
842 | | |
843 | 90.1k | ixheaacd_td_frm_dec(usac_data, chn, td_frame.mod[0]); |
844 | | |
845 | 90.1k | usac_data->window_shape_prev[chn] = usac_data->window_shape[chn]; |
846 | 90.1k | usac_data->window_sequence_last[chn] = EIGHT_SHORT_SEQUENCE; |
847 | | |
848 | 334k | } else { |
849 | 334k | memset(usac_data->coef_fix[chn], 0, LN2 * sizeof(*usac_data->coef_fix[0])); |
850 | | |
851 | 334k | if (usac_data->str_tddec[chn] && usac_data->td_frame_prev[chn]) { |
852 | 19.7k | 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 | 19.7k | ixheaacd_lpd_dec_update(usac_data->str_tddec[chn], usac_data, chn); |
857 | 19.7k | } |
858 | | |
859 | 334k | if (id != ID_USAC_LFE) { |
860 | 332k | if ((nr_core_coder_channels == 1) || |
861 | 223k | (pstr_core_coder->core_mode[0] != pstr_core_coder->core_mode[1])) |
862 | 127k | pstr_core_coder->tns_data_present[ch] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
863 | 332k | } |
864 | | |
865 | 334k | err_code = ixheaacd_fd_channel_stream( |
866 | 334k | usac_data, pstr_core_coder, &pstr_core_coder->max_sfb[ch], |
867 | 334k | usac_data->window_sequence_last[chn], chn, usac_data->noise_filling_config[elem_idx], |
868 | 334k | ch, it_bit_buff); |
869 | 334k | if (err_code == -1) return err_code; |
870 | 334k | } |
871 | 424k | } |
872 | | |
873 | 287k | if (pstr_core_coder->core_mode[0] == CORE_MODE_FD && |
874 | 227k | 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 | 287k | if (pstr_core_coder->tns_on_lr == 0 && (id != ID_USAC_LFE)) { |
881 | 655k | for (ch = 0, chn = left; chn <= right; ch++, chn++) { |
882 | 387k | if (pstr_core_coder->core_mode[ch] == CORE_MODE_FD) { |
883 | 298k | err_code = ixheaacd_tns_apply(usac_data, usac_data->coef_fix[chn], |
884 | 298k | pstr_core_coder->max_sfb[ch], |
885 | 298k | usac_data->pstr_sfb_info[chn], usac_data->pstr_tns[chn]); |
886 | 298k | if (err_code) return err_code; |
887 | 298k | } |
888 | 387k | } |
889 | 267k | } |
890 | | |
891 | 287k | if (nr_core_coder_channels == 2 && pstr_core_coder->core_mode[0] == 0 && |
892 | 118k | pstr_core_coder->core_mode[1] == 0) { |
893 | 101k | if (pstr_core_coder->ms_mask_present[0] == 3) { |
894 | 15.2k | ixheaacd_cplx_pred_upmixing(usac_data, usac_data->coef_fix[left], |
895 | 15.2k | usac_data->coef_fix[right], pstr_core_coder, left); |
896 | | |
897 | 86.6k | } else if (pstr_core_coder->ms_mask_present[0] > 0) { |
898 | 20.0k | ixheaacd_ms_stereo(usac_data, usac_data->coef_fix[right], usac_data->coef_fix[left], left, |
899 | 20.0k | pstr_core_coder->max_sfb[right] > pstr_core_coder->max_sfb[left] |
900 | 20.0k | ? pstr_core_coder->max_sfb[right] |
901 | 20.0k | : pstr_core_coder->max_sfb[left]); |
902 | 20.0k | } |
903 | | |
904 | 101k | if (pstr_core_coder->tns_on_lr) { |
905 | 47.3k | for (ch = 0, chn = left; chn <= right; ch++, chn++) { |
906 | 31.5k | if (pstr_core_coder->core_mode[ch] == CORE_MODE_FD) { |
907 | 31.5k | err_code = ixheaacd_tns_apply( |
908 | 31.5k | usac_data, usac_data->coef_fix[chn], pstr_core_coder->max_sfb[ch], |
909 | 31.5k | usac_data->pstr_sfb_info[chn], usac_data->pstr_tns[chn]); |
910 | 31.5k | if (err_code) return err_code; |
911 | 31.5k | } |
912 | 31.5k | } |
913 | 15.7k | } |
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 | 287k | 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 | 287k | } 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 | 708k | for (ch = left; ch <= right; ch++) { |
978 | 420k | FLOAT32 *ptr_scratch = |
979 | 420k | (FLOAT32 *)usac_data->str_error_concealment[ch].str_ec_scratch.spec_coeff; |
980 | 420k | if ((pstr_core_coder->core_mode[ch] != CORE_MODE_LPD && |
981 | 360k | usac_data->td_frame_prev[ch] != CORE_MODE_LPD && usac_data->ec_flag) || |
982 | 420k | (pstr_core_coder->core_mode[ch] == CORE_MODE_FD && usac_data->ec_flag == 0)) { |
983 | 360k | if (usac_data->tw_mdct[elem_idx]) { |
984 | 0 | err_code = -1; |
985 | 0 | return err_code; |
986 | |
|
987 | 360k | } else { |
988 | 360k | if (usac_data->frame_ok == 0) { |
989 | 0 | usac_data->fac_data_present[ch] = 0; |
990 | 0 | } |
991 | 360k | err_code = ixheaacd_fd_frm_dec(usac_data, ch); |
992 | 360k | if (err_code == -1) return err_code; |
993 | 359k | 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 | 359k | } else { |
1006 | 360M | for (k = 0; k < usac_data->ccfl; k++) { |
1007 | 360M | usac_data->time_sample_vector[ch][k] = |
1008 | 360M | (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] * |
1009 | 360M | (FLOAT32)(ONE_BY_TWO_POW_15)); |
1010 | 360M | } |
1011 | 359k | } |
1012 | 359k | } |
1013 | 359k | usac_data->window_shape_prev[ch] = usac_data->window_shape[ch]; |
1014 | 359k | usac_data->window_sequence_last[ch] = usac_data->window_sequence[ch]; |
1015 | 359k | } else { |
1016 | 60.7k | 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 | 60.7k | } else { |
1041 | 56.0M | for (k = 0; k < usac_data->ccfl; k++) { |
1042 | 56.0M | usac_data->time_sample_vector[ch][k] = |
1043 | 56.0M | (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] * |
1044 | 56.0M | (FLOAT32)(ONE_BY_TWO_POW_15)); |
1045 | 56.0M | } |
1046 | 60.7k | } |
1047 | 60.7k | } |
1048 | 420k | 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 | 420k | } |
1057 | 287k | 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 | 287k | } else { |
1064 | 707k | for (ch = 0, chn = left; chn <= right; chn++, ch++) |
1065 | 420k | usac_data->td_frame_prev[chn] = pstr_core_coder->core_mode[ch]; |
1066 | 287k | } |
1067 | | |
1068 | 287k | return 0; |
1069 | 287k | } |