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