Coverage Report

Created: 2026-01-09 06:51

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