Coverage Report

Created: 2025-07-11 06:33

/src/libxaac/decoder/ixheaacd_create.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 <stdio.h>
21
#include <stdlib.h>
22
#include <string.h>
23
#include <assert.h>
24
25
#include "ixheaac_type_def.h"
26
#include "ixheaac_constants.h"
27
#include "ixheaacd_cnst.h"
28
29
#include "ixheaacd_bitbuffer.h"
30
#include "ixheaacd_config.h"
31
#include "ixheaacd_interface.h"
32
#include "ixheaacd_acelp_info.h"
33
34
#include "ixheaacd_tns_usac.h"
35
#include "ixheaacd_sbrdecsettings.h"
36
#include "ixheaacd_info.h"
37
#include "ixheaacd_struct.h"
38
#include "ixheaacd_sbr_common.h"
39
#include "ixheaacd_drc_data_struct.h"
40
#include "ixheaacd_drc_dec.h"
41
42
#include "ixheaacd_sbr_scale.h"
43
#include "ixheaacd_env_extr_part.h"
44
#include "ixheaacd_sbr_rom.h"
45
#include "ixheaacd_hybrid.h"
46
#include "ixheaacd_ps_dec.h"
47
#include "ixheaacd_common_rom.h"
48
#include "ixheaacd_qmf_dec.h"
49
#include "ixheaac_sbr_const.h"
50
#include "ixheaacd_lpp_tran.h"
51
#include "ixheaacd_sbrdecoder.h"
52
#include "ixheaacd_env_extr.h"
53
#include "ixheaacd_env_calc.h"
54
#include "ixheaacd_pvc_dec.h"
55
#include "ixheaacd_sbr_dec.h"
56
#include "ixheaacd_mps_polyphase.h"
57
58
#include "ixheaacd_memory_standards.h"
59
#include "ixheaacd_defines.h"
60
#include "ixheaacd_aac_rom.h"
61
#include "ixheaacd_bitbuffer.h"
62
#include "ixheaacd_pulsedata.h"
63
#include "ixheaacd_pns.h"
64
65
#include "ixheaacd_ec_defines.h"
66
#include "ixheaacd_ec_struct_def.h"
67
#include "ixheaacd_main.h"
68
#include "ixheaacd_channelinfo.h"
69
#include "ixheaacd_ec.h"
70
#include "ixheaacd_audioobjtypes.h"
71
#include "ixheaacd_latmdemux.h"
72
#include "ixheaacd_aacdec.h"
73
#include "ixheaacd_mps_struct_def.h"
74
#include "ixheaacd_mps_res_rom.h"
75
#include "ixheaacd_mps_aac_struct.h"
76
#include "ixheaacd_mps_dec.h"
77
#include "ixheaacd_struct_def.h"
78
79
#include "ixheaacd_create.h"
80
81
#include "ixheaacd_mps_interface.h"
82
83
#include "ixheaacd_func_def.h"
84
85
extern const ia_huff_code_word_struct ixheaacd_huff_book_scl[];
86
87
extern const WORD32 ixheaacd_book_scl_index[];
88
extern const WORD16 ixheaacd_book_scl_code_book[];
89
90
extern const ia_usac_samp_rate_info ixheaacd_samp_rate_info[];
91
extern const WORD32 ixheaacd_sampling_boundaries[(1 << LEN_SAMP_IDX)];
92
93
const WORD32 ixheaacd_sampl_freq_idx_table[17] = {
94
    96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000,
95
    12000, 11025, 8000,  7350,  -1,    -1,    -1,    -1};
96
97
static VOID ixheaacd_info_init(const ia_usac_samp_rate_info *ptr_samp_info,
98
                               WORD32 block_size_samples,
99
                               ia_sfb_info_struct *pstr_sfb_info_long,
100
                               ia_sfb_info_struct *pstr_sfb_info_short,
101
                               WORD16 *sfb_width_short,
102
7.95k
                               WORD16 *sfb_width_long) {
103
7.95k
  WORD32 i, j, k, n, ws;
104
7.95k
  const WORD16 *sfbands;
105
7.95k
  ia_sfb_info_struct *pstr_sfb_info_ip;
106
107
7.95k
  pstr_sfb_info_long->islong = 1;
108
7.95k
  pstr_sfb_info_long->max_win_len = 1;
109
7.95k
  pstr_sfb_info_long->samp_per_bk = block_size_samples;
110
111
7.95k
  switch (block_size_samples) {
112
0
    case 480:
113
0
      pstr_sfb_info_long->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_480;
114
0
      pstr_sfb_info_long->sfb_per_sbk = ptr_samp_info->num_sfb_480;
115
0
      break;
116
0
    case 512:
117
0
      pstr_sfb_info_long->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_512;
118
0
      pstr_sfb_info_long->sfb_per_sbk = ptr_samp_info->num_sfb_512;
119
0
      break;
120
2.42k
    case 768:
121
2.42k
      pstr_sfb_info_long->sfb_per_sbk = ptr_samp_info->num_sfb_768;
122
2.42k
      pstr_sfb_info_long->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_768;
123
2.42k
      break;
124
0
    case 960:
125
0
      pstr_sfb_info_long->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_960;
126
0
      pstr_sfb_info_long->sfb_per_sbk = ptr_samp_info->num_sfb_960;
127
0
      break;
128
5.53k
    case 1024:
129
5.53k
      pstr_sfb_info_long->sfb_per_sbk = ptr_samp_info->num_sfb_1024;
130
5.53k
      pstr_sfb_info_long->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_1024;
131
5.53k
      break;
132
0
    default:
133
0
      assert(0);
134
0
      break;
135
7.95k
  }
136
137
7.95k
  pstr_sfb_info_long->sfb_width = sfb_width_long;
138
7.95k
  pstr_sfb_info_long->num_groups = 1;
139
7.95k
  pstr_sfb_info_long->group_len[0] = 1;
140
141
345k
  for (i = 0, j = 0, n = pstr_sfb_info_long->sfb_per_sbk; i < n; i++) {
142
337k
    k = pstr_sfb_info_long->ptr_sfb_tbl[i];
143
337k
    pstr_sfb_info_long->sfb_width[i] = k - j;
144
337k
    j = k;
145
337k
  }
146
147
7.95k
  pstr_sfb_info_short->islong = 0;
148
7.95k
  pstr_sfb_info_short->max_win_len = NSHORT;
149
7.95k
  pstr_sfb_info_short->samp_per_bk = block_size_samples;
150
151
71.6k
  for (i = 0; i < pstr_sfb_info_short->max_win_len; i++) {
152
63.6k
    switch (block_size_samples) {
153
19.3k
      case 768:
154
19.3k
        pstr_sfb_info_short->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_96;
155
19.3k
        pstr_sfb_info_short->sfb_per_sbk = ptr_samp_info->num_sfb_96;
156
19.3k
        break;
157
0
      case 960:
158
0
        pstr_sfb_info_short->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_120;
159
0
        pstr_sfb_info_short->sfb_per_sbk = ptr_samp_info->num_sfb_120;
160
0
        break;
161
44.2k
      case 1024:
162
44.2k
        pstr_sfb_info_short->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_128;
163
44.2k
        pstr_sfb_info_short->sfb_per_sbk = ptr_samp_info->num_sfb_128;
164
44.2k
        break;
165
0
      default:
166
0
        assert(0);
167
0
        break;
168
63.6k
    }
169
63.6k
  }
170
171
7.95k
  pstr_sfb_info_short->sfb_width = sfb_width_short;
172
121k
  for (i = 0, j = 0, n = pstr_sfb_info_short->sfb_per_sbk; i < n; i++) {
173
113k
    k = pstr_sfb_info_short->ptr_sfb_tbl[i];
174
113k
    pstr_sfb_info_short->sfb_width[i] = k - j;
175
113k
    j = k;
176
113k
  }
177
178
7.95k
  pstr_sfb_info_ip = pstr_sfb_info_long;
179
23.8k
  for (ws = 0; ws < 2; ws++) {
180
15.9k
    pstr_sfb_info_ip->sfb_per_bk = 0;
181
15.9k
    k = 0;
182
15.9k
    n = 0;
183
87.5k
    for (i = 0; i < pstr_sfb_info_ip->max_win_len; i++) {
184
71.6k
      pstr_sfb_info_ip->bins_per_sbk =
185
71.6k
          pstr_sfb_info_ip->samp_per_bk / pstr_sfb_info_ip->max_win_len;
186
187
71.6k
      pstr_sfb_info_ip->sfb_per_bk += pstr_sfb_info_ip->sfb_per_sbk;
188
189
71.6k
      sfbands = pstr_sfb_info_ip->ptr_sfb_tbl;
190
1.31M
      for (j = 0; j < pstr_sfb_info_ip->sfb_per_sbk; j++)
191
1.24M
        pstr_sfb_info_ip->sfb_idx_tbl[j + k] = sfbands[j] + n;
192
193
71.6k
      n += pstr_sfb_info_ip->bins_per_sbk;
194
71.6k
      k += pstr_sfb_info_ip->sfb_per_sbk;
195
71.6k
    }
196
15.9k
    pstr_sfb_info_ip = pstr_sfb_info_short;
197
15.9k
  }
198
7.95k
}
199
200
WORD32 ixheaacd_decode_init(
201
    VOID *handle, WORD32 sample_rate, ia_usac_data_struct *usac_data,
202
7.95k
    ia_audio_specific_config_struct *pstr_stream_config) {
203
7.95k
  WORD32 i;
204
7.95k
  ia_exhaacplus_dec_api_struct *codec_handle =
205
7.95k
      (ia_exhaacplus_dec_api_struct *)handle;
206
7.95k
  ia_aac_dec_state_struct *aac_dec_handle = codec_handle->p_state_aac;
207
7.95k
  WORD32 fscale;
208
209
7.95k
  WORD32 ele_id = 0;
210
211
7.95k
  ia_usac_config_struct *ptr_usac_config =
212
7.95k
      &(pstr_stream_config->str_usac_config);
213
7.95k
  ia_usac_decoder_config_struct *ptr_usac_dec_config =
214
7.95k
      &(pstr_stream_config->str_usac_config.str_usac_dec_config);
215
7.95k
  WORD32 num_elements = ptr_usac_dec_config->num_elements;
216
7.95k
  WORD32 chan = 0;
217
218
7.95k
  usac_data->ec_flag = codec_handle->aac_config.ui_err_conceal;
219
7.95k
  usac_data->huffman_code_book_scl = aac_dec_handle->huffman_code_book_scl;
220
7.95k
  usac_data->huffman_code_book_scl_index =
221
7.95k
      aac_dec_handle->huffman_code_book_scl_index;
222
223
7.95k
  usac_data->tns_coeff3_32 =
224
7.95k
      aac_dec_handle->pstr_aac_tables->pstr_block_tables->tns_coeff3_32;
225
7.95k
  usac_data->tns_coeff4_32 =
226
7.95k
      aac_dec_handle->pstr_aac_tables->pstr_block_tables->tns_coeff4_32;
227
7.95k
  usac_data->tns_max_bands_tbl_usac =
228
7.95k
      &aac_dec_handle->pstr_aac_tables->pstr_block_tables
229
7.95k
           ->tns_max_bands_tbl_usac;
230
55.7k
  for (WORD32 ch = 0; ch < MAX_NUM_CHANNELS; ch++) {
231
47.7k
    ixheaacd_usac_ec_init(&usac_data->str_error_concealment[ch], usac_data->core_mode);
232
47.7k
    memset(&usac_data->overlap_data_ptr[ch][0], 0, sizeof(usac_data->overlap_data_ptr[ch]));
233
47.7k
  }
234
235
72.1k
  for (i = 0; i < 11; i++) {
236
68.9k
    if (ixheaacd_sampling_boundaries[i] <= sample_rate) break;
237
68.9k
  }
238
239
7.95k
  if (i == (1 << LEN_SAMP_IDX)) return -1;
240
7.95k
  usac_data->sampling_rate_idx = i;
241
242
7.95k
  fscale = (WORD32)((double)sample_rate * (double)FSCALE_DENOM / 12800.0f);
243
244
55.7k
  for (i = 0; i < MAX_NUM_CHANNELS; i++) {
245
47.7k
    usac_data->window_shape_prev[i] = 0;
246
47.7k
    usac_data->window_shape[i] = 0;
247
47.7k
  }
248
249
7.95k
  ixheaacd_hufftab(&ixheaacd_book, ixheaacd_huff_book_scl,
250
7.95k
                   ixheaacd_book_scl_code_book, ixheaacd_book_scl_index, 1, 60,
251
7.95k
                   60, 1, 19);
252
253
7.95k
  usac_data->pstr_usac_winmap[0] = &usac_data->str_only_long_info;
254
7.95k
  usac_data->pstr_usac_winmap[1] = &usac_data->str_only_long_info;
255
7.95k
  usac_data->pstr_usac_winmap[2] = &usac_data->str_eight_short_info;
256
7.95k
  usac_data->pstr_usac_winmap[3] = &usac_data->str_only_long_info;
257
7.95k
  usac_data->pstr_usac_winmap[4] = &usac_data->str_only_long_info;
258
259
7.95k
  if ((usac_data->ccfl != 480) && (usac_data->ccfl != 512) &&
260
7.95k
      (usac_data->ccfl != 768) && (usac_data->ccfl != 960) &&
261
7.95k
      (usac_data->ccfl != 1024))
262
0
    return -1;
263
7.95k
  ixheaacd_info_init(&ixheaacd_samp_rate_info[usac_data->sampling_rate_idx],
264
7.95k
                     usac_data->ccfl, usac_data->pstr_usac_winmap[0],
265
7.95k
                     usac_data->pstr_usac_winmap[2], usac_data->sfb_width_short,
266
7.95k
                     usac_data->sfb_width_long);
267
268
55.7k
  for (i = 0; i < MAX_NUM_CHANNELS; i++) {
269
47.7k
    usac_data->str_tddec[i] = &usac_data->arr_str_tddec[i];
270
47.7k
    if (usac_data->ccfl == 768)
271
14.5k
      usac_data->str_tddec[i]->fscale = pstr_stream_config->sampling_frequency;
272
33.2k
    else
273
33.2k
      usac_data->str_tddec[i]->fscale =
274
33.2k
          ((fscale)*usac_data->ccfl) / LEN_SUPERFRAME;
275
47.7k
    usac_data->len_subfrm = usac_data->ccfl / 4;
276
277
47.7k
    {
278
47.7k
      WORD32 fac_length = usac_data->len_subfrm / 4;
279
47.7k
      if (fac_length & (fac_length - 1)) {
280
14.5k
        if ((fac_length != 48) && (fac_length != 96) && (fac_length != 192) &&
281
14.5k
            (fac_length != 384) && (fac_length != 768)) {
282
0
          return -1;
283
0
        }
284
14.5k
      }
285
47.7k
    }
286
47.7k
    usac_data->num_subfrm = (MAX_NUM_SUBFR * usac_data->ccfl) / LEN_SUPERFRAME;
287
288
47.7k
    ixheaacd_init_acelp_data(usac_data, usac_data->str_tddec[i]);
289
290
47.7k
    usac_data->str_tddec[i]->fd_synth =
291
47.7k
        &usac_data->str_tddec[i]->fd_synth_buf[LEN_FRAME];
292
47.7k
  }
293
294
26.0k
  for (ele_id = 0; ele_id < num_elements; ele_id++) {
295
18.0k
    UWORD32 ele_type;
296
18.0k
    WORD32 stereo_config_index;
297
298
18.0k
    ia_usac_dec_element_config_struct *ptr_usac_ele_config =
299
18.0k
        &ptr_usac_config->str_usac_dec_config.str_usac_element_config[ele_id];
300
301
18.0k
    if (ptr_usac_ele_config) {
302
18.0k
      if (usac_data->tw_mdct[ele_id]) {
303
13
        if (usac_data->ec_flag) {
304
0
          usac_data->tw_mdct[ele_id] = 0;
305
0
        } else
306
13
          return -1;
307
13
      }
308
309
18.0k
      usac_data->noise_filling_config[ele_id] = ptr_usac_ele_config->noise_filling;
310
18.0k
    }
311
312
18.0k
    ele_type = ptr_usac_config->str_usac_dec_config.usac_element_type[ele_id];
313
314
18.0k
    stereo_config_index = ptr_usac_ele_config->stereo_config_index;
315
316
18.0k
    switch (ele_type) {
317
3.78k
      case ID_USAC_SCE:
318
4.16k
      case ID_USAC_LFE:
319
320
4.16k
        if ((chan + 1) > MAX_NUM_CHANNELS_USAC_LVL2) return -1;
321
4.16k
        usac_data->seed_value[chan] = 0x3039;
322
4.16k
        chan++;
323
324
4.16k
        break;
325
326
3.88k
      case ID_USAC_CPE: {
327
3.88k
        static const WORD32 frame_len_tbl[MAX_CORE_SBR_FRAME_LEN_IDX + 1] = {
328
3.88k
            -1, -1, 32, 32, 64};
329
330
3.88k
        if ((chan + 2) > MAX_NUM_CHANNELS_USAC_LVL2) return -1;
331
3.88k
        usac_data->seed_value[chan] = 0x3039;
332
3.88k
        chan++;
333
334
3.88k
        usac_data->seed_value[chan] = 0x10932;
335
3.88k
        chan++;
336
337
3.88k
        if (stereo_config_index > 0) {
338
2.00k
          WORD32 bs_frame_length =
339
2.00k
              frame_len_tbl[ptr_usac_config->core_sbr_framelength_index];
340
2.00k
          WORD32 bs_residual_coding = (stereo_config_index > 1) ? 1 : 0;
341
342
2.00k
          ia_usac_dec_mps_config_struct *ptr_usac_mps212_config =
343
2.00k
              &(ptr_usac_config->str_usac_dec_config
344
2.00k
                    .str_usac_element_config[ele_id]
345
2.00k
                    .str_usac_mps212_config);
346
2.00k
          aac_dec_handle->mps_dec_handle.ec_flag = aac_dec_handle->ec_enable;
347
348
2.00k
          if (ixheaacd_mps_create(&aac_dec_handle->mps_dec_handle,
349
2.00k
                                  bs_frame_length, bs_residual_coding,
350
2.00k
                                  ptr_usac_mps212_config)) {
351
1
            return -1;
352
1
          }
353
2.00k
        }
354
3.88k
        break;
355
3.88k
      }
356
357
3.88k
      break;
358
10.0k
      case ID_USAC_EXT:
359
10.0k
        break;
360
0
      default:
361
0
        return -1;
362
0
        break;
363
18.0k
    }
364
18.0k
  }
365
366
7.94k
  return 0;
367
7.95k
}
368
369
WORD32 ixheaacd_dec_data_init(VOID *handle,
370
                              ia_frame_data_struct *pstr_frame_data,
371
7.96k
                              ia_usac_data_struct *usac_data) {
372
7.96k
  ia_audio_specific_config_struct *pstr_stream_config, *layer_config;
373
7.96k
  WORD32 err_code = 0;
374
7.96k
  WORD32 i_ch, i, ele_id;
375
7.96k
  WORD32 num_elements;
376
377
7.96k
  WORD32 out_frame_len, sbr_ratio_idx;
378
379
7.96k
  ia_usac_config_struct *ptr_usac_config =
380
7.96k
      &(pstr_frame_data->str_audio_specific_config.str_usac_config);
381
382
7.96k
  usac_data->last_frame_ok = 1;
383
7.96k
  usac_data->frame_ok = 1;
384
7.96k
  usac_data->window_shape_prev[0] = WIN_SEL_0;
385
7.96k
  usac_data->window_shape_prev[1] = WIN_SEL_0;
386
387
7.96k
  pstr_frame_data->str_layer.bit_rate =
388
7.96k
      pstr_frame_data->str_audio_specific_config.avg_bit_rate;
389
7.96k
  pstr_stream_config = &pstr_frame_data->str_audio_specific_config;
390
7.96k
  layer_config = &pstr_frame_data->str_audio_specific_config;
391
392
7.96k
  sbr_ratio_idx = ixheaacd_sbr_params(
393
7.96k
      ptr_usac_config->core_sbr_framelength_index, &out_frame_len,
394
7.96k
      &usac_data->ccfl, &usac_data->output_samples,
395
7.96k
      &pstr_frame_data->str_layer.sample_rate_layer,
396
7.96k
      &layer_config->samp_frequency_index);
397
7.96k
  if (!pstr_frame_data->str_layer.sample_rate_layer) {
398
2
    return -1;
399
2
  }
400
7.95k
  pstr_stream_config->sampling_frequency =
401
7.95k
      pstr_frame_data->str_layer.sample_rate_layer;
402
7.95k
  pstr_stream_config->samp_frequency_index = layer_config->samp_frequency_index;
403
404
7.95k
  num_elements = ptr_usac_config->str_usac_dec_config.num_elements;
405
406
26.0k
  for (ele_id = 0; ele_id < num_elements; ele_id++) {
407
18.1k
    ia_usac_dec_element_config_struct *ptr_usac_ele_config =
408
18.1k
        &(ptr_usac_config->str_usac_dec_config.str_usac_element_config[ele_id]);
409
410
18.1k
    if (ptr_usac_ele_config) {
411
18.1k
      usac_data->tw_mdct[ele_id] = ptr_usac_ele_config->tw_mdct;
412
18.1k
    }
413
414
18.1k
    {
415
18.1k
      ia_usac_dec_mps_config_struct *ptr_usac_mps212_config =
416
18.1k
          &ptr_usac_ele_config->str_usac_mps212_config;
417
18.1k
      WORD32 stereo_config_index = ptr_usac_ele_config->stereo_config_index;
418
419
18.1k
      usac_data->mps_pseudo_lr[ele_id] =
420
18.1k
          (stereo_config_index > 1) ? ptr_usac_mps212_config->bs_pseudo_lr : 0;
421
18.1k
    }
422
18.1k
  }
423
424
7.95k
  usac_data->sbr_ratio_idx = sbr_ratio_idx;
425
7.95k
  usac_data->esbr_bit_str[0].no_elements = 0;
426
7.95k
  usac_data->esbr_bit_str[1].no_elements = 0;
427
428
7.95k
  if (usac_data->ccfl == 768)
429
2.42k
    pstr_frame_data->str_layer.sample_rate_layer =
430
2.42k
        4 * pstr_frame_data->str_layer.sample_rate_layer / 3;
431
432
55.7k
  for (i = 0; i < MAX_NUM_CHANNELS; i++) {
433
47.7k
    usac_data->coef_fix[i] = &usac_data->arr_coef_fix[i][0];
434
47.7k
    usac_data->coef[i] = &usac_data->arr_coef[i][0];
435
47.7k
    usac_data->coef_save[i] = &usac_data->arr_coef_save[i][0];
436
47.7k
    usac_data->factors[i] = &usac_data->arr_factors[i][0];
437
47.7k
    usac_data->group_dis[i] = &usac_data->arr_group_dis[i][0];
438
47.7k
    usac_data->pstr_tns[i] = &usac_data->arr_str_tns[i];
439
47.7k
    usac_data->tw_ratio[i] = &usac_data->arr_tw_ratio[i][0];
440
47.7k
    usac_data->ms_used[i] = &usac_data->arr_ms_used[i][0];
441
47.7k
    usac_data->window_shape_prev[i] = WIN_SEL_0;
442
443
47.7k
    usac_data->seed_value[i] = 0x0;
444
445
47.7k
    usac_data->fac_data_present[i] = 0;
446
47.7k
  }
447
448
7.95k
  err_code =
449
7.95k
      ixheaacd_decode_init(handle, pstr_frame_data->str_layer.sample_rate_layer,
450
7.95k
                           usac_data, pstr_stream_config);
451
7.95k
  if (err_code != 0) return err_code;
452
453
55.6k
  for (i_ch = 0; i_ch < MAX_NUM_CHANNELS; i_ch++) {
454
47.6k
    if (usac_data->tw_mdct[0] == 1) {
455
0
      WORD32 i;
456
0
      for (i = 0; i < 2 * usac_data->ccfl; i++) {
457
0
        usac_data->warp_cont_mem[i_ch][i] = 1.0;
458
0
      }
459
0
      usac_data->warp_sum[i_ch][0] = usac_data->warp_sum[i_ch][1] =
460
0
          (FLOAT32)usac_data->ccfl;
461
0
    }
462
47.6k
  }
463
7.94k
  return err_code;
464
7.95k
}
465
466
static VOID ixheaacd_count_tracks_per_layer(int *max_layer, int *stream_count,
467
7.99k
                                            int *tracks_in_layer) {
468
7.99k
  WORD32 stream;
469
7.99k
  WORD32 num_layer;
470
7.99k
  WORD32 num_streams;
471
7.99k
  WORD32 layer = 0;
472
473
7.99k
  if (stream_count == NULL)
474
0
    num_streams = 0;
475
7.99k
  else
476
7.99k
    num_streams = *stream_count;
477
7.99k
  if (max_layer == NULL)
478
0
    num_layer = num_streams;
479
7.99k
  else
480
7.99k
    num_layer = *max_layer;
481
7.99k
  if (num_layer < 0) num_layer = num_streams;
482
483
15.9k
  for (stream = 0; (layer <= num_layer) && (stream < num_streams);) {
484
7.99k
    *tracks_in_layer = 1;
485
7.99k
    stream += 1;
486
7.99k
    layer++;
487
7.99k
    if (layer <= num_layer) *tracks_in_layer = 0;
488
7.99k
  }
489
490
7.99k
  if (max_layer) *max_layer = (layer - 1);
491
7.99k
  if (stream_count) *stream_count = stream;
492
7.99k
}
493
494
WORD32 ixheaacd_frm_data_init(ia_audio_specific_config_struct *pstr_audio_conf,
495
                              ia_dec_data_struct *pstr_dec_data)
496
497
7.99k
{
498
7.99k
  WORD32 layer;
499
7.99k
  WORD32 track;
500
7.99k
  WORD32 num_dec_streams;
501
7.99k
  ia_frame_data_struct *pstr_frame_data;
502
503
7.99k
  WORD32 stream_count = 1;
504
7.99k
  WORD32 max_layer = -1;
505
506
7.99k
  memset(pstr_dec_data, 0, IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8));
507
7.99k
  memset(&(pstr_dec_data->str_frame_data), 0,
508
7.99k
         sizeof(pstr_dec_data->str_frame_data));
509
510
7.99k
  pstr_frame_data = &(pstr_dec_data->str_frame_data);
511
512
7.99k
  if (max_layer < 0) max_layer = stream_count - 1;
513
514
7.99k
  ixheaacd_count_tracks_per_layer(&max_layer, &stream_count,
515
7.99k
                                  &pstr_frame_data->tracks_in_layer);
516
517
7.99k
  pstr_frame_data->scal_out_select = max_layer;
518
519
7.99k
  pstr_frame_data->stream_count = 0;
520
521
7.99k
  num_dec_streams = track = 0;
522
15.9k
  for (layer = 0; layer < (signed)pstr_frame_data->scal_out_select + 1;
523
7.99k
       layer++) {
524
7.99k
    WORD32 j;
525
15.9k
    for (j = 0; j < 1; j++, num_dec_streams++) {
526
7.99k
      pstr_frame_data->str_audio_specific_config = *pstr_audio_conf;
527
7.99k
      pstr_frame_data->str_layer.sample_rate_layer =
528
7.99k
          pstr_frame_data->str_audio_specific_config.sampling_frequency;
529
7.99k
      pstr_frame_data->str_layer.bit_rate =
530
7.99k
          pstr_frame_data->str_audio_specific_config.avg_bit_rate;
531
7.99k
    }
532
533
7.99k
    track += pstr_frame_data->tracks_in_layer;
534
7.99k
  }
535
536
7.99k
  pstr_frame_data->stream_count = num_dec_streams;
537
538
7.99k
  return num_dec_streams;
539
7.99k
}
540
541
WORD32 ixheaacd_decode_create(ia_exhaacplus_dec_api_struct *handle,
542
                              ia_dec_data_struct *pstr_dec_data,
543
7.96k
                              WORD32 tracks_for_decoder) {
544
7.96k
  WORD32 stream;
545
546
7.96k
  WORD32 err = 0;
547
7.96k
  ia_frame_data_struct *pstr_frame_data;
548
7.96k
  WORD32 stream_count;
549
7.96k
  ia_aac_dec_state_struct *aac_dec_handle = handle->p_state_aac;
550
7.96k
  pstr_frame_data = &(pstr_dec_data->str_frame_data);
551
7.96k
  stream_count = pstr_frame_data->stream_count;
552
7.96k
  pstr_frame_data->stream_count = tracks_for_decoder;
553
554
15.9k
  for (stream = 0; stream < stream_count; stream++) {
555
7.96k
    UWORD32 aot = pstr_frame_data->str_audio_specific_config.audio_object_type;
556
557
7.96k
    switch (aot) {
558
7.96k
      case AOT_USAC:
559
560
7.96k
        err = ixheaacd_dec_data_init(handle, pstr_frame_data,
561
7.96k
                                     &(pstr_dec_data->str_usac_data));
562
563
7.96k
        if (err != 0) {
564
16
          if (handle->aac_config.ui_err_conceal) {
565
0
            pstr_dec_data->str_usac_data.frame_ok = 0;
566
0
          } else
567
16
            return err;
568
16
        }
569
570
7.94k
        pstr_dec_data->str_usac_data.sampling_rate = pstr_frame_data->str_layer.sample_rate_layer;
571
572
7.94k
        switch (pstr_dec_data->str_usac_data.sbr_ratio_idx) {
573
3.22k
          case 0:
574
3.22k
            handle->aac_config.ui_sbr_mode = 0;
575
3.22k
            break;
576
3.24k
          case 1:
577
3.24k
            handle->aac_config.ui_sbr_mode = 1;
578
3.24k
            break;
579
981
          case 2:
580
981
            handle->aac_config.ui_sbr_mode = 1;
581
981
            break;
582
491
          case 3:
583
491
            handle->aac_config.ui_sbr_mode = 3;
584
491
            break;
585
586
0
          default:
587
0
            handle->aac_config.ui_sbr_mode = 0;
588
7.94k
        }
589
590
7.94k
        if (!aac_dec_handle->peak_lim_init && !handle->aac_config.peak_limiter_off &&
591
7.94k
            handle->aac_config.ui_err_conceal) {
592
0
          memset(&aac_dec_handle->peak_limiter, 0, sizeof(ia_peak_limiter_struct));
593
0
          ixheaacd_peak_limiter_init(&aac_dec_handle->peak_limiter, MAX_NUM_CHANNELS,
594
0
                                     pstr_dec_data->str_usac_data.sampling_rate,
595
0
                                     &aac_dec_handle->peak_limiter.buffer[0],
596
0
                                     &aac_dec_handle->delay_in_samples);
597
0
          aac_dec_handle->peak_lim_init++;
598
0
        }
599
600
7.94k
        break;
601
602
0
      default:
603
604
0
        break;
605
7.96k
    }
606
7.96k
  }
607
608
7.94k
  pstr_frame_data->scal_out_object_type =
609
7.94k
      pstr_frame_data->str_audio_specific_config.audio_object_type;
610
7.94k
  pstr_frame_data->scal_out_num_channels =
611
7.94k
      pstr_frame_data->str_audio_specific_config.channel_configuration;
612
7.94k
  pstr_frame_data->scal_out_sampling_frequency =
613
7.94k
      pstr_frame_data->str_audio_specific_config.sampling_frequency;
614
615
7.94k
  if (&(pstr_dec_data->str_usac_data) != NULL) {
616
7.94k
    ia_sbr_header_data_struct usac_def_header;
617
7.94k
    ia_audio_specific_config_struct *pstr_aud_spec_config =
618
7.94k
        &pstr_frame_data->str_audio_specific_config;
619
7.94k
    ia_usac_config_struct *ptr_usac_config =
620
7.94k
        &(pstr_frame_data->str_audio_specific_config.str_usac_config);
621
622
7.94k
    WORD32 inter_test_flag = 0;
623
7.94k
    WORD32 bs_pvc_flag = 0;
624
7.94k
    WORD32 harmonic_Sbr_flag = 0;
625
626
7.94k
    ia_usac_decoder_config_struct *ptr_usac_dec_config =
627
7.94k
        &ptr_usac_config->str_usac_dec_config;
628
7.94k
    WORD32 const num_ele = ptr_usac_dec_config->num_elements;
629
7.94k
    WORD32 elem_idx = 0;
630
631
7.94k
    memset(&usac_def_header, 0, sizeof(ia_sbr_header_data_struct));
632
633
26.0k
    for (elem_idx = 0; elem_idx < num_ele; elem_idx++) {
634
18.0k
      UWORD32 usac_ele_type =
635
18.0k
          ptr_usac_config->str_usac_dec_config.usac_element_type[elem_idx];
636
18.0k
      ia_usac_dec_element_config_struct *ptr_usac_ele_config =
637
18.0k
          &ptr_usac_config->str_usac_dec_config
638
18.0k
               .str_usac_element_config[elem_idx];
639
640
18.0k
      ia_usac_dec_sbr_config_struct *ptr_usac_sbr_config =
641
18.0k
          &(ptr_usac_dec_config->str_usac_element_config[elem_idx]
642
18.0k
                .str_usac_sbr_config);
643
644
18.0k
      if (ptr_usac_sbr_config->bs_inter_tes) inter_test_flag = 1;
645
18.0k
      if (ptr_usac_sbr_config->bs_pvc) bs_pvc_flag = 1;
646
18.0k
      if (ptr_usac_sbr_config->harmonic_sbr) harmonic_Sbr_flag = 1;
647
648
18.0k
      if ((usac_ele_type != ID_USAC_LFE) && (usac_ele_type != ID_USAC_EXT)) {
649
7.66k
        ia_usac_dec_sbr_config_struct *ptr_usac_sbr_config =
650
7.66k
            &(ptr_usac_ele_config->str_usac_sbr_config);
651
652
7.66k
        usac_def_header.start_freq = ptr_usac_sbr_config->dflt_start_freq;
653
7.66k
        usac_def_header.stop_freq = ptr_usac_sbr_config->dflt_stop_freq;
654
7.66k
        usac_def_header.header_extra_1 =
655
7.66k
            ptr_usac_sbr_config->dflt_header_extra1;
656
7.66k
        usac_def_header.header_extra_2 =
657
7.66k
            ptr_usac_sbr_config->dflt_header_extra2;
658
7.66k
        usac_def_header.freq_scale = ptr_usac_sbr_config->dflt_freq_scale;
659
7.66k
        usac_def_header.alter_scale = ptr_usac_sbr_config->dflt_alter_scale;
660
7.66k
        usac_def_header.noise_bands = ptr_usac_sbr_config->dflt_noise_bands;
661
7.66k
        usac_def_header.limiter_bands = ptr_usac_sbr_config->dflt_limiter_bands;
662
7.66k
        usac_def_header.limiter_gains = ptr_usac_sbr_config->dflt_limiter_gains;
663
7.66k
        usac_def_header.interpol_freq = ptr_usac_sbr_config->dflt_interpol_freq;
664
7.66k
        usac_def_header.smoothing_mode =
665
7.66k
            ptr_usac_sbr_config->dflt_smoothing_mode;
666
7.66k
      }
667
18.0k
    }
668
669
7.94k
    pstr_dec_data->str_usac_data.down_samp_sbr = 0;
670
671
7.94k
    if (pstr_dec_data->str_usac_data.sbr_ratio_idx > 0) {
672
4.72k
      if (pstr_aud_spec_config->ext_sampling_frequency ==
673
4.72k
          pstr_aud_spec_config->sampling_frequency) {
674
0
        pstr_dec_data->str_usac_data.down_samp_sbr = 1;
675
0
      }
676
4.72k
      if (pstr_dec_data->str_usac_data.down_samp_sbr == 0) {
677
4.72k
        if (pstr_dec_data->str_usac_data.sbr_ratio_idx == 3) {
678
491
          pstr_frame_data->scal_out_sampling_frequency =
679
491
              4 * pstr_frame_data->scal_out_sampling_frequency;
680
4.23k
        } else {
681
4.23k
          pstr_frame_data->scal_out_sampling_frequency =
682
4.23k
              2 * pstr_frame_data->scal_out_sampling_frequency;
683
4.23k
        }
684
4.72k
      }
685
686
4.72k
      {
687
4.72k
        void *sbr_persistent_mem_v = aac_dec_handle->sbr_persistent_mem_u;
688
689
4.72k
        pstr_dec_data->str_usac_data.pstr_esbr_dec = ixheaacd_init_sbr(
690
4.72k
            pstr_frame_data->str_layer.sample_rate_layer,
691
4.72k
            pstr_dec_data->str_usac_data.ccfl,
692
4.72k
            &pstr_dec_data->str_usac_data.down_samp_sbr, sbr_persistent_mem_v,
693
4.72k
            NULL, pstr_frame_data->scal_out_num_channels, 0,
694
4.72k
            pstr_dec_data->str_usac_data.sbr_ratio_idx,
695
4.72k
            pstr_dec_data->str_usac_data.output_samples, &harmonic_Sbr_flag,
696
4.72k
            (void *)&usac_def_header, aac_dec_handle->str_sbr_config,
697
4.72k
            pstr_dec_data->str_usac_data.audio_object_type, 0, 0);
698
4.72k
        pstr_dec_data->str_usac_data.sbr_scratch_mem_base =
699
4.72k
            aac_dec_handle->sbr_scratch_mem_u;
700
4.72k
        if (num_ele)
701
4.72k
          ixheaacd_setesbr_flags(sbr_persistent_mem_v, bs_pvc_flag,
702
4.72k
                                 harmonic_Sbr_flag, inter_test_flag);
703
4.72k
      }
704
705
4.72k
      if (pstr_dec_data->str_usac_data.pstr_esbr_dec == NULL) {
706
0
        return -1;
707
4.72k
      } else {
708
4.72k
        pstr_dec_data->str_usac_data.pstr_esbr_dec->xaac_jmp_buf =
709
4.72k
            &(aac_dec_handle->xaac_jmp_buf);
710
4.72k
      }
711
4.72k
    }
712
7.94k
  }
713
7.94k
  aac_dec_handle->decode_create_done = 1;
714
7.94k
  return 0;
715
7.94k
}