Coverage Report

Created: 2024-06-21 06:40

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