/src/libxaac/decoder/ixheaacd_channel.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * * |
3 | | * Copyright (C) 2018 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | #include <string.h> |
21 | | #include "ixheaacd_sbr_common.h" |
22 | | #include "ixheaac_type_def.h" |
23 | | |
24 | | #include "ixheaac_constants.h" |
25 | | #include "ixheaac_basic_ops32.h" |
26 | | #include "ixheaac_basic_ops16.h" |
27 | | #include "ixheaac_basic_ops40.h" |
28 | | #include "ixheaac_basic_ops.h" |
29 | | |
30 | | #include "ixheaacd_bitbuffer.h" |
31 | | #include "ixheaacd_error_codes.h" |
32 | | #include "ixheaacd_defines.h" |
33 | | #include "ixheaacd_aac_rom.h" |
34 | | #include "ixheaacd_pulsedata.h" |
35 | | |
36 | | #include "ixheaacd_pns.h" |
37 | | #include "ixheaacd_drc_data_struct.h" |
38 | | |
39 | | #include "ixheaacd_lt_predict.h" |
40 | | #include "ixheaacd_cnst.h" |
41 | | #include "ixheaacd_ec_defines.h" |
42 | | #include "ixheaacd_ec_struct_def.h" |
43 | | #include "ixheaacd_channelinfo.h" |
44 | | #include "ixheaacd_drc_dec.h" |
45 | | #include "ixheaacd_sbrdecoder.h" |
46 | | |
47 | | #include "ixheaacd_block.h" |
48 | | #include "ixheaacd_channel.h" |
49 | | |
50 | | #include "ixheaacd_common_rom.h" |
51 | | #include "ixheaacd_basic_funcs.h" |
52 | | #include "ixheaac_basic_op.h" |
53 | | #include "ixheaacd_intrinsics.h" |
54 | | #include "ixheaacd_stereo.h" |
55 | | |
56 | | #include "ixheaacd_tns.h" |
57 | | |
58 | | #include "ixheaacd_audioobjtypes.h" |
59 | | #include "ixheaacd_latmdemux.h" |
60 | | |
61 | | #include "ixheaacd_aacdec.h" |
62 | | #include "ixheaacd_definitions.h" |
63 | | |
64 | | #include "ixheaacd_error_codes.h" |
65 | | |
66 | | #include "ixheaacd_pulsedata.h" |
67 | | |
68 | | #include "ixheaacd_sbrdecsettings.h" |
69 | | #include "ixheaacd_sbr_scale.h" |
70 | | #include "ixheaacd_env_extr_part.h" |
71 | | #include "ixheaacd_sbr_rom.h" |
72 | | #include "ixheaacd_audioobjtypes.h" |
73 | | #include "ixheaacd_sbrdecoder.h" |
74 | | #include "ixheaacd_memory_standards.h" |
75 | | #include "ixheaacd_hybrid.h" |
76 | | #include "ixheaacd_ps_dec.h" |
77 | | #include "ixheaacd_mps_polyphase.h" |
78 | | #include "ixheaacd_config.h" |
79 | | #include "ixheaacd_qmf_dec.h" |
80 | | #include "ixheaacd_mps_macro_def.h" |
81 | | #include "ixheaacd_mps_struct_def.h" |
82 | | #include "ixheaacd_mps_res_rom.h" |
83 | | #include "ixheaacd_mps_aac_struct.h" |
84 | | #include "ixheaacd_mps_dec.h" |
85 | | #include "ixheaacd_struct_def.h" |
86 | | #include "ixheaacd_adts_crc_check.h" |
87 | | #include "ixheaacd_rvlc.h" |
88 | | #include "ixheaacd_hcr.h" |
89 | | #include "ixheaacd_function_selector.h" |
90 | | |
91 | 2.10M | #define SPEC(ptr, w, gl) ((ptr) + ((w) * (gl))) |
92 | | |
93 | | UWORD32 ixheaacd_aac_showbits_32(UWORD8 *ptr_read_next, WORD32 cnt_bits, |
94 | 2.96M | WORD32 *increment) { |
95 | 2.96M | UWORD8 *v = ptr_read_next; |
96 | 2.96M | UWORD32 b = 0; |
97 | 2.96M | WORD32 i; |
98 | 2.96M | WORD32 bumped = 0; |
99 | | |
100 | 14.8M | for (i = 0; i < 4; i++) { |
101 | 11.8M | b = b << 8; |
102 | 11.8M | if (cnt_bits > 0) { |
103 | 11.8M | b = b | *v; |
104 | 11.8M | v++; |
105 | 11.8M | bumped++; |
106 | 11.8M | } |
107 | 11.8M | cnt_bits -= 8; |
108 | 11.8M | } |
109 | 2.96M | if (increment != NULL) { |
110 | 1.93M | *increment = bumped; |
111 | 1.93M | } |
112 | 2.96M | return b; |
113 | 2.96M | } |
114 | | |
115 | | WORD16 *ixheaacd_getscalefactorbandoffsets( |
116 | | ia_ics_info_struct *ptr_ics_info, |
117 | 339k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
118 | 339k | if (ptr_ics_info->window_sequence != EIGHT_SHORT_SEQUENCE) { |
119 | 249k | return ptr_aac_tables->sfb_long_table; |
120 | 249k | } else { |
121 | 90.3k | return ptr_aac_tables->sfb_short_table; |
122 | 90.3k | } |
123 | 339k | } |
124 | | |
125 | | WORD8 *ixheaacd_getscalefactorbandwidth( |
126 | | ia_ics_info_struct *ptr_ics_info, |
127 | 50.0k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
128 | 50.0k | if (ptr_ics_info->frame_length == 512) { |
129 | 15.3k | return ( |
130 | 15.3k | WORD8 *)(&ptr_aac_tables |
131 | 15.3k | ->scale_fac_bands_512[ptr_ics_info->sampling_rate_index] |
132 | 15.3k | [0]); |
133 | 34.7k | } else if (ptr_ics_info->frame_length == 1024) { |
134 | 8.78k | return ( |
135 | 8.78k | WORD8 *)(&ptr_aac_tables |
136 | 8.78k | ->scale_factor_bands_long[ptr_ics_info->sampling_rate_index] |
137 | 8.78k | [0]); |
138 | 25.9k | } else { |
139 | 25.9k | return ( |
140 | 25.9k | WORD8 *)(&ptr_aac_tables |
141 | 25.9k | ->scale_fac_bands_480[ptr_ics_info->sampling_rate_index] |
142 | 25.9k | [0]); |
143 | 25.9k | } |
144 | 50.0k | } |
145 | | |
146 | | WORD32 ixheaacd_cblock_inv_quant_spect_data( |
147 | | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, |
148 | | ia_aac_dec_tables_struct *ptr_aac_tables); |
149 | | |
150 | | void ixheaacd_cblock_scale_spect_data( |
151 | | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, |
152 | | ia_aac_dec_tables_struct *ptr_aac_tables, WORD32 total_channels, |
153 | 50.0k | WORD32 object_type, WORD32 aac_sf_data_resil_flag) { |
154 | 50.0k | WORD32 *ptr_spect_coeff = ptr_aac_dec_channel_info->ptr_spec_coeff; |
155 | 50.0k | WORD8 *ptr_sfb_width = (WORD8 *)(ixheaacd_getscalefactorbandwidth( |
156 | 50.0k | &(ptr_aac_dec_channel_info->str_ics_info), ptr_aac_tables)); |
157 | 50.0k | WORD16 *ptr_scale_fac = ptr_aac_dec_channel_info->ptr_scale_factor; |
158 | 50.0k | WORD tot_bands = ptr_aac_dec_channel_info->str_ics_info.max_sfb; |
159 | | |
160 | 50.0k | WORD num_win_grp, group_len; |
161 | 50.0k | WORD32 *ptr_scale_table = ptr_aac_tables->pstr_block_tables->scale_table; |
162 | 50.0k | ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_channel_info->str_ics_info; |
163 | | |
164 | 50.0k | if (object_type == AOT_ER_AAC_LC) |
165 | 29.1k | ptr_sfb_width = ptr_aac_tables->str_aac_sfb_info[ptr_ics_info->window_sequence] |
166 | 29.1k | .sfb_width; |
167 | 121k | for (num_win_grp = 0; num_win_grp < ptr_ics_info->num_window_groups; |
168 | 71.1k | num_win_grp++) { |
169 | 71.1k | for (group_len = 0; |
170 | 266k | group_len < ptr_ics_info->window_group_length[num_win_grp]; |
171 | 195k | group_len++) { |
172 | 195k | (*ixheaacd_scale_factor_process)( |
173 | 195k | &ptr_spect_coeff[0], &ptr_scale_fac[0], tot_bands, |
174 | 195k | (WORD8 *)ptr_sfb_width, ptr_scale_table, total_channels, |
175 | 195k | object_type, aac_sf_data_resil_flag); |
176 | | |
177 | 195k | ptr_spect_coeff += MAX_BINS_SHORT; |
178 | 195k | } |
179 | 71.1k | ptr_scale_fac += MAX_SCALE_FACTOR_BANDS_SHORT; |
180 | 71.1k | } |
181 | 50.0k | } |
182 | | |
183 | | WORD32 ixheaacd_read_pulse_data(ia_bit_buf_struct *it_bit_buff, |
184 | | ia_pulse_info_struct *ptr_pulse_info, |
185 | 40.7k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
186 | 40.7k | WORD32 i, total_offset; |
187 | 40.7k | WORD32 error_code = 0; |
188 | | |
189 | 40.7k | WORD32 value = ixheaacd_read_bits_buf(it_bit_buff, 8); |
190 | 40.7k | ptr_pulse_info->number_pulse = value >> 6; |
191 | 40.7k | ptr_pulse_info->pulse_start_band = value & 0x3F; |
192 | | |
193 | 40.7k | if (ptr_pulse_info->pulse_start_band >= 52) { |
194 | 186 | return (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_PULSEDATA_ERROR; |
195 | 186 | } |
196 | | |
197 | 40.5k | total_offset = ptr_aac_tables->str_aac_sfb_info[0] |
198 | 40.5k | .sfb_index[ptr_pulse_info->pulse_start_band]; |
199 | | |
200 | 133k | for (i = 0; i < ptr_pulse_info->number_pulse + 1; i++) { |
201 | 92.6k | WORD32 value = ixheaacd_read_bits_buf(it_bit_buff, 9); |
202 | 92.6k | ptr_pulse_info->pulse_offset[i] = value >> 4; |
203 | 92.6k | ptr_pulse_info->pulse_amp[i] = value & 0xF; |
204 | 92.6k | total_offset += ptr_pulse_info->pulse_offset[i]; |
205 | | |
206 | 92.6k | if (total_offset >= 1024) { |
207 | 45 | error_code = (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_PULSEDATA_ERROR; |
208 | 45 | } |
209 | 92.6k | } |
210 | | |
211 | 40.5k | return error_code; |
212 | 40.7k | } |
213 | | |
214 | | static IA_ERRORCODE ixheaacd_read_block_data( |
215 | | ia_bit_buf_struct *it_bit_buff, |
216 | | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, |
217 | | ia_aac_dec_tables_struct *ptr_aac_tables, WORD32 total_channels, |
218 | | WORD32 frame_size, WORD32 object_type, WORD32 aac_spect_data_resil_flag, |
219 | | WORD32 aac_sect_data_resil_flag, WORD32 aac_sf_data_resil_flag, |
220 | | WORD32 ele_type, ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info) |
221 | | |
222 | 269k | { |
223 | 269k | FLAG gain_control_data_present; |
224 | 269k | WORD16 error_code = AAC_DEC_OK; |
225 | | |
226 | 269k | if (ptr_aac_dec_channel_info->str_ics_info.window_sequence == |
227 | 269k | EIGHT_SHORT_SEQUENCE) { |
228 | 49.2k | memset(ptr_aac_dec_channel_info->ptr_scale_factor, 0, |
229 | 49.2k | MAX_WINDOWS * MAX_SCALE_FACTOR_BANDS_SHORT * 3); |
230 | 49.2k | } |
231 | | |
232 | 269k | error_code = ixheaacd_read_section_data( |
233 | 269k | it_bit_buff, ptr_aac_dec_channel_info, aac_spect_data_resil_flag, |
234 | 269k | aac_sect_data_resil_flag, ptr_aac_tables); |
235 | | |
236 | 269k | if (error_code) { |
237 | 1.77k | return error_code; |
238 | 1.77k | } |
239 | 267k | if (aac_sf_data_resil_flag && |
240 | 101k | ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD))) |
241 | 67.2k | ixheaacd_rvlc_read(it_bit_buff, ptr_aac_dec_channel_info); |
242 | 200k | else |
243 | 200k | ixheaacd_read_scale_factor_data(it_bit_buff, ptr_aac_dec_channel_info, |
244 | 200k | ptr_aac_tables, object_type); |
245 | | |
246 | 267k | error_code = 0; |
247 | 267k | if (object_type != AOT_ER_AAC_ELD) { |
248 | 210k | ptr_aac_dec_channel_info->str_pulse_info.pulse_data_present = |
249 | 210k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
250 | 210k | if (ptr_aac_dec_channel_info->str_pulse_info.pulse_data_present) { |
251 | 40.7k | error_code = ixheaacd_read_pulse_data( |
252 | 40.7k | it_bit_buff, &ptr_aac_dec_channel_info->str_pulse_info, |
253 | 40.7k | ptr_aac_tables); |
254 | 40.7k | } |
255 | | |
256 | 210k | if (error_code) { |
257 | 207 | return error_code; |
258 | 207 | } |
259 | 210k | } |
260 | | |
261 | 267k | ptr_aac_dec_channel_info->str_tns_info.tns_data_present = |
262 | 267k | (FLAG)ixheaacd_read_bits_buf(it_bit_buff, 1); |
263 | | |
264 | 267k | if (object_type < ER_OBJECT_START) { |
265 | 75.6k | error_code = 0; |
266 | 75.6k | if (ptr_aac_dec_channel_info->str_tns_info.tns_data_present) { |
267 | 27.4k | error_code = |
268 | 27.4k | ixheaacd_read_tns_data(it_bit_buff, ptr_aac_dec_channel_info); |
269 | 27.4k | } |
270 | | |
271 | 75.6k | if (error_code) { |
272 | 31 | return error_code; |
273 | 31 | } |
274 | 75.6k | } |
275 | | |
276 | 267k | if (object_type != AOT_ER_AAC_ELD) { |
277 | 210k | gain_control_data_present = ixheaacd_read_bits_buf(it_bit_buff, 1); |
278 | | |
279 | 210k | if (gain_control_data_present) { |
280 | 681 | return (WORD16)( |
281 | 681 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_GAIN_CONTROL_DATA_PRESENT); |
282 | 681 | } |
283 | 210k | } |
284 | | |
285 | 266k | if (object_type == AOT_ER_AAC_ELD) { |
286 | 56.8k | if (ptr_aac_dec_channel_info->str_tns_info.tns_data_present) |
287 | 8.31k | error_code = |
288 | 8.31k | ixheaacd_read_tns_data(it_bit_buff, ptr_aac_dec_channel_info); |
289 | 56.8k | if (error_code) return error_code; |
290 | 56.8k | } |
291 | | |
292 | 266k | if (aac_spect_data_resil_flag && |
293 | 50.8k | ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD) |
294 | 29.7k | || (object_type == AOT_ER_AAC_LC))) |
295 | 50.8k | ixheaacd_hcr_read(it_bit_buff, ptr_aac_dec_channel_info, ele_type); |
296 | | |
297 | 266k | if (aac_sf_data_resil_flag && |
298 | 101k | ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD))) { |
299 | 67.0k | error_code = ixheaacd_rvlc_dec( |
300 | 67.0k | ptr_aac_dec_channel_info, ptr_aac_dec_static_channel_info, it_bit_buff); |
301 | 67.0k | if (error_code) return error_code; |
302 | | |
303 | 67.0k | it_bit_buff->bit_pos = 7 - it_bit_buff->bit_pos; |
304 | 67.0k | } |
305 | | |
306 | 266k | if (object_type == AOT_ER_AAC_LD || object_type == AOT_ER_AAC_LC) { |
307 | 134k | if (ptr_aac_dec_channel_info->str_tns_info.tns_data_present) |
308 | 42.8k | error_code = |
309 | 42.8k | ixheaacd_read_tns_data(it_bit_buff, ptr_aac_dec_channel_info); |
310 | 134k | if (error_code) return error_code; |
311 | 134k | } |
312 | | |
313 | 266k | { it_bit_buff->bit_pos = 7 - it_bit_buff->bit_pos; } |
314 | | |
315 | 266k | error_code = ixheaacd_read_spectral_data( |
316 | 266k | it_bit_buff, ptr_aac_dec_channel_info, ptr_aac_tables, total_channels, |
317 | 266k | frame_size, object_type, aac_spect_data_resil_flag, |
318 | 266k | aac_sf_data_resil_flag); |
319 | | |
320 | 266k | it_bit_buff->bit_pos = (7 - it_bit_buff->bit_pos); |
321 | | |
322 | 266k | return error_code; |
323 | 266k | } |
324 | | |
325 | | IA_ERRORCODE ixheaacd_ltp_decode(ia_bit_buf_struct *it_bit_buff, |
326 | | ia_ics_info_struct *ptr_ics_info, |
327 | | WORD32 object_type, WORD32 frame_size, |
328 | 11.5k | WORD32 ch) { |
329 | 11.5k | IA_ERRORCODE retval = AAC_DEC_OK; |
330 | | |
331 | 11.5k | if (ptr_ics_info->predictor_data_present) { |
332 | 3.58k | if (ch == 0) { |
333 | 1.79k | ixheaacd_init_ltp_object(&(ptr_ics_info->ltp)); |
334 | 1.79k | ptr_ics_info->ltp.data_present = ixheaacd_read_bits_buf(it_bit_buff, 1); |
335 | 1.79k | if (ptr_ics_info->ltp.data_present) { |
336 | 525 | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
337 | 525 | &(ptr_ics_info->ltp), it_bit_buff, |
338 | 525 | frame_size)) > 0) { |
339 | 0 | return retval; |
340 | 0 | } |
341 | 525 | } |
342 | 1.79k | } else { |
343 | 1.79k | ixheaacd_init_ltp_object(&(ptr_ics_info->ltp2)); |
344 | 1.79k | ptr_ics_info->ltp2.data_present = ixheaacd_read_bits_buf(it_bit_buff, 1); |
345 | 1.79k | if (ptr_ics_info->ltp2.data_present) { |
346 | 916 | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
347 | 916 | &(ptr_ics_info->ltp2), it_bit_buff, |
348 | 916 | frame_size)) > 0) { |
349 | 0 | return retval; |
350 | 0 | } |
351 | 916 | } |
352 | 1.79k | } |
353 | 3.58k | } |
354 | 11.5k | return retval; |
355 | 11.5k | } |
356 | | WORD16 ixheaacd_ics_read(ia_bit_buf_struct *it_bit_buff, |
357 | | ia_ics_info_struct *ptr_ics_info, |
358 | | WORD8 num_swb_window[2], WORD32 object_type, |
359 | 276k | WORD32 common_window, WORD32 frame_size) { |
360 | 276k | WORD i; |
361 | 276k | WORD mask; |
362 | 276k | WORD value = 0; |
363 | | |
364 | 276k | if (object_type == AOT_ER_AAC_ELD) { |
365 | 71.4k | ptr_ics_info->window_sequence = 0; |
366 | 71.4k | ptr_ics_info->window_shape = 1; |
367 | 205k | } else { |
368 | 205k | if (object_type != AOT_ER_AAC_LD) |
369 | 125k | { |
370 | 125k | if (frame_size == 960) |
371 | 55.2k | ptr_ics_info->frame_length = 960; |
372 | 70.0k | else |
373 | 70.0k | ptr_ics_info->frame_length = 1024; |
374 | 125k | } |
375 | 205k | value = ixheaacd_read_bits_buf(it_bit_buff, 4); |
376 | 205k | ptr_ics_info->window_sequence = (WORD16)((value & 0x6) >> 1); |
377 | 205k | ptr_ics_info->window_shape = (WORD16)((value & 0x1)); |
378 | 205k | } |
379 | | |
380 | 276k | if (ptr_ics_info->window_sequence != EIGHT_SHORT_SEQUENCE) { |
381 | 231k | ptr_ics_info->num_swb_window = num_swb_window[0]; |
382 | | |
383 | 231k | ptr_ics_info->num_window_groups = 1; |
384 | 231k | ptr_ics_info->window_group_length[0] = 1; |
385 | | |
386 | 231k | if (object_type == AOT_ER_AAC_ELD) { |
387 | 71.4k | ptr_ics_info->max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 6); |
388 | 71.4k | if (ptr_ics_info->max_sfb == 0) ptr_ics_info->num_swb_window = 0; |
389 | 159k | } else { |
390 | 159k | value = ixheaacd_read_bits_buf(it_bit_buff, 7); |
391 | 159k | ptr_ics_info->max_sfb = (value & 0x7E) >> 1; |
392 | 159k | } |
393 | | |
394 | 231k | if ((object_type != AOT_ER_AAC_LD) && (object_type != AOT_AAC_LTP)) { |
395 | 143k | if (value & 1) { |
396 | 432 | return (WORD16)( |
397 | 432 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_PREDICTION_DATA_PRESENT); |
398 | 432 | } |
399 | | |
400 | 143k | } else { |
401 | 88.0k | ptr_ics_info->predictor_data_present = value & 1; |
402 | | |
403 | 88.0k | if (ptr_ics_info->predictor_data_present) { |
404 | 59.6k | WORD32 retval = AAC_DEC_OK; |
405 | | |
406 | 59.6k | ixheaacd_init_ltp_object(&(ptr_ics_info->ltp)); |
407 | 59.6k | if (object_type < ER_OBJECT_START) { |
408 | 8.97k | if ((ptr_ics_info->ltp.data_present = |
409 | 8.97k | ixheaacd_read_bits_buf(it_bit_buff, 1)) & |
410 | 8.97k | 1) { |
411 | 8.86k | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
412 | 8.86k | &(ptr_ics_info->ltp), it_bit_buff, |
413 | 8.86k | frame_size)) > 0) { |
414 | 0 | return retval; |
415 | 0 | } |
416 | 8.86k | } |
417 | 8.97k | if (common_window) { |
418 | 393 | ixheaacd_init_ltp_object(&(ptr_ics_info->ltp2)); |
419 | 393 | if ((ptr_ics_info->ltp2.data_present = |
420 | 393 | ixheaacd_read_bits_buf(it_bit_buff, 1)) & |
421 | 393 | 1) { |
422 | 14 | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
423 | 14 | &(ptr_ics_info->ltp2), |
424 | 14 | it_bit_buff, frame_size)) > 0) { |
425 | 0 | return retval; |
426 | 0 | } |
427 | 14 | } |
428 | 393 | } |
429 | 8.97k | } |
430 | 59.6k | if ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD)) { |
431 | 50.6k | if (!common_window && (object_type >= ER_OBJECT_START)) { |
432 | 48.7k | if ((ptr_ics_info->ltp.data_present = |
433 | 48.7k | ixheaacd_read_bits_buf(it_bit_buff, 1)) & |
434 | 48.7k | 1) { |
435 | 42.2k | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
436 | 42.2k | &(ptr_ics_info->ltp), it_bit_buff, |
437 | 42.2k | frame_size)) < 0) { |
438 | 5 | return retval; |
439 | 5 | } |
440 | 42.2k | } |
441 | 48.7k | } |
442 | 50.6k | } |
443 | 59.6k | } |
444 | 88.0k | } |
445 | | |
446 | 231k | } else { |
447 | 45.5k | WORD32 num_groups = 0, scale_factor_grouping; |
448 | 45.5k | ptr_ics_info->num_swb_window = num_swb_window[1]; |
449 | | |
450 | 45.5k | value = ixheaacd_read_bits_buf(it_bit_buff, 11); |
451 | 45.5k | ptr_ics_info->max_sfb = (value & 0x780) >> 7; |
452 | | |
453 | 45.5k | scale_factor_grouping = (value & 0x7F); |
454 | | |
455 | 45.5k | mask = 0x40; |
456 | 363k | for (i = 0; i < 7; i++) { |
457 | 318k | ptr_ics_info->window_group_length[i] = 1; |
458 | | |
459 | 318k | if (scale_factor_grouping & mask) { |
460 | 206k | ptr_ics_info->window_group_length[num_groups] = |
461 | 206k | ptr_ics_info->window_group_length[num_groups] + 1; |
462 | | |
463 | 206k | } else { |
464 | 111k | num_groups = num_groups + 1; |
465 | 111k | } |
466 | | |
467 | 318k | mask = mask >> 1; |
468 | 318k | } |
469 | | |
470 | 45.5k | ptr_ics_info->window_group_length[7] = 1; |
471 | 45.5k | ptr_ics_info->num_window_groups = num_groups + 1; |
472 | 45.5k | } |
473 | | |
474 | 276k | if (ptr_ics_info->max_sfb > ptr_ics_info->num_swb_window) { |
475 | 27.6k | return (WORD16)IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_SFB_TRANSMITTED; |
476 | 27.6k | } |
477 | | |
478 | 248k | return AAC_DEC_OK; |
479 | 276k | } |
480 | | |
481 | | WORD16 ixheaacd_individual_ch_stream( |
482 | | ia_bit_buf_struct *it_bit_buff, ia_aac_decoder_struct *aac_dec_handle, |
483 | | WORD32 num_ch, WORD32 frame_size, WORD32 total_channels, WORD32 object_type, |
484 | 246k | ia_eld_specific_config_struct eld_specific_config, WORD32 ele_type) { |
485 | 246k | WORD16 error_code = AAC_DEC_OK; |
486 | 246k | WORD32 ch; |
487 | 246k | WORD32 crc_reg = 0; |
488 | | |
489 | 512k | for (ch = 0; ch < num_ch; ch++) { |
490 | 270k | ia_aac_dec_channel_info_struct *ptr_aac_dec_ch_info = |
491 | 270k | aac_dec_handle->pstr_aac_dec_ch_info[ch]; |
492 | 270k | ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_ch_info->str_ics_info; |
493 | | |
494 | 270k | if (ch == 1) { |
495 | 23.8k | if (it_bit_buff->pstr_adts_crc_info->crc_active == 1 && |
496 | 50 | (it_bit_buff->pstr_adts_crc_info->no_reg < 7)) { |
497 | 38 | crc_reg = |
498 | 38 | ixheaacd_adts_crc_start_reg(it_bit_buff->pstr_adts_crc_info, |
499 | 38 | it_bit_buff, CRC_ADTS_RAW_IIND_ICS); |
500 | 38 | } |
501 | 23.8k | } |
502 | 270k | ptr_aac_dec_ch_info->global_gain = |
503 | 270k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 8); |
504 | | |
505 | 270k | if (!(aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->common_window)) { |
506 | 228k | error_code = ixheaacd_ics_read( |
507 | 228k | it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, |
508 | 228k | object_type, |
509 | 228k | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->common_window, |
510 | 228k | aac_dec_handle->samples_per_frame); |
511 | 228k | if (ch == 1) |
512 | 3.27k | aac_dec_handle->pstr_aac_dec_ch_info[ch - 1]->str_ics_info.ltp2.lag = |
513 | 3.27k | ptr_ics_info->ltp.lag; |
514 | | |
515 | 228k | if (error_code) { |
516 | 1.12k | if (it_bit_buff->cnt_bits < 0) { |
517 | 0 | error_code = (WORD16)( |
518 | 0 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
519 | 0 | } |
520 | 1.12k | return error_code; |
521 | 1.12k | } |
522 | 228k | } |
523 | | |
524 | 269k | error_code = ixheaacd_read_block_data( |
525 | 269k | it_bit_buff, ptr_aac_dec_ch_info, aac_dec_handle->pstr_aac_tables, |
526 | 269k | total_channels, frame_size, object_type, |
527 | 269k | eld_specific_config.aac_spect_data_resil_flag, |
528 | 269k | eld_specific_config.aac_sect_data_resil_flag, |
529 | 269k | eld_specific_config.aac_sf_data_resil_flag, ele_type, |
530 | 269k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]); |
531 | 269k | if (error_code) { |
532 | 3.46k | if (it_bit_buff->cnt_bits < 0) { |
533 | 78 | error_code = (WORD16)( |
534 | 78 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
535 | 78 | } |
536 | | |
537 | 3.46k | return error_code; |
538 | 3.46k | } |
539 | | |
540 | 265k | if (ch == 0) { |
541 | 241k | if ((object_type == AOT_ER_AAC_LD) && |
542 | 76.5k | (aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->common_window) && |
543 | 5.77k | (ele_type == ID_CPE)) { |
544 | 5.77k | IA_ERRORCODE temp = |
545 | 5.77k | ixheaacd_ltp_decode(it_bit_buff, ptr_ics_info, object_type, |
546 | 5.77k | aac_dec_handle->samples_per_frame, 1); |
547 | | |
548 | 5.77k | if (temp != 0) { |
549 | 1 | return temp; |
550 | 1 | } |
551 | 5.77k | aac_dec_handle->pstr_aac_dec_ch_info[ch + 1]->str_ics_info.ltp.lag = |
552 | 5.77k | ptr_ics_info->ltp2.lag; |
553 | 5.77k | } |
554 | 241k | } |
555 | 265k | if (ch == 1) { |
556 | 23.5k | if (it_bit_buff->pstr_adts_crc_info->crc_active == 1) { |
557 | 39 | ixheaacd_adts_crc_end_reg(it_bit_buff->pstr_adts_crc_info, it_bit_buff, |
558 | 39 | crc_reg); |
559 | 39 | } |
560 | 23.5k | } |
561 | 265k | } |
562 | | |
563 | 242k | return error_code; |
564 | 246k | } |
565 | | |
566 | | VOID ixheaacd_read_ms_data( |
567 | | ia_bit_buf_struct *it_bit_buff, |
568 | 21.2k | ia_aac_dec_channel_info_struct *ptr_aac_dec_ch_info) { |
569 | 21.2k | WORD32 num_win_group, sfb; |
570 | 21.2k | WORD32 ms_mask_present; |
571 | 21.2k | UWORD8 *ptr_ms_used = &ptr_aac_dec_ch_info->pstr_stereo_info->ms_used[0][0]; |
572 | 21.2k | WORD32 num_window_groups = |
573 | 21.2k | ptr_aac_dec_ch_info->str_ics_info.num_window_groups; |
574 | 21.2k | WORD16 max_sfb = ptr_aac_dec_ch_info->str_ics_info.max_sfb; |
575 | | |
576 | 21.2k | ms_mask_present = ixheaacd_read_bits_buf(it_bit_buff, 2); |
577 | | |
578 | 21.2k | if (ms_mask_present < 1) { |
579 | 11.8k | memset(ptr_ms_used, 0, |
580 | 11.8k | sizeof(UWORD8) * JOINT_STEREO_MAX_BANDS * JOINT_STEREO_MAX_GROUPS); |
581 | 11.8k | } |
582 | | |
583 | 9.45k | else if (ms_mask_present == 1) { |
584 | 4.76k | for (num_win_group = 0; num_win_group < num_window_groups; |
585 | 2.44k | num_win_group++) { |
586 | 8.98k | for (sfb = 0; sfb < max_sfb; sfb++) { |
587 | 6.54k | ptr_aac_dec_ch_info->pstr_stereo_info->ms_used[num_win_group][sfb] = |
588 | 6.54k | (UWORD8)ixheaacd_read_bits_buf(it_bit_buff, 1); |
589 | 6.54k | } |
590 | 2.44k | } |
591 | | |
592 | 7.12k | } else { |
593 | 19.3k | for (num_win_group = 0; num_win_group < num_window_groups; |
594 | 12.2k | num_win_group++) { |
595 | 12.2k | ptr_ms_used = |
596 | 12.2k | &ptr_aac_dec_ch_info->pstr_stereo_info->ms_used[num_win_group][0]; |
597 | 12.2k | memset(ptr_ms_used, 1, (max_sfb) * sizeof(UWORD8)); |
598 | 12.2k | } |
599 | 7.12k | } |
600 | 21.2k | } |
601 | | |
602 | | IA_ERRORCODE ixheaacd_channel_pair_process( |
603 | | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info[CHANNELS], WORD32 num_ch, |
604 | | ia_aac_dec_tables_struct *ptr_aac_tables, WORD32 total_channels, WORD32 object_type, |
605 | | WORD32 aac_spect_data_resil_flag, WORD32 aac_sf_data_resil_flag, WORD32 *in_data, |
606 | 240k | WORD32 *out_data, void *self_ptr) { |
607 | 240k | WORD32 channel; |
608 | 240k | IA_ERRORCODE err = IA_NO_ERROR; |
609 | 240k | ia_aac_decoder_struct *self = self_ptr; |
610 | 240k | if (aac_spect_data_resil_flag && |
611 | 49.8k | ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_ER_AAC_ELD) || |
612 | 49.8k | (object_type == AOT_ER_AAC_LC))) { |
613 | 99.9k | for (channel = 0; channel < num_ch; channel++) { |
614 | 50.0k | err = ixheaacd_cblock_inv_quant_spect_data( |
615 | 50.0k | ptr_aac_dec_channel_info[channel], ptr_aac_tables); |
616 | 50.0k | if (err) return err; |
617 | 50.0k | ixheaacd_cblock_scale_spect_data(ptr_aac_dec_channel_info[channel], |
618 | 50.0k | ptr_aac_tables, num_ch, object_type, |
619 | 50.0k | aac_sf_data_resil_flag); |
620 | 50.0k | } |
621 | 49.8k | } |
622 | | |
623 | 240k | if (num_ch > 1) { |
624 | 23.5k | if (ptr_aac_dec_channel_info[LEFT]->common_window) { |
625 | 20.3k | if (ptr_aac_dec_channel_info[LEFT]->str_pns_info.pns_active || |
626 | 18.0k | ptr_aac_dec_channel_info[RIGHT]->str_pns_info.pns_active) { |
627 | 2.69k | ixheaacd_map_ms_mask_pns(ptr_aac_dec_channel_info); |
628 | 2.69k | } |
629 | | |
630 | 20.3k | ixheaacd_ms_stereo_process(ptr_aac_dec_channel_info, ptr_aac_tables); |
631 | 20.3k | } |
632 | | |
633 | 23.5k | ixheaacd_intensity_stereo_process( |
634 | 23.5k | ptr_aac_dec_channel_info, ptr_aac_tables, object_type, |
635 | 23.5k | aac_sf_data_resil_flag, |
636 | 23.5k | ptr_aac_dec_channel_info[LEFT]->str_ics_info.frame_length); |
637 | 23.5k | } |
638 | | |
639 | 505k | for (channel = 0; channel < num_ch; channel++) { |
640 | 264k | WORD32 *p_spectrum = ptr_aac_dec_channel_info[channel]->ptr_spec_coeff; |
641 | | |
642 | 264k | if (total_channels > 2) { |
643 | 9.68k | if (ptr_aac_dec_channel_info[channel]->str_ics_info.window_sequence != |
644 | 9.68k | EIGHT_SHORT_SEQUENCE) { |
645 | 7.24k | WORD16 *band_offsets = ptr_aac_tables->sfb_long_table; |
646 | 7.24k | WORD32 no_spec_coeff = band_offsets[ptr_aac_dec_channel_info[channel] |
647 | 7.24k | ->str_ics_info.max_sfb]; |
648 | 7.24k | ixheaacd_right_shift_block(p_spectrum, no_spec_coeff, 3); |
649 | 7.24k | } else { |
650 | 2.44k | ixheaacd_right_shift_block(p_spectrum, 1024, 3); |
651 | 2.44k | } |
652 | 9.68k | } |
653 | | |
654 | 264k | ixheaacd_pns_process(ptr_aac_dec_channel_info, channel, ptr_aac_tables); |
655 | | |
656 | 264k | if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) { |
657 | 108k | { |
658 | 108k | if (channel == 0) { |
659 | 99.7k | ltp_info *ltp1 = |
660 | 99.7k | &(ptr_aac_dec_channel_info[channel]->str_ics_info.ltp); |
661 | 99.7k | ixheaacd_lt_prediction(ptr_aac_dec_channel_info[channel], ltp1, |
662 | 99.7k | p_spectrum, ptr_aac_tables, |
663 | 99.7k | self->ptr_aac_dec_static_channel_info[LEFT] |
664 | 99.7k | ->overlap_add_data.win_shape, |
665 | 99.7k | self->sampling_rate_index, object_type, |
666 | 99.7k | self->samples_per_frame, in_data, out_data); |
667 | | |
668 | 99.7k | } else { |
669 | 8.56k | ltp_info *ltp2 = |
670 | 8.56k | (self->pstr_aac_dec_ch_info[0]->common_window) |
671 | 8.56k | ? &(ptr_aac_dec_channel_info[0]->str_ics_info.ltp2) |
672 | 8.56k | : |
673 | | |
674 | 8.56k | &(ptr_aac_dec_channel_info[1]->str_ics_info.ltp); |
675 | 8.56k | ixheaacd_lt_prediction(ptr_aac_dec_channel_info[channel], ltp2, |
676 | 8.56k | p_spectrum, ptr_aac_tables, |
677 | 8.56k | self->ptr_aac_dec_static_channel_info[RIGHT] |
678 | 8.56k | ->overlap_add_data.win_shape, |
679 | 8.56k | self->sampling_rate_index, object_type, |
680 | 8.56k | self->samples_per_frame, in_data, out_data); |
681 | 8.56k | } |
682 | 108k | } |
683 | 108k | } |
684 | | |
685 | 264k | if (ptr_aac_dec_channel_info[channel]->str_tns_info.tns_data_present) { |
686 | 77.8k | ixheaacd_aac_tns_process(ptr_aac_dec_channel_info[channel], |
687 | 77.8k | total_channels, ptr_aac_tables, object_type, 1, |
688 | 77.8k | NULL); |
689 | 77.8k | } |
690 | 264k | } |
691 | 240k | return err; |
692 | 240k | } |
693 | | |
694 | | VOID ixheaacd_set_corr_info( |
695 | 49.2k | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, WORD16 pns_band) { |
696 | 49.2k | ia_pns_correlation_info_struct *ptr_corr_info = |
697 | 49.2k | ptr_aac_dec_channel_info->pstr_pns_corr_info; |
698 | 49.2k | ptr_corr_info->correlated[(pns_band >> PNS_BAND_FLAGS_SHIFT)] |= |
699 | 49.2k | (1 << (pns_band & PNS_BAND_FLAGS_MASK)); |
700 | 49.2k | } |
701 | | |
702 | | VOID ixheaacd_map_ms_mask_pns( |
703 | 2.69k | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info[CHANNELS]) { |
704 | 2.69k | WORD32 num_win_group, sfb; |
705 | | |
706 | 2.69k | for (num_win_group = 0; |
707 | 5.38k | num_win_group < |
708 | 5.38k | ptr_aac_dec_channel_info[LEFT]->str_ics_info.num_window_groups; |
709 | 2.69k | num_win_group++) { |
710 | 54.2k | for (sfb = 0; sfb < ptr_aac_dec_channel_info[LEFT]->str_ics_info.max_sfb; |
711 | 51.5k | sfb++) { |
712 | 51.5k | if (ptr_aac_dec_channel_info[LEFT] |
713 | 51.5k | ->pstr_stereo_info->ms_used[num_win_group][sfb]) { |
714 | 49.2k | WORD16 pns_band = (num_win_group << 4) + sfb; |
715 | 49.2k | ixheaacd_set_corr_info(ptr_aac_dec_channel_info[LEFT], pns_band); |
716 | | |
717 | 49.2k | if (ptr_aac_dec_channel_info[LEFT]->str_pns_info.pns_used[pns_band] && |
718 | 31.4k | ptr_aac_dec_channel_info[RIGHT]->str_pns_info.pns_used[pns_band]) { |
719 | 19.8k | ptr_aac_dec_channel_info[LEFT] |
720 | 19.8k | ->pstr_stereo_info->ms_used[num_win_group][sfb] ^= 1; |
721 | 19.8k | } |
722 | 49.2k | } |
723 | 51.5k | } |
724 | 2.69k | } |
725 | 2.69k | } |
726 | | |
727 | | VOID ixheaacd_pulse_data_apply(ia_pulse_info_struct *ptr_pulse_info, |
728 | | WORD8 *pulse_scratch, |
729 | 187k | const WORD16 *ptr_swb_offset, WORD object_type) { |
730 | 187k | WORD i; |
731 | 187k | WORD32 k; |
732 | | |
733 | 187k | memset(pulse_scratch, 0, sizeof(WORD32) * 256); |
734 | | |
735 | 187k | if (object_type != AOT_ER_AAC_ELD) { |
736 | 133k | if (ptr_pulse_info->pulse_data_present) { |
737 | 25.7k | k = ptr_swb_offset[ptr_pulse_info->pulse_start_band]; |
738 | | |
739 | 84.7k | for (i = 0; i <= ptr_pulse_info->number_pulse; i++) { |
740 | 58.9k | k = k + ptr_pulse_info->pulse_offset[i]; |
741 | 58.9k | pulse_scratch[k] = ptr_pulse_info->pulse_amp[i]; |
742 | 58.9k | } |
743 | 25.7k | } |
744 | 133k | } else { |
745 | 53.5k | ptr_pulse_info->pulse_data_present = 0; |
746 | 53.5k | } |
747 | 187k | } |
748 | | |
749 | | IA_ERRORCODE ixheaacd_read_spectral_data( |
750 | | ia_bit_buf_struct *it_bit_buff, |
751 | | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, |
752 | | ia_aac_dec_tables_struct *ptr_aac_tables, WORD32 total_channels, |
753 | | WORD32 frame_size, WORD32 object_type, WORD32 aac_spect_data_resil_flag, |
754 | 265k | WORD32 aac_sf_data_resil_flag) { |
755 | 265k | WORD sfb, max_sfb; |
756 | 265k | WORD num_win_grp, group_len, grp_offset; |
757 | | |
758 | 265k | WORD index; |
759 | 265k | WORD8 *ptr_code_book; |
760 | 265k | WORD16 *ptr_scale_factor; |
761 | 265k | WORD32 *ptr_spec_coef; |
762 | 265k | ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_channel_info->str_ics_info; |
763 | 265k | WORD16 *swb_offset; |
764 | | |
765 | 265k | WORD32 maximum_bins_short = ptr_ics_info->frame_length >> 3; |
766 | | |
767 | 265k | WORD32 *ptr_spec_coef_out; |
768 | | |
769 | 265k | ptr_code_book = ptr_aac_dec_channel_info->ptr_code_book; |
770 | 265k | ptr_scale_factor = ptr_aac_dec_channel_info->ptr_scale_factor; |
771 | 265k | ptr_spec_coef = ptr_aac_dec_channel_info->ptr_spec_coeff; |
772 | 265k | max_sfb = ptr_ics_info->max_sfb; |
773 | | |
774 | 265k | swb_offset = |
775 | 265k | ptr_aac_tables->str_aac_sfb_info[ptr_ics_info->window_sequence].sfb_index; |
776 | | |
777 | 265k | if (!aac_spect_data_resil_flag) { |
778 | 215k | if (ptr_aac_dec_channel_info->str_ics_info.window_sequence != |
779 | 215k | EIGHT_SHORT_SEQUENCE) { |
780 | 187k | WORD8 *ptr_scratch; |
781 | | |
782 | 187k | if (object_type == AOT_ER_AAC_ELD) |
783 | 53.5k | ptr_scratch = (WORD8 *)ptr_aac_dec_channel_info->pulse_scratch; |
784 | 133k | else |
785 | 133k | ptr_scratch = (WORD8 *)ptr_aac_dec_channel_info->scratch_buf_ptr; |
786 | | |
787 | 187k | memset(ptr_spec_coef, 0, sizeof(WORD32) * 1024); |
788 | | |
789 | 187k | ixheaacd_pulse_data_apply(&ptr_aac_dec_channel_info->str_pulse_info, |
790 | 187k | ptr_scratch, swb_offset, object_type); |
791 | | |
792 | 187k | ptr_spec_coef_out = &ptr_spec_coef[0]; |
793 | 426k | for (sfb = 0; sfb < max_sfb;) { |
794 | 239k | WORD ret_val; |
795 | 239k | WORD32 sfb_width; |
796 | 239k | WORD32 sect_cb = ptr_code_book[sfb]; |
797 | 239k | WORD start = sfb; |
798 | 239k | if ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD) |
799 | 163k | || (object_type == AOT_ER_AAC_LC)) { |
800 | 163k | if ((sect_cb >= 16) && (sect_cb <= 31)) { |
801 | 62.1k | ptr_code_book[sfb] = sect_cb = 11; |
802 | 62.1k | } |
803 | 163k | } |
804 | 2.38M | for (; sfb < max_sfb && (ptr_code_book[sfb] == sect_cb); sfb++) |
805 | 2.14M | ; |
806 | | |
807 | 239k | sfb_width = swb_offset[sfb] - swb_offset[start]; |
808 | | |
809 | 239k | if (sect_cb > ZERO_HCB && (sect_cb < NOISE_HCB)) { |
810 | 170k | ret_val = ixheaacd_huffman_dec_word2(it_bit_buff, sect_cb, sfb_width, |
811 | 170k | ptr_aac_tables, |
812 | 170k | ptr_spec_coef_out, ptr_scratch); |
813 | | |
814 | 170k | if (ret_val != 0) { |
815 | 145 | return (WORD16)( |
816 | 145 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_MAX_HUFFDEC_VAL); |
817 | 145 | } |
818 | 170k | } |
819 | | |
820 | 69.4k | else { |
821 | 69.4k | if (ptr_aac_dec_channel_info->str_pulse_info.pulse_data_present) { |
822 | 22.5k | ixheaacd_inverse_quantize( |
823 | 22.5k | ptr_spec_coef_out, sfb_width, |
824 | 22.5k | (WORD32 *) |
825 | 22.5k | ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13, |
826 | 22.5k | ptr_scratch); |
827 | 22.5k | } |
828 | 69.4k | } |
829 | 239k | ptr_scratch += sfb_width; |
830 | 239k | ptr_spec_coef_out += sfb_width; |
831 | 239k | } |
832 | | |
833 | 187k | if ((object_type != AOT_ER_AAC_ELD) && (object_type != AOT_ER_AAC_LD)) |
834 | 83.9k | index = 1024 - swb_offset[max_sfb]; |
835 | 103k | else |
836 | 103k | index = frame_size - swb_offset[max_sfb]; |
837 | | |
838 | 187k | if (index < 0) return -1; |
839 | | |
840 | 187k | } else { |
841 | 27.6k | memset(ptr_spec_coef, 0, sizeof(WORD32) * 1024); |
842 | | |
843 | 27.6k | grp_offset = 0; |
844 | | |
845 | 166k | for (num_win_grp = 0; num_win_grp < ptr_ics_info->num_window_groups; |
846 | 138k | num_win_grp++) { |
847 | 138k | WORD grp_len = ptr_ics_info->window_group_length[num_win_grp]; |
848 | | |
849 | 138k | if (maximum_bins_short == 120) |
850 | 28.4k | ptr_spec_coef_out = &ptr_spec_coef[grp_offset * maximum_bins_short]; |
851 | 110k | else |
852 | 110k | ptr_spec_coef_out = &ptr_spec_coef[grp_offset * MAX_BINS_SHORT]; |
853 | | |
854 | 138k | WORD bands = num_win_grp * MAX_SCALE_FACTOR_BANDS_SHORT; |
855 | 226k | for (sfb = 0; sfb < max_sfb;) { |
856 | 88.4k | WORD sect_cb = ptr_code_book[bands]; |
857 | 88.4k | WORD start = sfb; |
858 | 88.4k | WORD ret_val; |
859 | | |
860 | 88.4k | if ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD) |
861 | 88.4k | || (object_type == AOT_ER_AAC_LC)) { |
862 | 78.0k | if ((sect_cb >= 16) && (sect_cb <= 31)) { |
863 | 56.8k | ptr_code_book[bands] = sect_cb = 11; |
864 | 56.8k | } |
865 | 78.0k | } |
866 | | |
867 | 282k | for (; sfb < max_sfb && (ptr_code_book[bands] == sect_cb); |
868 | 194k | sfb++, bands++) |
869 | 194k | ; |
870 | | |
871 | 88.4k | if (sect_cb > ZERO_HCB && (sect_cb < NOISE_HCB)) { |
872 | 72.8k | ret_val = ixheaacd_decode_huffman( |
873 | 72.8k | it_bit_buff, sect_cb, ptr_spec_coef_out, (WORD16 *)swb_offset, |
874 | 72.8k | start, sfb, grp_len, ptr_aac_tables, maximum_bins_short); |
875 | | |
876 | 72.8k | if (ret_val != 0) { |
877 | 117 | return (WORD16)( |
878 | 117 | (WORD32) |
879 | 117 | IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_MAX_HUFFDEC_VAL); |
880 | 117 | } |
881 | 72.8k | } |
882 | 88.4k | } |
883 | 138k | grp_offset = (grp_offset + grp_len); |
884 | 138k | } |
885 | 27.6k | } |
886 | 214k | { |
887 | 214k | WORD32 *ptr_scale_table; |
888 | | |
889 | 214k | if (maximum_bins_short != 120) |
890 | 179k | ptr_scale_table = ptr_aac_tables->pstr_block_tables->scale_table; |
891 | 35.0k | else |
892 | 35.0k | ptr_scale_table = ptr_aac_tables->pstr_block_tables->scale_table_960; |
893 | | |
894 | 214k | WORD8 *ptr_sfb_width = |
895 | 214k | ptr_aac_tables->str_aac_sfb_info[ptr_ics_info->window_sequence] |
896 | 214k | .sfb_width; |
897 | | |
898 | 540k | for (num_win_grp = 0; num_win_grp < ptr_ics_info->num_window_groups; |
899 | 325k | num_win_grp++) { |
900 | 325k | for (group_len = 0; |
901 | 733k | group_len < ptr_ics_info->window_group_length[num_win_grp]; |
902 | 407k | group_len++) { |
903 | 407k | (*ixheaacd_scale_factor_process)( |
904 | 407k | &ptr_spec_coef[0], &ptr_scale_factor[0], max_sfb, |
905 | 407k | (WORD8 *)ptr_sfb_width, ptr_scale_table, total_channels, |
906 | 407k | object_type, aac_sf_data_resil_flag); |
907 | | |
908 | 407k | if (maximum_bins_short == 120) |
909 | 74.2k | ptr_spec_coef += maximum_bins_short; |
910 | 333k | else |
911 | 333k | ptr_spec_coef += MAX_BINS_SHORT; |
912 | 407k | } |
913 | | |
914 | 325k | ptr_scale_factor += MAX_SCALE_FACTOR_BANDS_SHORT; |
915 | 325k | } |
916 | 214k | } |
917 | 214k | } else { |
918 | 50.8k | ia_hcr_info_struct *pstr_hcr_info = &ptr_aac_dec_channel_info->str_hcr_info; |
919 | 50.8k | WORD32 error = 0; |
920 | | |
921 | 50.8k | memset(ptr_spec_coef, 0, sizeof(WORD32) * 1024); |
922 | | |
923 | 50.8k | if (ptr_aac_dec_channel_info->reorder_spect_data_len != 0) { |
924 | 40.2k | error = ixheaacd_huff_code_reorder_init( |
925 | 40.2k | pstr_hcr_info, ptr_aac_dec_channel_info, ptr_aac_tables, it_bit_buff); |
926 | | |
927 | 40.2k | if (error != 0) { |
928 | 266 | return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; |
929 | 266 | } |
930 | 39.9k | error = ixheaacd_hcr_decoder(pstr_hcr_info, ptr_aac_dec_channel_info, |
931 | 39.9k | ptr_aac_tables, it_bit_buff); |
932 | | |
933 | 39.9k | if (error != 0) { |
934 | 32.7k | ixheaacd_huff_mute_erroneous_lines(pstr_hcr_info); |
935 | 32.7k | } |
936 | | |
937 | 39.9k | if (it_bit_buff->cnt_bits < |
938 | 39.9k | ptr_aac_dec_channel_info->reorder_spect_data_len) { |
939 | 394 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
940 | 394 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
941 | 394 | } |
942 | | |
943 | 39.5k | it_bit_buff->cnt_bits += |
944 | 39.5k | -ptr_aac_dec_channel_info->reorder_spect_data_len; |
945 | 39.5k | it_bit_buff->ptr_read_next = |
946 | 39.5k | it_bit_buff->ptr_bit_buf_base + |
947 | 39.5k | ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3); |
948 | 39.5k | it_bit_buff->bit_pos = (it_bit_buff->size - it_bit_buff->cnt_bits) & 7; |
949 | | |
950 | 39.5k | } else { |
951 | 10.5k | it_bit_buff->ptr_read_next = |
952 | 10.5k | it_bit_buff->ptr_bit_buf_base + |
953 | 10.5k | ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3); |
954 | 10.5k | it_bit_buff->bit_pos = (it_bit_buff->size - it_bit_buff->cnt_bits) & 7; |
955 | 10.5k | } |
956 | 50.8k | } |
957 | | |
958 | 265k | return AAC_DEC_OK; |
959 | 265k | } |
960 | | |
961 | | WORD16 ixheaacd_read_tns_data( |
962 | | ia_bit_buf_struct *it_bit_buff, |
963 | 78.6k | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) { |
964 | 78.6k | WORD win_size, window_per_frame; |
965 | 78.6k | WORD n_filt_bits, start_band_bits, order_bits; |
966 | 78.6k | WORD32 bottom; |
967 | | |
968 | 78.6k | ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_channel_info->str_ics_info; |
969 | 78.6k | ia_tns_info_aac_struct *ptr_tns_info = |
970 | 78.6k | &ptr_aac_dec_channel_info->str_tns_info; |
971 | | |
972 | 78.6k | if (ptr_ics_info->window_sequence != EIGHT_SHORT_SEQUENCE) { |
973 | 53.7k | n_filt_bits = 2; |
974 | 53.7k | start_band_bits = 6; |
975 | 53.7k | order_bits = 5; |
976 | 53.7k | window_per_frame = 1; |
977 | | |
978 | 53.7k | } else { |
979 | 24.8k | n_filt_bits = 1; |
980 | 24.8k | start_band_bits = 4; |
981 | 24.8k | order_bits = 3; |
982 | 24.8k | window_per_frame = 8; |
983 | 24.8k | } |
984 | | |
985 | 78.6k | bottom = ptr_ics_info->num_swb_window; |
986 | | |
987 | 331k | for (win_size = 0; win_size < window_per_frame; win_size++) { |
988 | 252k | WORD n_filt; |
989 | 252k | WORD start_band, coef_res; |
990 | 252k | ptr_tns_info->n_filt[win_size] = n_filt = |
991 | 252k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, n_filt_bits); |
992 | | |
993 | 252k | if (n_filt) { |
994 | 110k | WORD filt; |
995 | 110k | WORD top; |
996 | | |
997 | 110k | coef_res = ixheaacd_read_bits_buf(it_bit_buff, 1); |
998 | | |
999 | 110k | top = bottom; |
1000 | 235k | for (filt = 0; filt < n_filt; filt++) { |
1001 | 125k | WORD order; |
1002 | 125k | ia_filter_info_struct *filter = |
1003 | 125k | &ptr_tns_info->str_filter[win_size][filt]; |
1004 | | |
1005 | 125k | start_band = ixheaacd_read_bits_buf(it_bit_buff, start_band_bits); |
1006 | | |
1007 | 125k | if (top < start_band) { |
1008 | 90.0k | top = start_band; |
1009 | 90.0k | } |
1010 | 125k | filter->start_band = top - start_band; |
1011 | 125k | filter->stop_band = top; |
1012 | | |
1013 | 125k | top = filter->start_band; |
1014 | | |
1015 | 125k | if (filter->start_band < 0) { |
1016 | 0 | filter->order = -1; |
1017 | 0 | return (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_FATAL_TNS_RANGE_ERROR); |
1018 | 0 | } |
1019 | | |
1020 | 125k | filter->order = order = ixheaacd_read_bits_buf(it_bit_buff, order_bits); |
1021 | | |
1022 | 125k | if ((order - MAX_ORDER_LONG) > 0) { |
1023 | 196 | return (WORD16)( |
1024 | 196 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_TNS_ORDER_ERROR); |
1025 | 196 | } |
1026 | | |
1027 | 125k | if (order) { |
1028 | 108k | WORD i; |
1029 | 108k | WORD32 coef, coef_compress; |
1030 | 108k | WORD resolution, shift; |
1031 | | |
1032 | 108k | filter->direction = |
1033 | 108k | (WORD8)(ixheaacd_read_bits_buf(it_bit_buff, 1) ? -1 : 1); |
1034 | | |
1035 | 108k | coef_compress = ixheaacd_read_bits_buf(it_bit_buff, 1); |
1036 | | |
1037 | 108k | filter->resolution = coef_res; |
1038 | | |
1039 | 108k | resolution = coef_res + 3 - coef_compress; |
1040 | | |
1041 | 108k | shift = 32 - resolution; |
1042 | | |
1043 | 760k | for (i = 0; i < order; i++) { |
1044 | 651k | coef = ixheaacd_read_bits_buf(it_bit_buff, resolution); |
1045 | 651k | coef = coef << shift; |
1046 | 651k | filter->coef[i] = (WORD8)(coef >> shift); |
1047 | 651k | } |
1048 | 108k | } |
1049 | 125k | } |
1050 | 110k | } |
1051 | 252k | } |
1052 | 78.4k | return AAC_DEC_OK; |
1053 | 78.6k | } |
1054 | | |
1055 | | WORD32 ixheaacd_inv_quant(WORD32 *px_quant, WORD32 *ixheaacd_pow_table_Q13) |
1056 | | |
1057 | 39.1k | { |
1058 | 39.1k | WORD32 q1; |
1059 | 39.1k | WORD32 temp; |
1060 | 39.1k | WORD32 q_abs; |
1061 | 39.1k | WORD16 interp; |
1062 | 39.1k | WORD32 shift; |
1063 | | |
1064 | 39.1k | q_abs = *px_quant; |
1065 | | |
1066 | 39.1k | if (q_abs > (8191 + 32)) |
1067 | 236 | return IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_MAX_HUFFDEC_VAL; |
1068 | | |
1069 | 38.8k | if (q_abs < 1024) { |
1070 | 32.6k | shift = 3; |
1071 | 32.6k | } else { |
1072 | 6.28k | shift = 6; |
1073 | 6.28k | } |
1074 | | |
1075 | 38.8k | q1 = (q_abs) >> shift; |
1076 | | |
1077 | 38.8k | interp = q_abs - (q1 << shift); |
1078 | | |
1079 | 38.8k | temp = ixheaacd_pow_table_Q13[q1 + 1] - ixheaacd_pow_table_Q13[q1]; |
1080 | | |
1081 | 38.8k | temp = (WORD32)(temp * (WORD32)interp); |
1082 | | |
1083 | 38.8k | temp = temp + (ixheaacd_pow_table_Q13[q1] << shift); |
1084 | | |
1085 | 38.8k | if (shift == 3) |
1086 | 32.6k | temp = temp << 1; |
1087 | 6.28k | else |
1088 | 6.28k | temp = temp << 2; |
1089 | | |
1090 | 38.8k | *px_quant = temp; |
1091 | | |
1092 | 38.8k | return 0; |
1093 | 39.1k | } |
1094 | | |
1095 | 0 | void ixheaacd_scale_value_in_place(WORD32 *value, WORD32 scalefactor) { |
1096 | 0 | WORD32 newscale; |
1097 | |
|
1098 | 0 | if ((newscale = (scalefactor)) >= 0) { |
1099 | 0 | *(value) <<= newscale; |
1100 | 0 | } else { |
1101 | 0 | *(value) >>= -newscale; |
1102 | 0 | } |
1103 | 0 | } |
1104 | | |
1105 | | WORD32 ixheaacd_cblock_inv_quant_spect_data( |
1106 | | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, |
1107 | 50.0k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
1108 | 50.0k | int window, group, grp_win, band; |
1109 | 50.0k | IA_ERRORCODE err = IA_NO_ERROR; |
1110 | 50.0k | int sf_bands_transmitted = ptr_aac_dec_channel_info->str_ics_info.max_sfb; |
1111 | 50.0k | WORD8 *ptr_code_book = ptr_aac_dec_channel_info->ptr_code_book; |
1112 | 50.0k | const WORD16 *band_offsets = (WORD16 *)ixheaacd_getscalefactorbandoffsets( |
1113 | 50.0k | &(ptr_aac_dec_channel_info->str_ics_info), ptr_aac_tables); |
1114 | 50.0k | WORD32 *ptr_pow_table_Q13 = |
1115 | 50.0k | (WORD32 *)ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13; |
1116 | | |
1117 | 50.0k | for (window = 0, group = 0; |
1118 | 121k | group < ptr_aac_dec_channel_info->str_ics_info.num_window_groups; |
1119 | 71.1k | group++) { |
1120 | 71.1k | for (grp_win = 0; |
1121 | 266k | grp_win < |
1122 | 266k | ptr_aac_dec_channel_info->str_ics_info.window_group_length[group]; |
1123 | 195k | grp_win++, window++) { |
1124 | 2.30M | for (band = 0; band < sf_bands_transmitted; band++) { |
1125 | 2.10M | WORD32 *ptr_spec_coef = |
1126 | 2.10M | SPEC(ptr_aac_dec_channel_info->ptr_spec_coeff, window, |
1127 | 2.10M | ptr_aac_dec_channel_info->granule_len) + |
1128 | 2.10M | band_offsets[band]; |
1129 | 2.10M | int num_lines = band_offsets[band + 1] - band_offsets[band]; |
1130 | 2.10M | int bnds = group * 16 + band; |
1131 | 2.10M | int i; |
1132 | | |
1133 | 2.10M | if ((ptr_code_book[bnds] == ZERO_HCB) || |
1134 | 2.04M | (ptr_code_book[bnds] == INTENSITY_HCB) || |
1135 | 1.79M | (ptr_code_book[bnds] == INTENSITY_HCB2)) |
1136 | 567k | continue; |
1137 | | |
1138 | 1.54M | if (ptr_code_book[bnds] == NOISE_HCB) { |
1139 | 97.7k | continue; |
1140 | 97.7k | } |
1141 | | |
1142 | 16.9M | for (i = 0; i < num_lines; i++) { |
1143 | 15.4M | WORD8 temp = 0; |
1144 | 15.4M | WORD32 out1 = ptr_spec_coef[i]; |
1145 | 15.4M | if (out1 <= 0) { |
1146 | 12.4M | out1 = sub_d(temp, out1); |
1147 | 12.4M | if (out1 > 127) { |
1148 | 6.11k | err = ixheaacd_inv_quant(&out1, ptr_pow_table_Q13); |
1149 | 6.11k | if (err) return err; |
1150 | 6.11k | } else |
1151 | 12.4M | out1 = ptr_pow_table_Q13[out1]; |
1152 | 12.4M | ptr_spec_coef[i] = -out1; |
1153 | | |
1154 | 12.4M | } else { |
1155 | 2.99M | if (out1 > 127) { |
1156 | 18.2k | err = ixheaacd_inv_quant(&out1, ptr_pow_table_Q13); |
1157 | 18.2k | if (err) return err; |
1158 | 18.2k | } else |
1159 | 2.97M | out1 = ptr_pow_table_Q13[out1]; |
1160 | | |
1161 | 2.99M | ptr_spec_coef[i] = out1; |
1162 | 2.99M | } |
1163 | 15.4M | } |
1164 | 1.44M | } |
1165 | 195k | } |
1166 | 71.1k | } |
1167 | | |
1168 | 50.0k | return AAC_DEC_OK; |
1169 | 50.0k | } |
1170 | | |
1171 | 63.6k | void ixheaacd_init_ltp_object(ltp_info *ltp) { |
1172 | 63.6k | ltp->data_present = 0; |
1173 | 63.6k | ltp->last_band = 0; |
1174 | | |
1175 | 63.6k | ltp->lag_update = 0; |
1176 | 63.6k | ltp->coef = 0; |
1177 | 63.6k | } |
1178 | | |
1179 | | WORD32 ixheaacd_ltp_data(WORD32 object_type, ia_ics_info_struct *ics, |
1180 | | ltp_info *ltp, ia_bit_buf_struct *it_bit_buf, |
1181 | 52.5k | WORD32 frame_len) { |
1182 | 52.5k | UWORD8 sfb, w; |
1183 | | |
1184 | 52.5k | if (object_type == AOT_ER_AAC_LD) { |
1185 | 43.6k | ltp->lag_update = ixheaacd_read_bits_buf(it_bit_buf, 1); |
1186 | | |
1187 | 43.6k | if (ltp->lag_update) { |
1188 | 13.2k | ltp->lag = (UWORD16)ixheaacd_read_bits_buf(it_bit_buf, 10); |
1189 | 13.2k | } |
1190 | 43.6k | } else { |
1191 | 8.88k | ltp->lag = (UWORD16)ixheaacd_read_bits_buf(it_bit_buf, 11); |
1192 | 8.88k | } |
1193 | | |
1194 | 52.5k | if (ltp->lag > (frame_len << 1)) return -1; |
1195 | | |
1196 | 46.4k | ltp->coef = (UWORD8)ixheaacd_read_bits_buf(it_bit_buf, 3); |
1197 | | |
1198 | 46.4k | if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) { |
1199 | 0 | for (w = 0; w < 8; w++) { |
1200 | 0 | if ((ltp->short_used[w] = ixheaacd_read_bits_buf(it_bit_buf, 1)) & 1) { |
1201 | 0 | ltp->short_lag_present[w] = ixheaacd_read_bits_buf(it_bit_buf, 1); |
1202 | 0 | if (ltp->short_lag_present[w]) { |
1203 | 0 | ltp->short_lag[w] = (UWORD8)ixheaacd_read_bits_buf(it_bit_buf, 4); |
1204 | 0 | } |
1205 | 0 | } |
1206 | 0 | } |
1207 | 46.4k | } else { |
1208 | 46.4k | ltp->last_band = (ics->max_sfb < MAX_LTP_SFB ? ics->max_sfb : MAX_LTP_SFB); |
1209 | | |
1210 | 1.07M | for (sfb = 0; sfb < ltp->last_band; sfb++) { |
1211 | 1.02M | ltp->long_used[sfb] = ixheaacd_read_bits_buf(it_bit_buf, 1); |
1212 | 1.02M | } |
1213 | 46.4k | } |
1214 | 46.4k | if (ics->frame_length == 480) { |
1215 | 5.19k | if ((ics->sampling_rate_index > 5) && |
1216 | 113 | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_PLUS_480)) |
1217 | 60 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_PLUS_480; |
1218 | 5.13k | else if ((ics->sampling_rate_index == 5) && |
1219 | 2.63k | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_480)) |
1220 | 29 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_480; |
1221 | 5.10k | else if ((ics->sampling_rate_index < 5) && |
1222 | 2.44k | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_LESS_480)) |
1223 | 13 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_LESS_480; |
1224 | 41.2k | } else if (ics->frame_length == 512) { |
1225 | 26.4k | if ((ics->sampling_rate_index > 5) && |
1226 | 123 | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_PLUS_512)) |
1227 | 38 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_PLUS_512; |
1228 | 26.4k | else if ((ics->sampling_rate_index == 5) && |
1229 | 25.3k | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_512)) |
1230 | 148 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_512; |
1231 | 26.3k | else if ((ics->sampling_rate_index < 5) && |
1232 | 1.07k | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_LESS_512)) |
1233 | 55 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_LESS_512; |
1234 | 26.4k | } |
1235 | 46.4k | return 0; |
1236 | 52.5k | } |