/src/libxaac/decoder/ixheaacd_acelp_bitparse.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 <string.h> |
21 | | #include "ixheaac_type_def.h" |
22 | | |
23 | | #include "ixheaacd_acelp_com.h" |
24 | | #include "ixheaacd_bitbuffer.h" |
25 | | |
26 | | #include "ixheaacd_interface.h" |
27 | | #include "ixheaacd_cnst.h" |
28 | | #include "ixheaacd_info.h" |
29 | | #include "ixheaacd_sbr_common.h" |
30 | | #include "ixheaacd_drc_data_struct.h" |
31 | | #include "ixheaacd_defines.h" |
32 | | #include "ixheaacd_aac_rom.h" |
33 | | #include "ixheaacd_pulsedata.h" |
34 | | #include "ixheaacd_pns.h" |
35 | | #include "ixheaac_constants.h" |
36 | | #include "ixheaacd_sbrdecsettings.h" |
37 | | #include "ixheaacd_sbrdecoder.h" |
38 | | #include "ixheaacd_acelp_info.h" |
39 | | #include "ixheaacd_tns_usac.h" |
40 | | #include "ixheaacd_ec_defines.h" |
41 | | #include "ixheaacd_ec_struct_def.h" |
42 | | #include "ixheaacd_main.h" |
43 | | #include "ixheaacd_channelinfo.h" |
44 | | #include "ixheaacd_ec.h" |
45 | | #include "ixheaacd_arith_dec.h" |
46 | | #include "ixheaacd_func_def.h" |
47 | | #include "ixheaac_basic_ops32.h" |
48 | | #include "ixheaac_error_standards.h" |
49 | | #include "ixheaacd_error_codes.h" |
50 | | |
51 | | extern const ia_usac_samp_rate_info ixheaacd_samp_rate_info[]; |
52 | | |
53 | 363k | WORD32 ixheaacd_get_mode_lpc(WORD32 lpc_set, ia_bit_buf_struct *it_bit_buff, WORD32 *nk_mode) { |
54 | 363k | WORD32 mode_lpc = 0; |
55 | 363k | switch (lpc_set) { |
56 | 82.7k | case 4: |
57 | 82.7k | mode_lpc = 0; |
58 | 82.7k | break; |
59 | 58.3k | case 0: |
60 | 139k | case 2: |
61 | 139k | mode_lpc = ixheaacd_read_bits_buf(it_bit_buff, 1); |
62 | 139k | if (mode_lpc == 1) *nk_mode = 3; |
63 | 139k | break; |
64 | 64.6k | case 1: |
65 | 64.6k | if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0) |
66 | 47.3k | mode_lpc = *nk_mode = 2; |
67 | 17.2k | else { |
68 | 17.2k | if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0) |
69 | 12.8k | mode_lpc = *nk_mode = 0; |
70 | 4.36k | else |
71 | 4.36k | mode_lpc = *nk_mode = 1; |
72 | 17.2k | } |
73 | 64.6k | break; |
74 | 76.6k | case 3: |
75 | 76.6k | if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0) |
76 | 51.5k | mode_lpc = *nk_mode = 1; |
77 | 25.0k | else { |
78 | 25.0k | if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0) |
79 | 17.4k | mode_lpc = *nk_mode = 0; |
80 | 7.53k | else { |
81 | 7.53k | if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0) |
82 | 2.65k | mode_lpc = 2; |
83 | 4.88k | else |
84 | 4.88k | mode_lpc = 3; |
85 | 7.53k | *nk_mode = 2; |
86 | 7.53k | } |
87 | 25.0k | } |
88 | 76.6k | break; |
89 | 363k | } |
90 | 363k | return mode_lpc; |
91 | 363k | } |
92 | | |
93 | 359k | VOID ixheaacd_qn_data(WORD32 nk_mode, WORD32 *qn, ia_bit_buf_struct *it_bit_buff) { |
94 | 359k | WORD32 k; |
95 | 359k | switch (nk_mode) { |
96 | 51.5k | case 1: |
97 | 154k | for (k = 0; k < 2; k++) { |
98 | 150k | while (ixheaacd_read_bits_buf(it_bit_buff, 1) == 1) { |
99 | 47.0k | qn[k] += 1; |
100 | 47.0k | } |
101 | 103k | if (qn[k] > 0) qn[k] += 1; |
102 | 103k | } |
103 | 51.5k | break; |
104 | 202k | case 0: |
105 | 257k | case 2: |
106 | 307k | case 3: |
107 | 923k | for (k = 0; k < 2; k++) qn[k] = 2 + ixheaacd_read_bits_buf(it_bit_buff, 2); |
108 | | |
109 | 307k | if (nk_mode == 2) { |
110 | 164k | for (k = 0; k < 2; k++) { |
111 | 109k | if (qn[k] > 4) { |
112 | 13.6k | qn[k] = 0; |
113 | | |
114 | 30.6k | while (ixheaacd_read_bits_buf(it_bit_buff, 1) == 1) qn[k] += 1; |
115 | | |
116 | 13.6k | if (qn[k] > 0) qn[k] += 4; |
117 | 13.6k | } |
118 | 109k | } |
119 | 253k | } else { |
120 | 759k | for (k = 0; k < 2; k++) { |
121 | 506k | if (qn[k] > 4) { |
122 | 67.5k | WORD32 qn_ext = 0; |
123 | 188k | while (ixheaacd_read_bits_buf(it_bit_buff, 1) == 1) qn_ext += 1; |
124 | | |
125 | 67.5k | switch (qn_ext) { |
126 | 37.8k | case 0: |
127 | 37.8k | qn[k] = 5; |
128 | 37.8k | break; |
129 | 13.1k | case 1: |
130 | 13.1k | qn[k] = 6; |
131 | 13.1k | break; |
132 | 6.43k | case 2: |
133 | 6.43k | qn[k] = 0; |
134 | 6.43k | break; |
135 | 10.1k | default: |
136 | 10.1k | qn[k] = qn_ext + 4; |
137 | 10.1k | break; |
138 | 67.5k | } |
139 | 67.5k | } |
140 | 506k | } |
141 | 253k | } |
142 | 307k | break; |
143 | 359k | } |
144 | 359k | return; |
145 | 359k | } |
146 | | |
147 | | VOID ixheaacd_code_book_indices(ia_td_frame_data_struct *pstr_td_frame_data, WORD32 nk_mode, |
148 | 359k | WORD32 *pos, ia_bit_buf_struct *it_bit_buff) { |
149 | 359k | WORD32 k, qn[2] = {0, 0}, nk, n, i; |
150 | | |
151 | 359k | ixheaacd_qn_data(nk_mode, &qn[0], it_bit_buff); |
152 | | |
153 | 359k | pstr_td_frame_data->lpc_first_approx_idx[(*pos)++] = qn[0]; |
154 | 359k | pstr_td_frame_data->lpc_first_approx_idx[(*pos)++] = qn[1]; |
155 | | |
156 | 1.07M | for (k = 0; k < 2; k++) { |
157 | 719k | if (qn[k] > 0) { |
158 | 629k | if (qn[k] > 4) { |
159 | 67.3k | nk = (qn[k] - 3) / 2; |
160 | 67.3k | n = qn[k] - nk * 2; |
161 | 562k | } else { |
162 | 562k | nk = 0; |
163 | 562k | n = qn[k]; |
164 | 562k | } |
165 | 629k | pstr_td_frame_data->lpc_first_approx_idx[(*pos)++] = |
166 | 629k | ixheaacd_read_bits_buf(it_bit_buff, 4 * n); |
167 | | |
168 | 5.66M | for (i = 0; i < 8; i++) |
169 | 5.03M | pstr_td_frame_data->lpc_first_approx_idx[(*pos)++] = |
170 | 5.03M | ixheaacd_read_bits_buf(it_bit_buff, nk); |
171 | 629k | } |
172 | 719k | } |
173 | 359k | return; |
174 | 359k | } |
175 | | |
176 | | VOID ixheaacd_lpc_data(WORD32 first_lpd_flag, WORD32 mod[], |
177 | | ia_td_frame_data_struct *pstr_td_frame_data, |
178 | 82.7k | ia_bit_buf_struct *it_bit_buff) { |
179 | 82.7k | WORD32 mode_lpc, nk_mode = 0, j = 0; |
180 | | |
181 | 82.7k | mode_lpc = ixheaacd_get_mode_lpc(4, it_bit_buff, &nk_mode); |
182 | | |
183 | 82.7k | pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8); |
184 | | |
185 | 82.7k | ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff); |
186 | 82.7k | if (first_lpd_flag) { |
187 | 58.3k | mode_lpc = ixheaacd_get_mode_lpc(0, it_bit_buff, &nk_mode); |
188 | 58.3k | pstr_td_frame_data->lpc_first_approx_idx[j++] = mode_lpc; |
189 | | |
190 | 58.3k | if (mode_lpc == 0) |
191 | 42.5k | pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8); |
192 | | |
193 | 58.3k | ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff); |
194 | 58.3k | } |
195 | 82.7k | if (mod[0] < 3) { |
196 | 81.5k | mode_lpc = ixheaacd_get_mode_lpc(2, it_bit_buff, &nk_mode); |
197 | 81.5k | pstr_td_frame_data->lpc_first_approx_idx[j++] = mode_lpc; |
198 | | |
199 | 81.5k | if (mode_lpc == 0) |
200 | 59.0k | pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8); |
201 | | |
202 | 81.5k | ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff); |
203 | 81.5k | } |
204 | 82.7k | if (mod[0] < 2) { |
205 | 64.6k | mode_lpc = ixheaacd_get_mode_lpc(1, it_bit_buff, &nk_mode); |
206 | 64.6k | pstr_td_frame_data->lpc_first_approx_idx[j++] = mode_lpc; |
207 | | |
208 | 64.6k | if (mode_lpc == 0) |
209 | 12.8k | pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8); |
210 | | |
211 | 64.6k | if (mode_lpc != 1) ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff); |
212 | 64.6k | } |
213 | 82.7k | if (mod[2] < 2) { |
214 | 76.6k | mode_lpc = ixheaacd_get_mode_lpc(3, it_bit_buff, &nk_mode); |
215 | 76.6k | pstr_td_frame_data->lpc_first_approx_idx[j++] = mode_lpc; |
216 | | |
217 | 76.6k | if (mode_lpc == 0) |
218 | 17.4k | pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8); |
219 | | |
220 | 76.6k | ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff); |
221 | 76.6k | } |
222 | 82.7k | return; |
223 | 82.7k | } |
224 | | |
225 | | VOID ixheaacd_fac_decoding(WORD32 fac_length, WORD32 k, WORD32 *fac_prm, |
226 | 200k | ia_bit_buf_struct *it_bit_buff) { |
227 | 200k | WORD32 i, j, n, qn, nk, kv[8]; |
228 | 200k | long code_book_index; |
229 | | |
230 | 3.11M | for (i = 0; i < fac_length; i += 8) { |
231 | 2.91M | qn = 0; |
232 | 4.63M | while (ixheaacd_read_bits_buf(it_bit_buff, 1) == 1) { |
233 | 1.71M | qn += 1; |
234 | 1.71M | } |
235 | 2.91M | if (qn != 0) qn += 1; |
236 | | |
237 | 2.91M | nk = 0; |
238 | 2.91M | n = qn; |
239 | 2.91M | if (qn > 4) { |
240 | 44.2k | nk = (qn - 3) >> 1; |
241 | 44.2k | n = qn - nk * 2; |
242 | 44.2k | } |
243 | | |
244 | 2.91M | code_book_index = ixheaacd_read_bits_buf(it_bit_buff, 4 * n); |
245 | | |
246 | 26.2M | for (j = 0; j < 8; j++) { |
247 | 23.3M | kv[j] = ixheaacd_read_bits_buf(it_bit_buff, nk); |
248 | 23.3M | } |
249 | | |
250 | 2.91M | ixheaacd_rotated_gosset_mtx_dec(qn, code_book_index, kv, &fac_prm[k * FAC_LENGTH + i]); |
251 | 2.91M | } |
252 | 200k | } |
253 | | |
254 | | const UWORD8 ixheaacd_num_bites_celp_coding[8][4] = { |
255 | | {5, 5, 5, 5}, {9, 9, 5, 5}, {9, 9, 9, 9}, {13, 13, 9, 9}, |
256 | | {13, 13, 13, 13}, {16, 16, 16, 16}, {1, 5, 1, 5}, {1, 5, 5, 5}}; |
257 | | |
258 | | VOID ixheaacd_acelp_decoding(WORD32 k, ia_usac_data_struct *usac_data, |
259 | | ia_td_frame_data_struct *pstr_td_frame_data, |
260 | 190k | ia_bit_buf_struct *it_bit_buff, WORD32 chan) { |
261 | 190k | WORD32 sfr, kk; |
262 | 190k | WORD32 nb_subfr = usac_data->num_subfrm; |
263 | 190k | const UWORD8 *ptr_num_bits = |
264 | 190k | &ixheaacd_num_bites_celp_coding[pstr_td_frame_data->acelp_core_mode][0]; |
265 | | |
266 | 190k | chan = 0; |
267 | 190k | pstr_td_frame_data->mean_energy[k] = ixheaacd_read_bits_buf(it_bit_buff, 2); |
268 | | |
269 | 913k | for (sfr = 0; sfr < nb_subfr; sfr++) { |
270 | 723k | kk = k * 4 + sfr; |
271 | | |
272 | 723k | if ((sfr == 0) || ((nb_subfr == 4) && (sfr == 2))) |
273 | 342k | pstr_td_frame_data->acb_index[kk] = ixheaacd_read_bits_buf(it_bit_buff, 9); |
274 | | |
275 | 381k | else |
276 | 381k | pstr_td_frame_data->acb_index[kk] = ixheaacd_read_bits_buf(it_bit_buff, 6); |
277 | | |
278 | 723k | pstr_td_frame_data->ltp_filtering_flag[kk] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
279 | | |
280 | 723k | if (pstr_td_frame_data->acelp_core_mode == 5) { |
281 | 47.7k | pstr_td_frame_data->icb_index[kk][0] = |
282 | 47.7k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
283 | 47.7k | pstr_td_frame_data->icb_index[kk][1] = |
284 | 47.7k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
285 | 47.7k | pstr_td_frame_data->icb_index[kk][2] = |
286 | 47.7k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
287 | 47.7k | pstr_td_frame_data->icb_index[kk][3] = |
288 | 47.7k | ixheaacd_read_bits_buf(it_bit_buff, 2); |
289 | 47.7k | pstr_td_frame_data->icb_index[kk][4] = |
290 | 47.7k | ixheaacd_read_bits_buf(it_bit_buff, 14); |
291 | 47.7k | pstr_td_frame_data->icb_index[kk][5] = |
292 | 47.7k | ixheaacd_read_bits_buf(it_bit_buff, 14); |
293 | 47.7k | pstr_td_frame_data->icb_index[kk][6] = |
294 | 47.7k | ixheaacd_read_bits_buf(it_bit_buff, 14); |
295 | 47.7k | pstr_td_frame_data->icb_index[kk][7] = |
296 | 47.7k | ixheaacd_read_bits_buf(it_bit_buff, 14); |
297 | 675k | } else { |
298 | 675k | pstr_td_frame_data->icb_index[kk][0] = |
299 | 675k | ixheaacd_read_bits_buf(it_bit_buff, ptr_num_bits[0]); |
300 | 675k | pstr_td_frame_data->icb_index[kk][1] = |
301 | 675k | ixheaacd_read_bits_buf(it_bit_buff, ptr_num_bits[1]); |
302 | 675k | pstr_td_frame_data->icb_index[kk][2] = |
303 | 675k | ixheaacd_read_bits_buf(it_bit_buff, ptr_num_bits[2]); |
304 | 675k | pstr_td_frame_data->icb_index[kk][3] = |
305 | 675k | ixheaacd_read_bits_buf(it_bit_buff, ptr_num_bits[3]); |
306 | 675k | } |
307 | | |
308 | 723k | pstr_td_frame_data->gains[kk] = ixheaacd_read_bits_buf(it_bit_buff, 7); |
309 | 723k | } |
310 | 190k | } |
311 | | |
312 | | VOID ixheaacd_tcx_coding(ia_usac_data_struct *usac_data, pWORD32 quant, WORD32 k, |
313 | | WORD32 first_tcx_flag, ia_td_frame_data_struct *pstr_td_frame_data, |
314 | 117k | ia_bit_buf_struct *it_bit_buff) { |
315 | 117k | pstr_td_frame_data->noise_factor[k] = ixheaacd_read_bits_buf(it_bit_buff, 3); |
316 | | |
317 | 117k | pstr_td_frame_data->global_gain[k] = ixheaacd_read_bits_buf(it_bit_buff, 7); |
318 | | |
319 | 117k | switch (pstr_td_frame_data->mod[k]) { |
320 | 94.0k | case 1: |
321 | 94.0k | pstr_td_frame_data->tcx_lg[k] = usac_data->len_subfrm; |
322 | 94.0k | break; |
323 | 21.9k | case 2: |
324 | 21.9k | pstr_td_frame_data->tcx_lg[k] = 2 * (usac_data->len_subfrm); |
325 | 21.9k | break; |
326 | 1.09k | case 3: |
327 | 1.09k | pstr_td_frame_data->tcx_lg[k] = 4 * (usac_data->len_subfrm); |
328 | 1.09k | break; |
329 | 117k | } |
330 | | |
331 | 117k | if (first_tcx_flag) { |
332 | 76.8k | if (usac_data->usac_independency_flg) { |
333 | 22.0k | pstr_td_frame_data->arith_reset_flag = 1; |
334 | 54.8k | } else { |
335 | 54.8k | pstr_td_frame_data->arith_reset_flag = ixheaacd_read_bits_buf(it_bit_buff, 1); |
336 | 54.8k | } |
337 | 76.8k | } |
338 | | |
339 | 117k | ixheaacd_arith_data(pstr_td_frame_data, quant, usac_data, it_bit_buff, (first_tcx_flag), k); |
340 | | |
341 | 117k | return; |
342 | 117k | } |
343 | | |
344 | | WORD32 ixheaacd_lpd_channel_stream(ia_usac_data_struct *usac_data, |
345 | | ia_td_frame_data_struct *pstr_td_frame_data, |
346 | 91.3k | ia_bit_buf_struct *it_bit_buff, FLOAT32 *synth) { |
347 | 91.3k | WORD32 lpd_mode, k, cnt, ii; |
348 | 91.3k | WORD32 first_tcx_flag; |
349 | 91.3k | WORD32 *quant; |
350 | 91.3k | WORD32 core_mode_last = 0, fac_data_present; |
351 | 91.3k | WORD32 *fac_data; |
352 | 91.3k | WORD32 first_lpd_flag = 0; |
353 | 91.3k | WORD32 short_fac_flag; |
354 | 91.3k | WORD32 bpf_control_info = 0; |
355 | 91.3k | WORD32 chan = usac_data->present_chan; |
356 | 91.3k | WORD32 last_lpd_mode = usac_data->str_tddec[chan]->mode_prev; |
357 | 91.3k | WORD32 err = 0; |
358 | 91.3k | short_fac_flag = 0; |
359 | | |
360 | 91.3k | jmp_buf local; |
361 | | |
362 | 91.3k | if (usac_data->ec_flag) { |
363 | 0 | err = setjmp(local); |
364 | 0 | } |
365 | | |
366 | 91.3k | if (usac_data->sampling_rate_idx <= 5 && usac_data->ec_flag) { |
367 | 0 | usac_data->frame_ok = 0; |
368 | 0 | } |
369 | | |
370 | 91.3k | if (err == 0 && usac_data->frame_ok == 1) { |
371 | 91.3k | if (usac_data->ec_flag) { |
372 | 0 | it_bit_buff->xaac_jmp_buf = &local; |
373 | 0 | } |
374 | 91.3k | pstr_td_frame_data->acelp_core_mode = ixheaacd_read_bits_buf(it_bit_buff, 3); |
375 | | |
376 | 91.3k | lpd_mode = ixheaacd_read_bits_buf(it_bit_buff, 5); |
377 | | |
378 | 91.3k | if ((lpd_mode > 25 || lpd_mode < 0)) { |
379 | 7.81k | if (usac_data->ec_flag) { |
380 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
381 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
382 | 7.81k | } else { |
383 | 7.81k | return IA_FATAL_ERROR; |
384 | 7.81k | } |
385 | 7.81k | } |
386 | | |
387 | 83.5k | if (lpd_mode == 25) { |
388 | 1.09k | pstr_td_frame_data->mod[0] = pstr_td_frame_data->mod[1] = pstr_td_frame_data->mod[2] = |
389 | 1.09k | pstr_td_frame_data->mod[3] = 3; |
390 | 82.4k | } else if (lpd_mode == 24) { |
391 | 1.27k | pstr_td_frame_data->mod[0] = pstr_td_frame_data->mod[1] = pstr_td_frame_data->mod[2] = |
392 | 1.27k | pstr_td_frame_data->mod[3] = 2; |
393 | 81.1k | } else { |
394 | 81.1k | if (lpd_mode >= 20) { |
395 | 3.73k | pstr_td_frame_data->mod[0] = lpd_mode & 1; |
396 | 3.73k | pstr_td_frame_data->mod[1] = (lpd_mode >> 1) & 1; |
397 | 3.73k | pstr_td_frame_data->mod[2] = pstr_td_frame_data->mod[3] = 2; |
398 | 77.4k | } else if (lpd_mode >= 16) { |
399 | 15.7k | pstr_td_frame_data->mod[0] = pstr_td_frame_data->mod[1] = 2; |
400 | 15.7k | pstr_td_frame_data->mod[2] = lpd_mode & 1; |
401 | 15.7k | pstr_td_frame_data->mod[3] = (lpd_mode >> 1) & 1; |
402 | 61.6k | } else { |
403 | 61.6k | pstr_td_frame_data->mod[0] = lpd_mode & 1; |
404 | 61.6k | pstr_td_frame_data->mod[1] = (lpd_mode >> 1) & 1; |
405 | 61.6k | pstr_td_frame_data->mod[2] = (lpd_mode >> 2) & 1; |
406 | 61.6k | pstr_td_frame_data->mod[3] = (lpd_mode >> 3) & 1; |
407 | 61.6k | } |
408 | 81.1k | } |
409 | | |
410 | 83.5k | bpf_control_info = ixheaacd_read_bits_buf(it_bit_buff, 1); |
411 | | |
412 | 83.5k | core_mode_last = ixheaacd_read_bits_buf(it_bit_buff, 1); |
413 | | |
414 | 83.5k | fac_data_present = ixheaacd_read_bits_buf(it_bit_buff, 1); |
415 | | |
416 | 83.5k | first_lpd_flag = (core_mode_last == 0) ? 1 : 0; |
417 | | |
418 | 83.5k | quant = pstr_td_frame_data->x_tcx_invquant; |
419 | 83.5k | first_tcx_flag = 1; |
420 | 83.5k | k = 0; |
421 | 391k | while (k < 4) { |
422 | 307k | if (k == 0) { |
423 | 83.5k | if ((core_mode_last == 1) && (fac_data_present == 1)) |
424 | 12.8k | ixheaacd_fac_decoding((usac_data->len_subfrm) / 2, k, pstr_td_frame_data->fac, |
425 | 12.8k | it_bit_buff); |
426 | 224k | } else { |
427 | 224k | if (((last_lpd_mode == 0) && (pstr_td_frame_data->mod[k] > 0)) || |
428 | 224k | ((last_lpd_mode > 0) && (pstr_td_frame_data->mod[k] == 0))) |
429 | 93.7k | ixheaacd_fac_decoding((usac_data->len_subfrm) / 2, k, pstr_td_frame_data->fac, |
430 | 93.7k | it_bit_buff); |
431 | 224k | } |
432 | | |
433 | 307k | if (pstr_td_frame_data->mod[k] == 0) { |
434 | 190k | ixheaacd_acelp_decoding(k, usac_data, pstr_td_frame_data, it_bit_buff, chan); |
435 | 190k | last_lpd_mode = 0; |
436 | 190k | pstr_td_frame_data->tcx_lg[k] = 0; |
437 | 190k | k += 1; |
438 | 190k | } else { |
439 | 117k | ixheaacd_tcx_coding(usac_data, quant, k, first_tcx_flag, pstr_td_frame_data, it_bit_buff); |
440 | 117k | last_lpd_mode = pstr_td_frame_data->mod[k]; |
441 | 117k | quant += pstr_td_frame_data->tcx_lg[k]; |
442 | | |
443 | 117k | cnt = 1 << (pstr_td_frame_data->mod[k] - 1); |
444 | | |
445 | 142k | for (ii = 0; ii < cnt - 1; ii++) pstr_td_frame_data->tcx_lg[k + 1 + ii] = 0; |
446 | | |
447 | 117k | k += cnt; |
448 | 117k | first_tcx_flag = 0; |
449 | 117k | } |
450 | 307k | } |
451 | | |
452 | 83.5k | ixheaacd_lpc_data(first_lpd_flag, pstr_td_frame_data->mod, pstr_td_frame_data, it_bit_buff); |
453 | | |
454 | 83.5k | if ((core_mode_last == 0) && (fac_data_present == 1)) { |
455 | 13.8k | WORD32 fac_length; |
456 | 13.8k | short_fac_flag = ixheaacd_read_bits_buf(it_bit_buff, 1); |
457 | | |
458 | 13.8k | fac_length = (short_fac_flag) ? ((usac_data->ccfl) / 16) : ((usac_data->ccfl) / 8); |
459 | | |
460 | 13.8k | fac_data = pstr_td_frame_data->fac_data; |
461 | 13.8k | fac_data[0] = ixheaacd_read_bits_buf(it_bit_buff, 7); |
462 | 13.8k | if ((pstr_td_frame_data->fac_data[0] < 0) || (pstr_td_frame_data->fac_data[0] > 128)) { |
463 | 0 | if (usac_data->ec_flag) { |
464 | 0 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
465 | 0 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
466 | 0 | } else { |
467 | 0 | return IA_FATAL_ERROR; |
468 | 0 | } |
469 | 0 | } |
470 | 13.8k | ixheaacd_fac_decoding(fac_length, 0, &fac_data[1], it_bit_buff); |
471 | 13.8k | } |
472 | 83.5k | if (fac_data_present == 0) { |
473 | 56.0k | memset(&pstr_td_frame_data->fac_data[0], 0, sizeof(pstr_td_frame_data->fac_data)); |
474 | 56.0k | } |
475 | 83.5k | if (usac_data->ec_flag && usac_data->frame_ok) { |
476 | 0 | usac_data->bpf_control_info = bpf_control_info; |
477 | 0 | usac_data->core_mode_last = core_mode_last; |
478 | 0 | usac_data->first_lpd_flag = first_lpd_flag; |
479 | 0 | } |
480 | 83.5k | } else { |
481 | 0 | usac_data->frame_ok = 0; |
482 | 0 | } |
483 | | |
484 | 83.5k | if (usac_data->ec_flag) { |
485 | 0 | usac_data->str_error_concealment[chan].pstr_ec_scratch = |
486 | 0 | (ia_ec_scratch_str *)&usac_data->str_error_concealment[chan].str_ec_scratch; |
487 | |
|
488 | 0 | ixheaacd_usac_apply_ec(usac_data, &ixheaacd_samp_rate_info[0], chan); |
489 | |
|
490 | 0 | if (usac_data->frame_ok == 0) { |
491 | 0 | bpf_control_info = usac_data->bpf_control_info; |
492 | 0 | core_mode_last = usac_data->core_mode_last; |
493 | 0 | first_lpd_flag = usac_data->first_lpd_flag; |
494 | 0 | } |
495 | 0 | } |
496 | 83.5k | if (usac_data->frame_ok) { |
497 | 82.5k | err = ixheaacd_lpd_dec(usac_data, usac_data->str_tddec[chan], pstr_td_frame_data, synth, |
498 | 82.5k | first_lpd_flag, short_fac_flag, bpf_control_info); |
499 | 82.5k | } else { |
500 | 993 | if (usac_data->ec_flag) { |
501 | 0 | usac_data->fac_data_present[chan] = 0; |
502 | 0 | err = ixheaacd_lpd_dec(usac_data, usac_data->str_tddec[chan], |
503 | 0 | &usac_data->td_frame_data_prev[chan], synth, first_lpd_flag, |
504 | 0 | short_fac_flag, bpf_control_info); |
505 | 0 | } |
506 | 993 | } |
507 | | |
508 | 83.5k | return (err); |
509 | 91.3k | } |
510 | | |
511 | | WORD32 ixheaacd_tw_buff_update(ia_usac_data_struct *usac_data, WORD32 i, |
512 | 91.3k | ia_usac_lpd_decoder_handle st) { |
513 | 91.3k | WORD32 *p_ioverlap = usac_data->overlap_data_ptr[i]; |
514 | 91.3k | WORD32 td_frame_prev = usac_data->td_frame_prev[i]; |
515 | 91.3k | WORD32 window_sequence_last = usac_data->window_sequence_last[i]; |
516 | 91.3k | WORD32 tw_mdct = usac_data->tw_mdct[0]; |
517 | | |
518 | 91.3k | if (!td_frame_prev) { |
519 | 17.9k | if (tw_mdct) { |
520 | 0 | if (usac_data->ec_flag == 0) { |
521 | 0 | return -1; |
522 | 0 | } else { |
523 | 0 | tw_mdct = 0; |
524 | 0 | } |
525 | 17.9k | } else { |
526 | 17.9k | ixheaacd_reset_acelp_data_fix(usac_data, st, p_ioverlap, |
527 | 17.9k | (window_sequence_last == EIGHT_SHORT_SEQUENCE), 0); |
528 | 17.9k | } |
529 | 17.9k | } |
530 | 91.3k | return 0; |
531 | 91.3k | } |
532 | | |
533 | 90.3k | VOID ixheaacd_td_frm_dec(ia_usac_data_struct *usac_data, WORD32 k, WORD32 mod0) { |
534 | 90.3k | WORD32 i; |
535 | 90.3k | WORD32 lfac = 0; |
536 | | |
537 | 90.3k | WORD32 *p_out_idata = usac_data->output_data_ptr[k]; |
538 | 90.3k | WORD32 *p_ioverlap = usac_data->overlap_data_ptr[k]; |
539 | 90.3k | WORD32 nlong = usac_data->ccfl; |
540 | 90.3k | WORD32 window_sequence_last = usac_data->window_sequence_last[k]; |
541 | 90.3k | WORD32 td_frame_prev = usac_data->td_frame_prev[k]; |
542 | 90.3k | WORD32 tw_mdct = usac_data->tw_mdct[0]; |
543 | 90.3k | WORD32 nshort = nlong / 8; |
544 | 90.3k | WORD32 *p_in_idata = p_out_idata; |
545 | | |
546 | 90.3k | if (!td_frame_prev) { |
547 | 17.4k | if (window_sequence_last == EIGHT_SHORT_SEQUENCE) { |
548 | 4.78k | lfac = nshort / 2; |
549 | 12.6k | } else { |
550 | 12.6k | lfac = nshort; |
551 | 12.6k | } |
552 | 17.4k | } |
553 | | |
554 | 90.3k | if (!td_frame_prev && (mod0 == 0)) { |
555 | 2.65M | for (i = 0; i < (nlong / 2) - lfac - (LEN_SUBFR); i++) { |
556 | 2.65M | p_in_idata[i] = 0; |
557 | 2.65M | } |
558 | 82.1k | } else if (!td_frame_prev && (mod0 > 0)) { |
559 | 3.54M | for (i = 0; i < (nlong / 2) - lfac; i++) { |
560 | 3.53M | p_in_idata[i] = 0; |
561 | 3.53M | } |
562 | 9.27k | } |
563 | | |
564 | 90.3k | if (tw_mdct) { |
565 | 0 | if (!td_frame_prev && (mod0 == 0)) { |
566 | 0 | for (i = (nlong / 2) - lfac - (LEN_SUBFR); i < nlong / 2; i++) { |
567 | 0 | p_ioverlap[i + (nlong / 2)] = 0; |
568 | 0 | } |
569 | 0 | } |
570 | 0 | for (i = 0; i < nlong / 2; i++) { |
571 | 0 | p_out_idata[i] = p_ioverlap[i] << 1; |
572 | 0 | p_out_idata[i + nlong / 2] = |
573 | 0 | ixheaac_add32_sat(p_ioverlap[i + nlong / 2] << 1, p_in_idata[i]); |
574 | 0 | p_ioverlap[i] = ixheaac_add32_sat(p_in_idata[i + (nlong / 2)] >> 1, p_ioverlap[i + nlong]); |
575 | 0 | p_ioverlap[i + (nlong / 2)] = 0; |
576 | 0 | p_ioverlap[i + nlong] = 0; |
577 | 0 | p_ioverlap[i + nlong + (nlong / 2)] = 0; |
578 | 0 | } |
579 | 90.3k | } else { |
580 | 90.3k | if (!td_frame_prev && (mod0 == 0)) { |
581 | 1.43M | for (i = (nlong / 2) - lfac - (LEN_SUBFR); i < nlong / 2; i++) { |
582 | 1.42M | p_ioverlap[i] = 0; |
583 | 1.42M | } |
584 | 82.1k | } else if (!td_frame_prev) { |
585 | 5.44M | for (i = (nlong / 2) - lfac; i < nlong; i++) { |
586 | 5.43M | p_ioverlap[i] = 0; |
587 | 5.43M | } |
588 | 9.27k | } |
589 | 86.7M | for (i = 0; i < nlong; i++) { |
590 | 86.6M | p_out_idata[i] = ixheaac_add32_sat(p_ioverlap[i] << 1, p_in_idata[i]); |
591 | 86.6M | p_ioverlap[i] = 0; |
592 | 86.6M | } |
593 | 90.3k | } |
594 | 90.3k | } |