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