Coverage Report

Created: 2026-09-01 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_mps_bitdec.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2023 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 "ixheaac_type_def.h"
22
#include "ixheaacd_mps_struct_def.h"
23
#include "ixheaacd_error_codes.h"
24
#include "ixheaacd_bitbuffer.h"
25
#include "ixheaacd_mps_res_rom.h"
26
#include "ixheaacd_mps_aac_struct.h"
27
#include "ixheaacd_mps_res_channel.h"
28
#include "ixheaac_constants.h"
29
#include "ixheaac_basic_ops32.h"
30
#include "ixheaac_basic_ops40.h"
31
#include "ixheaacd_cnst.h"
32
#include "ixheaacd_common_rom.h"
33
#include "ixheaacd_sbrdecsettings.h"
34
#include "ixheaacd_sbr_scale.h"
35
#include "ixheaacd_env_extr_part.h"
36
#include "ixheaacd_sbr_rom.h"
37
#include "ixheaacd_hybrid.h"
38
#include "ixheaacd_ps_dec.h"
39
#include "ixheaacd_mps_polyphase.h"
40
#include "ixheaac_error_standards.h"
41
#include "ixheaacd_config.h"
42
#include "ixheaacd_qmf_dec.h"
43
#include "ixheaacd_mps_dec.h"
44
#include "ixheaacd_mps_interface.h"
45
#include "ixheaacd_mps_macro_def.h"
46
#include "ixheaacd_mps_nlc_dec.h"
47
#include "ixheaacd_mps_bitdec.h"
48
#include "ixheaacd_mps_res_tns.h"
49
#include "ixheaacd_mps_mdct_2_qmf.h"
50
#include "ixheaac_sbr_const.h"
51
52
static const WORD32 ixheaacd_freq_res_table[] = {0, 28, 20, 14, 10, 7, 5, 4};
53
54
3.00M
static WORD32 ixheaacd_bound_check(WORD32 var, WORD32 lower_bound, WORD32 upper_bound) {
55
3.00M
  var = min(var, upper_bound);
56
3.00M
  var = max(var, lower_bound);
57
3.00M
  return var;
58
3.00M
}
59
60
1.34k
FLAG ixheaacd_validate_res_frames_per_spatial_frame(WORD32 num_slots, WORD32 val) {
61
1.34k
  switch (num_slots) {
62
23
    case 15:
63
622
    case 16:
64
638
    case 18:
65
841
    case 24:
66
891
    case 30:
67
891
      return val == 0;
68
340
    case 32:
69
340
      return val == 0 || val == 1;
70
47
    case 36:
71
59
    case 48:
72
85
    case 60:
73
85
      return val == 1;
74
22
    case 64:
75
22
      return val == 1 || val == 3;
76
3
    case 72:
77
3
      return val == 2;
78
4
    default:
79
4
      return 0;
80
1.34k
  }
81
1.34k
}
82
83
static VOID ixheaacd_mps_check_index_bounds(
84
    WORD32 output_idx_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
85
    WORD32 num_parameter_sets, WORD32 start_band, WORD32 stop_band,
86
102k
    WORD32 param_type, WORD32 xtt_idx) {
87
102k
  WORD32 i, band;
88
289k
  for (i = 0; i < num_parameter_sets; i++) {
89
3.25M
    for (band = start_band; band < stop_band; band++) {
90
3.06M
      if (param_type == CLD) {
91
1.63M
        output_idx_data[xtt_idx][i][band] =
92
1.63M
          ixheaacd_bound_check(output_idx_data[xtt_idx][i][band], -15, 15);
93
1.63M
      } else if (param_type == ICC) {
94
1.37M
        output_idx_data[xtt_idx][i][band] =
95
1.37M
        ixheaacd_bound_check(output_idx_data[xtt_idx][i][band], 0, 7);
96
1.37M
      }
97
3.06M
    }
98
186k
  }
99
102k
}
100
101
static IA_ERRORCODE ixheaacd_parse_extension_config(
102
    ia_mps_spatial_bs_config_struct *config, WORD32 num_ott_boxes, WORD32 num_ttt_boxes,
103
    WORD32 num_out_chan, WORD32 bits_available, ia_bit_buf_struct *it_bit_buff,
104
4.67k
    ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
105
4.67k
  WORD32 i, ch, idx, tmp, tmp_open, sac_ext_len, bits_read, n_fill_bits, temp;
106
4.67k
  WORD32 ba = bits_available;
107
108
4.67k
  config->sac_ext_cnt = 0;
109
110
4.67k
  WORD32 num_slots = config->bs_frame_length + 1;
111
112
5.92k
  while (ba >= 8) {
113
1.32k
    ba -= 8;
114
1.32k
    temp = ixheaacd_read_bits_buf(it_bit_buff, 8);
115
1.32k
    config->bs_sac_ext_type[config->sac_ext_cnt] = (temp >> 4) & FOUR_BIT_MASK;
116
1.32k
    sac_ext_len = temp & FOUR_BIT_MASK;
117
1.32k
    if (sac_ext_len == 15) {
118
7
      sac_ext_len += ixheaacd_read_bits_buf(it_bit_buff, 8);
119
7
      ba -= 8;
120
7
      if (sac_ext_len == 15 + 255) {
121
1
        sac_ext_len += ixheaacd_read_bits_buf(it_bit_buff, 16);
122
1
        ba -= 16;
123
1
      }
124
7
    }
125
126
1.32k
    tmp = (WORD32)(((it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base + 1) << 3) -
127
1.32k
                   (it_bit_buff->bit_pos + 1));
128
129
1.32k
    switch (config->bs_sac_ext_type[config->sac_ext_cnt]) {
130
880
      case EXT_TYPE_0:
131
880
        config->bs_residual_coding = 1;
132
880
        temp = ixheaacd_read_bits_buf(it_bit_buff, 6);
133
880
        config->bs_residual_sampling_freq_index = (temp >> 2) & FOUR_BIT_MASK;
134
880
        if (config->bs_residual_sampling_freq_index > MAX_RES_SAMP_FREQ_IDX) {
135
3
          return IA_FATAL_ERROR;
136
3
        }
137
877
        config->bs_residual_frames_per_spatial_frame = temp & TWO_BIT_MASK;
138
139
877
        if (!ixheaacd_validate_res_frames_per_spatial_frame(
140
877
                num_slots, config->bs_residual_frames_per_spatial_frame)) {
141
9
          return IA_FATAL_ERROR;
142
9
        }
143
144
4.47k
        for (i = 0; i < num_ott_boxes + num_ttt_boxes; i++) {
145
3.61k
          config->bs_residual_present[i] = ixheaacd_read_bits_buf(it_bit_buff, 1);
146
3.61k
          if (config->bs_residual_present[i]) {
147
1.05k
            config->bs_residual_bands[i] = ixheaacd_read_bits_buf(it_bit_buff, 5);
148
1.05k
            if (config->bs_residual_bands[i] > MAX_PARAMETER_BANDS)
149
8
            {
150
8
              return IA_FATAL_ERROR;
151
8
            }
152
1.05k
          }
153
3.61k
        }
154
860
        break;
155
156
860
      case EXT_TYPE_1:
157
384
        config->bs_arbitrary_downmix = 2;
158
159
384
        temp = ixheaacd_read_bits_buf(it_bit_buff, 11);
160
384
        config->bs_arbitrary_downmix_residual_sampling_freq_index = (temp >> 7) & FOUR_BIT_MASK;
161
384
        if (config->bs_arbitrary_downmix_residual_sampling_freq_index > MAX_RES_SAMP_FREQ_IDX) {
162
1
          return IA_FATAL_ERROR;
163
1
        }
164
383
        config->bs_arbitrary_downmix_residual_frames_per_spatial_frame =
165
383
            (temp >> 5) & TWO_BIT_MASK;
166
167
383
        if (!ixheaacd_validate_res_frames_per_spatial_frame(
168
383
                num_slots, config->bs_arbitrary_downmix_residual_frames_per_spatial_frame)) {
169
4
          return IA_FATAL_ERROR;
170
4
        }
171
172
379
        config->bs_arbitrary_downmix_residual_bands = temp & FIVE_BIT_MASK;
173
379
        if (config->bs_arbitrary_downmix_residual_bands >=
174
379
            ixheaacd_freq_res_table[config->bs_freq_res]) {
175
3
          return IA_FATAL_ERROR;
176
3
        }
177
178
376
        break;
179
180
376
      case EXT_TYPE_2:
181
47
        config->arbitrary_tree = 1;
182
47
        config->num_out_chan_at = 0;
183
47
        config->num_ott_boxes_at = 0;
184
294
        for (ch = 0; ch < num_out_chan; ch++) {
185
260
          tmp_open = 1;
186
260
          idx = 0;
187
709
          while (tmp_open > 0) {
188
462
            config->bs_ott_box_present_at[ch][idx] = ixheaacd_read_bits_buf(it_bit_buff, 1);
189
462
            if (config->bs_ott_box_present_at[ch][idx]) {
190
124
              config->num_ott_boxes_at++;
191
124
              tmp_open++;
192
338
            } else {
193
338
              config->num_out_chan_at++;
194
338
              tmp_open--;
195
338
            }
196
462
            if (config->num_ott_boxes_at >= 56) return IA_FATAL_ERROR;
197
462
            if (config->num_out_chan_at > MAX_OUTPUT_CHANNELS_AT_MPS) return IA_FATAL_ERROR;
198
455
            idx++;
199
455
            if (idx >= MAX_ARBITRARY_TREE_INDEX) return IA_FATAL_ERROR;
200
455
          }
201
260
        }
202
203
85
        for (i = 0; i < config->num_ott_boxes_at; i++) {
204
52
          temp = ixheaacd_read_bits_buf(it_bit_buff, 2);
205
52
          config->bs_ott_default_cld_at[i] = (temp >> 1) & ONE_BIT_MASK;
206
52
          config->bs_ott_mode_lfe_at[i] = temp & ONE_BIT_MASK;
207
52
          if (config->bs_ott_mode_lfe_at[i]) {
208
26
            config->bs_ott_bands_at[i] = ixheaacd_read_bits_buf(it_bit_buff, 5);
209
26
            if (config->bs_ott_bands_at[i] > MAX_PARAMETER_BANDS) return IA_FATAL_ERROR;
210
26
          } else {
211
26
            config->bs_ott_bands_at[i] =
212
26
                ixheaacd_mps_dec_bitdec_tables->freq_res_table[config->bs_freq_res];
213
26
          }
214
52
        }
215
216
263
        for (i = 0; i < config->num_out_chan_at; i++) {
217
230
          config->bs_output_channel_pos_at[i] = ixheaacd_read_bits_buf(it_bit_buff, 5);
218
230
        }
219
220
33
        break;
221
222
6
      default:
223
6
        return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_EXTENSION_TYPE;
224
1.32k
    }
225
226
1.26k
    bits_read = (WORD32)(((it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base + 1) << 3) -
227
1.26k
                         (it_bit_buff->bit_pos + 1) - tmp);
228
1.26k
    n_fill_bits = 8 * sac_ext_len - bits_read;
229
230
4.95k
    while (n_fill_bits > 7) {
231
3.69k
      ixheaacd_read_bits_buf(it_bit_buff, 8);
232
3.69k
      n_fill_bits -= 8;
233
3.69k
    }
234
1.26k
    if (n_fill_bits > 0) {
235
586
      ixheaacd_read_bits_buf(it_bit_buff, n_fill_bits);
236
586
    }
237
238
1.26k
    ba -= 8 * sac_ext_len;
239
1.26k
    config->sac_ext_cnt++;
240
1.26k
    if (config->sac_ext_cnt >= MAX_NUM_EXT_TYPES) {
241
4
      return IA_FATAL_ERROR;
242
4
    }
243
1.26k
  }
244
245
4.60k
  return IA_NO_ERROR;
246
4.67k
}
247
248
IA_ERRORCODE ixheaacd_parse_specific_config(ia_heaac_mps_state_struct *pstr_mps_state,
249
4.70k
                                            WORD32 sac_header_len) {
250
4.70k
  IA_ERRORCODE err_code = IA_NO_ERROR;
251
4.70k
  ia_mps_spatial_bs_config_struct *config = &(pstr_mps_state->bs_config);
252
4.70k
  ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
253
4.70k
  const ia_mps_dec_tree_properties_struct *p_tree_property_table =
254
4.70k
      pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr->tree_property_table;
255
4.70k
  ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff;
256
257
4.70k
  WORD32 i, hc, hb, num_header_bits, ott_mode_lfe[MAX_NUM_OTT];
258
259
4.70k
  WORD32 tmp = (WORD32)(((mps_bit_buf->ptr_read_next - mps_bit_buf->ptr_bit_buf_base + 1) << 3) -
260
4.70k
                        (mps_bit_buf->bit_pos + 1));
261
4.70k
  WORD32 bits_available = (sac_header_len << 3);
262
4.70k
  WORD32 temp, alignment_bits = 0;
263
264
4.70k
  config->bs_sampling_freq_index = ixheaacd_read_bits_buf(mps_bit_buf, 4);
265
4.70k
  if (config->bs_sampling_freq_index == 15) {
266
11
    config->bs_sampling_frequency = ixheaacd_read_bits_buf(mps_bit_buf, 24);
267
11
  }
268
4.70k
  temp = ixheaacd_read_bits_buf(mps_bit_buf, 14);
269
4.70k
  config->bs_frame_length = (temp >> 7) & SEVEN_BIT_MASK;
270
4.70k
  if (config->bs_frame_length >= (MAX_QMF_BUF_LEN - 1)) {
271
1
    return IA_FATAL_ERROR;
272
1
  }
273
4.70k
  config->bs_freq_res = (temp >> 4) & THREE_BIT_MASK;
274
4.70k
  if (config->bs_freq_res == 0) {
275
1
    return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_PARAMETER_BANDS;
276
1
  }
277
4.70k
  config->bs_tree_config = (temp)&FOUR_BIT_MASK;
278
279
4.70k
  if (config->bs_tree_config >= 7) {
280
2
    return IA_FATAL_ERROR;
281
2
  }
282
283
4.69k
  if (config->bs_tree_config != 15) {
284
4.69k
    curr_state->num_ott_boxes = p_tree_property_table[config->bs_tree_config].num_ott_boxes;
285
4.69k
    curr_state->num_ttt_boxes = p_tree_property_table[config->bs_tree_config].num_ttt_boxes;
286
4.69k
    curr_state->num_input_channels =
287
4.69k
        p_tree_property_table[config->bs_tree_config].num_input_channels;
288
4.69k
    curr_state->num_output_channels =
289
4.69k
        p_tree_property_table[config->bs_tree_config].num_output_channels;
290
28.1k
    for (i = 0; i < MAX_NUM_OTT; i++) {
291
23.4k
      ott_mode_lfe[i] = p_tree_property_table[config->bs_tree_config].ott_mode_lfe[i];
292
23.4k
    }
293
4.69k
  }
294
4.69k
  temp = ixheaacd_read_bits_buf(mps_bit_buf, 19);
295
4.69k
  config->bs_quant_mode = (temp >> 17) & TWO_BIT_MASK;
296
4.69k
  config->bs_one_icc = (temp >> 16) & ONE_BIT_MASK;
297
4.69k
  config->bs_arbitrary_downmix = (temp >> 15) & ONE_BIT_MASK;
298
4.69k
  config->bs_fixed_gain_sur = (temp >> 12) & THREE_BIT_MASK;
299
4.69k
  if (config->bs_fixed_gain_sur >= 5) {
300
1
    return IA_FATAL_ERROR;
301
1
  }
302
4.69k
  config->bs_fixed_gain_lfe = (temp >> 9) & THREE_BIT_MASK;
303
304
4.69k
  if (config->bs_fixed_gain_lfe >= 5) return IA_FATAL_ERROR;
305
4.69k
  config->bs_fixed_gain_dmx = (temp >> 6) & THREE_BIT_MASK;
306
4.69k
  config->bs_matrix_mode = (temp >> 5) & ONE_BIT_MASK;
307
4.69k
  config->bs_temp_shape_config = (temp >> 3) & TWO_BIT_MASK;
308
4.69k
  if (config->bs_temp_shape_config == 3)
309
1
    return IA_FATAL_ERROR;
310
311
4.69k
  config->bs_decorr_config = (temp >> 1) & TWO_BIT_MASK;
312
4.69k
  config->bs_3d_audio_mode = (temp)&ONE_BIT_MASK;
313
314
20.4k
  for (i = 0; i < curr_state->num_ott_boxes; i++) {
315
15.7k
    if (ott_mode_lfe[i]) {
316
2.97k
      config->bs_ott_bands[i] = ixheaacd_read_bits_buf(mps_bit_buf, 5);
317
2.97k
      if (config->bs_ott_bands[i] > MAX_PARAMETER_BANDS) return IA_FATAL_ERROR;
318
2.97k
    }
319
15.7k
  }
320
321
6.70k
  for (i = 0; i < curr_state->num_ttt_boxes; i++) {
322
2.00k
    temp = ixheaacd_read_bits_buf(mps_bit_buf, 4);
323
2.00k
    config->bs_ttt_dual_mode[i] = (temp >> 3) & ONE_BIT_MASK;
324
2.00k
    config->bs_ttt_mode_low[i] = (temp)&THREE_BIT_MASK;
325
2.00k
    if (config->bs_ttt_dual_mode[i]) {
326
1.43k
      temp = ixheaacd_read_bits_buf(mps_bit_buf, 8);
327
1.43k
      config->bs_ttt_mode_high[i] = (temp >> 5) & THREE_BIT_MASK;
328
1.43k
      config->bs_ttt_bands_low[i] = (temp)&FIVE_BIT_MASK;
329
1.43k
      if (config->bs_ttt_bands_low[i] > MAX_PARAMETER_BANDS) return IA_FATAL_ERROR;
330
1.43k
    }
331
2.00k
  }
332
333
4.69k
  if (config->bs_temp_shape_config == 2) {
334
1.59k
    config->bs_env_quant_mode = ixheaacd_read_bits_buf(mps_bit_buf, 1);
335
1.59k
  }
336
337
4.69k
  if (config->bs_3d_audio_mode) {
338
37
    config->bs_3d_audio_hrtf_set = ixheaacd_read_bits_buf(mps_bit_buf, 2);
339
37
    if (config->bs_3d_audio_hrtf_set == 0) {
340
30
      temp = ixheaacd_read_bits_buf(mps_bit_buf, 4);
341
30
      config->bs_hrtf_freq_res = (temp >> 1) & THREE_BIT_MASK;
342
30
      config->bs_hrtf_num_chan = 5;
343
30
      config->bs_hrtf_asymmetric = (temp)&ONE_BIT_MASK;
344
345
30
      config->hrtf_num_band = pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr
346
30
                                  ->freq_res_table[config->bs_hrtf_freq_res];
347
348
121
      for (hc = 0; hc < config->bs_hrtf_num_chan; hc++) {
349
633
        for (hb = 0; hb < config->hrtf_num_band; hb++) {
350
542
          config->bs_hrtf_level_left[hc][hb] = ixheaacd_read_bits_buf(mps_bit_buf, 6);
351
542
        }
352
540
        for (hb = 0; hb < config->hrtf_num_band; hb++) {
353
449
          config->bs_hrtf_level_right[hc][hb] = config->bs_hrtf_asymmetric
354
449
                                                    ? ixheaacd_read_bits_buf(mps_bit_buf, 6)
355
449
                                                    : config->bs_hrtf_level_left[hc][hb];
356
449
        }
357
91
        config->bs_hrtf_phase[hc] = ixheaacd_read_bits_buf(mps_bit_buf, 1);
358
490
        for (hb = 0; hb < config->hrtf_num_band; hb++) {
359
399
          config->bs_hrtf_phase_lr[hc][hb] =
360
399
              config->bs_hrtf_phase[hc] ? ixheaacd_read_bits_buf(mps_bit_buf, 6) : 0;
361
399
        }
362
91
      }
363
30
    }
364
37
  }
365
366
4.69k
  ixheaacd_byte_align(mps_bit_buf, &alignment_bits);
367
368
4.69k
  num_header_bits =
369
4.69k
      (WORD32)(((mps_bit_buf->ptr_read_next - mps_bit_buf->ptr_bit_buf_base + 1) << 3) -
370
4.69k
               (mps_bit_buf->bit_pos + 1) - tmp);
371
4.69k
  bits_available -= num_header_bits;
372
373
4.69k
  err_code = ixheaacd_parse_extension_config(
374
4.69k
      config, curr_state->num_ott_boxes, curr_state->num_ttt_boxes,
375
4.69k
      curr_state->num_output_channels, bits_available, mps_bit_buf,
376
4.69k
      pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr);
377
4.69k
  if (err_code != IA_NO_ERROR) return err_code;
378
379
4.64k
  return IA_NO_ERROR;
380
4.69k
}
381
382
IA_ERRORCODE ixheaacd_default_specific_config(ia_heaac_mps_state_struct *pstr_mps_state,
383
0
                                              WORD32 sampling_freq) {
384
0
  ia_mps_spatial_bs_config_struct *config = &(pstr_mps_state->bs_config);
385
0
  ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
386
0
  const ia_mps_dec_tree_properties_struct *p_tree_property_table =
387
0
      pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr->tree_property_table;
388
0
  WORD32 i, ott_mode_lfe[MAX_NUM_OTT];
389
390
0
  config->bs_sampling_freq_index = 15;
391
0
  for (i = 0; i < 15; i++) {
392
0
    if (sampling_freq ==
393
0
        pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr->sampling_freq_table[i]) {
394
0
      config->bs_sampling_freq_index = i;
395
0
    }
396
0
  }
397
0
  if (config->bs_sampling_freq_index == 15) {
398
0
    config->bs_sampling_frequency = sampling_freq;
399
0
  }
400
0
  config->bs_frame_length = 31;
401
0
  config->bs_freq_res = 1;
402
0
  config->bs_tree_config = 2;
403
0
  if (config->bs_tree_config > 5) return IA_XHEAAC_MPS_DEC_EXE_FATAL_UNSUPPRORTED_TREE_CONFIG;
404
0
  if (config->bs_tree_config != 15) {
405
0
    curr_state->num_ott_boxes = p_tree_property_table[config->bs_tree_config].num_ott_boxes;
406
0
    curr_state->num_ttt_boxes = p_tree_property_table[config->bs_tree_config].num_ttt_boxes;
407
0
    curr_state->num_input_channels =
408
0
        p_tree_property_table[config->bs_tree_config].num_input_channels;
409
0
    curr_state->num_output_channels =
410
0
        p_tree_property_table[config->bs_tree_config].num_output_channels;
411
0
    memcpy(ott_mode_lfe, p_tree_property_table[config->bs_tree_config].ott_mode_lfe,
412
0
           MAX_NUM_OTT * sizeof(ott_mode_lfe[0]));
413
0
  }
414
0
  config->bs_quant_mode = 0;
415
0
  config->bs_one_icc = 0;
416
0
  config->bs_arbitrary_downmix = 0;
417
0
  config->bs_residual_coding = 0;
418
0
  config->bs_smooth_config = 0;
419
0
  config->bs_fixed_gain_sur = 2;
420
0
  config->bs_fixed_gain_lfe = 1;
421
0
  config->bs_fixed_gain_dmx = 0;
422
0
  config->bs_matrix_mode = 1;
423
0
  config->bs_temp_shape_config = 0;
424
0
  config->bs_decorr_config = 0;
425
0
  if (config->bs_tree_config == 15) {
426
0
    return IA_XHEAAC_MPS_DEC_EXE_FATAL_UNSUPPRORTED_TREE_CONFIG;
427
0
  }
428
0
  for (i = 0; i < curr_state->num_ott_boxes; i++) {
429
0
    if (ott_mode_lfe[i]) {
430
0
      config->bs_ott_bands[i] = 28;
431
0
    }
432
0
  }
433
0
  for (i = 0; i < curr_state->num_ttt_boxes; i++) {
434
0
    config->bs_ttt_dual_mode[i] = 0;
435
0
    config->bs_ttt_mode_low[i] = 1;
436
0
    if (config->bs_ttt_dual_mode[i]) {
437
0
      config->bs_ttt_mode_high[i] = 1;
438
0
      config->bs_ttt_bands_low[i] = 28;
439
0
    }
440
0
  }
441
0
  return IA_NO_ERROR;
442
0
}
443
444
static VOID ixheaacd_coarse_2_fine(WORD32 *data, WORD32 data_type, WORD32 start_band,
445
8.89k
                                   WORD32 num_bands) {
446
8.89k
  WORD32 i;
447
448
112k
  for (i = start_band; i < start_band + num_bands; i++) {
449
103k
    data[i] <<= 1;
450
103k
  }
451
452
8.89k
  if (data_type == CLD) {
453
69.8k
    for (i = start_band; i < start_band + num_bands; i++) {
454
63.7k
      if (data[i] == -14)
455
9.66k
        data[i] = -15;
456
54.0k
      else if (data[i] == 14)
457
10.9k
        data[i] = 15;
458
63.7k
    }
459
6.09k
  }
460
8.89k
}
461
462
7.29k
static VOID ixheaacd_fine_2_coarse(WORD32 *data, WORD32 start_band, WORD32 num_bands) {
463
7.29k
  WORD32 i;
464
465
105k
  for (i = start_band; i < start_band + num_bands; i++) {
466
98.2k
    data[i] >>= 1;
467
98.2k
  }
468
7.29k
}
469
470
static WORD32 ixheaacd_get_stride_map(
471
    WORD32 freq_res_stride, WORD32 start_band, WORD32 stop_band, WORD32 *a_strides,
472
27.7k
    ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
473
27.7k
  WORD32 i, pb, pb_stride, data_bands, str_offset;
474
475
27.7k
  pb_stride = ixheaacd_mps_dec_bitdec_tables->pb_stride_table[freq_res_stride];
476
27.7k
  data_bands = (stop_band - start_band - 1) / pb_stride + 1;
477
478
27.7k
  a_strides[0] = start_band;
479
195k
  for (pb = 1; pb <= data_bands; pb++) {
480
167k
    a_strides[pb] = a_strides[pb - 1] + pb_stride;
481
167k
  }
482
27.7k
  str_offset = 0;
483
156k
  while (a_strides[data_bands] > stop_band) {
484
128k
    if (str_offset < data_bands) str_offset++;
485
264k
    for (i = str_offset; i <= data_bands; i++) {
486
136k
      a_strides[i]--;
487
136k
    }
488
128k
  }
489
490
27.7k
  return data_bands;
491
27.7k
}
492
493
static IA_ERRORCODE ixheaacd_ec_data_dec(ia_heaac_mps_state_struct *pstr_mps_state,
494
                                         ia_mps_dec_lossless_data_struct *ll_data,
495
                                         WORD32 data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
496
                                         WORD32 lastdata[][MAX_PARAMETER_BANDS], WORD32 datatype,
497
                                         WORD32 box_idx, WORD32 param_idx, WORD32 start_band,
498
100k
                                         WORD32 stop_band) {
499
100k
  IA_ERRORCODE error_code = IA_NO_ERROR;
500
100k
  WORD32 i, pb, data_sets, set_idx, bs_data_pair, data_bands, old_quant_coarse_xxx, temp;
501
100k
  WORD32 a_strides[MAX_PARAMETER_BANDS + 1] = {0};
502
503
100k
  ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame;
504
100k
  ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff;
505
506
100k
  data_sets = 0;
507
283k
  for (i = 0; i < pstr_mps_state->num_parameter_sets; i++) {
508
182k
    ll_data->bs_xxx_data_mode[param_idx][i] = ixheaacd_read_bits_buf(mps_bit_buf, 2);
509
182k
    if (ll_data->bs_xxx_data_mode[param_idx][i] == 3) {
510
33.9k
      data_sets++;
511
33.9k
    }
512
182k
  }
513
100k
  set_idx = 0;
514
100k
  old_quant_coarse_xxx = ll_data->bs_quant_coarse_xxx_prev[param_idx];
515
516
128k
  while (set_idx < data_sets) {
517
27.7k
    temp = ixheaacd_read_bits_buf(mps_bit_buf, 4);
518
27.7k
    bs_data_pair = (temp >> 3) & ONE_BIT_MASK;
519
27.7k
    ll_data->bs_quant_coarse_xxx[param_idx][set_idx] = (temp >> 2) & ONE_BIT_MASK;
520
27.7k
    ll_data->bs_freq_res_stride_xxx[param_idx][set_idx] = temp & TWO_BIT_MASK;
521
522
27.7k
    if (set_idx == 7 && bs_data_pair == 1) {
523
6
      if (pstr_mps_state->ec_flag) {
524
0
        bs_data_pair = 0;
525
6
      } else {
526
6
        return IA_FATAL_ERROR;
527
6
      }
528
6
    }
529
530
27.7k
    if (ll_data->bs_quant_coarse_xxx[param_idx][set_idx] != old_quant_coarse_xxx) {
531
8.53k
      if (old_quant_coarse_xxx) {
532
1.24k
        ixheaacd_coarse_2_fine(lastdata[box_idx], datatype, start_band, stop_band - start_band);
533
7.29k
      } else {
534
7.29k
        ixheaacd_fine_2_coarse(lastdata[box_idx], start_band, stop_band - start_band);
535
7.29k
      }
536
8.53k
    }
537
538
27.7k
    data_bands = ixheaacd_get_stride_map(ll_data->bs_freq_res_stride_xxx[param_idx][set_idx],
539
27.7k
                                         start_band, stop_band, a_strides,
540
27.7k
                                         pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr);
541
542
195k
    for (pb = 0; pb < data_bands; pb++) {
543
167k
      lastdata[box_idx][start_band + pb] = lastdata[box_idx][a_strides[pb]];
544
167k
    }
545
546
27.7k
    error_code = ixheaacd_mps_ecdatapairdec(
547
27.7k
        mps_bit_buf, data[box_idx], lastdata[box_idx], datatype, set_idx, start_band, data_bands,
548
27.7k
        bs_data_pair, ll_data->bs_quant_coarse_xxx[param_idx][set_idx],
549
27.7k
        (!frame->bs_independency_flag || (set_idx > 0)), 0, 1, pstr_mps_state->ec_flag);
550
27.7k
    if (error_code != IA_NO_ERROR) return error_code;
551
552
27.7k
    if (datatype == CLD) {
553
20.9k
      WORD32 band;
554
87.7k
      for (i = 0; i < pstr_mps_state->num_parameter_sets; i++) {
555
1.04M
        for (band = start_band; band < stop_band; band++) {
556
979k
          if (data[box_idx][i][band] > 15 || data[box_idx][i][band] < -15) {
557
53
            return IA_FATAL_ERROR;
558
53
          }
559
979k
        }
560
66.8k
      }
561
20.9k
    } else if (datatype == ICC) {
562
5.23k
      WORD32 band;
563
27.6k
      for (i = 0; i < pstr_mps_state->num_parameter_sets; i++) {
564
350k
        for (band = start_band; band < stop_band; band++) {
565
328k
          if (data[box_idx][i][band] > 7 || data[box_idx][i][band] < 0) {
566
44
            return IA_FATAL_ERROR;
567
44
          }
568
328k
        }
569
22.4k
      }
570
5.23k
    }
571
572
192k
    for (pb = 0; pb < data_bands; pb++) {
573
612k
      for (i = a_strides[pb]; i < a_strides[pb + 1]; i++) {
574
447k
        lastdata[box_idx][i] = data[box_idx][set_idx + bs_data_pair][start_band + pb];
575
447k
      }
576
165k
    }
577
578
27.6k
    old_quant_coarse_xxx = ll_data->bs_quant_coarse_xxx[param_idx][set_idx];
579
580
27.6k
    if (bs_data_pair) {
581
17.5k
      ll_data->bs_quant_coarse_xxx[param_idx][set_idx + 1] =
582
17.5k
          ll_data->bs_quant_coarse_xxx[param_idx][set_idx];
583
17.5k
      ll_data->bs_freq_res_stride_xxx[param_idx][set_idx + 1] =
584
17.5k
          ll_data->bs_freq_res_stride_xxx[param_idx][set_idx];
585
17.5k
    }
586
27.6k
    set_idx += bs_data_pair + 1;
587
27.6k
  }
588
100k
  return error_code;
589
100k
}
590
591
static IA_ERRORCODE ixheaacd_parse_arbitrary_downmix_data(
592
1.62k
    ia_heaac_mps_state_struct *pstr_mps_state) {
593
1.62k
  ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame;
594
1.62k
  IA_ERRORCODE error_code = IA_NO_ERROR;
595
1.62k
  WORD32 offset = pstr_mps_state->num_ott_boxes + 4 * pstr_mps_state->num_ttt_boxes;
596
1.62k
  WORD32 num_input_channels = pstr_mps_state->num_input_channels;
597
1.62k
  WORD32 bitstream_parameter_bands = pstr_mps_state->bitstream_parameter_bands;
598
1.62k
  WORD32 ch;
599
600
3.97k
  for (ch = 0; ch < num_input_channels; ch++) {
601
2.37k
    error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data,
602
2.37k
                                      frame->cmp_arbdmx_gain_idx, frame->cmp_arbdmx_gain_idx_prev,
603
2.37k
                                      CLD, ch, offset + ch, 0, bitstream_parameter_bands);
604
2.37k
    if (error_code != IA_NO_ERROR) return error_code;
605
2.37k
  }
606
1.59k
  return error_code;
607
1.62k
}
608
609
5.30k
static WORD32 ixheaacd_decode_icc_diff_code(ia_bit_buf_struct *it_bit_buff) {
610
5.30k
  WORD32 value = 0;
611
5.30k
  WORD32 count = 0;
612
12.7k
  while ((ixheaacd_read_bits_buf(it_bit_buff, 1) == 0) && (count++ < 7)) {
613
7.39k
    value++;
614
7.39k
  }
615
616
5.30k
  return value;
617
5.30k
}
618
619
738
static IA_ERRORCODE ixheaacd_parse_residual_data(ia_heaac_mps_state_struct *pstr_mps_state) {
620
738
  WORD32 ich, ch;
621
738
  WORD32 rfpsf;
622
738
  WORD32 ps;
623
738
  WORD32 pb;
624
625
738
  ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr =
626
738
      pstr_mps_state->ia_mps_dec_mps_table.aac_tab;
627
738
  WORD32 i;
628
629
738
  ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame;
630
738
  ia_mps_spatial_bs_config_struct *config = &(pstr_mps_state->bs_config);
631
632
738
  WORD32 num_ott_boxes = pstr_mps_state->num_ott_boxes;
633
738
  WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
634
738
  WORD32 residual_frames_per_spatial_frame = pstr_mps_state->residual_frames_per_spatial_frame;
635
738
  WORD32 upd_qmf = pstr_mps_state->upd_qmf;
636
637
738
  WORD32 loop_counter = num_ott_boxes + pstr_mps_state->num_ttt_boxes;
638
738
  WORD32 *p_mdct_res;
639
640
738
  WORD32 *p_res_mdct = pstr_mps_state->array_struct->res_mdct;
641
738
  ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff;
642
738
  WORD16 error_code = IA_NO_ERROR;
643
644
3.49k
  for (ich = 0; ich < loop_counter; ich++) {
645
2.83k
    ch = ich;
646
647
2.83k
    p_mdct_res = p_res_mdct;
648
2.83k
    if (config->bs_residual_bands[ch] > 0) {
649
855
      if (ch < num_ott_boxes) {
650
2.54k
        for (ps = 0; ps < num_parameter_sets; ps++) {
651
1.72k
          frame->res_data.bs_icc_diff_present[ch][ps] = ixheaacd_read_bits_buf(mps_bit_buf, 1);
652
1.72k
          if (frame->res_data.bs_icc_diff_present[ch][ps]) {
653
5.70k
            for (pb = 0; pb < config->bs_residual_bands[ch]; pb++) {
654
5.30k
              frame->res_data.bs_icc_diff[ch][ps][pb] =
655
5.30k
                  ixheaacd_decode_icc_diff_code(mps_bit_buf);
656
5.30k
              frame->ott_icc_diff_idx[ch][ps][pb] = frame->res_data.bs_icc_diff[ch][ps][pb];
657
5.30k
            }
658
397
          }
659
1.72k
        }
660
817
      }
661
855
      p_mdct_res = p_res_mdct;
662
1.68k
      for (rfpsf = 0; rfpsf < residual_frames_per_spatial_frame; rfpsf++) {
663
899
        error_code =
664
899
            ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1,
665
899
                                  aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
666
899
        if (error_code) {
667
65
          if (pstr_mps_state->ec_flag) {
668
0
            pstr_mps_state->frame_ok = 0;
669
0
          } else
670
65
            return error_code;
671
65
        }
672
834
        if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
673
201
          ixheaacd_res_ctns_apply(
674
201
              pstr_mps_state->p_aac_decoder_channel_info[0],
675
201
              pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands,
676
201
              aac_tables_ptr);
677
834
        pstr_mps_state->res_block_type[ch][rfpsf] =
678
834
            pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence;
679
840k
        for (i = 0; i < AAC_FRAME_LENGTH; i++) {
680
839k
          *p_mdct_res++ =
681
839k
              (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]);
682
839k
        }
683
684
834
        if ((pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence ==
685
834
             EIGHT_SHORT_SEQUENCE) &&
686
408
            ((upd_qmf == UPD_QMF_18) || (upd_qmf == UPD_QMF_24) || (upd_qmf == UPD_QMF_30))) {
687
72
          error_code =
688
72
              ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1,
689
72
                                    aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
690
72
          if (error_code) {
691
6
            if (pstr_mps_state->ec_flag) {
692
0
              pstr_mps_state->frame_ok = 0;
693
0
            } else
694
6
              return error_code;
695
6
          }
696
66
          if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
697
4
            ixheaacd_res_ctns_apply(
698
4
                pstr_mps_state->p_aac_decoder_channel_info[0],
699
4
                pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands,
700
4
                aac_tables_ptr);
701
47.1k
          for (i = 0; i < AAC_FRAME_LENGTH; i++) {
702
47.1k
            *p_mdct_res++ =
703
47.1k
                (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]);
704
47.1k
          }
705
66
        }
706
834
      }
707
855
    }
708
709
2.76k
    p_res_mdct += RFX2XMDCTCOEF;
710
2.76k
  }
711
667
  return IA_NO_ERROR;
712
738
}
713
714
20.8k
static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *pstr_mps_state) {
715
20.8k
  WORD32 i, fr, gr, offset, ch;
716
20.8k
  WORD32 ext_num, sac_ext_type, sac_ext_len, tmp, bits_read, n_fill_bits, temp;
717
20.8k
  WORD32 channel_grouping[MAX_INPUT_CHANNELS_MPS];
718
719
20.8k
  ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame;
720
20.8k
  ia_mps_spatial_bs_config_struct *p_bs_config = &pstr_mps_state->bs_config;
721
722
20.8k
  ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr =
723
20.8k
      pstr_mps_state->ia_mps_dec_mps_table.aac_tab;
724
725
20.8k
  WORD32 arbdmx_upd_qmf = pstr_mps_state->arbdmx_upd_qmf;
726
20.8k
  WORD32 num_ott_boxes = pstr_mps_state->num_ott_boxes;
727
20.8k
  WORD32 num_input_channels = pstr_mps_state->num_input_channels;
728
20.8k
  WORD32 num_ttt_boxes = pstr_mps_state->num_ttt_boxes;
729
20.8k
  WORD32 arbdmx_frames_per_spatial_frame = pstr_mps_state->arbdmx_frames_per_spatial_frame;
730
20.8k
  WORD32 *p_res_mdct, *p_mdct_res;
731
732
20.8k
  WORD32 sfidx;
733
20.8k
  VOID *free_scratch = pstr_mps_state->mps_scratch_mem_v;
734
20.8k
  ia_mps_dec_residual_sfband_info_struct *p_sfband_info_tab = &pstr_mps_state->sfband_info_tab;
735
20.8k
  ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff;
736
20.8k
  IA_ERRORCODE error_code = IA_NO_ERROR;
737
738
62.5k
  for (ch = 0; ch < 2; ch++) {
739
41.7k
    pstr_mps_state->p_aac_decoder_channel_info[ch] = free_scratch;
740
41.7k
    free_scratch =
741
41.7k
        (WORD8 *)free_scratch +
742
41.7k
        IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_residual_channel_info_struct), BYTE_ALIGN_8);
743
41.7k
    pstr_mps_state->p_aac_decoder_dynamic_data_init[ch] = free_scratch;
744
41.7k
    free_scratch =
745
41.7k
        (WORD8 *)free_scratch +
746
41.7k
        IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_residual_dynamic_data_struct), BYTE_ALIGN_8);
747
41.7k
    pstr_mps_state->p_aac_decoder_channel_info[ch]->p_scale_factor =
748
41.7k
        pstr_mps_state->p_aac_decoder_dynamic_data_init[ch]->a_scale_factor;
749
41.7k
    pstr_mps_state->p_aac_decoder_channel_info[ch]->p_code_book =
750
41.7k
        pstr_mps_state->p_aac_decoder_dynamic_data_init[ch]->a_code_book;
751
41.7k
    pstr_mps_state->p_aac_decoder_channel_info[ch]->p_spectral_coefficient = free_scratch;
752
41.7k
    free_scratch = (WORD8 *)free_scratch + IXHEAAC_GET_SIZE_ALIGNED(4096, BYTE_ALIGN_8);
753
41.7k
    pstr_mps_state->p_aac_decoder_channel_info[ch]->p_tns_scratch = free_scratch;
754
41.7k
    free_scratch = (WORD8 *)free_scratch + IXHEAAC_GET_SIZE_ALIGNED(4096, BYTE_ALIGN_8);
755
41.7k
    pstr_mps_state->p_aac_decoder_channel_info[ch]->ics_info.frame_length = AAC_FRAME_LENGTH;
756
41.7k
    pstr_mps_state->p_aac_decoder_channel_info[ch]->common_window = 0;
757
41.7k
  }
758
20.8k
  if (pstr_mps_state->arbitrary_downmix == 2)
759
362
    sfidx = p_bs_config->bs_arbitrary_downmix_residual_sampling_freq_index;
760
20.4k
  else
761
20.4k
    sfidx = p_bs_config->bs_residual_sampling_freq_index;
762
20.8k
  {
763
20.8k
    WORD16 *psfb_idx[2];
764
20.8k
    const WORD8 *psfb_width[2];
765
20.8k
    WORD width_idx;
766
20.8k
    WORD32 j;
767
768
20.8k
    pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.sampling_rate_index = sfidx;
769
20.8k
    psfb_idx[0] = p_sfband_info_tab->sfb_long_idx;
770
20.8k
    psfb_idx[1] = p_sfband_info_tab->sfb_short_idx;
771
20.8k
    psfb_width[0] = aac_tables_ptr->scale_factor_bands_long[sfidx];
772
20.8k
    psfb_width[1] = aac_tables_ptr->scale_factor_bands_short[sfidx];
773
774
62.5k
    for (j = 1; j >= 0; j--) {
775
41.7k
      const WORD8 *ptr_w = psfb_width[j];
776
41.7k
      WORD16 *ptr_i = psfb_idx[j];
777
41.7k
      width_idx = 0;
778
41.7k
      *ptr_i++ = width_idx;
779
1.11M
      do {
780
1.11M
        width_idx += (*ptr_w++);
781
1.11M
        *ptr_i++ = width_idx;
782
1.11M
      } while (*ptr_w != -1);
783
784
41.7k
      pstr_mps_state->tot_sf_bands_ls[j] = (WORD8)(ptr_w - psfb_width[j]);
785
41.7k
    }
786
787
20.8k
    {
788
20.8k
      aac_tables_ptr->sfb_index_long = p_sfband_info_tab->sfb_long_idx;
789
20.8k
      aac_tables_ptr->sfb_index_short = p_sfband_info_tab->sfb_short_idx;
790
20.8k
      aac_tables_ptr->sfb_index_long_width = (WORD8 *)psfb_width[0];
791
20.8k
      aac_tables_ptr->sfb_index_short_width = (WORD8 *)psfb_width[1];
792
20.8k
    }
793
20.8k
  }
794
795
21.7k
  for (ext_num = 0; ext_num < p_bs_config->sac_ext_cnt; ext_num++) {
796
1.11k
    sac_ext_type = p_bs_config->bs_sac_ext_type[ext_num];
797
798
1.11k
    if (sac_ext_type < 12) {
799
1.11k
      sac_ext_len = ixheaacd_read_bits_buf(mps_bit_buf, 8);
800
1.11k
      if (sac_ext_len == 255) {
801
5
        sac_ext_len += ixheaacd_read_bits_buf(mps_bit_buf, 16);
802
5
      }
803
804
1.11k
      tmp = (WORD32)(((mps_bit_buf->ptr_read_next - mps_bit_buf->ptr_bit_buf_base + 1) << 3) -
805
1.11k
                     (mps_bit_buf->bit_pos + 1));
806
807
1.11k
      switch (sac_ext_type) {
808
738
        case EXT_TYPE_0:
809
738
          error_code = ixheaacd_parse_residual_data(pstr_mps_state);
810
738
          if (error_code) {
811
71
            if (pstr_mps_state->ec_flag) {
812
0
              pstr_mps_state->frame_ok = 0;
813
0
            } else
814
71
              return error_code;
815
71
          }
816
667
          break;
817
818
667
        case EXT_TYPE_1:
819
356
          switch (num_input_channels) {
820
281
            case IN_CH_1:
821
281
              channel_grouping[0] = 1;
822
281
              break;
823
69
            case IN_CH_2:
824
69
              channel_grouping[0] = 2;
825
69
              break;
826
6
            case IN_CH_6:
827
6
              channel_grouping[0] = 2;
828
6
              channel_grouping[1] = 2;
829
6
              channel_grouping[2] = 2;
830
6
              break;
831
0
            default:
832
0
              return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_INPUT_CHANNEL;
833
0
              break;
834
356
          }
835
836
356
          offset = num_ott_boxes + num_ttt_boxes;
837
838
356
          p_res_mdct = pstr_mps_state->array_struct->res_mdct + offset * RFX2XMDCTCOEF;
839
840
677
          for (ch = 0, gr = 0; ch < num_input_channels; ch += channel_grouping[gr++]) {
841
367
            p_mdct_res = p_res_mdct;
842
843
367
            temp = ixheaacd_read_bits_buf(mps_bit_buf, 2);
844
367
            frame->bs_arbitrary_downmix_residual_abs[ch] = (temp >> 1) & ONE_BIT_MASK;
845
367
            frame->bs_arbitrary_downmix_residual_alpha_update_set[ch] = temp & ONE_BIT_MASK;
846
847
367
            if (channel_grouping[gr] == 1) {
848
541
              for (fr = 0; fr < arbdmx_frames_per_spatial_frame; fr++) {
849
291
                error_code =
850
291
                    ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info,
851
291
                                          1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
852
291
                if (error_code) {
853
30
                  if (pstr_mps_state->ec_flag) {
854
0
                    pstr_mps_state->frame_ok = 0;
855
0
                  } else
856
30
                    return error_code;
857
30
                }
858
261
                if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
859
54
                  ixheaacd_res_ctns_apply(
860
54
                      pstr_mps_state->p_aac_decoder_channel_info[0],
861
54
                      pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands,
862
54
                      aac_tables_ptr);
863
864
261
                pstr_mps_state->res_block_type[offset + ch][fr] =
865
261
                    pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence;
866
264k
                for (i = 0; i < AAC_FRAME_LENGTH; i++) {
867
264k
                  *p_mdct_res++ =
868
264k
                      (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]);
869
264k
                }
870
871
261
                if ((pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence ==
872
261
                     EIGHT_SHORT_SEQUENCE) &&
873
17
                    ((arbdmx_upd_qmf == UPD_QMF_18) || (arbdmx_upd_qmf == UPD_QMF_24) ||
874
14
                     (arbdmx_upd_qmf == UPD_QMF_30))) {
875
5
                  error_code = ixheaacd_res_read_ics(
876
5
                      mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, aac_tables_ptr,
877
5
                      pstr_mps_state->tot_sf_bands_ls);
878
5
                  if (error_code) {
879
1
                    if (pstr_mps_state->ec_flag) {
880
0
                      pstr_mps_state->frame_ok = 0;
881
0
                    } else
882
1
                      return error_code;
883
1
                  }
884
4
                  if (1 ==
885
4
                      pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
886
1
                    ixheaacd_res_ctns_apply(
887
1
                        pstr_mps_state->p_aac_decoder_channel_info[0],
888
1
                        pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands,
889
1
                        aac_tables_ptr);
890
4.10k
                  for (i = 0; i < AAC_FRAME_LENGTH; i++) {
891
4.09k
                    *p_mdct_res++ = (pstr_mps_state->p_aac_decoder_channel_info[0]
892
4.09k
                                         ->p_spectral_coefficient[i]);
893
4.09k
                  }
894
4
                }
895
261
              }
896
250
              p_res_mdct += RFX2XMDCTCOEF;
897
250
            } else {
898
86
              frame->bs_arbitrary_downmix_residual_abs[ch + 1] =
899
86
                  frame->bs_arbitrary_downmix_residual_abs[ch];
900
86
              frame->bs_arbitrary_downmix_residual_alpha_update_set[ch + 1] =
901
86
                  frame->bs_arbitrary_downmix_residual_alpha_update_set[ch];
902
903
177
              for (fr = 0; fr < arbdmx_frames_per_spatial_frame; fr++) {
904
106
                WORD32 *res_mdct_1 = p_mdct_res + RFX2XMDCTCOEF;
905
106
                WORD32 temp, win1, win2;
906
106
                temp = ixheaacd_read_bits_buf(mps_bit_buf, 4);
907
106
                temp = ixheaacd_read_bits_buf(mps_bit_buf, 1);
908
909
106
                if (temp != 0) {
910
1
                  return IA_XHEAAC_MPS_DEC_EXE_FATAL_NONZERO_BIT;
911
1
                }
912
913
105
                error_code =
914
105
                    ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info,
915
105
                                          1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
916
105
                if (error_code) {
917
2
                  if (pstr_mps_state->ec_flag) {
918
0
                    pstr_mps_state->frame_ok = 0;
919
0
                  } else
920
2
                    return error_code;
921
2
                }
922
923
103
                if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
924
1
                  ixheaacd_res_ctns_apply(
925
1
                      pstr_mps_state->p_aac_decoder_channel_info[0],
926
1
                      pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands,
927
1
                      aac_tables_ptr);
928
103
                win1 = pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence;
929
103
                pstr_mps_state->res_block_type[offset + ch][fr] =
930
103
                    pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence;
931
932
104k
                for (i = 0; i < AAC_FRAME_LENGTH; i++) {
933
104k
                  *p_mdct_res++ =
934
104k
                      (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]);
935
104k
                }
936
937
103
                error_code =
938
103
                    ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info,
939
103
                                          1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
940
103
                if (error_code) {
941
2
                  if (pstr_mps_state->ec_flag) {
942
0
                    pstr_mps_state->frame_ok = 0;
943
0
                  } else
944
2
                    return error_code;
945
2
                }
946
947
101
                if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
948
13
                  ixheaacd_res_ctns_apply(
949
13
                      pstr_mps_state->p_aac_decoder_channel_info[0],
950
13
                      pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands,
951
13
                      aac_tables_ptr);
952
101
                win2 = pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence;
953
95.3k
                for (i = 0; i < AAC_FRAME_LENGTH; i++) {
954
95.2k
                  *res_mdct_1++ =
955
95.2k
                      (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]);
956
95.2k
                }
957
958
101
                if (win1 != win2) return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_WINDOW_SEQUENCE;
959
960
97
                if ((win1 == EIGHT_SHORT_SEQUENCE) &&
961
17
                    ((arbdmx_upd_qmf == UPD_QMF_18) || (arbdmx_upd_qmf == UPD_QMF_24) ||
962
15
                     (arbdmx_upd_qmf == UPD_QMF_30))) {
963
15
                  temp = ixheaacd_read_bits_buf(mps_bit_buf, 4);
964
15
                  temp = ixheaacd_read_bits_buf(mps_bit_buf, 1);
965
966
15
                  if (temp != 0) {
967
1
                    return IA_XHEAAC_MPS_DEC_EXE_FATAL_NONZERO_BIT;
968
1
                  }
969
970
14
                  error_code = ixheaacd_res_read_ics(
971
14
                      mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, aac_tables_ptr,
972
14
                      pstr_mps_state->tot_sf_bands_ls);
973
14
                  if (error_code) {
974
1
                    if (pstr_mps_state->ec_flag) {
975
0
                      pstr_mps_state->frame_ok = 0;
976
0
                    } else
977
1
                      return error_code;
978
1
                  }
979
980
13
                  if (1 ==
981
13
                      pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
982
2
                    ixheaacd_res_ctns_apply(
983
2
                        pstr_mps_state->p_aac_decoder_channel_info[0],
984
2
                        pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands,
985
2
                        aac_tables_ptr);
986
13
                  win1 = pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence;
987
988
12.3k
                  for (i = 0; i < AAC_FRAME_LENGTH; i++) {
989
12.2k
                    *p_mdct_res++ = (pstr_mps_state->p_aac_decoder_channel_info[0]
990
12.2k
                                         ->p_spectral_coefficient[i]);
991
12.2k
                  }
992
993
13
                  error_code = ixheaacd_res_read_ics(
994
13
                      mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, aac_tables_ptr,
995
13
                      pstr_mps_state->tot_sf_bands_ls);
996
13
                  if (error_code) {
997
1
                    if (pstr_mps_state->ec_flag) {
998
0
                      pstr_mps_state->frame_ok = 0;
999
0
                    } else
1000
1
                      return error_code;
1001
1
                  }
1002
1003
12
                  if (1 ==
1004
12
                      pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
1005
2
                    ixheaacd_res_ctns_apply(
1006
2
                        pstr_mps_state->p_aac_decoder_channel_info[0],
1007
2
                        pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands,
1008
2
                        aac_tables_ptr);
1009
12
                  win2 = pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence;
1010
10.2k
                  for (i = 0; i < AAC_FRAME_LENGTH; i++) {
1011
10.2k
                    *res_mdct_1++ = (pstr_mps_state->p_aac_decoder_channel_info[0]
1012
10.2k
                                         ->p_spectral_coefficient[i]);
1013
10.2k
                  }
1014
1015
12
                  if (win1 != win2) return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_WINDOW_SEQUENCE;
1016
12
                }
1017
97
              }
1018
71
              p_res_mdct += RFX2XMDCTCOEF;
1019
71
            }
1020
367
          }
1021
1022
310
          break;
1023
1024
310
        case EXT_TYPE_2:
1025
19
          for (i = 0; i < p_bs_config->num_ott_boxes_at; i++) {
1026
9
            error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data,
1027
9
                                              frame->cmp_ott_cld_idx, frame->cmp_ott_cld_idx_prev,
1028
9
                                              CLD, num_ott_boxes + i, num_ott_boxes + i, 0,
1029
9
                                              p_bs_config->bs_ott_bands_at[i]);
1030
9
            if (error_code != IA_NO_ERROR) return error_code;
1031
9
          }
1032
1033
10
          break;
1034
1035
10
        default:
1036
0
          return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_EXTENSION_TYPE;
1037
1.11k
      }
1038
1039
921
      bits_read =
1040
921
          (WORD32)(((mps_bit_buf->ptr_read_next - mps_bit_buf->ptr_bit_buf_base + 1) << 3) -
1041
921
                   (mps_bit_buf->bit_pos + 1) - tmp);
1042
921
      n_fill_bits = (sac_ext_len << 3) - bits_read;
1043
1044
1.44k
      while (n_fill_bits > 7) {
1045
520
        ixheaacd_read_bits_buf(mps_bit_buf, 8);
1046
520
        n_fill_bits -= 8;
1047
520
      }
1048
921
      if (n_fill_bits > 0) {
1049
4
        ixheaacd_read_bits_buf(mps_bit_buf, n_fill_bits);
1050
4
      }
1051
921
    }
1052
1.11k
  }
1053
20.6k
  return IA_NO_ERROR;
1054
20.8k
}
1055
1056
21.1k
IA_ERRORCODE ixheaacd_parse_frame(ia_heaac_mps_state_struct *pstr_mps_state) {
1057
21.1k
  ia_mps_spatial_bs_config_struct *p_bs_config = &pstr_mps_state->bs_config;
1058
1059
21.1k
  ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
1060
21.1k
  WORD32 i, bs_framing_type, prev_param_slot, data_bands, bs_temp_shape_enable,
1061
21.1k
      num_temp_shape_chan;
1062
21.1k
  WORD32 ttt_off, ps, pg, ts, pb, temp;
1063
21.1k
  WORD32 *bs_env_shape_data = pstr_mps_state->mps_scratch_mem_v;
1064
21.1k
  WORD32 const *reciprocal_tab = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->reciprocal;
1065
21.1k
  WORD32 num_parameter_sets;
1066
1067
21.1k
  ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame;
1068
21.1k
  ia_mps_dec_bitdec_tables_struct *bitdec_table =
1069
21.1k
      pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr;
1070
21.1k
  WORD32 bs_num_output_channels =
1071
21.1k
      bitdec_table->tree_property_table[pstr_mps_state->tree_config].num_output_channels;
1072
1073
21.1k
  WORD32 time_slots = pstr_mps_state->time_slots;
1074
21.1k
  WORD32 bitstream_parameter_bands = pstr_mps_state->bitstream_parameter_bands;
1075
21.1k
  WORD32 *b_ott_bands = pstr_mps_state->bitstream_ott_bands;
1076
21.1k
  WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot;
1077
1078
21.1k
  WORD32 num_ott_boxes = pstr_mps_state->num_ott_boxes;
1079
1080
21.1k
  WORD32 reciprocal, alignment_bits = 0;
1081
21.1k
  ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff;
1082
21.1k
  IA_ERRORCODE error_code = IA_NO_ERROR;
1083
1084
21.1k
  if (pstr_mps_state->parse_next_bitstream_frame == 0) return IA_NO_ERROR;
1085
1086
21.1k
  temp = ixheaacd_read_bits_buf(mps_bit_buf, 4);
1087
21.1k
  bs_framing_type = (temp >> 3) & ONE_BIT_MASK;
1088
21.1k
  num_parameter_sets = (temp & THREE_BIT_MASK) + 1;
1089
21.1k
  pstr_mps_state->num_parameter_sets = num_parameter_sets;
1090
1091
21.1k
  reciprocal = reciprocal_tab[num_parameter_sets - 1];
1092
1093
21.1k
  prev_param_slot = -1;
1094
56.7k
  for (i = 0; i < num_parameter_sets; i++) {
1095
35.5k
    if (bs_framing_type) {
1096
11.5k
      WORD32 bits_param_slot = 0;
1097
51.4k
      while ((1 << bits_param_slot) < (time_slots - num_parameter_sets + i - prev_param_slot))
1098
39.8k
        bits_param_slot++;
1099
11.5k
      param_slot[i] =
1100
11.5k
          bits_param_slot
1101
11.5k
              ? prev_param_slot + 1 + ixheaacd_read_bits_buf(mps_bit_buf, bits_param_slot)
1102
11.5k
              : prev_param_slot + 1;
1103
11.5k
      prev_param_slot = param_slot[i];
1104
23.9k
    } else {
1105
23.9k
      WORD64 temp = (WORD64)(
1106
23.9k
          ((WORD64)((time_slots * (i + 1)) + num_parameter_sets - 1) * (WORD64)reciprocal) >> 28);
1107
23.9k
      param_slot[i] = (WORD32)(temp - 1);
1108
23.9k
    }
1109
35.5k
  }
1110
21.1k
  frame->bs_independency_flag = ixheaacd_read_bits_buf(mps_bit_buf, 1);
1111
1112
72.3k
  for (i = 0; i < num_ott_boxes; i++) {
1113
51.2k
    error_code =
1114
51.2k
        ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data, frame->cmp_ott_cld_idx,
1115
51.2k
                             frame->cmp_ott_cld_idx_prev, CLD, i, i, 0, b_ott_bands[i]);
1116
51.2k
    if (error_code != IA_NO_ERROR) return error_code;
1117
51.2k
  }
1118
21.1k
  if (pstr_mps_state->one_icc) {
1119
4.75k
    error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->icc_lossless_data,
1120
4.75k
                                      frame->cmp_ott_icc_idx, frame->cmp_ott_icc_idx_prev, ICC, 0,
1121
4.75k
                                      0, 0, bitstream_parameter_bands);
1122
4.75k
    if (error_code != IA_NO_ERROR) return error_code;
1123
16.3k
  } else {
1124
50.5k
    for (i = 0; i < num_ott_boxes; i++) {
1125
34.2k
      if (!pstr_mps_state->ott_mode_lfe[i]) {
1126
33.4k
        error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->icc_lossless_data,
1127
33.4k
                                          frame->cmp_ott_icc_idx, frame->cmp_ott_icc_idx_prev,
1128
33.4k
                                          ICC, i, i, 0, b_ott_bands[i]);
1129
33.4k
        if (error_code != IA_NO_ERROR) return error_code;
1130
33.4k
      }
1131
34.2k
    }
1132
16.3k
  }
1133
1134
21.0k
  ttt_off = num_ott_boxes;
1135
23.8k
  for (i = 0; i < pstr_mps_state->num_ttt_boxes; i++) {
1136
2.74k
    if (p_aux_struct->ttt_config[0][i].mode < 2) {
1137
1.18k
      error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cpc_lossless_data,
1138
1.18k
                                        frame->cmp_ttt_cpc_1_idx, frame->cmp_ttt_cpc_1_idx_prev,
1139
1.18k
                                        CPC, i, ttt_off + 4 * i,
1140
1.18k
                                        p_aux_struct->ttt_config[0][i].bitstream_start_band,
1141
1.18k
                                        p_aux_struct->ttt_config[0][i].bitstream_stop_band);
1142
1.18k
      if (error_code != IA_NO_ERROR) return error_code;
1143
1144
1.18k
      error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cpc_lossless_data,
1145
1.18k
                                        frame->cmp_ttt_cpc_2_idx, frame->cmp_ttt_cpc_2_idx_prev,
1146
1.18k
                                        CPC, i, ttt_off + 4 * i + 1,
1147
1.18k
                                        p_aux_struct->ttt_config[0][i].bitstream_start_band,
1148
1.18k
                                        p_aux_struct->ttt_config[0][i].bitstream_stop_band);
1149
1.18k
      if (error_code != IA_NO_ERROR) return error_code;
1150
1151
1.17k
      error_code =
1152
1.17k
          ixheaacd_ec_data_dec(pstr_mps_state, &frame->icc_lossless_data, frame->cmp_ttt_icc_idx,
1153
1.17k
                               frame->cmp_ttt_icc_idx_prev, ICC, i, ttt_off + 4 * i,
1154
1.17k
                               p_aux_struct->ttt_config[0][i].bitstream_start_band,
1155
1.17k
                               p_aux_struct->ttt_config[0][i].bitstream_stop_band);
1156
1.17k
      if (error_code != IA_NO_ERROR) return error_code;
1157
1.56k
    } else {
1158
1.56k
      error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data,
1159
1.56k
                                        frame->cmp_ttt_cld_1_idx, frame->cmp_ttt_cld_1_idx_prev,
1160
1.56k
                                        CLD, i, ttt_off + 4 * i,
1161
1.56k
                                        p_aux_struct->ttt_config[0][i].bitstream_start_band,
1162
1.56k
                                        p_aux_struct->ttt_config[0][i].bitstream_stop_band);
1163
1.56k
      if (error_code != IA_NO_ERROR) return error_code;
1164
1165
1.56k
      error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data,
1166
1.56k
                                        frame->cmp_ttt_cld_2_idx, frame->cmp_ttt_cld_2_idx_prev,
1167
1.56k
                                        CLD, i, ttt_off + 4 * i + 1,
1168
1.56k
                                        p_aux_struct->ttt_config[0][i].bitstream_start_band,
1169
1.56k
                                        p_aux_struct->ttt_config[0][i].bitstream_stop_band);
1170
1.56k
      if (error_code != IA_NO_ERROR) return error_code;
1171
1.56k
    }
1172
1173
2.73k
    if (p_aux_struct->ttt_config[1][i].bitstream_start_band <
1174
2.73k
        p_aux_struct->ttt_config[1][i].bitstream_stop_band) {
1175
1.00k
      if (p_aux_struct->ttt_config[1][i].mode < 2) {
1176
273
        error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cpc_lossless_data,
1177
273
                                          frame->cmp_ttt_cpc_1_idx, frame->cmp_ttt_cpc_1_idx_prev,
1178
273
                                          CPC, i, ttt_off + 4 * i + 2,
1179
273
                                          p_aux_struct->ttt_config[1][i].bitstream_start_band,
1180
273
                                          p_aux_struct->ttt_config[1][i].bitstream_stop_band);
1181
273
        if (error_code != IA_NO_ERROR) return error_code;
1182
1183
272
        error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cpc_lossless_data,
1184
272
                                          frame->cmp_ttt_cpc_2_idx, frame->cmp_ttt_cpc_2_idx_prev,
1185
272
                                          CPC, i, ttt_off + 4 * i + 3,
1186
272
                                          p_aux_struct->ttt_config[1][i].bitstream_start_band,
1187
272
                                          p_aux_struct->ttt_config[1][i].bitstream_stop_band);
1188
272
        if (error_code != IA_NO_ERROR) return error_code;
1189
1190
271
        error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->icc_lossless_data,
1191
271
                                          frame->cmp_ttt_icc_idx, frame->cmp_ttt_icc_idx_prev,
1192
271
                                          ICC, i, ttt_off + 4 * i + 2,
1193
271
                                          p_aux_struct->ttt_config[1][i].bitstream_start_band,
1194
271
                                          p_aux_struct->ttt_config[1][i].bitstream_stop_band);
1195
271
        if (error_code != IA_NO_ERROR) return error_code;
1196
734
      } else {
1197
734
        error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data,
1198
734
                                          frame->cmp_ttt_cld_1_idx, frame->cmp_ttt_cld_1_idx_prev,
1199
734
                                          CLD, i, ttt_off + 4 * i + 2,
1200
734
                                          p_aux_struct->ttt_config[1][i].bitstream_start_band,
1201
734
                                          p_aux_struct->ttt_config[1][i].bitstream_stop_band);
1202
734
        if (error_code != IA_NO_ERROR) return error_code;
1203
1204
733
        error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data,
1205
733
                                          frame->cmp_ttt_cld_2_idx, frame->cmp_ttt_cld_2_idx_prev,
1206
733
                                          CLD, i, ttt_off + 4 * i + 3,
1207
733
                                          p_aux_struct->ttt_config[1][i].bitstream_start_band,
1208
733
                                          p_aux_struct->ttt_config[1][i].bitstream_stop_band);
1209
733
        if (error_code != IA_NO_ERROR) return error_code;
1210
733
      }
1211
1.00k
    }
1212
2.73k
  }
1213
1214
21.0k
  frame->bs_smooth_control = 1;
1215
1216
21.0k
  if (frame->bs_smooth_control) {
1217
55.3k
    for (ps = 0; ps < num_parameter_sets; ps++) {
1218
34.4k
      frame->bs_smooth_mode[ps] = ixheaacd_read_bits_buf(mps_bit_buf, 2);
1219
34.4k
      if (frame->bs_smooth_mode[ps] > 3 || frame->bs_smooth_mode[ps] < 0) {
1220
0
        return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_SMOOTH_MODE;
1221
0
      }
1222
34.4k
      if (frame->bs_smooth_mode[ps] >= 2) {
1223
8.35k
        frame->bs_smooth_time[ps] = ixheaacd_read_bits_buf(mps_bit_buf, 2);
1224
8.35k
      }
1225
34.4k
      if (frame->bs_smooth_mode[ps] == 3) {
1226
2.93k
        frame->bs_freq_res_stride_smg[ps] = ixheaacd_read_bits_buf(mps_bit_buf, 2);
1227
2.93k
        data_bands = (bitstream_parameter_bands - 1) /
1228
2.93k
                         bitdec_table->pb_stride_table[frame->bs_freq_res_stride_smg[ps]] +
1229
2.93k
                     1;
1230
17.0k
        for (pg = 0; pg < data_bands; pg++) {
1231
14.0k
          frame->bs_smg_data[ps][pg] = ixheaacd_read_bits_buf(mps_bit_buf, 1);
1232
14.0k
        }
1233
2.93k
      }
1234
34.4k
    }
1235
20.9k
  }
1236
1237
183k
  for (i = 0; i < bs_num_output_channels; i++) {
1238
162k
    p_aux_struct->temp_shape_enable_channel_stp[i] = 0;
1239
162k
    p_aux_struct->temp_shape_enable_channel_ges[i] = 0;
1240
162k
  }
1241
1242
21.0k
  if (p_bs_config->bs_temp_shape_config != 0) {
1243
20.1k
    bs_temp_shape_enable = ixheaacd_read_bits_buf(mps_bit_buf, 1);
1244
20.1k
    if (bs_temp_shape_enable) {
1245
4.57k
      num_temp_shape_chan =
1246
4.57k
          bitdec_table->temp_shape_chan_table[p_bs_config->bs_temp_shape_config - 1]
1247
4.57k
                                             [p_bs_config->bs_tree_config];
1248
4.57k
      switch (pstr_mps_state->temp_shape_config) {
1249
1.31k
        case 1:
1250
7.21k
          for (i = 0; i < num_temp_shape_chan; i++) {
1251
5.89k
            p_aux_struct->temp_shape_enable_channel_stp[i] =
1252
5.89k
                ixheaacd_read_bits_buf(mps_bit_buf, 1);
1253
5.89k
          }
1254
1.31k
          break;
1255
3.26k
        case 2:
1256
16.7k
          for (i = 0; i < num_temp_shape_chan; i++) {
1257
13.4k
            p_aux_struct->temp_shape_enable_channel_ges[i] =
1258
13.4k
                ixheaacd_read_bits_buf(mps_bit_buf, 1);
1259
13.4k
          }
1260
16.6k
          for (i = 0; i < num_temp_shape_chan; i++) {
1261
13.4k
            if (p_aux_struct->temp_shape_enable_channel_ges[i]) {
1262
1.83k
              WORD32 const *envshape_data =
1263
1.83k
                  &bitdec_table->envshape_data[pstr_mps_state->env_quant_mode][0];
1264
1.83k
              ixheaacd_mps_huff_decode(mps_bit_buf, bs_env_shape_data, time_slots);
1265
51.5k
              for (ts = 0; ts < time_slots; ts++) {
1266
49.6k
                p_aux_struct->env_shape_data[i][ts] = envshape_data[bs_env_shape_data[ts]];
1267
49.6k
              }
1268
1.83k
            }
1269
13.4k
          }
1270
3.26k
          break;
1271
0
        default:
1272
0
          return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_TEMPORAL_SHAPING_CONFIG;
1273
4.57k
      }
1274
4.57k
    }
1275
20.1k
  }
1276
1277
21.0k
  if (pstr_mps_state->up_mix_type == 2) {
1278
0
    for (i = 0; i < bs_num_output_channels; i++) {
1279
0
      p_aux_struct->temp_shape_enable_channel_stp[i] = 0;
1280
0
      p_aux_struct->temp_shape_enable_channel_ges[i] = 0;
1281
0
    }
1282
0
  }
1283
1284
21.0k
  if (pstr_mps_state->arbitrary_downmix != 0) {
1285
1.62k
    ixheaacd_parse_arbitrary_downmix_data(pstr_mps_state);
1286
1.62k
  }
1287
1288
21.0k
  ixheaacd_byte_align(mps_bit_buf, &alignment_bits);
1289
21.0k
  error_code = ixheaacd_parse_extension_frame(pstr_mps_state);
1290
21.0k
  if (error_code) {
1291
118
    if (pstr_mps_state->ec_flag) {
1292
0
      pstr_mps_state->frame_ok = 0;
1293
0
    }
1294
118
    else
1295
118
      return error_code;
1296
118
  }
1297
1298
70.1k
  for (i = 0; i < num_ott_boxes; i++) {
1299
138k
    for (ps = 0; ps < num_parameter_sets; ps++) {
1300
89.3k
      if (!frame->res_data.bs_icc_diff_present[i][ps] || (pstr_mps_state->up_mix_type == 2) ||
1301
89.1k
          (pstr_mps_state->up_mix_type == 3)) {
1302
1.56M
        for (pb = 0; pb < bitstream_parameter_bands; pb++) {
1303
1.47M
          pstr_mps_state->bs_frame->ott_icc_diff_idx[i][ps][pb] = 0;
1304
1.47M
        }
1305
89.1k
      }
1306
89.3k
    }
1307
49.2k
  }
1308
1309
20.9k
  pstr_mps_state->parse_next_bitstream_frame = 1;
1310
1311
20.9k
  return IA_NO_ERROR;
1312
21.0k
}
1313
1314
static VOID ixheaacd_create_mapping(WORD32 a_map[MAX_PARAMETER_BANDS + 1], WORD32 start_band,
1315
39.1k
                                    WORD32 stop_band, WORD32 stride, VOID *scratch) {
1316
39.1k
  WORD32 in_bands, out_bands, bands_achived, bands_diff, incr, k, i;
1317
39.1k
  WORD32 *v_dk;
1318
39.1k
  in_bands = stop_band - start_band;
1319
39.1k
  out_bands = (in_bands - 1) / stride + 1;
1320
39.1k
  v_dk = scratch;
1321
39.1k
  if (out_bands < 1) {
1322
16
    out_bands = 1;
1323
16
  }
1324
1325
39.1k
  bands_achived = out_bands * stride;
1326
39.1k
  bands_diff = in_bands - bands_achived;
1327
245k
  for (i = 0; i < out_bands; i++) {
1328
206k
    v_dk[i] = stride;
1329
206k
  }
1330
1331
39.1k
  if (bands_diff > 0) {
1332
0
    incr = -1;
1333
0
    k = out_bands - 1;
1334
39.1k
  } else {
1335
39.1k
    incr = 1;
1336
39.1k
    k = 0;
1337
39.1k
  }
1338
1339
254k
  while (bands_diff != 0) {
1340
214k
    v_dk[k] = v_dk[k] - incr;
1341
214k
    k = k + incr;
1342
214k
    bands_diff = bands_diff + incr;
1343
214k
    if (k >= out_bands) {
1344
210k
      if (bands_diff > 0) {
1345
0
        k = out_bands - 1;
1346
210k
      } else if (bands_diff < 0) {
1347
194k
        k = 0;
1348
194k
      }
1349
210k
    }
1350
214k
  }
1351
39.1k
  a_map[0] = start_band;
1352
245k
  for (i = 0; i < out_bands; i++) {
1353
206k
    a_map[i + 1] = a_map[i] + v_dk[i];
1354
206k
  }
1355
39.1k
}
1356
1357
static VOID ixheaacd_map_frequency(WORD32 *p_input, WORD32 *p_output, WORD32 *p_map,
1358
36.4k
                                   WORD32 data_bands) {
1359
36.4k
  WORD32 i, j, start_band, stop_band, value;
1360
36.4k
  WORD32 start_band_0 = p_map[0];
1361
1362
230k
  for (i = 0; i < data_bands; i++) {
1363
193k
    value = p_input[i + start_band_0];
1364
1365
193k
    start_band = p_map[i];
1366
193k
    stop_band = p_map[i + 1];
1367
765k
    for (j = start_band; j < stop_band; j++) {
1368
571k
      p_output[j] = value;
1369
571k
    }
1370
193k
  }
1371
36.4k
}
1372
1373
static IA_ERRORCODE ixheaacd_deq_coarse(
1374
    WORD32 value, WORD32 param_type, WORD32 *dequant,
1375
268k
    ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
1376
268k
  switch (param_type) {
1377
98.2k
    case CLD:
1378
98.2k
      if (value >= 8 || value < -7) return IA_FATAL_ERROR;
1379
98.2k
      *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_cld_coarse[value + 7];
1380
98.2k
      break;
1381
1382
150k
    case ICC:
1383
150k
      if (value >= 8 || value < 0) return IA_FATAL_ERROR;
1384
150k
      *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_icc[value];
1385
150k
      break;
1386
1387
19.1k
    case CPC:
1388
19.1k
      if (value >= 16 || value < -10) return IA_FATAL_ERROR;
1389
19.1k
      *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_cpc_coarse[value + 10];
1390
19.1k
      break;
1391
0
    default:
1392
0
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_DEQUANT_PARAM;
1393
268k
  }
1394
268k
  return IA_NO_ERROR;
1395
268k
}
1396
1397
static IA_ERRORCODE ia_mps_dec_deq(
1398
    WORD32 value, WORD32 param_type, WORD32 *dequant,
1399
2.91M
    ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
1400
2.91M
  switch (param_type) {
1401
1.65M
    case CLD:
1402
1.65M
      if (value >= 16 || value < -15) return IA_FATAL_ERROR;
1403
1.64M
      *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_cld[value + 15];
1404
1.64M
      break;
1405
1406
1.22M
    case ICC:
1407
1.22M
      if (value >= 8 || value < 0) return IA_FATAL_ERROR;
1408
1.21M
      *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_icc[value];
1409
1.21M
      break;
1410
1411
41.3k
    case CPC:
1412
41.3k
      if (value >= 32 || value < -20) return IA_FATAL_ERROR;
1413
41.1k
      *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_cpc[value + 20];
1414
41.1k
      break;
1415
1416
0
    default:
1417
0
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_DEQUANT_PARAM;
1418
2.91M
  }
1419
2.90M
  return IA_NO_ERROR;
1420
2.91M
}
1421
1422
static IA_ERRORCODE ixheaacd_factor_funct(WORD32 ott_vs_tot_db, WORD32 quant_mode,
1423
113k
                                          WORD32 *factor) {
1424
113k
  WORD32 db_diff;
1425
113k
  WORD32 x_linear = 0;
1426
1427
113k
  WORD32 maxfactor = 0;
1428
113k
  WORD32 constfact;
1429
1430
113k
  if (ott_vs_tot_db > 0) return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_MPS_PARAM;
1431
112k
  db_diff = ixheaac_negate32_sat(ott_vs_tot_db);
1432
1433
112k
  switch (quant_mode) {
1434
0
    case QUANT_MODE_0:
1435
0
      return (ONE_IN_Q24);
1436
0
      break;
1437
18.4k
    case QUANT_MODE_1:
1438
18.4k
      x_linear = 1024;
1439
1440
18.4k
      maxfactor = 83886080;
1441
18.4k
      constfact = 3277;
1442
18.4k
      break;
1443
30.5k
    case QUANT_MODE_2:
1444
30.5k
      x_linear = 1024;
1445
1446
30.5k
      maxfactor = (ONE_IN_Q27);
1447
30.5k
      constfact = 4779;
1448
30.5k
      break;
1449
63.9k
    default:
1450
63.9k
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_QUANT_MODE;
1451
112k
  }
1452
1453
48.9k
  if (db_diff > (x_linear << 5)) {
1454
17.1k
    WORD32 db_diff_fix = db_diff >> 5;
1455
17.1k
    *factor = ixheaac_add32_sat(
1456
17.1k
        ixheaac_sat64_32(ixheaac_mult64(ixheaac_sub32_sat(db_diff_fix, x_linear), constfact)),
1457
17.1k
        ONE_IN_Q24);
1458
31.8k
  } else {
1459
31.8k
    *factor = ONE_IN_Q24;
1460
31.8k
  }
1461
1462
48.9k
  *factor = min(maxfactor, *factor);
1463
48.9k
  return IA_NO_ERROR;
1464
112k
}
1465
1466
static VOID ixheaacd_factor_cld(WORD32 *idx, WORD32 ott_vs_tot_db, WORD32 *ott_vs_tot_db_1,
1467
                                WORD32 *ott_vs_tot_db_2, WORD32 quant_mode,
1468
113k
                                ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
1469
113k
  WORD32 factor = 0;
1470
113k
  WORD32 c1;
1471
113k
  WORD32 c2;
1472
113k
  WORD32 cld_idx;
1473
1474
113k
  ixheaacd_factor_funct(ott_vs_tot_db, quant_mode, &factor);
1475
1476
113k
  cld_idx = ixheaac_mul32_sh(*idx, factor, 23);
1477
113k
  cld_idx = ixheaac_shr32(ixheaac_add32(cld_idx, 1), 1);
1478
1479
113k
  cld_idx = min(cld_idx, 15);
1480
113k
  cld_idx = max(cld_idx, -15);
1481
1482
113k
  *idx = cld_idx;
1483
1484
113k
  c1 = ixheaacd_mps_dec_bitdec_tables->factor_cld_tab_1[*idx + 15];
1485
113k
  c2 = ixheaacd_mps_dec_bitdec_tables->factor_cld_tab_1[15 - *idx];
1486
1487
113k
  *ott_vs_tot_db_1 = ixheaac_add32_sat(c1, ott_vs_tot_db);
1488
113k
  *ott_vs_tot_db_2 = ixheaac_add32_sat(c2, ott_vs_tot_db);
1489
113k
}
1490
1491
static IA_ERRORCODE ixheaacd_map_index_data(
1492
    ia_mps_dec_lossless_data_struct *ll_data,
1493
    WORD32 output_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
1494
    WORD32 output_idx_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
1495
    WORD32 cmp_idx_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
1496
    WORD32 diff_idx_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS], WORD32 xtt_idx,
1497
    WORD32 idx_prev[MAX_NUM_OTT][MAX_PARAMETER_BANDS], WORD32 param_idx, WORD32 param_type,
1498
    WORD32 start_band, WORD32 stop_band, WORD32 default_value, WORD32 num_parameter_sets,
1499
    WORD32 *param_slot, WORD32 extend_frame, WORD32 quant_mode, WORD32 *ott_vs_tot_db_in,
1500
    WORD32 *ott_vs_tot_db_1, WORD32 *ott_vs_tot_db_2,
1501
102k
    ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables, VOID *scratch) {
1502
102k
  WORD32 *a_param_slots;
1503
102k
  WORD32 *a_interpolate;
1504
1505
102k
  WORD32 data_sets;
1506
102k
  WORD32 *a_map;
1507
102k
  VOID *free_scratch;
1508
1509
102k
  WORD32 set_idx, i, band, parm_slot;
1510
102k
  WORD32 data_bands, stride;
1511
102k
  WORD32 ps, pb;
1512
1513
102k
  WORD32 i1, i2, x1, xi, x2;
1514
102k
  WORD32 *db_in;
1515
102k
  WORD32 *db_1, *db_2;
1516
102k
  IA_ERRORCODE error_code = IA_NO_ERROR;
1517
102k
  db_in = ott_vs_tot_db_in;
1518
102k
  db_1 = ott_vs_tot_db_1;
1519
102k
  db_2 = ott_vs_tot_db_2;
1520
102k
  a_param_slots = scratch;
1521
102k
  a_interpolate = a_param_slots + IXHEAAC_GET_SIZE_ALIGNED_TYPE(
1522
102k
                                      MAX_PARAMETER_SETS, sizeof(*a_interpolate), BYTE_ALIGN_8);
1523
102k
  a_map = a_interpolate +
1524
102k
          IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_SETS, sizeof(*a_map), BYTE_ALIGN_8);
1525
102k
  free_scratch = a_map + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS_PLUS_1, sizeof(*a_map),
1526
102k
                                                       BYTE_ALIGN_8);
1527
1528
102k
  data_sets = 0;
1529
289k
  for (i = 0; i < num_parameter_sets; i++) {
1530
187k
    if (ll_data->bs_xxx_data_mode[param_idx][i] == 3) {
1531
36.4k
      a_param_slots[data_sets] = i;
1532
36.4k
      data_sets++;
1533
36.4k
    }
1534
187k
  }
1535
1536
102k
  set_idx = 0;
1537
1538
289k
  for (i = 0; i < num_parameter_sets; i++) {
1539
187k
    if (ll_data->bs_xxx_data_mode[param_idx][i] == 0) {
1540
122k
      ll_data->no_cmp_quant_coarse_xxx[param_idx][i] = 0;
1541
2.18M
      for (band = start_band; band < stop_band; band++) {
1542
2.06M
        output_idx_data[xtt_idx][i][band] = default_value;
1543
2.06M
      }
1544
2.18M
      for (band = start_band; band < stop_band; band++) {
1545
2.06M
        idx_prev[xtt_idx][band] = output_idx_data[xtt_idx][i][band];
1546
2.06M
      }
1547
122k
    }
1548
1549
187k
    if (ll_data->bs_xxx_data_mode[param_idx][i] == 1) {
1550
299k
      for (band = start_band; band < stop_band; band++) {
1551
282k
        output_idx_data[xtt_idx][i][band] = idx_prev[xtt_idx][band];
1552
282k
      }
1553
17.4k
      ll_data->no_cmp_quant_coarse_xxx[param_idx][i] =
1554
17.4k
          ll_data->bs_quant_coarse_xxx_prev[param_idx];
1555
17.4k
    }
1556
1557
187k
    if (ll_data->bs_xxx_data_mode[param_idx][i] == 2) {
1558
172k
      for (band = start_band; band < stop_band; band++) {
1559
161k
        output_idx_data[xtt_idx][i][band] = idx_prev[xtt_idx][band];
1560
161k
      }
1561
11.1k
      a_interpolate[i] = 1;
1562
176k
    } else {
1563
176k
      a_interpolate[i] = 0;
1564
176k
    }
1565
1566
187k
    if (ll_data->bs_xxx_data_mode[param_idx][i] == 3) {
1567
36.4k
      parm_slot = a_param_slots[set_idx];
1568
36.4k
      stride = ixheaacd_mps_dec_bitdec_tables
1569
36.4k
                   ->pb_stride_table[ll_data->bs_freq_res_stride_xxx[param_idx][set_idx]];
1570
36.4k
      data_bands = (stop_band - start_band - 1) / stride + 1;
1571
36.4k
      ixheaacd_create_mapping(a_map, start_band, stop_band, stride, free_scratch);
1572
36.4k
      ixheaacd_map_frequency(&cmp_idx_data[xtt_idx][set_idx][0],
1573
36.4k
                             &output_idx_data[xtt_idx][parm_slot][0], a_map, data_bands);
1574
1575
608k
      for (band = start_band; band < stop_band; band++) {
1576
571k
        idx_prev[xtt_idx][band] = output_idx_data[xtt_idx][parm_slot][band];
1577
571k
      }
1578
1579
36.4k
      ll_data->bs_quant_coarse_xxx_prev[param_idx] =
1580
36.4k
          ll_data->bs_quant_coarse_xxx[param_idx][set_idx];
1581
36.4k
      ll_data->no_cmp_quant_coarse_xxx[param_idx][i] =
1582
36.4k
          ll_data->bs_quant_coarse_xxx[param_idx][set_idx];
1583
1584
36.4k
      set_idx++;
1585
36.4k
    }
1586
1587
187k
    if (diff_idx_data != NULL) {
1588
1.42M
      for (band = start_band; band < stop_band; band++) {
1589
1.34M
        output_idx_data[xtt_idx][i][band] += diff_idx_data[xtt_idx][i][band];
1590
1.34M
      }
1591
78.5k
    }
1592
187k
  }
1593
1594
289k
  for (i = 0; i < num_parameter_sets; i++) {
1595
187k
    if (a_interpolate[i] != 1) {
1596
176k
      if (ll_data->no_cmp_quant_coarse_xxx[param_idx][i] == 1) {
1597
287k
        for (band = start_band; band < stop_band; band++) {
1598
268k
          error_code = ixheaacd_deq_coarse(output_idx_data[xtt_idx][i][band], param_type,
1599
268k
                                           &(output_data[xtt_idx][i][band]),
1600
268k
                                           ixheaacd_mps_dec_bitdec_tables);
1601
268k
          if (error_code) {
1602
43
            return error_code;
1603
43
          }
1604
268k
        }
1605
157k
      } else {
1606
2.80M
        for (band = start_band; band < stop_band; band++) {
1607
2.64M
          error_code =
1608
2.64M
              ia_mps_dec_deq(output_idx_data[xtt_idx][i][band], param_type,
1609
2.64M
                             &(output_data[xtt_idx][i][band]), ixheaacd_mps_dec_bitdec_tables);
1610
2.64M
          if (error_code) {
1611
13
            return error_code;
1612
13
          }
1613
2.64M
        }
1614
157k
      }
1615
176k
    }
1616
187k
  }
1617
1618
102k
  if (quant_mode && (param_type == CLD)) {
1619
3.95k
    if (db_in == 0 || db_1 == 0 || db_2 == 0)
1620
30
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_MPS_PARAM;
1621
1622
16.1k
    for (ps = 0; ps < num_parameter_sets; ps++) {
1623
12.1k
      if (a_interpolate[ps] != 1) {
1624
10.6k
        if (ll_data->no_cmp_quant_coarse_xxx[param_idx][ps]) {
1625
1.35k
          ixheaacd_coarse_2_fine(output_idx_data[xtt_idx][ps], param_type, start_band,
1626
1.35k
                                 stop_band - start_band);
1627
1.35k
        }
1628
123k
        for (pb = start_band; pb < stop_band; pb++) {
1629
113k
          ll_data->no_cmp_quant_coarse_xxx[param_idx][ps] = 1;
1630
113k
          ixheaacd_factor_cld(&(output_idx_data[xtt_idx][ps][pb]), *db_in++, &(*db_1++),
1631
113k
                              &(*db_2++), quant_mode, ixheaacd_mps_dec_bitdec_tables);
1632
113k
          ia_mps_dec_deq(output_idx_data[xtt_idx][ps][pb], param_type,
1633
113k
                         &(output_data[xtt_idx][ps][pb]), ixheaacd_mps_dec_bitdec_tables);
1634
113k
        }
1635
10.6k
      }
1636
12.1k
    }
1637
3.92k
  }
1638
1639
102k
  i1 = 0;
1640
102k
  x1 = 0;
1641
102k
  i2 = 0;
1642
289k
  for (i = 0; i < num_parameter_sets; i++) {
1643
187k
    if (a_interpolate[i] != 1) {
1644
176k
      i1 = i;
1645
176k
    }
1646
187k
    i2 = i;
1647
200k
    while (a_interpolate[i2] == 1) {
1648
13.2k
      i2++;
1649
13.2k
    }
1650
187k
    x1 = param_slot[i1];
1651
187k
    xi = param_slot[i];
1652
187k
    x2 = param_slot[i2];
1653
1654
187k
    if (a_interpolate[i] == 1) {
1655
11.1k
      if (i2 >= num_parameter_sets) return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_PARAMETER_SETS;
1656
11.0k
      if (ll_data->no_cmp_quant_coarse_xxx[param_idx][i1]) {
1657
2.98k
        ixheaacd_coarse_2_fine(output_idx_data[xtt_idx][i1], param_type, start_band,
1658
2.98k
                               stop_band - start_band);
1659
2.98k
      }
1660
11.0k
      if (ll_data->no_cmp_quant_coarse_xxx[param_idx][i2]) {
1661
3.31k
        ixheaacd_coarse_2_fine(output_idx_data[xtt_idx][i2], param_type, start_band,
1662
3.31k
                               stop_band - start_band);
1663
3.31k
      }
1664
170k
      for (band = start_band; band < stop_band; band++) {
1665
159k
        WORD32 yi = 0, y1, y2;
1666
159k
        y1 = output_idx_data[xtt_idx][i1][band];
1667
159k
        y2 = output_idx_data[xtt_idx][i2][band];
1668
1669
159k
        if (x2 != x1) {
1670
159k
          yi = y1 + (xi - x1) * (y2 - y1) / (x2 - x1);
1671
159k
        }
1672
159k
        output_idx_data[xtt_idx][i][band] = yi;
1673
159k
        ia_mps_dec_deq(output_idx_data[xtt_idx][i][band], param_type,
1674
159k
                       &(output_data[xtt_idx][i][band]), ixheaacd_mps_dec_bitdec_tables);
1675
159k
      }
1676
11.0k
    }
1677
187k
  }
1678
1679
102k
  ixheaacd_mps_check_index_bounds(output_idx_data, num_parameter_sets, start_band,
1680
102k
                                  stop_band, param_type, xtt_idx);
1681
1682
102k
  if (extend_frame) {
1683
543k
    for (band = start_band; band < stop_band; band++) {
1684
515k
      output_data[xtt_idx][num_parameter_sets][band] =
1685
515k
          output_data[xtt_idx][num_parameter_sets - 1][band];
1686
515k
      output_idx_data[xtt_idx][num_parameter_sets][band] =
1687
515k
          output_idx_data[xtt_idx][num_parameter_sets - 1][band];
1688
515k
    }
1689
28.1k
  }
1690
102k
  return IA_NO_ERROR;
1691
102k
}
1692
1693
static VOID ixheaacd_get_parameters_mapping(
1694
    WORD32 bs_parameter_bands, WORD32 *mapping,
1695
0
    ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
1696
0
  switch (bs_parameter_bands) {
1697
0
    case PARAMETER_BANDS_4:
1698
0
      mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_4_to_28;
1699
0
      break;
1700
0
    case PARAMETER_BANDS_5:
1701
0
      mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_5_to_28;
1702
0
      break;
1703
0
    case PARAMETER_BANDS_7:
1704
0
      mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_7_to_28;
1705
0
      break;
1706
0
    case PARAMETER_BANDS_10:
1707
0
      mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_10_to_28;
1708
0
      break;
1709
0
    case PARAMETER_BANDS_14:
1710
0
      mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_14_to_28;
1711
0
      break;
1712
0
    case PARAMETER_BANDS_20:
1713
0
      mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_20_to_28;
1714
0
      break;
1715
0
    case PARAMETER_BANDS_28:
1716
0
      break;
1717
0
    default:
1718
0
      break;
1719
0
  }
1720
0
  return;
1721
0
}
1722
1723
static VOID ixheaacd_map_number_of_bands_to_28_bands(
1724
    WORD32 bands, WORD32 bs_parameter_bands, WORD32 *bands28,
1725
0
    ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
1726
0
  WORD32 *mapping = NULL;
1727
0
  WORD32 pb;
1728
1729
0
  *bands28 = bands;
1730
1731
0
  ixheaacd_get_parameters_mapping(bs_parameter_bands, mapping, ixheaacd_mps_dec_bitdec_tables);
1732
1733
0
  if (mapping != NULL) {
1734
0
    for (pb = 0; pb < MAX_PARAMETER_BANDS; pb++) {
1735
0
      if (mapping[pb] == bands) {
1736
0
        break;
1737
0
      }
1738
0
    }
1739
0
    *bands28 = pb;
1740
0
  }
1741
0
  return;
1742
0
}
1743
1744
static VOID ixheaacd_map_data_to_28_bands(
1745
    WORD32 *data, WORD32 bs_parameter_bands,
1746
0
    ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
1747
0
  WORD32 *mapping = NULL;
1748
0
  WORD32 pb;
1749
1750
0
  ixheaacd_get_parameters_mapping(bs_parameter_bands, mapping, ixheaacd_mps_dec_bitdec_tables);
1751
1752
0
  if (mapping != NULL) {
1753
0
    for (pb = MAX_PARAMETER_BANDS - 1; pb >= 0; pb--) {
1754
0
      data[pb] = data[mapping[pb]];
1755
0
    }
1756
0
  }
1757
0
  return;
1758
0
}
1759
1760
static IA_ERRORCODE ixheaacd_decode_and_map_frame_ott(ia_heaac_mps_state_struct *pstr_mps_state)
1761
20.5k
{
1762
20.5k
  IA_ERRORCODE error_code = IA_NO_ERROR;
1763
20.5k
  ia_mps_dec_spatial_bs_frame_struct *p_cur_bs;
1764
20.5k
  ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
1765
20.5k
  ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
1766
20.5k
  ia_mps_dec_bitdec_tables_struct *bitdec_table =
1767
20.5k
      pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr;
1768
20.5k
  WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot;
1769
1770
20.5k
  WORD32 i, num_parameter_sets, ott_idx, band;
1771
20.5k
  WORD32 num_ott_boxes;
1772
20.5k
  VOID *free_scratch;
1773
1774
20.5k
  WORD32 ps, pb;
1775
1776
20.5k
  WORD32 *tot_db;
1777
20.5k
  WORD32 *ott_vs_tot_db_fc;
1778
20.5k
  WORD32 *ott_vs_tot_db_s;
1779
20.5k
  WORD32 *ott_vs_tot_db_f;
1780
20.5k
  WORD32 *ott_vs_tot_db_c;
1781
20.5k
  WORD32 *ott_vs_tot_db_lr;
1782
20.5k
  WORD32 *ott_vs_tot_db_l;
1783
20.5k
  WORD32 *ott_vs_tot_db_r;
1784
20.5k
  WORD32 *tmp1;
1785
20.5k
  WORD32 *tmp2;
1786
1787
20.5k
  WORD32 bitstream_parameter_bands = curr_state->bitstream_parameter_bands;
1788
20.5k
  WORD32 *b_ott_bands = curr_state->bitstream_ott_bands;
1789
20.5k
  WORD32 *ott_cld_default = curr_state->ott_cld_default;
1790
20.5k
  WORD32 parameter_sets = curr_state->num_parameter_sets;
1791
20.5k
  WORD32 extend_frame = curr_state->extend_frame;
1792
20.5k
  WORD32 quant_mode = curr_state->quant_mode;
1793
1794
20.5k
  tot_db = pstr_mps_state->mps_scratch_mem_v;
1795
20.5k
  ott_vs_tot_db_fc =
1796
20.5k
      tot_db + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PSXPB, sizeof(*ott_vs_tot_db_fc), BYTE_ALIGN_8);
1797
20.5k
  ott_vs_tot_db_s = ott_vs_tot_db_fc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(
1798
20.5k
                                           MAX_PSXPB, sizeof(*ott_vs_tot_db_s), BYTE_ALIGN_8);
1799
20.5k
  ott_vs_tot_db_f = ott_vs_tot_db_s + IXHEAAC_GET_SIZE_ALIGNED_TYPE(
1800
20.5k
                                          MAX_PSXPB, sizeof(*ott_vs_tot_db_f), BYTE_ALIGN_8);
1801
20.5k
  ott_vs_tot_db_c = ott_vs_tot_db_f + IXHEAAC_GET_SIZE_ALIGNED_TYPE(
1802
20.5k
                                          MAX_PSXPB, sizeof(*ott_vs_tot_db_c), BYTE_ALIGN_8);
1803
20.5k
  ott_vs_tot_db_lr = ott_vs_tot_db_c + IXHEAAC_GET_SIZE_ALIGNED_TYPE(
1804
20.5k
                                           MAX_PSXPB, sizeof(*ott_vs_tot_db_lr), BYTE_ALIGN_8);
1805
20.5k
  ott_vs_tot_db_l = ott_vs_tot_db_lr + IXHEAAC_GET_SIZE_ALIGNED_TYPE(
1806
20.5k
                                           MAX_PSXPB, sizeof(*ott_vs_tot_db_l), BYTE_ALIGN_8);
1807
20.5k
  ott_vs_tot_db_r = ott_vs_tot_db_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(
1808
20.5k
                                          MAX_PSXPB, sizeof(*ott_vs_tot_db_r), BYTE_ALIGN_8);
1809
20.5k
  tmp1 = ott_vs_tot_db_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PSXPB, sizeof(*tmp1), BYTE_ALIGN_8);
1810
20.5k
  tmp2 = tmp1 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PSXPB, sizeof(*tmp2), BYTE_ALIGN_8);
1811
20.5k
  free_scratch = tmp2 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PSXPB, sizeof(*tmp2), BYTE_ALIGN_8);
1812
1813
20.5k
  p_cur_bs = pstr_mps_state->bs_frame;
1814
20.5k
  num_ott_boxes = curr_state->num_ott_boxes;
1815
1816
20.5k
  pb = MAX_PSXPB;
1817
4.62M
  for (i = 0; i < pb; i++) tot_db[i] = 0;
1818
1819
20.5k
  switch (curr_state->tree_config) {
1820
511
    case TREE_5151:
1821
511
      i = 0;
1822
511
      error_code = ixheaacd_map_index_data(
1823
511
          &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
1824
511
          p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
1825
511
          b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1826
511
          quant_mode, tot_db, ott_vs_tot_db_fc, ott_vs_tot_db_s, bitdec_table, free_scratch);
1827
511
      if (error_code) return error_code;
1828
1829
507
      i = 1;
1830
507
      error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
1831
507
                              p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
1832
507
                              p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
1833
507
                              ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1834
507
                              quant_mode, ott_vs_tot_db_fc, ott_vs_tot_db_f, ott_vs_tot_db_c,
1835
507
                              bitdec_table, free_scratch);
1836
507
      if (error_code) return error_code;
1837
1838
503
      i = 2;
1839
503
      error_code = ixheaacd_map_index_data(
1840
503
          &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
1841
503
          p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
1842
503
          b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1843
503
          quant_mode, ott_vs_tot_db_s, tmp1, tmp2, bitdec_table, free_scratch);
1844
503
      if (error_code) return error_code;
1845
1846
493
      i = 3;
1847
493
      error_code = ixheaacd_map_index_data(
1848
493
          &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
1849
493
          p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
1850
493
          b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1851
493
          quant_mode, ott_vs_tot_db_f, tmp1, tmp2, bitdec_table, free_scratch);
1852
493
      if (error_code) return error_code;
1853
1854
490
      i = 4;
1855
490
      error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
1856
490
                              p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
1857
490
                              p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
1858
490
                              ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1859
490
                              quant_mode, tot_db, tmp1, tmp2, bitdec_table, free_scratch);
1860
490
      if (error_code) return error_code;
1861
1862
485
      break;
1863
1864
556
    case TREE_5152:
1865
556
      i = 0;
1866
556
      error_code = ixheaacd_map_index_data(
1867
556
          &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
1868
556
          p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
1869
556
          b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1870
556
          quant_mode, tot_db, ott_vs_tot_db_lr, ott_vs_tot_db_c, bitdec_table, free_scratch);
1871
556
      if (error_code) return error_code;
1872
1873
554
      i = 1;
1874
554
      error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
1875
554
                              p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
1876
554
                              p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
1877
554
                              ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1878
554
                              quant_mode, ott_vs_tot_db_lr, ott_vs_tot_db_l, ott_vs_tot_db_r,
1879
554
                              bitdec_table, free_scratch);
1880
554
      if (error_code) return error_code;
1881
1882
549
      i = 2;
1883
549
      error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
1884
549
                              p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
1885
549
                              p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
1886
549
                              ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1887
549
                              quant_mode, tot_db, tmp1, tmp2, bitdec_table, free_scratch);
1888
549
      if (error_code) return error_code;
1889
1890
539
      i = 3;
1891
539
      error_code = ixheaacd_map_index_data(
1892
539
          &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
1893
539
          p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
1894
539
          b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1895
539
          quant_mode, ott_vs_tot_db_l, tmp1, tmp2, bitdec_table, free_scratch);
1896
539
      if (error_code) return error_code;
1897
1898
535
      i = 4;
1899
535
      error_code = ixheaacd_map_index_data(
1900
535
          &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
1901
535
          p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
1902
535
          b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1903
535
          quant_mode, ott_vs_tot_db_r, tmp1, tmp2, bitdec_table, free_scratch);
1904
535
      if (error_code) return error_code;
1905
529
      break;
1906
1907
19.4k
    default:
1908
63.1k
      for (i = 0; i < num_ott_boxes; i++) {
1909
43.7k
        error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
1910
43.7k
                                p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
1911
43.7k
                                p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
1912
43.7k
                                ott_cld_default[i], parameter_sets, param_slot, extend_frame,
1913
43.7k
                                (curr_state->tree_config == TREE_525) ? 0 : quant_mode, NULL,
1914
43.7k
                                NULL, NULL, bitdec_table, free_scratch);
1915
43.7k
        if (error_code) return error_code;
1916
43.7k
      }
1917
19.4k
      break;
1918
20.5k
  }
1919
1920
20.4k
  if (curr_state->one_icc == 1) {
1921
4.43k
    if (extend_frame == 0) {
1922
3.39k
      num_parameter_sets = parameter_sets;
1923
3.39k
    } else {
1924
1.04k
      num_parameter_sets = parameter_sets + 1;
1925
1.04k
    }
1926
1927
15.4k
    for (ott_idx = 1; ott_idx < num_ott_boxes; ott_idx++) {
1928
11.0k
      if (curr_state->ott_mode_lfe[ott_idx] == 0) {
1929
39.3k
        for (i = 0; i < num_parameter_sets; i++) {
1930
433k
          for (band = 0; band < bitstream_parameter_bands; band++) {
1931
403k
            p_cur_bs->cmp_ott_icc_idx[ott_idx][i][band] = p_cur_bs->cmp_ott_icc_idx[0][i][band];
1932
403k
          }
1933
29.2k
        }
1934
10.1k
      }
1935
11.0k
    }
1936
1937
19.8k
    for (ott_idx = 0; ott_idx < num_ott_boxes; ott_idx++) {
1938
15.4k
      if (curr_state->ott_mode_lfe[ott_idx] == 0) {
1939
12.5k
        error_code = ixheaacd_map_index_data(&p_cur_bs->icc_lossless_data, p_aux_struct->ott_icc,
1940
12.5k
                                p_cur_bs->ott_icc_idx, p_cur_bs->cmp_ott_icc_idx,
1941
12.5k
                                p_cur_bs->ott_icc_diff_idx, ott_idx, p_cur_bs->ott_icc_idx_prev,
1942
12.5k
                                0, ICC, 0, b_ott_bands[ott_idx], curr_state->icc_default,
1943
12.5k
                                parameter_sets, param_slot, extend_frame, quant_mode, NULL, NULL,
1944
12.5k
                                NULL, bitdec_table, free_scratch);
1945
12.5k
        if (error_code) return error_code;
1946
12.5k
      }
1947
15.4k
    }
1948
16.0k
  } else {
1949
49.2k
    for (ott_idx = 0; ott_idx < num_ott_boxes; ott_idx++) {
1950
33.2k
      if (curr_state->ott_mode_lfe[ott_idx] == 0) {
1951
32.7k
        error_code = ixheaacd_map_index_data(&p_cur_bs->icc_lossless_data, p_aux_struct->ott_icc,
1952
32.7k
                                p_cur_bs->ott_icc_idx, p_cur_bs->cmp_ott_icc_idx,
1953
32.7k
                                p_cur_bs->ott_icc_diff_idx, ott_idx, p_cur_bs->ott_icc_idx_prev,
1954
32.7k
                                ott_idx, ICC, 0, b_ott_bands[ott_idx], curr_state->icc_default,
1955
32.7k
                                parameter_sets, param_slot, extend_frame, quant_mode, NULL, NULL,
1956
32.7k
                                NULL, bitdec_table, free_scratch);
1957
32.7k
        if (error_code) return error_code;
1958
32.7k
      }
1959
33.2k
    }
1960
16.0k
  }
1961
1962
20.3k
  if (curr_state->up_mix_type == 2) {
1963
0
    WORD32 num_parameter_sets = parameter_sets;
1964
1965
0
    if (extend_frame) {
1966
0
      num_parameter_sets++;
1967
0
    }
1968
1969
0
    for (ott_idx = 0; ott_idx < curr_state->num_ott_boxes; ott_idx++) {
1970
0
      for (ps = 0; ps < num_parameter_sets; ps++) {
1971
0
        ixheaacd_map_data_to_28_bands(p_aux_struct->ott_cld[ott_idx][ps],
1972
0
                                      bitstream_parameter_bands, bitdec_table);
1973
0
        ixheaacd_map_data_to_28_bands(p_aux_struct->ott_icc[ott_idx][ps],
1974
0
                                      bitstream_parameter_bands, bitdec_table);
1975
0
      }
1976
0
    }
1977
0
  }
1978
20.3k
  return error_code;
1979
20.4k
}
1980
1981
static IA_ERRORCODE ixheaacd_decode_and_map_frame_ttt(ia_heaac_mps_state_struct *pstr_mps_state)
1982
20.3k
{
1983
20.3k
  IA_ERRORCODE error_code = IA_NO_ERROR;
1984
20.3k
  ia_mps_dec_spatial_bs_frame_struct *p_cur_bs;
1985
20.3k
  ia_mps_dec_bitdec_tables_struct *bitdec_table =
1986
20.3k
      pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr;
1987
20.3k
  ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
1988
20.3k
  WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot;
1989
1990
20.3k
  WORD32 num_bands;
1991
1992
20.3k
  WORD32 i, j, offset;
1993
20.3k
  WORD32 num_ttt_boxes;
1994
20.3k
  VOID *free_scratch;
1995
1996
20.3k
  p_cur_bs = pstr_mps_state->bs_frame;
1997
20.3k
  num_bands = pstr_mps_state->bitstream_parameter_bands;
1998
20.3k
  offset = pstr_mps_state->num_ott_boxes;
1999
20.3k
  num_ttt_boxes = pstr_mps_state->num_ttt_boxes;
2000
20.3k
  free_scratch = pstr_mps_state->mps_scratch_mem_v;
2001
2002
22.6k
  for (i = 0; i < num_ttt_boxes; i++) {
2003
2.35k
    for (j = 0;
2004
4.91k
         (j < 2) &&
2005
4.40k
         p_aux_struct->ttt_config[j][i].start_band < p_aux_struct->ttt_config[j][i].stop_band;
2006
2.61k
         j++) {
2007
2.61k
      if (p_aux_struct->ttt_config[j][i].mode < 2) {
2008
872
        error_code = ixheaacd_map_index_data(
2009
872
            &p_cur_bs->cpc_lossless_data, p_aux_struct->ttt_cpc_1, p_cur_bs->ttt_cpc_1_idx,
2010
872
            p_cur_bs->cmp_ttt_cpc_1_idx, NULL, i, p_cur_bs->ttt_cpc_1_idx_prev,
2011
872
            offset + 4 * i + 2 * j, CPC, p_aux_struct->ttt_config[j][i].bitstream_start_band,
2012
872
            p_aux_struct->ttt_config[j][i].bitstream_stop_band, pstr_mps_state->cpc_default,
2013
872
            pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame,
2014
872
            pstr_mps_state->quant_mode, NULL, NULL, NULL, bitdec_table, free_scratch);
2015
872
        if (error_code) return error_code;
2016
2017
862
        error_code = ixheaacd_map_index_data(
2018
862
            &p_cur_bs->cpc_lossless_data, p_aux_struct->ttt_cpc_2, p_cur_bs->ttt_cpc_2_idx,
2019
862
            p_cur_bs->cmp_ttt_cpc_2_idx, NULL, i, p_cur_bs->ttt_cpc_2_idx_prev,
2020
862
            offset + 4 * i + 1 + 2 * j, CPC, p_aux_struct->ttt_config[j][i].bitstream_start_band,
2021
862
            p_aux_struct->ttt_config[j][i].bitstream_stop_band, pstr_mps_state->cpc_default,
2022
862
            pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame,
2023
862
            pstr_mps_state->quant_mode, NULL, NULL, NULL, bitdec_table, free_scratch);
2024
862
        if (error_code) return error_code;
2025
2026
850
        error_code = ixheaacd_map_index_data(
2027
850
            &p_cur_bs->icc_lossless_data, p_aux_struct->ttt_icc, p_cur_bs->ttt_icc_idx,
2028
850
            p_cur_bs->cmp_ttt_icc_idx, NULL, i, p_cur_bs->ttt_icc_idx_prev,
2029
850
            offset + 4 * i + 2 * j, ICC, p_aux_struct->ttt_config[j][i].bitstream_start_band,
2030
850
            p_aux_struct->ttt_config[j][i].bitstream_stop_band, pstr_mps_state->icc_default,
2031
850
            pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame,
2032
850
            pstr_mps_state->quant_mode, NULL, NULL, NULL, bitdec_table, free_scratch);
2033
850
        if (error_code) return error_code;
2034
850
      }
2035
2036
1.74k
      else {
2037
1.74k
        error_code = ixheaacd_map_index_data(
2038
1.74k
            &p_cur_bs->cld_lossless_data, p_aux_struct->ttt_cld_1, p_cur_bs->ttt_cld_1_idx,
2039
1.74k
            p_cur_bs->cmp_ttt_cld_1_idx, NULL, i, p_cur_bs->ttt_cld_1_idx_prev,
2040
1.74k
            offset + 4 * i + 2 * j, CLD, p_aux_struct->ttt_config[j][i].bitstream_start_band,
2041
1.74k
            p_aux_struct->ttt_config[j][i].bitstream_stop_band,
2042
1.74k
            pstr_mps_state->ttt_cld_1_default[i], pstr_mps_state->num_parameter_sets, param_slot,
2043
1.74k
            pstr_mps_state->extend_frame, pstr_mps_state->quant_mode, NULL, NULL, NULL,
2044
1.74k
            bitdec_table, free_scratch);
2045
1.74k
        if (error_code) return error_code;
2046
2047
1.71k
        error_code = ixheaacd_map_index_data(
2048
1.71k
            &p_cur_bs->cld_lossless_data, p_aux_struct->ttt_cld_2, p_cur_bs->ttt_cld_2_idx,
2049
1.71k
            p_cur_bs->cmp_ttt_cld_2_idx, NULL, i, p_cur_bs->ttt_cld_2_idx_prev,
2050
1.71k
            offset + 4 * i + 1 + 2 * j, CLD, p_aux_struct->ttt_config[j][i].bitstream_start_band,
2051
1.71k
            p_aux_struct->ttt_config[j][i].bitstream_stop_band,
2052
1.71k
            pstr_mps_state->ttt_cld_2_default[i], pstr_mps_state->num_parameter_sets, param_slot,
2053
1.71k
            pstr_mps_state->extend_frame, pstr_mps_state->quant_mode, NULL, NULL, NULL,
2054
1.71k
            bitdec_table, free_scratch);
2055
1.71k
        if (error_code) return error_code;
2056
1.71k
      }
2057
2058
2.55k
      if (pstr_mps_state->up_mix_type == 2) {
2059
0
        WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
2060
0
        WORD32 ps;
2061
2062
0
        if (pstr_mps_state->extend_frame) {
2063
0
          num_parameter_sets++;
2064
0
        }
2065
2066
0
        for (ps = 0; ps < num_parameter_sets; ps++) {
2067
0
          ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_cpc_1[i][ps], num_bands, bitdec_table);
2068
0
          ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_cpc_2[i][ps], num_bands, bitdec_table);
2069
0
          ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_cld_1[i][ps], num_bands, bitdec_table);
2070
0
          ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_cld_2[i][ps], num_bands, bitdec_table);
2071
0
          ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_icc[i][ps], num_bands, bitdec_table);
2072
0
        }
2073
0
      }
2074
2.55k
    }
2075
2.35k
  }
2076
20.3k
  return error_code;
2077
20.3k
}
2078
2079
20.3k
static VOID ixheaacd_decode_and_map_frame_smg(ia_heaac_mps_state_struct *pstr_mps_state) {
2080
20.3k
  ia_mps_dec_smoothing_state_struct *smooth_state =
2081
20.3k
      pstr_mps_state->mps_persistent_mem.smooth_state;
2082
20.3k
  ia_mps_dec_bitdec_tables_struct *bitdec_table =
2083
20.3k
      pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr;
2084
20.3k
  ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
2085
20.3k
  WORD32 *smg_time = p_aux_struct->smg_time;
2086
20.3k
  WORD32 ps, pb, pg, pb_stride, data_bands, pb_start, pb_stop;
2087
20.3k
  WORD32 *a_group_to_band;
2088
20.3k
  VOID *free_scratch;
2089
20.3k
  ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame;
2090
20.3k
  pstr_mps_state->smooth_control = frame->bs_smooth_control;
2091
20.3k
  a_group_to_band = pstr_mps_state->mps_scratch_mem_v;
2092
20.3k
  free_scratch =
2093
20.3k
      a_group_to_band + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS_PLUS_1,
2094
20.3k
                                                      sizeof(*a_group_to_band), BYTE_ALIGN_8);
2095
2096
20.3k
  if (pstr_mps_state->smooth_control) {
2097
53.3k
    for (ps = 0; ps < pstr_mps_state->num_parameter_sets; ps++) {
2098
33.0k
      switch (frame->bs_smooth_mode[ps]) {
2099
17.7k
        case SMOOTH_MODE_0:
2100
17.7k
          smg_time[ps] = 256;
2101
331k
          for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) {
2102
313k
            p_aux_struct->smg_data[ps][pb] = 0;
2103
313k
          }
2104
17.7k
          break;
2105
2106
7.44k
        case SMOOTH_MODE_1:
2107
7.44k
          if (ps > 0)
2108
1.27k
            smg_time[ps] = smg_time[ps - 1];
2109
6.16k
          else
2110
6.16k
            smg_time[ps] = smooth_state->prev_smg_time;
2111
2112
149k
          for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) {
2113
141k
            if (ps > 0)
2114
20.9k
              p_aux_struct->smg_data[ps][pb] = p_aux_struct->smg_data[ps - 1][pb];
2115
120k
            else
2116
120k
              p_aux_struct->smg_data[ps][pb] = smooth_state->prev_smg_data[pb];
2117
141k
          }
2118
7.44k
          break;
2119
2120
5.20k
        case SMOOTH_MODE_2:
2121
5.20k
          smg_time[ps] = bitdec_table->smg_time_table[frame->bs_smooth_time[ps]];
2122
102k
          for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) {
2123
97.1k
            p_aux_struct->smg_data[ps][pb] = 1;
2124
97.1k
          }
2125
5.20k
          break;
2126
2127
2.68k
        case SMOOTH_MODE_3:
2128
2.68k
          smg_time[ps] = bitdec_table->smg_time_table[frame->bs_smooth_time[ps]];
2129
2.68k
          pb_stride = bitdec_table->pb_stride_table[frame->bs_freq_res_stride_smg[ps]];
2130
2.68k
          data_bands = (pstr_mps_state->bitstream_parameter_bands - 1) / pb_stride + 1;
2131
2.68k
          ixheaacd_create_mapping(a_group_to_band, 0, pstr_mps_state->bitstream_parameter_bands,
2132
2.68k
                                  pb_stride, free_scratch);
2133
15.5k
          for (pg = 0; pg < data_bands; pg++) {
2134
12.8k
            pb_start = a_group_to_band[pg];
2135
12.8k
            pb_stop = a_group_to_band[pg + 1];
2136
51.4k
            for (pb = pb_start; pb < pb_stop; pb++) {
2137
38.6k
              p_aux_struct->smg_data[ps][pb] = frame->bs_smg_data[ps][pg];
2138
38.6k
            }
2139
12.8k
          }
2140
2.68k
          break;
2141
2142
0
        default:
2143
0
          break;
2144
33.0k
      }
2145
33.0k
    }
2146
2147
20.3k
    smooth_state->prev_smg_time = smg_time[pstr_mps_state->num_parameter_sets - 1];
2148
399k
    for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) {
2149
379k
      smooth_state->prev_smg_data[pb] =
2150
379k
          p_aux_struct->smg_data[pstr_mps_state->num_parameter_sets - 1][pb];
2151
379k
    }
2152
2153
20.3k
    if (pstr_mps_state->extend_frame) {
2154
5.89k
      smg_time[pstr_mps_state->num_parameter_sets] =
2155
5.89k
          smg_time[pstr_mps_state->num_parameter_sets - 1];
2156
117k
      for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) {
2157
112k
        p_aux_struct->smg_data[pstr_mps_state->num_parameter_sets][pb] =
2158
112k
            p_aux_struct->smg_data[pstr_mps_state->num_parameter_sets - 1][pb];
2159
112k
      }
2160
5.89k
    }
2161
2162
20.3k
    if (pstr_mps_state->up_mix_type == 2) {
2163
0
      WORD32 *mapping = NULL;
2164
0
      ixheaacd_get_parameters_mapping(pstr_mps_state->bitstream_parameter_bands, mapping,
2165
0
                                      bitdec_table);
2166
2167
0
      if (mapping != NULL) {
2168
0
        WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
2169
2170
0
        if (pstr_mps_state->extend_frame) {
2171
0
          num_parameter_sets++;
2172
0
        }
2173
2174
0
        for (ps = 0; ps < num_parameter_sets; ps++) {
2175
0
          for (pb = MAX_PARAMETER_BANDS - 1; pb >= 0; pb--) {
2176
0
            p_aux_struct->smg_data[ps][pb] = p_aux_struct->smg_data[ps][mapping[pb]];
2177
0
          }
2178
0
        }
2179
0
      }
2180
0
    }
2181
20.3k
  }
2182
20.3k
  return;
2183
20.3k
}
2184
2185
static IA_ERRORCODE ixheaacd_decode_and_map_frame_arbdmx(
2186
1.41k
  ia_heaac_mps_state_struct *pstr_mps_state) {
2187
1.41k
  IA_ERRORCODE error_code = IA_NO_ERROR;
2188
1.41k
  ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame;
2189
1.41k
  ia_mps_dec_bitdec_tables_struct *bitdec_table =
2190
1.41k
      pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr;
2191
1.41k
  ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
2192
1.41k
  WORD32 *param_slot = p_aux_struct->param_slot;
2193
1.41k
  WORD32 offset = pstr_mps_state->num_ott_boxes + 4 * pstr_mps_state->num_ttt_boxes;
2194
1.41k
  WORD32 ch;
2195
2196
1.41k
  VOID *scratch = pstr_mps_state->mps_scratch_mem_v;
2197
2198
3.44k
  for (ch = 0; ch < pstr_mps_state->num_input_channels; ch++) {
2199
2.05k
    error_code = ixheaacd_map_index_data(
2200
2.05k
        &frame->cld_lossless_data, p_aux_struct->arbdmx_gain, frame->arbdmx_gain_idx,
2201
2.05k
        frame->cmp_arbdmx_gain_idx, NULL, ch, frame->arbdmx_gain_idx_prev, offset + ch, CLD, 0,
2202
2.05k
        pstr_mps_state->bitstream_parameter_bands, pstr_mps_state->arbdmx_gain_default,
2203
2.05k
        pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame, 0, NULL,
2204
2.05k
        NULL, NULL, bitdec_table, scratch);
2205
2.05k
    if (error_code) return error_code;
2206
2207
2.03k
    p_aux_struct->arbdmx_residual_abs[ch] = frame->bs_arbitrary_downmix_residual_abs[ch];
2208
2.03k
    p_aux_struct->arbdmx_alpha_upd_set[ch] =
2209
2.03k
        frame->bs_arbitrary_downmix_residual_alpha_update_set[ch];
2210
2211
2.03k
    if (pstr_mps_state->up_mix_type == 2) {
2212
0
      WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
2213
0
      WORD32 ps;
2214
2215
0
      if (pstr_mps_state->extend_frame) {
2216
0
        num_parameter_sets++;
2217
0
      }
2218
2219
0
      for (ps = 0; ps < num_parameter_sets; ps++) {
2220
0
        ixheaacd_map_data_to_28_bands(p_aux_struct->arbdmx_gain[ch][ps],
2221
0
                                      pstr_mps_state->bitstream_parameter_bands, bitdec_table);
2222
0
      }
2223
0
    }
2224
2.03k
  }
2225
1.39k
  return error_code;
2226
1.41k
}
2227
2228
static IA_ERRORCODE ixheaacd_decode_and_map_frame_arb_tree(
2229
7
  ia_heaac_mps_state_struct *pstr_mps_state) {
2230
7
  IA_ERRORCODE error_code = IA_NO_ERROR;
2231
7
  ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
2232
7
  ia_mps_spatial_bs_config_struct *p_config = &(pstr_mps_state->bs_config);
2233
7
  ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
2234
7
  WORD32 *param_slot = p_aux_struct->param_slot;
2235
7
  WORD32 offset = pstr_mps_state->num_ott_boxes;
2236
2237
7
  VOID *scratch = pstr_mps_state->mps_scratch_mem_v;
2238
2239
7
  WORD32 i;
2240
2241
10
  for (i = 0; i < p_config->num_ott_boxes_at; i++) {
2242
4
    error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
2243
4
                            p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, offset + i,
2244
4
                            p_cur_bs->ott_cld_idx_prev, offset + i, CLD, 0,
2245
4
                            p_config->bs_ott_bands_at[i], p_config->bs_ott_default_cld_at[i],
2246
4
                            pstr_mps_state->num_parameter_sets, param_slot,
2247
4
                            pstr_mps_state->extend_frame, pstr_mps_state->quant_mode, NULL, NULL,
2248
4
                            NULL, pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr, scratch);
2249
4
    if (error_code) return error_code;
2250
4
  }
2251
6
  return error_code;
2252
7
}
2253
2254
20.5k
IA_ERRORCODE ixheaacd_decode_frame(ia_heaac_mps_state_struct *pstr_mps_state) {
2255
20.5k
  IA_ERRORCODE error_code = IA_NO_ERROR;
2256
20.5k
  ia_mps_spatial_bs_config_struct *p_bs_config = &pstr_mps_state->bs_config;
2257
20.5k
  WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot;
2258
2259
20.5k
  pstr_mps_state->extend_frame = 0;
2260
20.5k
  if (param_slot[pstr_mps_state->num_parameter_sets - 1] != pstr_mps_state->time_slots - 1) {
2261
5.96k
    pstr_mps_state->extend_frame = 1;
2262
5.96k
  }
2263
20.5k
  if (pstr_mps_state->extend_frame)
2264
5.96k
  {
2265
5.96k
    if (pstr_mps_state->num_parameter_sets == MAX_PARAMETER_SETS) {
2266
4
      if (pstr_mps_state->ec_flag)
2267
0
        pstr_mps_state->num_parameter_sets = 1;
2268
4
      else
2269
4
        return IA_FATAL_ERROR;
2270
4
    }
2271
5.96k
  }
2272
2273
20.5k
  error_code = ixheaacd_decode_and_map_frame_ott(pstr_mps_state);
2274
20.5k
  if (error_code)
2275
154
  {
2276
154
    if (pstr_mps_state->ec_flag)
2277
0
    {
2278
0
      pstr_mps_state->frame_ok = 0;
2279
0
      for (WORD32 idx = 0; idx < MAX_NUM_OTT; idx++)
2280
0
      {
2281
0
        ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ott_cld_idx,
2282
0
            pstr_mps_state->num_parameter_sets, 0, pstr_mps_state->bitstream_ott_bands[idx],
2283
0
            CLD, idx);
2284
0
        ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ott_icc_idx,
2285
0
            pstr_mps_state->num_parameter_sets, 0, pstr_mps_state->bitstream_ott_bands[idx],
2286
0
            ICC, idx);
2287
0
      }
2288
0
    }
2289
154
    else
2290
154
      return error_code;
2291
154
  }
2292
2293
20.3k
  error_code = ixheaacd_decode_and_map_frame_ttt(pstr_mps_state);
2294
20.3k
  if (error_code)
2295
62
  {
2296
62
    if (pstr_mps_state->ec_flag)
2297
0
    {
2298
0
      pstr_mps_state->frame_ok = 0;
2299
0
      ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ttt_icc_idx,
2300
0
          pstr_mps_state->num_parameter_sets, 0, MAX_PARAMETER_BANDS,
2301
0
          ICC, 0);
2302
0
    }
2303
62
    else
2304
62
      return error_code;
2305
62
  }
2306
2307
20.3k
  ixheaacd_decode_and_map_frame_smg(pstr_mps_state);
2308
20.3k
  if (p_bs_config->arbitrary_tree != 0) {
2309
7
    error_code = ixheaacd_decode_and_map_frame_arb_tree(pstr_mps_state);
2310
7
    if (error_code)
2311
1
    {
2312
1
      if (pstr_mps_state->ec_flag)
2313
0
      {
2314
0
        pstr_mps_state->frame_ok = 0;
2315
0
        for (WORD32 idx = 0; idx < MAX_NUM_OTT; idx++)
2316
0
        {
2317
0
          ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ott_cld_idx,
2318
0
              pstr_mps_state->num_parameter_sets, 0, MAX_PARAMETER_BANDS,
2319
0
              CLD, idx);
2320
0
        }
2321
0
      }
2322
1
      else
2323
1
        return error_code;
2324
1
    }
2325
7
  }
2326
2327
20.3k
  if (pstr_mps_state->arbitrary_downmix != 0) {
2328
1.41k
    error_code = ixheaacd_decode_and_map_frame_arbdmx(pstr_mps_state);
2329
1.41k
    if (error_code)
2330
18
    {
2331
18
      if (pstr_mps_state->ec_flag)
2332
0
      {
2333
0
        pstr_mps_state->frame_ok = 0;
2334
0
        for (WORD32 idx = 0; idx < MAX_INPUT_CHANNELS_MPS; idx++)
2335
0
        {
2336
0
          ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->arbdmx_gain_idx,
2337
0
              pstr_mps_state->num_parameter_sets, 0, MAX_PARAMETER_BANDS,
2338
0
              CLD, idx);
2339
0
        }
2340
0
      }
2341
18
      else
2342
18
        return error_code;
2343
18
    }
2344
1.41k
  }
2345
2346
20.3k
  if (pstr_mps_state->extend_frame) {
2347
5.88k
    pstr_mps_state->num_parameter_sets++;
2348
5.88k
    param_slot[pstr_mps_state->num_parameter_sets - 1] = pstr_mps_state->time_slots - 1;
2349
5.88k
  }
2350
20.3k
  return IA_NO_ERROR;
2351
20.3k
}
2352
2353
4.60k
IA_ERRORCODE ixheaacd_set_current_state_parameters(ia_heaac_mps_state_struct *pstr_mps_state) {
2354
4.60k
  WORD32 i;
2355
2356
4.60k
  ia_mps_spatial_bs_config_struct *config = &(pstr_mps_state->bs_config);
2357
4.60k
  ia_mps_spatial_bs_config_struct *p_bs_config = &pstr_mps_state->bs_config;
2358
4.60k
  ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
2359
4.60k
  ia_mps_dec_bitdec_tables_struct *bitdec_table =
2360
4.60k
      pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr;
2361
4.60k
  ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
2362
4.60k
  WORD32 *b_ott_bands = curr_state->bitstream_ott_bands;
2363
2364
4.60k
  if (config->bs_sampling_freq_index == 15) {
2365
6
    curr_state->sampling_freq = config->bs_sampling_frequency;
2366
4.60k
  } else {
2367
4.60k
    curr_state->sampling_freq = bitdec_table->sampling_freq_table[config->bs_sampling_freq_index];
2368
4.60k
  }
2369
4.60k
  curr_state->time_slots = config->bs_frame_length + 1;
2370
4.60k
  curr_state->frame_length = curr_state->time_slots * curr_state->qmf_bands;
2371
4.60k
  curr_state->bitstream_parameter_bands = bitdec_table->freq_res_table[config->bs_freq_res];
2372
2373
4.60k
  curr_state->hybrid_bands = curr_state->qmf_bands - QMF_BANDS_TO_HYBRID + 10;
2374
4.60k
  curr_state->tp_hyb_band_border = 12;
2375
4.60k
  if (curr_state->hybrid_bands > 71) {
2376
1
    return IA_FATAL_ERROR;
2377
1
  }
2378
4.60k
  if (curr_state->up_mix_type == 2) {
2379
0
    curr_state->num_parameter_bands = MAX_PARAMETER_BANDS;
2380
4.60k
  } else {
2381
4.60k
    curr_state->num_parameter_bands = curr_state->bitstream_parameter_bands;
2382
4.60k
  }
2383
2384
4.60k
  switch (curr_state->num_parameter_bands) {
2385
520
    case PARAMETER_BANDS_4:
2386
21.2k
      for (i = 0; i < curr_state->hybrid_bands; i++) {
2387
20.6k
        curr_state->kernels[i] = bitdec_table->kernel_table.kernels_4_to_71[i];
2388
20.6k
      }
2389
520
      break;
2390
298
    case PARAMETER_BANDS_5:
2391
17.0k
      for (i = 0; i < curr_state->hybrid_bands; i++) {
2392
16.7k
        curr_state->kernels[i] = bitdec_table->kernel_table.kernels_5_to_71[i];
2393
16.7k
      }
2394
298
      break;
2395
33
    case PARAMETER_BANDS_7:
2396
1.38k
      for (i = 0; i < curr_state->hybrid_bands; i++) {
2397
1.35k
        curr_state->kernels[i] = bitdec_table->kernel_table.kernels_7_to_71[i];
2398
1.35k
      }
2399
33
      break;
2400
223
    case PARAMETER_BANDS_10:
2401
9.27k
      for (i = 0; i < curr_state->hybrid_bands; i++) {
2402
9.04k
        curr_state->kernels[i] = bitdec_table->kernel_table.kernels_10_to_71[i];
2403
9.04k
      }
2404
223
      break;
2405
1.40k
    case PARAMETER_BANDS_14:
2406
56.5k
      for (i = 0; i < curr_state->hybrid_bands; i++) {
2407
55.1k
        curr_state->kernels[i] = bitdec_table->kernel_table.kernels_14_to_71[i];
2408
55.1k
      }
2409
1.40k
      break;
2410
1.86k
    case PARAMETER_BANDS_20:
2411
103k
      for (i = 0; i < curr_state->hybrid_bands; i++) {
2412
101k
        curr_state->kernels[i] = bitdec_table->kernel_table.kernels_20_to_71[i];
2413
101k
      }
2414
1.86k
      break;
2415
263
    case PARAMETER_BANDS_28:
2416
10.5k
      for (i = 0; i < curr_state->hybrid_bands; i++) {
2417
10.3k
        curr_state->kernels[i] = bitdec_table->kernel_table.kernels_28_to_71[i];
2418
10.3k
      }
2419
263
      break;
2420
0
    default:
2421
0
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_PARAMETER_BANDS;
2422
4.60k
  };
2423
2424
4.60k
  curr_state->tree_config = config->bs_tree_config;
2425
2426
4.60k
  switch (curr_state->tree_config) {
2427
495
    case TREE_5151:
2428
944
    case TREE_5152:
2429
2.17k
    case TREE_525:
2430
2.17k
      config->ui_channel_mask = FIVE_POINT_ONE_CHANNEL_MASK;
2431
2.17k
      break;
2432
423
    case TREE_7271:
2433
718
    case TREE_7571:
2434
718
      config->ui_channel_mask = SEVEN_POINT_ONE_CHANNEL_MASK1;
2435
718
      break;
2436
293
    case TREE_7272:
2437
1.71k
    case TREE_7572:
2438
1.71k
      config->ui_channel_mask = SEVEN_POINT_ONE_CHANNEL_MASK2;
2439
1.71k
      break;
2440
0
    default:
2441
0
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_UNSUPPRORTED_TREE_CONFIG;
2442
4.60k
  }
2443
2444
4.60k
  curr_state->num_ott_boxes =
2445
4.60k
      bitdec_table->tree_property_table[curr_state->tree_config].num_ott_boxes;
2446
4.60k
  curr_state->num_ttt_boxes =
2447
4.60k
      bitdec_table->tree_property_table[curr_state->tree_config].num_ttt_boxes;
2448
4.60k
  curr_state->num_input_channels =
2449
4.60k
      bitdec_table->tree_property_table[curr_state->tree_config].num_input_channels;
2450
4.60k
  curr_state->num_output_channels =
2451
4.60k
      bitdec_table->tree_property_table[curr_state->tree_config].num_output_channels;
2452
4.60k
  curr_state->quant_mode = config->bs_quant_mode;
2453
4.60k
  curr_state->one_icc = config->bs_one_icc;
2454
4.60k
  curr_state->arbitrary_downmix = config->bs_arbitrary_downmix;
2455
4.60k
  curr_state->residual_coding = config->bs_residual_coding;
2456
4.60k
  curr_state->smooth_config = config->bs_smooth_config;
2457
4.60k
  curr_state->mtx_inversion = config->bs_matrix_mode;
2458
4.60k
  curr_state->temp_shape_config = config->bs_temp_shape_config;
2459
4.60k
  curr_state->decorr_config = config->bs_decorr_config;
2460
4.60k
  curr_state->env_quant_mode = config->bs_env_quant_mode;
2461
4.60k
  curr_state->lfe_gain = bitdec_table->lfe_gain_table[config->bs_fixed_gain_lfe];
2462
4.60k
  curr_state->surround_gain = bitdec_table->surround_gain_table[config->bs_fixed_gain_sur];
2463
4.60k
  curr_state->clip_protect_gain = bitdec_table->clip_gain_table[config->bs_fixed_gain_dmx];
2464
2465
4.60k
  if (curr_state->up_mix_type == 2) {
2466
0
    curr_state->num_output_channels = 2;
2467
0
    curr_state->decorr_config = 0;
2468
0
  }
2469
2470
4.60k
  if (curr_state->up_mix_type == 3) {
2471
0
    curr_state->num_output_channels = 2;
2472
0
  }
2473
2474
4.60k
  if (p_bs_config->arbitrary_tree == 1)
2475
10
    curr_state->num_output_channels_at = p_bs_config->num_out_chan_at;
2476
4.59k
  else
2477
4.59k
    curr_state->num_output_channels_at = curr_state->num_output_channels;
2478
2479
4.60k
  p_bs_config->ui_out_channels = curr_state->num_output_channels_at;
2480
2481
4.60k
  curr_state->_3d_stereo_inversion = config->bs_3d_audio_mode;
2482
2483
4.60k
  if (curr_state->mtx_inversion == 1 || curr_state->_3d_stereo_inversion == 1)
2484
2.33k
    curr_state->m1_param_imag_present = 1;
2485
2486
20.0k
  for (i = 0; i < curr_state->num_ott_boxes; i++) {
2487
15.4k
    if (bitdec_table->tree_property_table[curr_state->tree_config].ott_mode_lfe[i]) {
2488
2.89k
      b_ott_bands[i] = config->bs_ott_bands[i];
2489
2.89k
      curr_state->ott_mode_lfe[i] = 1;
2490
12.5k
    } else {
2491
12.5k
      b_ott_bands[i] = curr_state->bitstream_parameter_bands;
2492
12.5k
      curr_state->ott_mode_lfe[i] = 0;
2493
12.5k
    }
2494
2495
15.4k
    if (curr_state->up_mix_type == 2) {
2496
0
      ixheaacd_map_number_of_bands_to_28_bands(b_ott_bands[i],
2497
0
                                               curr_state->bitstream_parameter_bands,
2498
0
                                               &p_aux_struct->num_ott_bands[i], bitdec_table);
2499
15.4k
    } else {
2500
15.4k
      p_aux_struct->num_ott_bands[i] = b_ott_bands[i];
2501
15.4k
    }
2502
15.4k
  }
2503
6.55k
  for (i = 0; i < curr_state->num_ttt_boxes; i++) {
2504
1.94k
    p_aux_struct->ttt_config[0][i].mode = config->bs_ttt_mode_low[i];
2505
1.94k
    p_aux_struct->ttt_config[1][i].mode = config->bs_ttt_mode_high[i];
2506
1.94k
    p_aux_struct->ttt_config[0][i].bitstream_start_band = 0;
2507
1.94k
    p_aux_struct->ttt_config[1][i].bitstream_stop_band = curr_state->bitstream_parameter_bands;
2508
2509
1.94k
    if (config->bs_ttt_dual_mode[i]) {
2510
1.40k
      p_aux_struct->ttt_config[0][i].bitstream_stop_band = config->bs_ttt_bands_low[i];
2511
1.40k
      p_aux_struct->ttt_config[1][i].bitstream_start_band = config->bs_ttt_bands_low[i];
2512
1.40k
    } else {
2513
548
      p_aux_struct->ttt_config[0][i].bitstream_stop_band = curr_state->bitstream_parameter_bands;
2514
548
      p_aux_struct->ttt_config[1][i].bitstream_start_band = curr_state->bitstream_parameter_bands;
2515
548
    }
2516
2517
1.94k
    if (curr_state->up_mix_type == 2) {
2518
0
      ixheaacd_map_number_of_bands_to_28_bands(
2519
0
          p_aux_struct->ttt_config[0][i].bitstream_start_band,
2520
0
          curr_state->bitstream_parameter_bands, &p_aux_struct->ttt_config[0][i].start_band,
2521
0
          bitdec_table);
2522
2523
0
      ixheaacd_map_number_of_bands_to_28_bands(p_aux_struct->ttt_config[0][i].bitstream_stop_band,
2524
0
                                               curr_state->bitstream_parameter_bands,
2525
0
                                               &p_aux_struct->ttt_config[0][i].stop_band,
2526
0
                                               bitdec_table);
2527
2528
0
      ixheaacd_map_number_of_bands_to_28_bands(
2529
0
          p_aux_struct->ttt_config[1][i].bitstream_start_band,
2530
0
          curr_state->bitstream_parameter_bands, &p_aux_struct->ttt_config[1][i].start_band,
2531
0
          bitdec_table);
2532
2533
0
      ixheaacd_map_number_of_bands_to_28_bands(p_aux_struct->ttt_config[1][i].bitstream_stop_band,
2534
0
                                               curr_state->bitstream_parameter_bands,
2535
0
                                               &p_aux_struct->ttt_config[1][i].stop_band,
2536
0
                                               bitdec_table);
2537
1.94k
    } else {
2538
1.94k
      p_aux_struct->ttt_config[0][i].start_band =
2539
1.94k
          p_aux_struct->ttt_config[0][i].bitstream_start_band;
2540
1.94k
      p_aux_struct->ttt_config[0][i].stop_band =
2541
1.94k
          p_aux_struct->ttt_config[0][i].bitstream_stop_band;
2542
1.94k
      p_aux_struct->ttt_config[1][i].start_band =
2543
1.94k
          p_aux_struct->ttt_config[1][i].bitstream_start_band;
2544
1.94k
      p_aux_struct->ttt_config[1][i].stop_band =
2545
1.94k
          p_aux_struct->ttt_config[1][i].bitstream_stop_band;
2546
1.94k
    }
2547
1.94k
  }
2548
4.60k
  curr_state->residual_coding = config->bs_residual_coding;
2549
4.60k
  curr_state->num_residual_signals = 0;
2550
4.60k
  if (curr_state->residual_coding) {
2551
3.79k
    for (i = 0; i < curr_state->num_ttt_boxes + curr_state->num_ott_boxes; i++) {
2552
3.05k
      if (config->bs_residual_present[i]) {
2553
969
        curr_state->res_bands[i] = config->bs_residual_bands[i];
2554
969
        curr_state->num_residual_signals++;
2555
2.08k
      } else {
2556
2.08k
        curr_state->res_bands[i] = 0;
2557
2.08k
      }
2558
2559
3.05k
      if (curr_state->up_mix_type == 2 || curr_state->up_mix_type == 3) {
2560
0
        curr_state->res_bands[i] = 0;
2561
0
      }
2562
3.05k
    }
2563
734
  }
2564
2565
4.60k
  curr_state->residual_frames_per_spatial_frame =
2566
4.60k
      p_bs_config->bs_residual_frames_per_spatial_frame + 1;
2567
4.60k
  if (curr_state->residual_frames_per_spatial_frame > 0) {
2568
4.60k
    WORD32 const *reciprocal_tab =
2569
4.60k
        pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->reciprocal;
2570
2571
4.60k
    WORD64 temp =
2572
4.60k
        (WORD64)(((WORD64)(p_bs_config->bs_frame_length + 1) *
2573
4.60k
                  (WORD64)reciprocal_tab[p_bs_config->bs_residual_frames_per_spatial_frame]) >>
2574
4.60k
                 28);
2575
4.60k
    curr_state->upd_qmf = (WORD32)temp;
2576
4.60k
    if (curr_state->upd_qmf != UPD_QMF_15 && curr_state->upd_qmf != UPD_QMF_16 &&
2577
3.17k
        curr_state->upd_qmf != UPD_QMF_32 && curr_state->upd_qmf != UPD_QMF_18 &&
2578
709
        curr_state->upd_qmf != UPD_QMF_30 && curr_state->upd_qmf != UPD_QMF_24)
2579
4
      return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_QMF_UPDATE;
2580
4.60k
  }
2581
2582
4.60k
  curr_state->arbdmx_residual_bands = config->bs_arbitrary_downmix_residual_bands;
2583
4.60k
  curr_state->arbdmx_frames_per_spatial_frame =
2584
4.60k
      config->bs_arbitrary_downmix_residual_frames_per_spatial_frame + 1;
2585
4.60k
  if (curr_state->arbdmx_frames_per_spatial_frame > 0) {
2586
4.60k
    curr_state->arbdmx_upd_qmf =
2587
4.60k
        curr_state->time_slots / curr_state->arbdmx_frames_per_spatial_frame;
2588
4.60k
    if (curr_state->arbdmx_upd_qmf != UPD_QMF_15 && curr_state->arbdmx_upd_qmf != UPD_QMF_16 &&
2589
3.16k
        curr_state->arbdmx_upd_qmf != UPD_QMF_32 && curr_state->arbdmx_upd_qmf != UPD_QMF_18 &&
2590
706
        curr_state->arbdmx_upd_qmf != UPD_QMF_30 && curr_state->arbdmx_upd_qmf != UPD_QMF_24)
2591
1
      return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_QMF_UPDATE;
2592
2593
4.60k
    if ((curr_state->arbdmx_upd_qmf * 1.5f) > (curr_state->upd_qmf * 2))
2594
1
      return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_QMF_UPDATE;
2595
4.60k
  }
2596
2597
4.59k
  curr_state->cpc_default = 10;
2598
4.59k
  curr_state->ttt_cld_1_default[0] = 15;
2599
4.59k
  curr_state->ttt_cld_2_default[0] = 0;
2600
4.59k
  curr_state->icc_default = 0;
2601
4.59k
  curr_state->arbdmx_gain_default = 0;
2602
2603
4.59k
  if (curr_state->_3d_stereo_inversion) {
2604
3
    if (config->bs_3d_audio_hrtf_set == 0) {
2605
2
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_HRTF_SET;
2606
2
    } else {
2607
1
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_HRTF_SET;
2608
1
    }
2609
3
  }
2610
2611
4.59k
  switch (curr_state->tree_config) {
2612
491
    case TREE_5151:
2613
491
      curr_state->num_direct_signals = 1;
2614
491
      curr_state->num_decor_signals = 4;
2615
2616
491
      if (curr_state->up_mix_type == 2) {
2617
0
        curr_state->num_decor_signals = 1;
2618
0
      }
2619
2620
491
      if (curr_state->up_mix_type == 3) {
2621
0
        curr_state->num_decor_signals = 3;
2622
0
      }
2623
2624
491
      curr_state->num_x_channels = 1;
2625
491
      if (curr_state->arbitrary_downmix == 2) {
2626
212
        curr_state->num_x_channels += 1;
2627
212
      }
2628
491
      curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals;
2629
491
      curr_state->num_w_channels = curr_state->num_v_channels;
2630
491
      curr_state->w_start_residual_idx = 0;
2631
491
      curr_state->ott_cld_default[0] = 15;
2632
491
      curr_state->ott_cld_default[1] = 15;
2633
491
      curr_state->ott_cld_default[2] = 0;
2634
491
      curr_state->ott_cld_default[3] = 0;
2635
491
      curr_state->ott_cld_default[4] = 15;
2636
491
      break;
2637
448
    case TREE_5152:
2638
448
      curr_state->num_direct_signals = 1;
2639
448
      curr_state->num_decor_signals = 4;
2640
2641
448
      if (curr_state->up_mix_type == 2) {
2642
0
        curr_state->num_decor_signals = 1;
2643
0
      }
2644
2645
448
      if (curr_state->up_mix_type == 3) {
2646
0
        curr_state->num_decor_signals = 2;
2647
0
      }
2648
2649
448
      curr_state->num_x_channels = 1;
2650
448
      if (curr_state->arbitrary_downmix == 2) {
2651
66
        curr_state->num_x_channels += 1;
2652
66
      }
2653
448
      curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals;
2654
448
      curr_state->num_w_channels = curr_state->num_v_channels;
2655
448
      curr_state->w_start_residual_idx = 0;
2656
448
      curr_state->ott_cld_default[0] = 15;
2657
448
      curr_state->ott_cld_default[1] = 0;
2658
448
      curr_state->ott_cld_default[2] = 15;
2659
448
      curr_state->ott_cld_default[3] = 15;
2660
448
      curr_state->ott_cld_default[4] = 15;
2661
448
      break;
2662
1.23k
    case TREE_525:
2663
1.23k
      curr_state->num_direct_signals = 3;
2664
2665
3.68k
      for (i = 0; i < 2; i++) {
2666
2.46k
        switch (p_aux_struct->ttt_config[i][0].mode) {
2667
958
          case TTT_MODE_0:
2668
958
            p_aux_struct->ttt_config[i][0].use_ttt_decorr = 1;
2669
958
            curr_state->num_decor_signals = 3;
2670
958
            break;
2671
262
          case TTT_MODE_1:
2672
423
          case TTT_MODE_2:
2673
630
          case TTT_MODE_3:
2674
1.11k
          case TTT_MODE_4:
2675
1.32k
          case TTT_MODE_5:
2676
1.32k
            p_aux_struct->ttt_config[i][0].use_ttt_decorr = 0;
2677
1.32k
            curr_state->num_decor_signals = 2;
2678
1.32k
            break;
2679
175
          default:
2680
175
            if (p_bs_config->bs_ttt_mode_low[0] <= 1)
2681
1
              return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_TTT_MODE;
2682
174
            break;
2683
2.46k
        }
2684
2.46k
      }
2685
2686
1.22k
      if (curr_state->residual_coding == 1) {
2687
633
        curr_state->num_x_channels = 3;
2688
633
      } else {
2689
596
        curr_state->num_x_channels = 2;
2690
596
      }
2691
2692
1.22k
      if (curr_state->arbitrary_downmix == 2) {
2693
42
        curr_state->num_x_channels = 5;
2694
42
      }
2695
2696
1.22k
      if (curr_state->up_mix_type == 2) {
2697
0
        curr_state->num_direct_signals = 2;
2698
0
        curr_state->num_decor_signals = 0;
2699
0
        curr_state->num_x_channels = 2;
2700
2701
0
        if (curr_state->arbitrary_downmix == 2) {
2702
0
          curr_state->num_direct_signals = 4;
2703
0
          curr_state->num_x_channels = 5;
2704
0
        }
2705
0
      }
2706
2707
1.22k
      curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals;
2708
1.22k
      curr_state->num_w_channels = curr_state->num_v_channels;
2709
1.22k
      curr_state->w_start_residual_idx = 1;
2710
1.22k
      curr_state->ott_cld_default[0] = 15;
2711
1.22k
      curr_state->ott_cld_default[1] = 15;
2712
1.22k
      curr_state->ott_cld_default[2] = 15;
2713
1.22k
      break;
2714
423
    case TREE_7271:
2715
716
    case TREE_7272:
2716
716
      curr_state->num_direct_signals = 3;
2717
2718
2.14k
      for (i = 0; i < 2; i++) {
2719
1.43k
        switch (p_aux_struct->ttt_config[i][0].mode) {
2720
627
          case TTT_MODE_0:
2721
627
            p_aux_struct->ttt_config[i][0].use_ttt_decorr = 1;
2722
627
            curr_state->num_decor_signals = 5;
2723
627
            break;
2724
80
          case TTT_MODE_1:
2725
173
          case TTT_MODE_2:
2726
456
          case TTT_MODE_3:
2727
609
          case TTT_MODE_4:
2728
666
          case TTT_MODE_5:
2729
666
            p_aux_struct->ttt_config[i][0].use_ttt_decorr = 0;
2730
666
            curr_state->num_decor_signals = 5;
2731
666
            break;
2732
139
          default:
2733
139
            if (p_bs_config->bs_ttt_mode_low[0] <= 1)
2734
1
              return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_TTT_MODE;
2735
138
            break;
2736
1.43k
        }
2737
1.43k
      }
2738
2739
715
      if (curr_state->residual_coding == 1) {
2740
34
        curr_state->num_x_channels = 3;
2741
681
      } else {
2742
681
        curr_state->num_x_channels = 2;
2743
681
      }
2744
2745
715
      if (curr_state->arbitrary_downmix == 2) {
2746
35
        curr_state->num_x_channels = 5;
2747
35
      }
2748
2749
715
      if (curr_state->up_mix_type == 2) {
2750
0
        curr_state->num_direct_signals = 2;
2751
0
        curr_state->num_decor_signals = 0;
2752
0
        curr_state->num_x_channels = 2;
2753
2754
0
        if (curr_state->arbitrary_downmix == 2) {
2755
0
          curr_state->num_direct_signals = 4;
2756
0
          curr_state->num_x_channels = 5;
2757
0
        }
2758
0
      }
2759
2760
715
      curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals;
2761
715
      curr_state->num_w_channels = curr_state->num_v_channels;
2762
715
      curr_state->w_start_residual_idx = 1;
2763
715
      curr_state->ott_cld_default[0] = 15;
2764
715
      curr_state->ott_cld_default[1] = 15;
2765
715
      curr_state->ott_cld_default[2] = 15;
2766
715
      curr_state->ott_cld_default[3] = 15;
2767
715
      curr_state->ott_cld_default[4] = 15;
2768
715
      break;
2769
295
    case TREE_7571:
2770
1.71k
    case TREE_7572:
2771
1.71k
      curr_state->num_direct_signals = 6;
2772
1.71k
      curr_state->num_decor_signals = 2;
2773
1.71k
      curr_state->num_x_channels = 6;
2774
1.71k
      curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals;
2775
1.71k
      curr_state->num_w_channels = curr_state->num_v_channels;
2776
1.71k
      curr_state->w_start_residual_idx = 0;
2777
1.71k
      curr_state->ott_cld_default[0] = 15;
2778
1.71k
      curr_state->ott_cld_default[1] = 15;
2779
1.71k
      break;
2780
0
    default:
2781
0
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_UNSUPPRORTED_TREE_CONFIG;
2782
0
      break;
2783
4.59k
  }
2784
4.59k
  return IA_NO_ERROR;
2785
4.59k
}
2786
2787
VOID ixheaacd_get_dequant_tables(
2788
    WORD32 **cld, WORD32 **icc, WORD32 **cpc,
2789
0
    ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
2790
0
  *cld = ixheaacd_mps_dec_bitdec_tables->dequant_cld;
2791
0
  *icc = ixheaacd_mps_dec_bitdec_tables->dequant_icc;
2792
0
  *cpc = ixheaacd_mps_dec_bitdec_tables->dequant_cpc;
2793
0
}
2794
2795
WORD32 ixheaacd_quantize_cld(WORD32 v,
2796
0
                             ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
2797
0
  WORD32 i = 1;
2798
0
  WORD32 temp_1;
2799
0
  WORD32 vmin = ixheaacd_mps_dec_bitdec_tables->dequant_cld[0];
2800
0
  WORD32 dmin = abs(v - vmin);
2801
2802
0
  do {
2803
0
    temp_1 = abs(v - ixheaacd_mps_dec_bitdec_tables->dequant_cld[i]);
2804
0
    if (temp_1 < dmin) {
2805
0
      dmin = temp_1;
2806
0
      vmin = ixheaacd_mps_dec_bitdec_tables->dequant_cld[i];
2807
0
    }
2808
0
  } while (ixheaacd_mps_dec_bitdec_tables->dequant_cld[i++] < ONE_FORTYNINE_Q15);
2809
0
  return vmin;
2810
0
}
2811
2812
WORD32 ixheaacd_quantize_icc(WORD32 v,
2813
0
                             ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) {
2814
0
  WORD32 i = 1;
2815
0
  WORD32 temp_1;
2816
0
  WORD32 vmin = ixheaacd_mps_dec_bitdec_tables->dequant_icc[0];
2817
0
  WORD32 dmin = abs(v - vmin);
2818
2819
0
  do {
2820
0
    temp_1 = abs(v - ixheaacd_mps_dec_bitdec_tables->dequant_icc[i]);
2821
0
    if (temp_1 < dmin) {
2822
0
      dmin = temp_1;
2823
0
      vmin = ixheaacd_mps_dec_bitdec_tables->dequant_icc[i];
2824
0
    }
2825
0
  } while (ixheaacd_mps_dec_bitdec_tables->dequant_icc[i++] > MINUS_POINT_NINE_EIGHT_Q15);
2826
2827
0
  return vmin;
2828
0
}