/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.61M | #define SPEC(ptr, w, gl) ((ptr) + ((w) * (gl))) |
92 | | |
93 | | UWORD32 ixheaacd_aac_showbits_32(UWORD8 *ptr_read_next, WORD32 cnt_bits, |
94 | 2.81M | WORD32 *increment) { |
95 | 2.81M | UWORD8 *v = ptr_read_next; |
96 | 2.81M | UWORD32 b = 0; |
97 | 2.81M | WORD32 i; |
98 | 2.81M | WORD32 bumped = 0; |
99 | | |
100 | 14.0M | for (i = 0; i < 4; i++) { |
101 | 11.2M | b = b << 8; |
102 | 11.2M | if (cnt_bits > 0) { |
103 | 11.2M | b = b | *v; |
104 | 11.2M | v++; |
105 | 11.2M | bumped++; |
106 | 11.2M | } |
107 | 11.2M | cnt_bits -= 8; |
108 | 11.2M | } |
109 | 2.81M | if (increment != NULL) { |
110 | 1.94M | *increment = bumped; |
111 | 1.94M | } |
112 | 2.81M | return b; |
113 | 2.81M | } |
114 | | |
115 | | WORD16 *ixheaacd_getscalefactorbandoffsets( |
116 | | ia_ics_info_struct *ptr_ics_info, |
117 | 417k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
118 | 417k | if (ptr_ics_info->window_sequence != EIGHT_SHORT_SEQUENCE) { |
119 | 314k | return ptr_aac_tables->sfb_long_table; |
120 | 314k | } else { |
121 | 102k | return ptr_aac_tables->sfb_short_table; |
122 | 102k | } |
123 | 417k | } |
124 | | |
125 | | WORD8 *ixheaacd_getscalefactorbandwidth( |
126 | | ia_ics_info_struct *ptr_ics_info, |
127 | 62.9k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
128 | 62.9k | if (ptr_ics_info->frame_length == 512) { |
129 | 14.1k | return ( |
130 | 14.1k | WORD8 *)(&ptr_aac_tables |
131 | 14.1k | ->scale_fac_bands_512[ptr_ics_info->sampling_rate_index] |
132 | 14.1k | [0]); |
133 | 48.7k | } else if (ptr_ics_info->frame_length == 1024) { |
134 | 7.59k | return ( |
135 | 7.59k | WORD8 *)(&ptr_aac_tables |
136 | 7.59k | ->scale_factor_bands_long[ptr_ics_info->sampling_rate_index] |
137 | 7.59k | [0]); |
138 | 41.1k | } else { |
139 | 41.1k | return ( |
140 | 41.1k | WORD8 *)(&ptr_aac_tables |
141 | 41.1k | ->scale_fac_bands_480[ptr_ics_info->sampling_rate_index] |
142 | 41.1k | [0]); |
143 | 41.1k | } |
144 | 62.9k | } |
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 | 62.9k | WORD32 object_type, WORD32 aac_sf_data_resil_flag) { |
154 | 62.9k | WORD32 *ptr_spect_coeff = ptr_aac_dec_channel_info->ptr_spec_coeff; |
155 | 62.9k | WORD8 *ptr_sfb_width = (WORD8 *)(ixheaacd_getscalefactorbandwidth( |
156 | 62.9k | &(ptr_aac_dec_channel_info->str_ics_info), ptr_aac_tables)); |
157 | 62.9k | WORD16 *ptr_scale_fac = ptr_aac_dec_channel_info->ptr_scale_factor; |
158 | 62.9k | WORD tot_bands = ptr_aac_dec_channel_info->str_ics_info.max_sfb; |
159 | | |
160 | 62.9k | WORD num_win_grp, group_len; |
161 | 62.9k | WORD32 *ptr_scale_table = ptr_aac_tables->pstr_block_tables->scale_table; |
162 | 62.9k | ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_channel_info->str_ics_info; |
163 | | |
164 | 62.9k | if (object_type == AOT_ER_AAC_LC) |
165 | 35.4k | ptr_sfb_width = ptr_aac_tables->str_aac_sfb_info[ptr_ics_info->window_sequence] |
166 | 35.4k | .sfb_width; |
167 | 152k | for (num_win_grp = 0; num_win_grp < ptr_ics_info->num_window_groups; |
168 | 90.0k | num_win_grp++) { |
169 | 90.0k | for (group_len = 0; |
170 | 302k | group_len < ptr_ics_info->window_group_length[num_win_grp]; |
171 | 212k | group_len++) { |
172 | 212k | (*ixheaacd_scale_factor_process)( |
173 | 212k | &ptr_spect_coeff[0], &ptr_scale_fac[0], tot_bands, |
174 | 212k | (WORD8 *)ptr_sfb_width, ptr_scale_table, total_channels, |
175 | 212k | object_type, aac_sf_data_resil_flag); |
176 | | |
177 | 212k | ptr_spect_coeff += MAX_BINS_SHORT; |
178 | 212k | } |
179 | 90.0k | ptr_scale_fac += MAX_SCALE_FACTOR_BANDS_SHORT; |
180 | 90.0k | } |
181 | 62.9k | } |
182 | | |
183 | | WORD32 ixheaacd_read_pulse_data(ia_bit_buf_struct *it_bit_buff, |
184 | | ia_pulse_info_struct *ptr_pulse_info, |
185 | 52.6k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
186 | 52.6k | WORD32 i, total_offset; |
187 | 52.6k | WORD32 error_code = 0; |
188 | | |
189 | 52.6k | WORD32 value = ixheaacd_read_bits_buf(it_bit_buff, 8); |
190 | 52.6k | ptr_pulse_info->number_pulse = value >> 6; |
191 | 52.6k | ptr_pulse_info->pulse_start_band = value & 0x3F; |
192 | | |
193 | 52.6k | if (ptr_pulse_info->pulse_start_band >= 52) { |
194 | 214 | return (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_PULSEDATA_ERROR; |
195 | 214 | } |
196 | | |
197 | 52.3k | total_offset = ptr_aac_tables->str_aac_sfb_info[0] |
198 | 52.3k | .sfb_index[ptr_pulse_info->pulse_start_band]; |
199 | | |
200 | 168k | for (i = 0; i < ptr_pulse_info->number_pulse + 1; i++) { |
201 | 116k | WORD32 value = ixheaacd_read_bits_buf(it_bit_buff, 9); |
202 | 116k | ptr_pulse_info->pulse_offset[i] = value >> 4; |
203 | 116k | ptr_pulse_info->pulse_amp[i] = value & 0xF; |
204 | 116k | total_offset += ptr_pulse_info->pulse_offset[i]; |
205 | | |
206 | 116k | if (total_offset >= 1024) { |
207 | 35 | error_code = (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_PULSEDATA_ERROR; |
208 | 35 | } |
209 | 116k | } |
210 | | |
211 | 52.3k | return error_code; |
212 | 52.6k | } |
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 | 334k | { |
223 | 334k | FLAG gain_control_data_present; |
224 | 334k | WORD16 error_code = AAC_DEC_OK; |
225 | | |
226 | 334k | if (ptr_aac_dec_channel_info->str_ics_info.window_sequence == |
227 | 334k | EIGHT_SHORT_SEQUENCE) { |
228 | 61.2k | memset(ptr_aac_dec_channel_info->ptr_scale_factor, 0, |
229 | 61.2k | MAX_WINDOWS * MAX_SCALE_FACTOR_BANDS_SHORT * 3); |
230 | 61.2k | } |
231 | | |
232 | 334k | error_code = ixheaacd_read_section_data( |
233 | 334k | it_bit_buff, ptr_aac_dec_channel_info, aac_spect_data_resil_flag, |
234 | 334k | aac_sect_data_resil_flag, ptr_aac_tables); |
235 | | |
236 | 334k | if (error_code) { |
237 | 1.65k | return error_code; |
238 | 1.65k | } |
239 | 332k | if (aac_sf_data_resil_flag && |
240 | 113k | ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD))) |
241 | 75.2k | ixheaacd_rvlc_read(it_bit_buff, ptr_aac_dec_channel_info); |
242 | 257k | else |
243 | 257k | ixheaacd_read_scale_factor_data(it_bit_buff, ptr_aac_dec_channel_info, |
244 | 257k | ptr_aac_tables, object_type); |
245 | | |
246 | 332k | error_code = 0; |
247 | 332k | if (object_type != AOT_ER_AAC_ELD) { |
248 | 264k | ptr_aac_dec_channel_info->str_pulse_info.pulse_data_present = |
249 | 264k | ixheaacd_read_bits_buf(it_bit_buff, 1); |
250 | 264k | if (ptr_aac_dec_channel_info->str_pulse_info.pulse_data_present) { |
251 | 52.6k | error_code = ixheaacd_read_pulse_data( |
252 | 52.6k | it_bit_buff, &ptr_aac_dec_channel_info->str_pulse_info, |
253 | 52.6k | ptr_aac_tables); |
254 | 52.6k | } |
255 | | |
256 | 264k | if (error_code) { |
257 | 230 | return error_code; |
258 | 230 | } |
259 | 264k | } |
260 | | |
261 | 332k | ptr_aac_dec_channel_info->str_tns_info.tns_data_present = |
262 | 332k | (FLAG)ixheaacd_read_bits_buf(it_bit_buff, 1); |
263 | | |
264 | 332k | if (object_type < ER_OBJECT_START) { |
265 | 98.1k | error_code = 0; |
266 | 98.1k | if (ptr_aac_dec_channel_info->str_tns_info.tns_data_present) { |
267 | 30.4k | error_code = |
268 | 30.4k | ixheaacd_read_tns_data(it_bit_buff, ptr_aac_dec_channel_info); |
269 | 30.4k | } |
270 | | |
271 | 98.1k | if (error_code) { |
272 | 122 | return error_code; |
273 | 122 | } |
274 | 98.1k | } |
275 | | |
276 | 332k | if (object_type != AOT_ER_AAC_ELD) { |
277 | 264k | gain_control_data_present = ixheaacd_read_bits_buf(it_bit_buff, 1); |
278 | | |
279 | 264k | if (gain_control_data_present) { |
280 | 552 | return (WORD16)( |
281 | 552 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_GAIN_CONTROL_DATA_PRESENT); |
282 | 552 | } |
283 | 264k | } |
284 | | |
285 | 331k | if (object_type == AOT_ER_AAC_ELD) { |
286 | 68.1k | if (ptr_aac_dec_channel_info->str_tns_info.tns_data_present) |
287 | 6.27k | error_code = |
288 | 6.27k | ixheaacd_read_tns_data(it_bit_buff, ptr_aac_dec_channel_info); |
289 | 68.1k | if (error_code) return error_code; |
290 | 68.1k | } |
291 | | |
292 | 331k | if (aac_spect_data_resil_flag && |
293 | 63.9k | ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD) |
294 | 36.0k | || (object_type == AOT_ER_AAC_LC))) |
295 | 63.9k | ixheaacd_hcr_read(it_bit_buff, ptr_aac_dec_channel_info, ele_type); |
296 | | |
297 | 331k | if (aac_sf_data_resil_flag && |
298 | 112k | ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD))) { |
299 | 75.1k | error_code = ixheaacd_rvlc_dec( |
300 | 75.1k | ptr_aac_dec_channel_info, ptr_aac_dec_static_channel_info, it_bit_buff); |
301 | 75.1k | if (error_code) return error_code; |
302 | | |
303 | 75.0k | it_bit_buff->bit_pos = 7 - it_bit_buff->bit_pos; |
304 | 75.0k | } |
305 | | |
306 | 331k | if (object_type == AOT_ER_AAC_LD || object_type == AOT_ER_AAC_LC) { |
307 | 165k | if (ptr_aac_dec_channel_info->str_tns_info.tns_data_present) |
308 | 45.7k | error_code = |
309 | 45.7k | ixheaacd_read_tns_data(it_bit_buff, ptr_aac_dec_channel_info); |
310 | 165k | if (error_code) return error_code; |
311 | 165k | } |
312 | | |
313 | 331k | { it_bit_buff->bit_pos = 7 - it_bit_buff->bit_pos; } |
314 | | |
315 | 331k | error_code = ixheaacd_read_spectral_data( |
316 | 331k | it_bit_buff, ptr_aac_dec_channel_info, ptr_aac_tables, total_channels, |
317 | 331k | frame_size, object_type, aac_spect_data_resil_flag, |
318 | 331k | aac_sf_data_resil_flag); |
319 | | |
320 | 331k | it_bit_buff->bit_pos = (7 - it_bit_buff->bit_pos); |
321 | | |
322 | 331k | return error_code; |
323 | 331k | } |
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 | 20.2k | WORD32 ch) { |
329 | 20.2k | IA_ERRORCODE retval = AAC_DEC_OK; |
330 | | |
331 | 20.2k | if (ptr_ics_info->predictor_data_present) { |
332 | 4.07k | if (ch == 0) { |
333 | 2.04k | ixheaacd_init_ltp_object(&(ptr_ics_info->ltp)); |
334 | 2.04k | ptr_ics_info->ltp.data_present = ixheaacd_read_bits_buf(it_bit_buff, 1); |
335 | 2.04k | if (ptr_ics_info->ltp.data_present) { |
336 | 859 | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
337 | 859 | &(ptr_ics_info->ltp), it_bit_buff, |
338 | 859 | frame_size)) > 0) { |
339 | 0 | return retval; |
340 | 0 | } |
341 | 859 | } |
342 | 2.04k | } else { |
343 | 2.02k | ixheaacd_init_ltp_object(&(ptr_ics_info->ltp2)); |
344 | 2.02k | ptr_ics_info->ltp2.data_present = ixheaacd_read_bits_buf(it_bit_buff, 1); |
345 | 2.02k | if (ptr_ics_info->ltp2.data_present) { |
346 | 1.24k | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
347 | 1.24k | &(ptr_ics_info->ltp2), it_bit_buff, |
348 | 1.24k | frame_size)) > 0) { |
349 | 0 | return retval; |
350 | 0 | } |
351 | 1.24k | } |
352 | 2.02k | } |
353 | 4.07k | } |
354 | 20.2k | return retval; |
355 | 20.2k | } |
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 | 338k | WORD32 common_window, WORD32 frame_size) { |
360 | 338k | WORD i; |
361 | 338k | WORD mask; |
362 | 338k | WORD value = 0; |
363 | | |
364 | 338k | if (object_type == AOT_ER_AAC_ELD) { |
365 | 86.1k | ptr_ics_info->window_sequence = 0; |
366 | 86.1k | ptr_ics_info->window_shape = 1; |
367 | 251k | } else { |
368 | 251k | if (object_type != AOT_ER_AAC_LD) |
369 | 156k | { |
370 | 156k | if (frame_size == 960) |
371 | 79.0k | ptr_ics_info->frame_length = 960; |
372 | 77.5k | else |
373 | 77.5k | ptr_ics_info->frame_length = 1024; |
374 | 156k | } |
375 | 251k | value = ixheaacd_read_bits_buf(it_bit_buff, 4); |
376 | 251k | ptr_ics_info->window_sequence = (WORD16)((value & 0x6) >> 1); |
377 | 251k | ptr_ics_info->window_shape = (WORD16)((value & 0x1)); |
378 | 251k | } |
379 | | |
380 | 338k | if (ptr_ics_info->window_sequence != EIGHT_SHORT_SEQUENCE) { |
381 | 284k | ptr_ics_info->num_swb_window = num_swb_window[0]; |
382 | | |
383 | 284k | ptr_ics_info->num_window_groups = 1; |
384 | 284k | ptr_ics_info->window_group_length[0] = 1; |
385 | | |
386 | 284k | if (object_type == AOT_ER_AAC_ELD) { |
387 | 86.1k | ptr_ics_info->max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 6); |
388 | 86.1k | if (ptr_ics_info->max_sfb == 0) ptr_ics_info->num_swb_window = 0; |
389 | 198k | } else { |
390 | 198k | value = ixheaacd_read_bits_buf(it_bit_buff, 7); |
391 | 198k | ptr_ics_info->max_sfb = (value & 0x7E) >> 1; |
392 | 198k | } |
393 | | |
394 | 284k | if ((object_type != AOT_ER_AAC_LD) && (object_type != AOT_AAC_LTP)) { |
395 | 174k | if (value & 1) { |
396 | 416 | return (WORD16)( |
397 | 416 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_PREDICTION_DATA_PRESENT); |
398 | 416 | } |
399 | | |
400 | 174k | } else { |
401 | 110k | ptr_ics_info->predictor_data_present = value & 1; |
402 | | |
403 | 110k | if (ptr_ics_info->predictor_data_present) { |
404 | 66.4k | WORD32 retval = AAC_DEC_OK; |
405 | | |
406 | 66.4k | ixheaacd_init_ltp_object(&(ptr_ics_info->ltp)); |
407 | 66.4k | if (object_type < ER_OBJECT_START) { |
408 | 11.9k | if ((ptr_ics_info->ltp.data_present = |
409 | 11.9k | ixheaacd_read_bits_buf(it_bit_buff, 1)) & |
410 | 11.9k | 1) { |
411 | 11.8k | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
412 | 11.8k | &(ptr_ics_info->ltp), it_bit_buff, |
413 | 11.8k | frame_size)) > 0) { |
414 | 0 | return retval; |
415 | 0 | } |
416 | 11.8k | } |
417 | 11.9k | if (common_window) { |
418 | 313 | ixheaacd_init_ltp_object(&(ptr_ics_info->ltp2)); |
419 | 313 | if ((ptr_ics_info->ltp2.data_present = |
420 | 313 | ixheaacd_read_bits_buf(it_bit_buff, 1)) & |
421 | 313 | 1) { |
422 | 18 | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
423 | 18 | &(ptr_ics_info->ltp2), |
424 | 18 | it_bit_buff, frame_size)) > 0) { |
425 | 0 | return retval; |
426 | 0 | } |
427 | 18 | } |
428 | 313 | } |
429 | 11.9k | } |
430 | 66.4k | if ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD)) { |
431 | 54.5k | if (!common_window && (object_type >= ER_OBJECT_START)) { |
432 | 52.2k | if ((ptr_ics_info->ltp.data_present = |
433 | 52.2k | ixheaacd_read_bits_buf(it_bit_buff, 1)) & |
434 | 52.2k | 1) { |
435 | 44.8k | if ((retval = ixheaacd_ltp_data(object_type, ptr_ics_info, |
436 | 44.8k | &(ptr_ics_info->ltp), it_bit_buff, |
437 | 44.8k | frame_size)) < 0) { |
438 | 3 | return retval; |
439 | 3 | } |
440 | 44.8k | } |
441 | 52.2k | } |
442 | 54.5k | } |
443 | 66.4k | } |
444 | 110k | } |
445 | | |
446 | 284k | } else { |
447 | 53.1k | WORD32 num_groups = 0, scale_factor_grouping; |
448 | 53.1k | ptr_ics_info->num_swb_window = num_swb_window[1]; |
449 | | |
450 | 53.1k | value = ixheaacd_read_bits_buf(it_bit_buff, 11); |
451 | 53.1k | ptr_ics_info->max_sfb = (value & 0x780) >> 7; |
452 | | |
453 | 53.1k | scale_factor_grouping = (value & 0x7F); |
454 | | |
455 | 53.1k | mask = 0x40; |
456 | 424k | for (i = 0; i < 7; i++) { |
457 | 371k | ptr_ics_info->window_group_length[i] = 1; |
458 | | |
459 | 371k | if (scale_factor_grouping & mask) { |
460 | 224k | ptr_ics_info->window_group_length[num_groups] = |
461 | 224k | ptr_ics_info->window_group_length[num_groups] + 1; |
462 | | |
463 | 224k | } else { |
464 | 147k | num_groups = num_groups + 1; |
465 | 147k | } |
466 | | |
467 | 371k | mask = mask >> 1; |
468 | 371k | } |
469 | | |
470 | 53.1k | ptr_ics_info->window_group_length[7] = 1; |
471 | 53.1k | ptr_ics_info->num_window_groups = num_groups + 1; |
472 | 53.1k | } |
473 | | |
474 | 337k | if (ptr_ics_info->max_sfb > ptr_ics_info->num_swb_window) { |
475 | 32.8k | return (WORD16)IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_SFB_TRANSMITTED; |
476 | 32.8k | } |
477 | | |
478 | 304k | return AAC_DEC_OK; |
479 | 337k | } |
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 | 300k | ia_eld_specific_config_struct eld_specific_config, WORD32 ele_type) { |
485 | 300k | WORD16 error_code = AAC_DEC_OK; |
486 | 300k | WORD32 ch; |
487 | 300k | WORD32 crc_reg = 0; |
488 | | |
489 | 632k | for (ch = 0; ch < num_ch; ch++) { |
490 | 335k | ia_aac_dec_channel_info_struct *ptr_aac_dec_ch_info = |
491 | 335k | aac_dec_handle->pstr_aac_dec_ch_info[ch]; |
492 | 335k | ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_ch_info->str_ics_info; |
493 | | |
494 | 335k | if (ch == 1) { |
495 | 34.7k | if (it_bit_buff->pstr_adts_crc_info->crc_active == 1 && |
496 | 38 | (it_bit_buff->pstr_adts_crc_info->no_reg < 7)) { |
497 | 27 | crc_reg = |
498 | 27 | ixheaacd_adts_crc_start_reg(it_bit_buff->pstr_adts_crc_info, |
499 | 27 | it_bit_buff, CRC_ADTS_RAW_IIND_ICS); |
500 | 27 | } |
501 | 34.7k | } |
502 | 335k | ptr_aac_dec_ch_info->global_gain = |
503 | 335k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, 8); |
504 | | |
505 | 335k | if (!(aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->common_window)) { |
506 | 274k | error_code = ixheaacd_ics_read( |
507 | 274k | it_bit_buff, ptr_ics_info, aac_dec_handle->num_swb_window, |
508 | 274k | object_type, |
509 | 274k | aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->common_window, |
510 | 274k | aac_dec_handle->samples_per_frame); |
511 | 274k | if (ch == 1) |
512 | 4.72k | aac_dec_handle->pstr_aac_dec_ch_info[ch - 1]->str_ics_info.ltp2.lag = |
513 | 4.72k | ptr_ics_info->ltp.lag; |
514 | | |
515 | 274k | if (error_code) { |
516 | 740 | 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 | 740 | return error_code; |
521 | 740 | } |
522 | 274k | } |
523 | | |
524 | 334k | error_code = ixheaacd_read_block_data( |
525 | 334k | it_bit_buff, ptr_aac_dec_ch_info, aac_dec_handle->pstr_aac_tables, |
526 | 334k | total_channels, frame_size, object_type, |
527 | 334k | eld_specific_config.aac_spect_data_resil_flag, |
528 | 334k | eld_specific_config.aac_sect_data_resil_flag, |
529 | 334k | eld_specific_config.aac_sf_data_resil_flag, ele_type, |
530 | 334k | aac_dec_handle->pstr_aac_dec_overlap_info[ch]); |
531 | 334k | if (error_code) { |
532 | 3.46k | if (it_bit_buff->cnt_bits < 0) { |
533 | 105 | error_code = (WORD16)( |
534 | 105 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
535 | 105 | } |
536 | | |
537 | 3.46k | return error_code; |
538 | 3.46k | } |
539 | | |
540 | 331k | if (ch == 0) { |
541 | 295k | if ((object_type == AOT_ER_AAC_LD) && |
542 | 90.7k | (aac_dec_handle->pstr_aac_dec_ch_info[LEFT]->common_window) && |
543 | 10.1k | (ele_type == ID_CPE)) { |
544 | 10.1k | IA_ERRORCODE temp = |
545 | 10.1k | ixheaacd_ltp_decode(it_bit_buff, ptr_ics_info, object_type, |
546 | 10.1k | aac_dec_handle->samples_per_frame, 1); |
547 | | |
548 | 10.1k | if (temp != 0) { |
549 | 1 | return temp; |
550 | 1 | } |
551 | 10.1k | aac_dec_handle->pstr_aac_dec_ch_info[ch + 1]->str_ics_info.ltp.lag = |
552 | 10.1k | ptr_ics_info->ltp2.lag; |
553 | 10.1k | } |
554 | 295k | } |
555 | 331k | if (ch == 1) { |
556 | 34.2k | if (it_bit_buff->pstr_adts_crc_info->crc_active == 1) { |
557 | 30 | ixheaacd_adts_crc_end_reg(it_bit_buff->pstr_adts_crc_info, it_bit_buff, |
558 | 30 | crc_reg); |
559 | 30 | } |
560 | 34.2k | } |
561 | 331k | } |
562 | | |
563 | 296k | return error_code; |
564 | 300k | } |
565 | | |
566 | | VOID ixheaacd_read_ms_data( |
567 | | ia_bit_buf_struct *it_bit_buff, |
568 | 30.5k | ia_aac_dec_channel_info_struct *ptr_aac_dec_ch_info) { |
569 | 30.5k | WORD32 num_win_group, sfb; |
570 | 30.5k | WORD32 ms_mask_present; |
571 | 30.5k | UWORD8 *ptr_ms_used = &ptr_aac_dec_ch_info->pstr_stereo_info->ms_used[0][0]; |
572 | 30.5k | WORD32 num_window_groups = |
573 | 30.5k | ptr_aac_dec_ch_info->str_ics_info.num_window_groups; |
574 | 30.5k | WORD16 max_sfb = ptr_aac_dec_ch_info->str_ics_info.max_sfb; |
575 | | |
576 | 30.5k | ms_mask_present = ixheaacd_read_bits_buf(it_bit_buff, 2); |
577 | | |
578 | 30.5k | if (ms_mask_present < 1) { |
579 | 18.6k | memset(ptr_ms_used, 0, |
580 | 18.6k | sizeof(UWORD8) * JOINT_STEREO_MAX_BANDS * JOINT_STEREO_MAX_GROUPS); |
581 | 18.6k | } |
582 | | |
583 | 11.9k | else if (ms_mask_present == 1) { |
584 | 7.11k | for (num_win_group = 0; num_win_group < num_window_groups; |
585 | 3.73k | num_win_group++) { |
586 | 10.4k | for (sfb = 0; sfb < max_sfb; sfb++) { |
587 | 6.72k | ptr_aac_dec_ch_info->pstr_stereo_info->ms_used[num_win_group][sfb] = |
588 | 6.72k | (UWORD8)ixheaacd_read_bits_buf(it_bit_buff, 1); |
589 | 6.72k | } |
590 | 3.73k | } |
591 | | |
592 | 8.55k | } else { |
593 | 25.3k | for (num_win_group = 0; num_win_group < num_window_groups; |
594 | 16.7k | num_win_group++) { |
595 | 16.7k | ptr_ms_used = |
596 | 16.7k | &ptr_aac_dec_ch_info->pstr_stereo_info->ms_used[num_win_group][0]; |
597 | 16.7k | memset(ptr_ms_used, 1, (max_sfb) * sizeof(UWORD8)); |
598 | 16.7k | } |
599 | 8.55k | } |
600 | 30.5k | } |
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 | 295k | WORD32 *out_data, void *self_ptr) { |
607 | 295k | WORD32 channel; |
608 | 295k | IA_ERRORCODE err = IA_NO_ERROR; |
609 | 295k | ia_aac_decoder_struct *self = self_ptr; |
610 | 295k | if (aac_spect_data_resil_flag && |
611 | 62.6k | ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_ER_AAC_ELD) || |
612 | 62.6k | (object_type == AOT_ER_AAC_LC))) { |
613 | 125k | for (channel = 0; channel < num_ch; channel++) { |
614 | 62.9k | err = ixheaacd_cblock_inv_quant_spect_data( |
615 | 62.9k | ptr_aac_dec_channel_info[channel], ptr_aac_tables); |
616 | 62.9k | if (err) return err; |
617 | 62.9k | ixheaacd_cblock_scale_spect_data(ptr_aac_dec_channel_info[channel], |
618 | 62.9k | ptr_aac_tables, num_ch, object_type, |
619 | 62.9k | aac_sf_data_resil_flag); |
620 | 62.9k | } |
621 | 62.6k | } |
622 | | |
623 | 295k | if (num_ch > 1) { |
624 | 34.2k | if (ptr_aac_dec_channel_info[LEFT]->common_window) { |
625 | 29.5k | if (ptr_aac_dec_channel_info[LEFT]->str_pns_info.pns_active || |
626 | 25.1k | ptr_aac_dec_channel_info[RIGHT]->str_pns_info.pns_active) { |
627 | 4.96k | ixheaacd_map_ms_mask_pns(ptr_aac_dec_channel_info); |
628 | 4.96k | } |
629 | | |
630 | 29.5k | ixheaacd_ms_stereo_process(ptr_aac_dec_channel_info, ptr_aac_tables); |
631 | 29.5k | } |
632 | | |
633 | 34.2k | ixheaacd_intensity_stereo_process( |
634 | 34.2k | ptr_aac_dec_channel_info, ptr_aac_tables, object_type, |
635 | 34.2k | aac_sf_data_resil_flag, |
636 | 34.2k | ptr_aac_dec_channel_info[LEFT]->str_ics_info.frame_length); |
637 | 34.2k | } |
638 | | |
639 | 624k | for (channel = 0; channel < num_ch; channel++) { |
640 | 329k | WORD32 *p_spectrum = ptr_aac_dec_channel_info[channel]->ptr_spec_coeff; |
641 | | |
642 | 329k | if (total_channels > 2) { |
643 | 15.4k | if (ptr_aac_dec_channel_info[channel]->str_ics_info.window_sequence != |
644 | 15.4k | EIGHT_SHORT_SEQUENCE) { |
645 | 11.5k | WORD16 *band_offsets = ptr_aac_tables->sfb_long_table; |
646 | 11.5k | WORD32 no_spec_coeff = band_offsets[ptr_aac_dec_channel_info[channel] |
647 | 11.5k | ->str_ics_info.max_sfb]; |
648 | 11.5k | ixheaacd_right_shift_block(p_spectrum, no_spec_coeff, 3); |
649 | 11.5k | } else { |
650 | 3.93k | ixheaacd_right_shift_block(p_spectrum, 1024, 3); |
651 | 3.93k | } |
652 | 15.4k | } |
653 | | |
654 | 329k | ixheaacd_pns_process(ptr_aac_dec_channel_info, channel, ptr_aac_tables); |
655 | | |
656 | 329k | if ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_AAC_LTP)) { |
657 | 142k | { |
658 | 142k | if (channel == 0) { |
659 | 128k | ltp_info *ltp1 = |
660 | 128k | &(ptr_aac_dec_channel_info[channel]->str_ics_info.ltp); |
661 | 128k | ixheaacd_lt_prediction(ptr_aac_dec_channel_info[channel], ltp1, |
662 | 128k | p_spectrum, ptr_aac_tables, |
663 | 128k | self->ptr_aac_dec_static_channel_info[LEFT] |
664 | 128k | ->overlap_add_data.win_shape, |
665 | 128k | self->sampling_rate_index, object_type, |
666 | 128k | self->samples_per_frame, in_data, out_data); |
667 | | |
668 | 128k | } else { |
669 | 14.2k | ltp_info *ltp2 = |
670 | 14.2k | (self->pstr_aac_dec_ch_info[0]->common_window) |
671 | 14.2k | ? &(ptr_aac_dec_channel_info[0]->str_ics_info.ltp2) |
672 | 14.2k | : |
673 | | |
674 | 14.2k | &(ptr_aac_dec_channel_info[1]->str_ics_info.ltp); |
675 | 14.2k | ixheaacd_lt_prediction(ptr_aac_dec_channel_info[channel], ltp2, |
676 | 14.2k | p_spectrum, ptr_aac_tables, |
677 | 14.2k | self->ptr_aac_dec_static_channel_info[RIGHT] |
678 | 14.2k | ->overlap_add_data.win_shape, |
679 | 14.2k | self->sampling_rate_index, object_type, |
680 | 14.2k | self->samples_per_frame, in_data, out_data); |
681 | 14.2k | } |
682 | 142k | } |
683 | 142k | } |
684 | | |
685 | 329k | if (ptr_aac_dec_channel_info[channel]->str_tns_info.tns_data_present) { |
686 | 81.5k | ixheaacd_aac_tns_process(ptr_aac_dec_channel_info[channel], |
687 | 81.5k | total_channels, ptr_aac_tables, object_type, 1, |
688 | 81.5k | NULL); |
689 | 81.5k | } |
690 | 329k | } |
691 | 295k | return err; |
692 | 295k | } |
693 | | |
694 | | VOID ixheaacd_set_corr_info( |
695 | 74.6k | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, WORD16 pns_band) { |
696 | 74.6k | ia_pns_correlation_info_struct *ptr_corr_info = |
697 | 74.6k | ptr_aac_dec_channel_info->pstr_pns_corr_info; |
698 | 74.6k | ptr_corr_info->correlated[(pns_band >> PNS_BAND_FLAGS_SHIFT)] |= |
699 | 74.6k | (1 << (pns_band & PNS_BAND_FLAGS_MASK)); |
700 | 74.6k | } |
701 | | |
702 | | VOID ixheaacd_map_ms_mask_pns( |
703 | 4.96k | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info[CHANNELS]) { |
704 | 4.96k | WORD32 num_win_group, sfb; |
705 | | |
706 | 4.96k | for (num_win_group = 0; |
707 | 10.0k | num_win_group < |
708 | 10.0k | ptr_aac_dec_channel_info[LEFT]->str_ics_info.num_window_groups; |
709 | 5.03k | num_win_group++) { |
710 | 105k | for (sfb = 0; sfb < ptr_aac_dec_channel_info[LEFT]->str_ics_info.max_sfb; |
711 | 100k | sfb++) { |
712 | 100k | if (ptr_aac_dec_channel_info[LEFT] |
713 | 100k | ->pstr_stereo_info->ms_used[num_win_group][sfb]) { |
714 | 74.6k | WORD16 pns_band = (num_win_group << 4) + sfb; |
715 | 74.6k | ixheaacd_set_corr_info(ptr_aac_dec_channel_info[LEFT], pns_band); |
716 | | |
717 | 74.6k | if (ptr_aac_dec_channel_info[LEFT]->str_pns_info.pns_used[pns_band] && |
718 | 36.0k | ptr_aac_dec_channel_info[RIGHT]->str_pns_info.pns_used[pns_band]) { |
719 | 9.31k | ptr_aac_dec_channel_info[LEFT] |
720 | 9.31k | ->pstr_stereo_info->ms_used[num_win_group][sfb] ^= 1; |
721 | 9.31k | } |
722 | 74.6k | } |
723 | 100k | } |
724 | 5.03k | } |
725 | 4.96k | } |
726 | | |
727 | | VOID ixheaacd_pulse_data_apply(ia_pulse_info_struct *ptr_pulse_info, |
728 | | WORD8 *pulse_scratch, |
729 | 228k | const WORD16 *ptr_swb_offset, WORD object_type) { |
730 | 228k | WORD i; |
731 | 228k | WORD32 k; |
732 | | |
733 | 228k | memset(pulse_scratch, 0, sizeof(WORD32) * 256); |
734 | | |
735 | 228k | if (object_type != AOT_ER_AAC_ELD) { |
736 | 163k | if (ptr_pulse_info->pulse_data_present) { |
737 | 33.5k | k = ptr_swb_offset[ptr_pulse_info->pulse_start_band]; |
738 | | |
739 | 107k | for (i = 0; i <= ptr_pulse_info->number_pulse; i++) { |
740 | 74.4k | k = k + ptr_pulse_info->pulse_offset[i]; |
741 | 74.4k | pulse_scratch[k] = ptr_pulse_info->pulse_amp[i]; |
742 | 74.4k | } |
743 | 33.5k | } |
744 | 163k | } else { |
745 | 64.8k | ptr_pulse_info->pulse_data_present = 0; |
746 | 64.8k | } |
747 | 228k | } |
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 | 331k | WORD32 aac_sf_data_resil_flag) { |
755 | 331k | WORD sfb, max_sfb; |
756 | 331k | WORD num_win_grp, group_len, grp_offset; |
757 | | |
758 | 331k | WORD index; |
759 | 331k | WORD8 *ptr_code_book; |
760 | 331k | WORD16 *ptr_scale_factor; |
761 | 331k | WORD32 *ptr_spec_coef; |
762 | 331k | ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_channel_info->str_ics_info; |
763 | 331k | WORD16 *swb_offset; |
764 | | |
765 | 331k | WORD32 maximum_bins_short = ptr_ics_info->frame_length >> 3; |
766 | | |
767 | 331k | WORD32 *ptr_spec_coef_out; |
768 | | |
769 | 331k | ptr_code_book = ptr_aac_dec_channel_info->ptr_code_book; |
770 | 331k | ptr_scale_factor = ptr_aac_dec_channel_info->ptr_scale_factor; |
771 | 331k | ptr_spec_coef = ptr_aac_dec_channel_info->ptr_spec_coeff; |
772 | 331k | max_sfb = ptr_ics_info->max_sfb; |
773 | | |
774 | 331k | swb_offset = |
775 | 331k | ptr_aac_tables->str_aac_sfb_info[ptr_ics_info->window_sequence].sfb_index; |
776 | | |
777 | 331k | if (!aac_spect_data_resil_flag) { |
778 | 267k | if (ptr_aac_dec_channel_info->str_ics_info.window_sequence != |
779 | 267k | EIGHT_SHORT_SEQUENCE) { |
780 | 228k | WORD8 *ptr_scratch; |
781 | | |
782 | 228k | if (object_type == AOT_ER_AAC_ELD) |
783 | 64.8k | ptr_scratch = (WORD8 *)ptr_aac_dec_channel_info->pulse_scratch; |
784 | 163k | else |
785 | 163k | ptr_scratch = (WORD8 *)ptr_aac_dec_channel_info->scratch_buf_ptr; |
786 | | |
787 | 228k | memset(ptr_spec_coef, 0, sizeof(WORD32) * 1024); |
788 | | |
789 | 228k | ixheaacd_pulse_data_apply(&ptr_aac_dec_channel_info->str_pulse_info, |
790 | 228k | ptr_scratch, swb_offset, object_type); |
791 | | |
792 | 228k | ptr_spec_coef_out = &ptr_spec_coef[0]; |
793 | 515k | for (sfb = 0; sfb < max_sfb;) { |
794 | 286k | WORD ret_val; |
795 | 286k | WORD32 sfb_width; |
796 | 286k | WORD32 sect_cb = ptr_code_book[sfb]; |
797 | 286k | WORD start = sfb; |
798 | 286k | if ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD) |
799 | 183k | || (object_type == AOT_ER_AAC_LC)) { |
800 | 183k | if ((sect_cb >= 16) && (sect_cb <= 31)) { |
801 | 64.5k | ptr_code_book[sfb] = sect_cb = 11; |
802 | 64.5k | } |
803 | 183k | } |
804 | 2.86M | for (; sfb < max_sfb && (ptr_code_book[sfb] == sect_cb); sfb++) |
805 | 2.58M | ; |
806 | | |
807 | 286k | sfb_width = swb_offset[sfb] - swb_offset[start]; |
808 | | |
809 | 286k | if (sect_cb > ZERO_HCB && (sect_cb < NOISE_HCB)) { |
810 | 200k | ret_val = ixheaacd_huffman_dec_word2(it_bit_buff, sect_cb, sfb_width, |
811 | 200k | ptr_aac_tables, |
812 | 200k | ptr_spec_coef_out, ptr_scratch); |
813 | | |
814 | 200k | if (ret_val != 0) { |
815 | 226 | return (WORD16)( |
816 | 226 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_MAX_HUFFDEC_VAL); |
817 | 226 | } |
818 | 200k | } |
819 | | |
820 | 86.1k | else { |
821 | 86.1k | if (ptr_aac_dec_channel_info->str_pulse_info.pulse_data_present) { |
822 | 28.2k | ixheaacd_inverse_quantize( |
823 | 28.2k | ptr_spec_coef_out, sfb_width, |
824 | 28.2k | (WORD32 *) |
825 | 28.2k | ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13, |
826 | 28.2k | ptr_scratch); |
827 | 28.2k | } |
828 | 86.1k | } |
829 | 286k | ptr_scratch += sfb_width; |
830 | 286k | ptr_spec_coef_out += sfb_width; |
831 | 286k | } |
832 | | |
833 | 228k | if ((object_type != AOT_ER_AAC_ELD) && (object_type != AOT_ER_AAC_LD)) |
834 | 107k | index = 1024 - swb_offset[max_sfb]; |
835 | 121k | else |
836 | 121k | index = frame_size - swb_offset[max_sfb]; |
837 | | |
838 | 228k | if (index < 0) return -1; |
839 | | |
840 | 228k | } else { |
841 | 39.0k | memset(ptr_spec_coef, 0, sizeof(WORD32) * 1024); |
842 | | |
843 | 39.0k | grp_offset = 0; |
844 | | |
845 | 246k | for (num_win_grp = 0; num_win_grp < ptr_ics_info->num_window_groups; |
846 | 207k | num_win_grp++) { |
847 | 207k | WORD grp_len = ptr_ics_info->window_group_length[num_win_grp]; |
848 | | |
849 | 207k | if (maximum_bins_short == 120) |
850 | 50.8k | ptr_spec_coef_out = &ptr_spec_coef[grp_offset * maximum_bins_short]; |
851 | 156k | else |
852 | 156k | ptr_spec_coef_out = &ptr_spec_coef[grp_offset * MAX_BINS_SHORT]; |
853 | | |
854 | 207k | WORD bands = num_win_grp * MAX_SCALE_FACTOR_BANDS_SHORT; |
855 | 285k | for (sfb = 0; sfb < max_sfb;) { |
856 | 78.1k | WORD sect_cb = ptr_code_book[bands]; |
857 | 78.1k | WORD start = sfb; |
858 | 78.1k | WORD ret_val; |
859 | | |
860 | 78.1k | if ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD) |
861 | 78.1k | || (object_type == AOT_ER_AAC_LC)) { |
862 | 63.2k | if ((sect_cb >= 16) && (sect_cb <= 31)) { |
863 | 48.9k | ptr_code_book[bands] = sect_cb = 11; |
864 | 48.9k | } |
865 | 63.2k | } |
866 | | |
867 | 250k | for (; sfb < max_sfb && (ptr_code_book[bands] == sect_cb); |
868 | 172k | sfb++, bands++) |
869 | 172k | ; |
870 | | |
871 | 78.1k | if (sect_cb > ZERO_HCB && (sect_cb < NOISE_HCB)) { |
872 | 62.1k | ret_val = ixheaacd_decode_huffman( |
873 | 62.1k | it_bit_buff, sect_cb, ptr_spec_coef_out, (WORD16 *)swb_offset, |
874 | 62.1k | start, sfb, grp_len, ptr_aac_tables, maximum_bins_short); |
875 | | |
876 | 62.1k | if (ret_val != 0) { |
877 | 98 | return (WORD16)( |
878 | 98 | (WORD32) |
879 | 98 | IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_MAX_HUFFDEC_VAL); |
880 | 98 | } |
881 | 62.1k | } |
882 | 78.1k | } |
883 | 207k | grp_offset = (grp_offset + grp_len); |
884 | 207k | } |
885 | 39.0k | } |
886 | 267k | { |
887 | 267k | WORD32 *ptr_scale_table; |
888 | | |
889 | 267k | if (maximum_bins_short != 120) |
890 | 213k | ptr_scale_table = ptr_aac_tables->pstr_block_tables->scale_table; |
891 | 53.7k | else |
892 | 53.7k | ptr_scale_table = ptr_aac_tables->pstr_block_tables->scale_table_960; |
893 | | |
894 | 267k | WORD8 *ptr_sfb_width = |
895 | 267k | ptr_aac_tables->str_aac_sfb_info[ptr_ics_info->window_sequence] |
896 | 267k | .sfb_width; |
897 | | |
898 | 702k | for (num_win_grp = 0; num_win_grp < ptr_ics_info->num_window_groups; |
899 | 435k | num_win_grp++) { |
900 | 435k | for (group_len = 0; |
901 | 975k | group_len < ptr_ics_info->window_group_length[num_win_grp]; |
902 | 540k | group_len++) { |
903 | 540k | (*ixheaacd_scale_factor_process)( |
904 | 540k | &ptr_spec_coef[0], &ptr_scale_factor[0], max_sfb, |
905 | 540k | (WORD8 *)ptr_sfb_width, ptr_scale_table, total_channels, |
906 | 540k | object_type, aac_sf_data_resil_flag); |
907 | | |
908 | 540k | if (maximum_bins_short == 120) |
909 | 116k | ptr_spec_coef += maximum_bins_short; |
910 | 423k | else |
911 | 423k | ptr_spec_coef += MAX_BINS_SHORT; |
912 | 540k | } |
913 | | |
914 | 435k | ptr_scale_factor += MAX_SCALE_FACTOR_BANDS_SHORT; |
915 | 435k | } |
916 | 267k | } |
917 | 267k | } else { |
918 | 63.8k | ia_hcr_info_struct *pstr_hcr_info = &ptr_aac_dec_channel_info->str_hcr_info; |
919 | 63.8k | WORD32 error = 0; |
920 | | |
921 | 63.8k | memset(ptr_spec_coef, 0, sizeof(WORD32) * 1024); |
922 | | |
923 | 63.8k | if (ptr_aac_dec_channel_info->reorder_spect_data_len != 0) { |
924 | 49.8k | error = ixheaacd_huff_code_reorder_init( |
925 | 49.8k | pstr_hcr_info, ptr_aac_dec_channel_info, ptr_aac_tables, it_bit_buff); |
926 | | |
927 | 49.8k | if (error != 0) { |
928 | 300 | return IA_XHEAAC_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; |
929 | 300 | } |
930 | 49.5k | error = ixheaacd_hcr_decoder(pstr_hcr_info, ptr_aac_dec_channel_info, |
931 | 49.5k | ptr_aac_tables, it_bit_buff); |
932 | | |
933 | 49.5k | if (error != 0) { |
934 | 42.0k | ixheaacd_huff_mute_erroneous_lines(pstr_hcr_info); |
935 | 42.0k | } |
936 | | |
937 | 49.5k | if (it_bit_buff->cnt_bits < |
938 | 49.5k | ptr_aac_dec_channel_info->reorder_spect_data_len) { |
939 | 435 | longjmp(*(it_bit_buff->xaac_jmp_buf), |
940 | 435 | IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); |
941 | 435 | } |
942 | | |
943 | 49.1k | it_bit_buff->cnt_bits += |
944 | 49.1k | -ptr_aac_dec_channel_info->reorder_spect_data_len; |
945 | 49.1k | it_bit_buff->ptr_read_next = |
946 | 49.1k | it_bit_buff->ptr_bit_buf_base + |
947 | 49.1k | ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3); |
948 | 49.1k | it_bit_buff->bit_pos = (it_bit_buff->size - it_bit_buff->cnt_bits) & 7; |
949 | | |
950 | 49.1k | } else { |
951 | 13.9k | it_bit_buff->ptr_read_next = |
952 | 13.9k | it_bit_buff->ptr_bit_buf_base + |
953 | 13.9k | ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3); |
954 | 13.9k | it_bit_buff->bit_pos = (it_bit_buff->size - it_bit_buff->cnt_bits) & 7; |
955 | 13.9k | } |
956 | 63.8k | } |
957 | | |
958 | 330k | return AAC_DEC_OK; |
959 | 331k | } |
960 | | |
961 | | WORD16 ixheaacd_read_tns_data( |
962 | | ia_bit_buf_struct *it_bit_buff, |
963 | 82.4k | ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) { |
964 | 82.4k | WORD win_size, window_per_frame; |
965 | 82.4k | WORD n_filt_bits, start_band_bits, order_bits; |
966 | 82.4k | WORD32 bottom; |
967 | | |
968 | 82.4k | ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_channel_info->str_ics_info; |
969 | 82.4k | ia_tns_info_aac_struct *ptr_tns_info = |
970 | 82.4k | &ptr_aac_dec_channel_info->str_tns_info; |
971 | | |
972 | 82.4k | if (ptr_ics_info->window_sequence != EIGHT_SHORT_SEQUENCE) { |
973 | 58.2k | n_filt_bits = 2; |
974 | 58.2k | start_band_bits = 6; |
975 | 58.2k | order_bits = 5; |
976 | 58.2k | window_per_frame = 1; |
977 | | |
978 | 58.2k | } else { |
979 | 24.2k | n_filt_bits = 1; |
980 | 24.2k | start_band_bits = 4; |
981 | 24.2k | order_bits = 3; |
982 | 24.2k | window_per_frame = 8; |
983 | 24.2k | } |
984 | | |
985 | 82.4k | bottom = ptr_ics_info->num_swb_window; |
986 | | |
987 | 333k | for (win_size = 0; win_size < window_per_frame; win_size++) { |
988 | 251k | WORD n_filt; |
989 | 251k | WORD start_band, coef_res; |
990 | 251k | ptr_tns_info->n_filt[win_size] = n_filt = |
991 | 251k | (WORD16)ixheaacd_read_bits_buf(it_bit_buff, n_filt_bits); |
992 | | |
993 | 251k | if (n_filt) { |
994 | 95.3k | WORD filt; |
995 | 95.3k | WORD top; |
996 | | |
997 | 95.3k | coef_res = ixheaacd_read_bits_buf(it_bit_buff, 1); |
998 | | |
999 | 95.3k | top = bottom; |
1000 | 206k | for (filt = 0; filt < n_filt; filt++) { |
1001 | 111k | WORD order; |
1002 | 111k | ia_filter_info_struct *filter = |
1003 | 111k | &ptr_tns_info->str_filter[win_size][filt]; |
1004 | | |
1005 | 111k | start_band = ixheaacd_read_bits_buf(it_bit_buff, start_band_bits); |
1006 | | |
1007 | 111k | if (top < start_band) { |
1008 | 85.7k | top = start_band; |
1009 | 85.7k | } |
1010 | 111k | filter->start_band = top - start_band; |
1011 | 111k | filter->stop_band = top; |
1012 | | |
1013 | 111k | top = filter->start_band; |
1014 | | |
1015 | 111k | 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 | 111k | filter->order = order = ixheaacd_read_bits_buf(it_bit_buff, order_bits); |
1021 | | |
1022 | 111k | if ((order - MAX_ORDER_LONG) > 0) { |
1023 | 295 | return (WORD16)( |
1024 | 295 | (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_TNS_ORDER_ERROR); |
1025 | 295 | } |
1026 | | |
1027 | 111k | if (order) { |
1028 | 95.2k | WORD i; |
1029 | 95.2k | WORD32 coef, coef_compress; |
1030 | 95.2k | WORD resolution, shift; |
1031 | | |
1032 | 95.2k | filter->direction = |
1033 | 95.2k | (WORD8)(ixheaacd_read_bits_buf(it_bit_buff, 1) ? -1 : 1); |
1034 | | |
1035 | 95.2k | coef_compress = ixheaacd_read_bits_buf(it_bit_buff, 1); |
1036 | | |
1037 | 95.2k | filter->resolution = coef_res; |
1038 | | |
1039 | 95.2k | resolution = coef_res + 3 - coef_compress; |
1040 | | |
1041 | 95.2k | shift = 32 - resolution; |
1042 | | |
1043 | 668k | for (i = 0; i < order; i++) { |
1044 | 573k | coef = ixheaacd_read_bits_buf(it_bit_buff, resolution); |
1045 | 573k | coef = coef << shift; |
1046 | 573k | filter->coef[i] = (WORD8)(coef >> shift); |
1047 | 573k | } |
1048 | 95.2k | } |
1049 | 111k | } |
1050 | 95.3k | } |
1051 | 251k | } |
1052 | 82.1k | return AAC_DEC_OK; |
1053 | 82.4k | } |
1054 | | |
1055 | | WORD32 ixheaacd_inv_quant(WORD32 *px_quant, WORD32 *ixheaacd_pow_table_Q13) |
1056 | | |
1057 | 26.3k | { |
1058 | 26.3k | WORD32 q1; |
1059 | 26.3k | WORD32 temp; |
1060 | 26.3k | WORD32 q_abs; |
1061 | 26.3k | WORD16 interp; |
1062 | 26.3k | WORD32 shift; |
1063 | | |
1064 | 26.3k | q_abs = *px_quant; |
1065 | | |
1066 | 26.3k | if (q_abs > (8191 + 32)) |
1067 | 211 | return IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_MAX_HUFFDEC_VAL; |
1068 | | |
1069 | 26.1k | if (q_abs < 1024) { |
1070 | 19.5k | shift = 3; |
1071 | 19.5k | } else { |
1072 | 6.60k | shift = 6; |
1073 | 6.60k | } |
1074 | | |
1075 | 26.1k | q1 = (q_abs) >> shift; |
1076 | | |
1077 | 26.1k | interp = q_abs - (q1 << shift); |
1078 | | |
1079 | 26.1k | temp = ixheaacd_pow_table_Q13[q1 + 1] - ixheaacd_pow_table_Q13[q1]; |
1080 | | |
1081 | 26.1k | temp = (WORD32)(temp * (WORD32)interp); |
1082 | | |
1083 | 26.1k | temp = temp + (ixheaacd_pow_table_Q13[q1] << shift); |
1084 | | |
1085 | 26.1k | if (shift == 3) |
1086 | 19.5k | temp = temp << 1; |
1087 | 6.60k | else |
1088 | 6.60k | temp = temp << 2; |
1089 | | |
1090 | 26.1k | *px_quant = temp; |
1091 | | |
1092 | 26.1k | return 0; |
1093 | 26.3k | } |
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 | 62.9k | ia_aac_dec_tables_struct *ptr_aac_tables) { |
1108 | 62.9k | int window, group, grp_win, band; |
1109 | 62.9k | IA_ERRORCODE err = IA_NO_ERROR; |
1110 | 62.9k | int sf_bands_transmitted = ptr_aac_dec_channel_info->str_ics_info.max_sfb; |
1111 | 62.9k | WORD8 *ptr_code_book = ptr_aac_dec_channel_info->ptr_code_book; |
1112 | 62.9k | const WORD16 *band_offsets = (WORD16 *)ixheaacd_getscalefactorbandoffsets( |
1113 | 62.9k | &(ptr_aac_dec_channel_info->str_ics_info), ptr_aac_tables); |
1114 | 62.9k | WORD32 *ptr_pow_table_Q13 = |
1115 | 62.9k | (WORD32 *)ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13; |
1116 | | |
1117 | 62.9k | for (window = 0, group = 0; |
1118 | 152k | group < ptr_aac_dec_channel_info->str_ics_info.num_window_groups; |
1119 | 90.0k | group++) { |
1120 | 90.0k | for (grp_win = 0; |
1121 | 302k | grp_win < |
1122 | 302k | ptr_aac_dec_channel_info->str_ics_info.window_group_length[group]; |
1123 | 212k | grp_win++, window++) { |
1124 | 2.82M | for (band = 0; band < sf_bands_transmitted; band++) { |
1125 | 2.61M | WORD32 *ptr_spec_coef = |
1126 | 2.61M | SPEC(ptr_aac_dec_channel_info->ptr_spec_coeff, window, |
1127 | 2.61M | ptr_aac_dec_channel_info->granule_len) + |
1128 | 2.61M | band_offsets[band]; |
1129 | 2.61M | int num_lines = band_offsets[band + 1] - band_offsets[band]; |
1130 | 2.61M | int bnds = group * 16 + band; |
1131 | 2.61M | int i; |
1132 | | |
1133 | 2.61M | if ((ptr_code_book[bnds] == ZERO_HCB) || |
1134 | 2.55M | (ptr_code_book[bnds] == INTENSITY_HCB) || |
1135 | 2.26M | (ptr_code_book[bnds] == INTENSITY_HCB2)) |
1136 | 690k | continue; |
1137 | | |
1138 | 1.91M | if (ptr_code_book[bnds] == NOISE_HCB) { |
1139 | 196k | continue; |
1140 | 196k | } |
1141 | | |
1142 | 23.8M | for (i = 0; i < num_lines; i++) { |
1143 | 22.0M | WORD8 temp = 0; |
1144 | 22.0M | WORD32 out1 = ptr_spec_coef[i]; |
1145 | 22.0M | if (out1 <= 0) { |
1146 | 18.0M | out1 = sub_d(temp, out1); |
1147 | 18.0M | if (out1 > 127) { |
1148 | 5.46k | err = ixheaacd_inv_quant(&out1, ptr_pow_table_Q13); |
1149 | 5.46k | if (err) return err; |
1150 | 5.46k | } else |
1151 | 18.0M | out1 = ptr_pow_table_Q13[out1]; |
1152 | 18.0M | ptr_spec_coef[i] = -out1; |
1153 | | |
1154 | 18.0M | } else { |
1155 | 4.02M | if (out1 > 127) { |
1156 | 4.57k | err = ixheaacd_inv_quant(&out1, ptr_pow_table_Q13); |
1157 | 4.57k | if (err) return err; |
1158 | 4.57k | } else |
1159 | 4.01M | out1 = ptr_pow_table_Q13[out1]; |
1160 | | |
1161 | 4.02M | ptr_spec_coef[i] = out1; |
1162 | 4.02M | } |
1163 | 22.0M | } |
1164 | 1.72M | } |
1165 | 212k | } |
1166 | 90.0k | } |
1167 | | |
1168 | 62.9k | return AAC_DEC_OK; |
1169 | 62.9k | } |
1170 | | |
1171 | 70.8k | void ixheaacd_init_ltp_object(ltp_info *ltp) { |
1172 | 70.8k | ltp->data_present = 0; |
1173 | 70.8k | ltp->last_band = 0; |
1174 | | |
1175 | 70.8k | ltp->lag_update = 0; |
1176 | 70.8k | ltp->coef = 0; |
1177 | 70.8k | } |
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 | 58.8k | WORD32 frame_len) { |
1182 | 58.8k | UWORD8 sfb, w; |
1183 | | |
1184 | 58.8k | if (object_type == AOT_ER_AAC_LD) { |
1185 | 46.9k | ltp->lag_update = ixheaacd_read_bits_buf(it_bit_buf, 1); |
1186 | | |
1187 | 46.9k | if (ltp->lag_update) { |
1188 | 17.6k | ltp->lag = (UWORD16)ixheaacd_read_bits_buf(it_bit_buf, 10); |
1189 | 17.6k | } |
1190 | 46.9k | } else { |
1191 | 11.8k | ltp->lag = (UWORD16)ixheaacd_read_bits_buf(it_bit_buf, 11); |
1192 | 11.8k | } |
1193 | | |
1194 | 58.8k | if (ltp->lag > (frame_len << 1)) return -1; |
1195 | | |
1196 | 50.1k | ltp->coef = (UWORD8)ixheaacd_read_bits_buf(it_bit_buf, 3); |
1197 | | |
1198 | 50.1k | 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 | 50.1k | } else { |
1208 | 50.1k | ltp->last_band = (ics->max_sfb < MAX_LTP_SFB ? ics->max_sfb : MAX_LTP_SFB); |
1209 | | |
1210 | 1.14M | for (sfb = 0; sfb < ltp->last_band; sfb++) { |
1211 | 1.09M | ltp->long_used[sfb] = ixheaacd_read_bits_buf(it_bit_buf, 1); |
1212 | 1.09M | } |
1213 | 50.1k | } |
1214 | 50.1k | if (ics->frame_length == 480) { |
1215 | 5.39k | if ((ics->sampling_rate_index > 5) && |
1216 | 547 | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_PLUS_480)) |
1217 | 67 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_PLUS_480; |
1218 | 5.32k | else if ((ics->sampling_rate_index == 5) && |
1219 | 1.69k | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_480)) |
1220 | 79 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_480; |
1221 | 5.24k | else if ((ics->sampling_rate_index < 5) && |
1222 | 3.15k | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_LESS_480)) |
1223 | 64 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_LESS_480; |
1224 | 44.7k | } else if (ics->frame_length == 512) { |
1225 | 29.8k | if ((ics->sampling_rate_index > 5) && |
1226 | 286 | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_PLUS_512)) |
1227 | 35 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_PLUS_512; |
1228 | 29.8k | else if ((ics->sampling_rate_index == 5) && |
1229 | 28.7k | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_512)) |
1230 | 54 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_512; |
1231 | 29.7k | else if ((ics->sampling_rate_index < 5) && |
1232 | 764 | (ltp->last_band > MAX_LTP_SFB_SR_FIVE_LESS_512)) |
1233 | 25 | ltp->last_band = MAX_LTP_SFB_SR_FIVE_LESS_512; |
1234 | 29.8k | } |
1235 | 50.1k | return 0; |
1236 | 58.8k | } |