Coverage Report

Created: 2026-03-31 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_create.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#include <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
6.31k
                               WORD16 *sfb_width_long) {
103
6.31k
  WORD32 i, j, k, n, ws;
104
6.31k
  const WORD16 *sfbands;
105
6.31k
  ia_sfb_info_struct *pstr_sfb_info_ip;
106
107
6.31k
  pstr_sfb_info_long->islong = 1;
108
6.31k
  pstr_sfb_info_long->max_win_len = 1;
109
6.31k
  pstr_sfb_info_long->samp_per_bk = block_size_samples;
110
111
6.31k
  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.06k
    case 768:
121
2.06k
      pstr_sfb_info_long->sfb_per_sbk = ptr_samp_info->num_sfb_768;
122
2.06k
      pstr_sfb_info_long->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_768;
123
2.06k
      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
4.24k
    case 1024:
129
4.24k
      pstr_sfb_info_long->sfb_per_sbk = ptr_samp_info->num_sfb_1024;
130
4.24k
      pstr_sfb_info_long->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_1024;
131
4.24k
      break;
132
0
    default:
133
0
      assert(0);
134
0
      break;
135
6.31k
  }
136
137
6.31k
  pstr_sfb_info_long->sfb_width = sfb_width_long;
138
6.31k
  pstr_sfb_info_long->num_groups = 1;
139
6.31k
  pstr_sfb_info_long->group_len[0] = 1;
140
141
273k
  for (i = 0, j = 0, n = pstr_sfb_info_long->sfb_per_sbk; i < n; i++) {
142
267k
    k = pstr_sfb_info_long->ptr_sfb_tbl[i];
143
267k
    pstr_sfb_info_long->sfb_width[i] = k - j;
144
267k
    j = k;
145
267k
  }
146
147
6.31k
  pstr_sfb_info_short->islong = 0;
148
6.31k
  pstr_sfb_info_short->max_win_len = NSHORT;
149
6.31k
  pstr_sfb_info_short->samp_per_bk = block_size_samples;
150
151
56.7k
  for (i = 0; i < pstr_sfb_info_short->max_win_len; i++) {
152
50.4k
    switch (block_size_samples) {
153
16.5k
      case 768:
154
16.5k
        pstr_sfb_info_short->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_96;
155
16.5k
        pstr_sfb_info_short->sfb_per_sbk = ptr_samp_info->num_sfb_96;
156
16.5k
        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
33.9k
      case 1024:
162
33.9k
        pstr_sfb_info_short->ptr_sfb_tbl = ptr_samp_info->ptr_sfb_128;
163
33.9k
        pstr_sfb_info_short->sfb_per_sbk = ptr_samp_info->num_sfb_128;
164
33.9k
        break;
165
0
      default:
166
0
        assert(0);
167
0
        break;
168
50.4k
    }
169
50.4k
  }
170
171
6.31k
  pstr_sfb_info_short->sfb_width = sfb_width_short;
172
96.1k
  for (i = 0, j = 0, n = pstr_sfb_info_short->sfb_per_sbk; i < n; i++) {
173
89.8k
    k = pstr_sfb_info_short->ptr_sfb_tbl[i];
174
89.8k
    pstr_sfb_info_short->sfb_width[i] = k - j;
175
89.8k
    j = k;
176
89.8k
  }
177
178
6.31k
  pstr_sfb_info_ip = pstr_sfb_info_long;
179
18.9k
  for (ws = 0; ws < 2; ws++) {
180
12.6k
    pstr_sfb_info_ip->sfb_per_bk = 0;
181
12.6k
    k = 0;
182
12.6k
    n = 0;
183
69.4k
    for (i = 0; i < pstr_sfb_info_ip->max_win_len; i++) {
184
56.7k
      pstr_sfb_info_ip->bins_per_sbk =
185
56.7k
          pstr_sfb_info_ip->samp_per_bk / pstr_sfb_info_ip->max_win_len;
186
187
56.7k
      pstr_sfb_info_ip->sfb_per_bk += pstr_sfb_info_ip->sfb_per_sbk;
188
189
56.7k
      sfbands = pstr_sfb_info_ip->ptr_sfb_tbl;
190
1.04M
      for (j = 0; j < pstr_sfb_info_ip->sfb_per_sbk; j++)
191
985k
        pstr_sfb_info_ip->sfb_idx_tbl[j + k] = sfbands[j] + n;
192
193
56.7k
      n += pstr_sfb_info_ip->bins_per_sbk;
194
56.7k
      k += pstr_sfb_info_ip->sfb_per_sbk;
195
56.7k
    }
196
12.6k
    pstr_sfb_info_ip = pstr_sfb_info_short;
197
12.6k
  }
198
6.31k
}
199
200
WORD32 ixheaacd_decode_init(
201
    VOID *handle, WORD32 sample_rate, ia_usac_data_struct *usac_data,
202
6.31k
    ia_audio_specific_config_struct *pstr_stream_config) {
203
6.31k
  WORD32 i;
204
6.31k
  ia_exhaacplus_dec_api_struct *codec_handle =
205
6.31k
      (ia_exhaacplus_dec_api_struct *)handle;
206
6.31k
  ia_aac_dec_state_struct *aac_dec_handle = codec_handle->p_state_aac;
207
6.31k
  WORD32 fscale;
208
209
6.31k
  WORD32 ele_id = 0;
210
211
6.31k
  ia_usac_config_struct *ptr_usac_config =
212
6.31k
      &(pstr_stream_config->str_usac_config);
213
6.31k
  ia_usac_decoder_config_struct *ptr_usac_dec_config =
214
6.31k
      &(pstr_stream_config->str_usac_config.str_usac_dec_config);
215
6.31k
  WORD32 num_elements = ptr_usac_dec_config->num_elements;
216
6.31k
  WORD32 chan = 0;
217
218
6.31k
  usac_data->ec_flag = codec_handle->aac_config.ui_err_conceal;
219
6.31k
  usac_data->huffman_code_book_scl = aac_dec_handle->huffman_code_book_scl;
220
6.31k
  usac_data->huffman_code_book_scl_index =
221
6.31k
      aac_dec_handle->huffman_code_book_scl_index;
222
223
6.31k
  usac_data->tns_coeff3_32 =
224
6.31k
      aac_dec_handle->pstr_aac_tables->pstr_block_tables->tns_coeff3_32;
225
6.31k
  usac_data->tns_coeff4_32 =
226
6.31k
      aac_dec_handle->pstr_aac_tables->pstr_block_tables->tns_coeff4_32;
227
6.31k
  usac_data->tns_max_bands_tbl_usac =
228
6.31k
      &aac_dec_handle->pstr_aac_tables->pstr_block_tables
229
6.31k
           ->tns_max_bands_tbl_usac;
230
44.1k
  for (WORD32 ch = 0; ch < MAX_NUM_CHANNELS; ch++) {
231
37.8k
    ixheaacd_usac_ec_init(&usac_data->str_error_concealment[ch], usac_data->core_mode);
232
37.8k
    memset(&usac_data->overlap_data_ptr[ch][0], 0, sizeof(usac_data->overlap_data_ptr[ch]));
233
37.8k
  }
234
235
57.4k
  for (i = 0; i < 11; i++) {
236
54.8k
    if (ixheaacd_sampling_boundaries[i] <= sample_rate) break;
237
54.8k
  }
238
239
6.31k
  if (i == (1 << LEN_SAMP_IDX)) return -1;
240
6.31k
  usac_data->sampling_rate_idx = i;
241
242
6.31k
  fscale = (WORD32)((double)sample_rate * (double)FSCALE_DENOM / 12800.0f);
243
244
44.1k
  for (i = 0; i < MAX_NUM_CHANNELS; i++) {
245
37.8k
    usac_data->window_shape_prev[i] = 0;
246
37.8k
    usac_data->window_shape[i] = 0;
247
37.8k
  }
248
249
6.31k
  ixheaacd_hufftab(&ixheaacd_book, ixheaacd_huff_book_scl,
250
6.31k
                   ixheaacd_book_scl_code_book, ixheaacd_book_scl_index, 1, 60,
251
6.31k
                   60, 1, 19);
252
253
6.31k
  usac_data->pstr_usac_winmap[0] = &usac_data->str_only_long_info;
254
6.31k
  usac_data->pstr_usac_winmap[1] = &usac_data->str_only_long_info;
255
6.31k
  usac_data->pstr_usac_winmap[2] = &usac_data->str_eight_short_info;
256
6.31k
  usac_data->pstr_usac_winmap[3] = &usac_data->str_only_long_info;
257
6.31k
  usac_data->pstr_usac_winmap[4] = &usac_data->str_only_long_info;
258
259
6.31k
  if ((usac_data->ccfl != 480) && (usac_data->ccfl != 512) &&
260
6.31k
      (usac_data->ccfl != 768) && (usac_data->ccfl != 960) &&
261
4.24k
      (usac_data->ccfl != 1024))
262
0
    return -1;
263
6.31k
  ixheaacd_info_init(&ixheaacd_samp_rate_info[usac_data->sampling_rate_idx],
264
6.31k
                     usac_data->ccfl, usac_data->pstr_usac_winmap[0],
265
6.31k
                     usac_data->pstr_usac_winmap[2], usac_data->sfb_width_short,
266
6.31k
                     usac_data->sfb_width_long);
267
268
44.1k
  for (i = 0; i < MAX_NUM_CHANNELS; i++) {
269
37.8k
    usac_data->str_tddec[i] = &usac_data->arr_str_tddec[i];
270
37.8k
    if (usac_data->ccfl == 768)
271
12.3k
      usac_data->str_tddec[i]->fscale = pstr_stream_config->sampling_frequency;
272
25.4k
    else
273
25.4k
      usac_data->str_tddec[i]->fscale =
274
25.4k
          ((fscale)*usac_data->ccfl) / LEN_SUPERFRAME;
275
37.8k
    usac_data->len_subfrm = usac_data->ccfl / 4;
276
277
37.8k
    {
278
37.8k
      WORD32 fac_length = usac_data->len_subfrm / 4;
279
37.8k
      if (fac_length & (fac_length - 1)) {
280
12.3k
        if ((fac_length != 48) && (fac_length != 96) && (fac_length != 192) &&
281
0
            (fac_length != 384) && (fac_length != 768)) {
282
0
          return -1;
283
0
        }
284
12.3k
      }
285
37.8k
    }
286
37.8k
    usac_data->num_subfrm = (MAX_NUM_SUBFR * usac_data->ccfl) / LEN_SUPERFRAME;
287
288
37.8k
    ixheaacd_init_acelp_data(usac_data, usac_data->str_tddec[i]);
289
290
37.8k
    usac_data->str_tddec[i]->fd_synth =
291
37.8k
        &usac_data->str_tddec[i]->fd_synth_buf[LEN_FRAME];
292
37.8k
  }
293
294
20.8k
  for (ele_id = 0; ele_id < num_elements; ele_id++) {
295
14.5k
    UWORD32 ele_type;
296
14.5k
    WORD32 stereo_config_index;
297
298
14.5k
    ia_usac_dec_element_config_struct *ptr_usac_ele_config =
299
14.5k
        &ptr_usac_config->str_usac_dec_config.str_usac_element_config[ele_id];
300
301
14.5k
    if (ptr_usac_ele_config) {
302
14.5k
      if (usac_data->tw_mdct[ele_id]) {
303
22
        if (usac_data->ec_flag) {
304
0
          usac_data->tw_mdct[ele_id] = 0;
305
0
        } else
306
22
          return -1;
307
22
      }
308
309
14.5k
      usac_data->noise_filling_config[ele_id] = ptr_usac_ele_config->noise_filling;
310
14.5k
    }
311
312
14.5k
    ele_type = ptr_usac_config->str_usac_dec_config.usac_element_type[ele_id];
313
314
14.5k
    stereo_config_index = ptr_usac_ele_config->stereo_config_index;
315
316
14.5k
    switch (ele_type) {
317
2.42k
      case ID_USAC_SCE:
318
2.67k
      case ID_USAC_LFE:
319
320
2.67k
        if ((chan + 1) > MAX_NUM_CHANNELS_USAC_LVL2) return -1;
321
2.67k
        usac_data->seed_value[chan] = 0x3039;
322
2.67k
        chan++;
323
324
2.67k
        break;
325
326
3.25k
      case ID_USAC_CPE: {
327
3.25k
        static const WORD32 frame_len_tbl[MAX_CORE_SBR_FRAME_LEN_IDX + 1] = {
328
3.25k
            -1, -1, 32, 32, 64};
329
330
3.25k
        if ((chan + 2) > MAX_NUM_CHANNELS_USAC_LVL2) return -1;
331
3.25k
        usac_data->seed_value[chan] = 0x3039;
332
3.25k
        chan++;
333
334
3.25k
        usac_data->seed_value[chan] = 0x10932;
335
3.25k
        chan++;
336
337
3.25k
        if (stereo_config_index > 0) {
338
1.80k
          WORD32 bs_frame_length =
339
1.80k
              frame_len_tbl[ptr_usac_config->core_sbr_framelength_index];
340
1.80k
          WORD32 bs_residual_coding = (stereo_config_index > 1) ? 1 : 0;
341
342
1.80k
          ia_usac_dec_mps_config_struct *ptr_usac_mps212_config =
343
1.80k
              &(ptr_usac_config->str_usac_dec_config
344
1.80k
                    .str_usac_element_config[ele_id]
345
1.80k
                    .str_usac_mps212_config);
346
1.80k
          aac_dec_handle->mps_dec_handle.ec_flag = aac_dec_handle->ec_enable;
347
348
1.80k
          if (ixheaacd_mps_create(&aac_dec_handle->mps_dec_handle,
349
1.80k
                                  bs_frame_length, bs_residual_coding,
350
1.80k
                                  ptr_usac_mps212_config)) {
351
2
            return -1;
352
2
          }
353
1.80k
        }
354
3.25k
        break;
355
3.25k
      }
356
357
3.25k
      break;
358
8.60k
      case ID_USAC_EXT:
359
8.60k
        break;
360
0
      default:
361
0
        return -1;
362
0
        break;
363
14.5k
    }
364
14.5k
  }
365
366
6.28k
  return 0;
367
6.31k
}
368
369
WORD32 ixheaacd_dec_data_init(VOID *handle,
370
                              ia_frame_data_struct *pstr_frame_data,
371
6.31k
                              ia_usac_data_struct *usac_data) {
372
6.31k
  ia_audio_specific_config_struct *pstr_stream_config, *layer_config;
373
6.31k
  WORD32 err_code = 0;
374
6.31k
  WORD32 i_ch, i, ele_id;
375
6.31k
  WORD32 num_elements;
376
377
6.31k
  WORD32 out_frame_len, sbr_ratio_idx;
378
379
6.31k
  ia_usac_config_struct *ptr_usac_config =
380
6.31k
      &(pstr_frame_data->str_audio_specific_config.str_usac_config);
381
382
6.31k
  usac_data->last_frame_ok = 1;
383
6.31k
  usac_data->frame_ok = 1;
384
6.31k
  usac_data->window_shape_prev[0] = WIN_SEL_0;
385
6.31k
  usac_data->window_shape_prev[1] = WIN_SEL_0;
386
387
6.31k
  pstr_frame_data->str_layer.bit_rate =
388
6.31k
      pstr_frame_data->str_audio_specific_config.avg_bit_rate;
389
6.31k
  pstr_stream_config = &pstr_frame_data->str_audio_specific_config;
390
6.31k
  layer_config = &pstr_frame_data->str_audio_specific_config;
391
392
6.31k
  sbr_ratio_idx = ixheaacd_sbr_params(
393
6.31k
      ptr_usac_config->core_sbr_framelength_index, &out_frame_len,
394
6.31k
      &usac_data->ccfl, &usac_data->output_samples,
395
6.31k
      &pstr_frame_data->str_layer.sample_rate_layer,
396
6.31k
      &layer_config->samp_frequency_index);
397
6.31k
  if (!pstr_frame_data->str_layer.sample_rate_layer) {
398
3
    return -1;
399
3
  }
400
6.31k
  pstr_stream_config->sampling_frequency =
401
6.31k
      pstr_frame_data->str_layer.sample_rate_layer;
402
6.31k
  pstr_stream_config->samp_frequency_index = layer_config->samp_frequency_index;
403
404
6.31k
  num_elements = ptr_usac_config->str_usac_dec_config.num_elements;
405
406
20.8k
  for (ele_id = 0; ele_id < num_elements; ele_id++) {
407
14.5k
    ia_usac_dec_element_config_struct *ptr_usac_ele_config =
408
14.5k
        &(ptr_usac_config->str_usac_dec_config.str_usac_element_config[ele_id]);
409
410
14.5k
    if (ptr_usac_ele_config) {
411
14.5k
      usac_data->tw_mdct[ele_id] = ptr_usac_ele_config->tw_mdct;
412
14.5k
    }
413
414
14.5k
    {
415
14.5k
      ia_usac_dec_mps_config_struct *ptr_usac_mps212_config =
416
14.5k
          &ptr_usac_ele_config->str_usac_mps212_config;
417
14.5k
      WORD32 stereo_config_index = ptr_usac_ele_config->stereo_config_index;
418
419
14.5k
      usac_data->mps_pseudo_lr[ele_id] =
420
14.5k
          (stereo_config_index > 1) ? ptr_usac_mps212_config->bs_pseudo_lr : 0;
421
14.5k
    }
422
14.5k
  }
423
424
6.31k
  usac_data->sbr_ratio_idx = sbr_ratio_idx;
425
6.31k
  usac_data->esbr_bit_str[0].no_elements = 0;
426
6.31k
  usac_data->esbr_bit_str[1].no_elements = 0;
427
428
6.31k
  if (usac_data->ccfl == 768)
429
2.06k
    pstr_frame_data->str_layer.sample_rate_layer =
430
2.06k
        4 * pstr_frame_data->str_layer.sample_rate_layer / 3;
431
432
44.1k
  for (i = 0; i < MAX_NUM_CHANNELS; i++) {
433
37.8k
    usac_data->coef_fix[i] = &usac_data->arr_coef_fix[i][0];
434
37.8k
    usac_data->coef[i] = &usac_data->arr_coef[i][0];
435
37.8k
    usac_data->coef_save[i] = &usac_data->arr_coef_save[i][0];
436
37.8k
    usac_data->factors[i] = &usac_data->arr_factors[i][0];
437
37.8k
    usac_data->group_dis[i] = &usac_data->arr_group_dis[i][0];
438
37.8k
    usac_data->pstr_tns[i] = &usac_data->arr_str_tns[i];
439
37.8k
    usac_data->tw_ratio[i] = &usac_data->arr_tw_ratio[i][0];
440
37.8k
    usac_data->ms_used[i] = &usac_data->arr_ms_used[i][0];
441
37.8k
    usac_data->window_shape_prev[i] = WIN_SEL_0;
442
443
37.8k
    usac_data->seed_value[i] = 0x0;
444
445
37.8k
    usac_data->fac_data_present[i] = 0;
446
37.8k
  }
447
448
6.31k
  err_code =
449
6.31k
      ixheaacd_decode_init(handle, pstr_frame_data->str_layer.sample_rate_layer,
450
6.31k
                           usac_data, pstr_stream_config);
451
6.31k
  if (err_code != 0) return err_code;
452
453
44.0k
  for (i_ch = 0; i_ch < MAX_NUM_CHANNELS; i_ch++) {
454
37.7k
    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
37.7k
  }
463
6.28k
  return err_code;
464
6.31k
}
465
466
static VOID ixheaacd_count_tracks_per_layer(int *max_layer, int *stream_count,
467
6.32k
                                            int *tracks_in_layer) {
468
6.32k
  WORD32 stream;
469
6.32k
  WORD32 num_layer;
470
6.32k
  WORD32 num_streams;
471
6.32k
  WORD32 layer = 0;
472
473
6.32k
  if (stream_count == NULL)
474
0
    num_streams = 0;
475
6.32k
  else
476
6.32k
    num_streams = *stream_count;
477
6.32k
  if (max_layer == NULL)
478
0
    num_layer = num_streams;
479
6.32k
  else
480
6.32k
    num_layer = *max_layer;
481
6.32k
  if (num_layer < 0) num_layer = num_streams;
482
483
12.6k
  for (stream = 0; (layer <= num_layer) && (stream < num_streams);) {
484
6.32k
    *tracks_in_layer = 1;
485
6.32k
    stream += 1;
486
6.32k
    layer++;
487
6.32k
    if (layer <= num_layer) *tracks_in_layer = 0;
488
6.32k
  }
489
490
6.32k
  if (max_layer) *max_layer = (layer - 1);
491
6.32k
  if (stream_count) *stream_count = stream;
492
6.32k
}
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
6.32k
{
498
6.32k
  WORD32 layer;
499
6.32k
  WORD32 track;
500
6.32k
  WORD32 num_dec_streams;
501
6.32k
  ia_frame_data_struct *pstr_frame_data;
502
503
6.32k
  WORD32 stream_count = 1;
504
6.32k
  WORD32 max_layer = -1;
505
506
6.32k
  memset(pstr_dec_data, 0, IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_dec_data_struct), BYTE_ALIGN_8));
507
6.32k
  memset(&(pstr_dec_data->str_frame_data), 0,
508
6.32k
         sizeof(pstr_dec_data->str_frame_data));
509
510
6.32k
  pstr_frame_data = &(pstr_dec_data->str_frame_data);
511
512
6.32k
  if (max_layer < 0) max_layer = stream_count - 1;
513
514
6.32k
  ixheaacd_count_tracks_per_layer(&max_layer, &stream_count,
515
6.32k
                                  &pstr_frame_data->tracks_in_layer);
516
517
6.32k
  pstr_frame_data->scal_out_select = max_layer;
518
519
6.32k
  pstr_frame_data->stream_count = 0;
520
521
6.32k
  num_dec_streams = track = 0;
522
12.6k
  for (layer = 0; layer < (signed)pstr_frame_data->scal_out_select + 1;
523
6.32k
       layer++) {
524
6.32k
    WORD32 j;
525
12.6k
    for (j = 0; j < 1; j++, num_dec_streams++) {
526
6.32k
      pstr_frame_data->str_audio_specific_config = *pstr_audio_conf;
527
6.32k
      pstr_frame_data->str_layer.sample_rate_layer =
528
6.32k
          pstr_frame_data->str_audio_specific_config.sampling_frequency;
529
6.32k
      pstr_frame_data->str_layer.bit_rate =
530
6.32k
          pstr_frame_data->str_audio_specific_config.avg_bit_rate;
531
6.32k
    }
532
533
6.32k
    track += pstr_frame_data->tracks_in_layer;
534
6.32k
  }
535
536
6.32k
  pstr_frame_data->stream_count = num_dec_streams;
537
538
6.32k
  return num_dec_streams;
539
6.32k
}
540
541
WORD32 ixheaacd_decode_create(ia_exhaacplus_dec_api_struct *handle,
542
                              ia_dec_data_struct *pstr_dec_data,
543
6.31k
                              WORD32 tracks_for_decoder) {
544
6.31k
  WORD32 stream;
545
546
6.31k
  WORD32 err = 0;
547
6.31k
  ia_frame_data_struct *pstr_frame_data;
548
6.31k
  WORD32 stream_count;
549
6.31k
  ia_aac_dec_state_struct *aac_dec_handle = handle->p_state_aac;
550
6.31k
  pstr_frame_data = &(pstr_dec_data->str_frame_data);
551
6.31k
  stream_count = pstr_frame_data->stream_count;
552
6.31k
  pstr_frame_data->stream_count = tracks_for_decoder;
553
554
12.6k
  for (stream = 0; stream < stream_count; stream++) {
555
6.31k
    UWORD32 aot = pstr_frame_data->str_audio_specific_config.audio_object_type;
556
557
6.31k
    switch (aot) {
558
6.31k
      case AOT_USAC:
559
560
6.31k
        err = ixheaacd_dec_data_init(handle, pstr_frame_data,
561
6.31k
                                     &(pstr_dec_data->str_usac_data));
562
563
6.31k
        if (err != 0) {
564
27
          if (handle->aac_config.ui_err_conceal) {
565
0
            pstr_dec_data->str_usac_data.frame_ok = 0;
566
0
          } else
567
27
            return err;
568
27
        }
569
570
6.28k
        pstr_dec_data->str_usac_data.sampling_rate = pstr_frame_data->str_layer.sample_rate_layer;
571
572
6.28k
        switch (pstr_dec_data->str_usac_data.sbr_ratio_idx) {
573
2.48k
          case 0:
574
2.48k
            handle->aac_config.ui_sbr_mode = 0;
575
2.48k
            break;
576
2.59k
          case 1:
577
2.59k
            handle->aac_config.ui_sbr_mode = 1;
578
2.59k
            break;
579
865
          case 2:
580
865
            handle->aac_config.ui_sbr_mode = 1;
581
865
            break;
582
343
          case 3:
583
343
            handle->aac_config.ui_sbr_mode = 3;
584
343
            break;
585
586
0
          default:
587
0
            handle->aac_config.ui_sbr_mode = 0;
588
6.28k
        }
589
590
6.28k
        if (!aac_dec_handle->peak_lim_init && !handle->aac_config.peak_limiter_off &&
591
6.28k
            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
6.28k
        break;
601
602
0
      default:
603
604
0
        break;
605
6.31k
    }
606
6.31k
  }
607
608
6.28k
  pstr_frame_data->scal_out_object_type =
609
6.28k
      pstr_frame_data->str_audio_specific_config.audio_object_type;
610
6.28k
  pstr_frame_data->scal_out_num_channels =
611
6.28k
      pstr_frame_data->str_audio_specific_config.channel_configuration;
612
6.28k
  pstr_frame_data->scal_out_sampling_frequency =
613
6.28k
      pstr_frame_data->str_audio_specific_config.sampling_frequency;
614
615
6.28k
  if (&(pstr_dec_data->str_usac_data) != NULL) {
616
6.28k
    ia_sbr_header_data_struct usac_def_header;
617
6.28k
    ia_audio_specific_config_struct *pstr_aud_spec_config =
618
6.28k
        &pstr_frame_data->str_audio_specific_config;
619
6.28k
    ia_usac_config_struct *ptr_usac_config =
620
6.28k
        &(pstr_frame_data->str_audio_specific_config.str_usac_config);
621
622
6.28k
    WORD32 inter_test_flag = 0;
623
6.28k
    WORD32 bs_pvc_flag = 0;
624
6.28k
    WORD32 harmonic_Sbr_flag = 0;
625
626
6.28k
    ia_usac_decoder_config_struct *ptr_usac_dec_config =
627
6.28k
        &ptr_usac_config->str_usac_dec_config;
628
6.28k
    WORD32 const num_ele = ptr_usac_dec_config->num_elements;
629
6.28k
    WORD32 elem_idx = 0;
630
631
6.28k
    memset(&usac_def_header, 0, sizeof(ia_sbr_header_data_struct));
632
633
20.8k
    for (elem_idx = 0; elem_idx < num_ele; elem_idx++) {
634
14.5k
      UWORD32 usac_ele_type =
635
14.5k
          ptr_usac_config->str_usac_dec_config.usac_element_type[elem_idx];
636
14.5k
      ia_usac_dec_element_config_struct *ptr_usac_ele_config =
637
14.5k
          &ptr_usac_config->str_usac_dec_config
638
14.5k
               .str_usac_element_config[elem_idx];
639
640
14.5k
      ia_usac_dec_sbr_config_struct *ptr_usac_sbr_config =
641
14.5k
          &(ptr_usac_dec_config->str_usac_element_config[elem_idx]
642
14.5k
                .str_usac_sbr_config);
643
644
14.5k
      if (ptr_usac_sbr_config->bs_inter_tes) inter_test_flag = 1;
645
14.5k
      if (ptr_usac_sbr_config->bs_pvc) bs_pvc_flag = 1;
646
14.5k
      if (ptr_usac_sbr_config->harmonic_sbr) harmonic_Sbr_flag = 1;
647
648
14.5k
      if ((usac_ele_type != ID_USAC_LFE) && (usac_ele_type != ID_USAC_EXT)) {
649
5.67k
        ia_usac_dec_sbr_config_struct *ptr_usac_sbr_config =
650
5.67k
            &(ptr_usac_ele_config->str_usac_sbr_config);
651
652
5.67k
        usac_def_header.start_freq = ptr_usac_sbr_config->dflt_start_freq;
653
5.67k
        usac_def_header.stop_freq = ptr_usac_sbr_config->dflt_stop_freq;
654
5.67k
        usac_def_header.header_extra_1 =
655
5.67k
            ptr_usac_sbr_config->dflt_header_extra1;
656
5.67k
        usac_def_header.header_extra_2 =
657
5.67k
            ptr_usac_sbr_config->dflt_header_extra2;
658
5.67k
        usac_def_header.freq_scale = ptr_usac_sbr_config->dflt_freq_scale;
659
5.67k
        usac_def_header.alter_scale = ptr_usac_sbr_config->dflt_alter_scale;
660
5.67k
        usac_def_header.noise_bands = ptr_usac_sbr_config->dflt_noise_bands;
661
5.67k
        usac_def_header.limiter_bands = ptr_usac_sbr_config->dflt_limiter_bands;
662
5.67k
        usac_def_header.limiter_gains = ptr_usac_sbr_config->dflt_limiter_gains;
663
5.67k
        usac_def_header.interpol_freq = ptr_usac_sbr_config->dflt_interpol_freq;
664
5.67k
        usac_def_header.smoothing_mode =
665
5.67k
            ptr_usac_sbr_config->dflt_smoothing_mode;
666
5.67k
      }
667
14.5k
    }
668
669
6.28k
    pstr_dec_data->str_usac_data.down_samp_sbr = 0;
670
671
6.28k
    if (pstr_dec_data->str_usac_data.sbr_ratio_idx > 0) {
672
3.79k
      if (pstr_aud_spec_config->ext_sampling_frequency ==
673
3.79k
          pstr_aud_spec_config->sampling_frequency) {
674
0
        pstr_dec_data->str_usac_data.down_samp_sbr = 1;
675
0
      }
676
3.79k
      if (pstr_dec_data->str_usac_data.down_samp_sbr == 0) {
677
3.79k
        if (pstr_dec_data->str_usac_data.sbr_ratio_idx == 3) {
678
343
          pstr_frame_data->scal_out_sampling_frequency =
679
343
              4 * pstr_frame_data->scal_out_sampling_frequency;
680
3.45k
        } else {
681
3.45k
          pstr_frame_data->scal_out_sampling_frequency =
682
3.45k
              2 * pstr_frame_data->scal_out_sampling_frequency;
683
3.45k
        }
684
3.79k
      }
685
686
3.79k
      {
687
3.79k
        void *sbr_persistent_mem_v = aac_dec_handle->sbr_persistent_mem_u;
688
689
3.79k
        pstr_dec_data->str_usac_data.pstr_esbr_dec = ixheaacd_init_sbr(
690
3.79k
            pstr_frame_data->str_layer.sample_rate_layer,
691
3.79k
            pstr_dec_data->str_usac_data.ccfl,
692
3.79k
            &pstr_dec_data->str_usac_data.down_samp_sbr, sbr_persistent_mem_v,
693
3.79k
            NULL, pstr_frame_data->scal_out_num_channels, 0,
694
3.79k
            pstr_dec_data->str_usac_data.sbr_ratio_idx,
695
3.79k
            pstr_dec_data->str_usac_data.output_samples, &harmonic_Sbr_flag,
696
3.79k
            (void *)&usac_def_header, aac_dec_handle->str_sbr_config,
697
3.79k
            pstr_dec_data->str_usac_data.audio_object_type, 0, 0);
698
3.79k
        pstr_dec_data->str_usac_data.sbr_scratch_mem_base =
699
3.79k
            aac_dec_handle->sbr_scratch_mem_u;
700
3.79k
        if (num_ele)
701
3.79k
          ixheaacd_setesbr_flags(sbr_persistent_mem_v, bs_pvc_flag,
702
3.79k
                                 harmonic_Sbr_flag, inter_test_flag);
703
3.79k
      }
704
705
3.79k
      if (pstr_dec_data->str_usac_data.pstr_esbr_dec == NULL) {
706
0
        return -1;
707
3.79k
      } else {
708
3.79k
        pstr_dec_data->str_usac_data.pstr_esbr_dec->xaac_jmp_buf =
709
3.79k
            &(aac_dec_handle->xaac_jmp_buf);
710
3.79k
      }
711
3.79k
    }
712
6.28k
  }
713
6.28k
  aac_dec_handle->decode_create_done = 1;
714
6.28k
  return 0;
715
6.28k
}