Coverage Report

Created: 2025-08-24 07:17

/src/libxaac/decoder/ixheaacd_mps_dec.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#include <math.h>
21
#include <string.h>
22
#include "ixheaac_type_def.h"
23
#include "ixheaac_constants.h"
24
#include "ixheaac_basic_ops32.h"
25
#include "ixheaac_basic_ops40.h"
26
#include "ixheaacd_bitbuffer.h"
27
#include "ixheaacd_defines.h"
28
#include "ixheaac_sbr_const.h"
29
#include "ixheaacd_memory_standards.h"
30
#include "ixheaacd_sbrdecsettings.h"
31
#include "ixheaacd_env_extr_part.h"
32
#include "ixheaacd_aac_rom.h"
33
#include "ixheaacd_common_rom.h"
34
#include "ixheaacd_sbr_rom.h"
35
#include "ixheaacd_pulsedata.h"
36
#include "ixheaacd_pns.h"
37
#include "ixheaacd_sbr_common.h"
38
#include "ixheaacd_drc_data_struct.h"
39
#include "ixheaacd_cnst.h"
40
#include "ixheaacd_ec_defines.h"
41
#include "ixheaacd_ec_struct_def.h"
42
#include "ixheaacd_error_codes.h"
43
#include "ixheaacd_channelinfo.h"
44
#include "ixheaacd_sbrdecoder.h"
45
#include "ixheaacd_audioobjtypes.h"
46
#include "ixheaacd_latmdemux.h"
47
#include "ixheaacd_aacdec.h"
48
#include "ixheaacd_hybrid.h"
49
#include "ixheaacd_sbr_scale.h"
50
#include "ixheaacd_ps_dec.h"
51
#include "ixheaacd_lpp_tran.h"
52
#include "ixheaacd_env_extr.h"
53
#include "ixheaacd_qmf_dec.h"
54
#include "ixheaacd_env_calc.h"
55
#include "ixheaacd_pvc_dec.h"
56
#include "ixheaacd_sbr_dec.h"
57
#include "ixheaacd_mps_polyphase.h"
58
#include "ixheaacd_config.h"
59
#include "ixheaacd_mps_macro_def.h"
60
#include "ixheaacd_mps_struct_def.h"
61
#include "ixheaacd_mps_res_rom.h"
62
#include "ixheaacd_mps_aac_struct.h"
63
#include "ixheaacd_mps_dec.h"
64
#include "ixheaacd_mps_interface.h"
65
#include "ixheaacd_struct_def.h"
66
#include "ixheaacd_mps_process.h"
67
#include "ixheaacd_mps_bitdec.h"
68
#include "ixheaacd_mps_smoothing.h"
69
#include "ixheaacd_mps_tp_process.h"
70
#include "ixheaacd_mps_reshape_bb_env.h"
71
#include "ixheaacd_mps_blind.h"
72
#include "ixheaacd_mps_m1m2.h"
73
#include "ixheaacd_mps_basic_op.h"
74
#include "ixheaacd_mps_decor.h"
75
#include "ixheaacd_mps_hybfilter.h"
76
#include "ixheaacd_mps_nlc_dec.h"
77
#include "ixheaacd_mps_huff_tab.h"
78
79
extern const ia_huff_pt0_nodes_struct ixheaacd_huff_part0_nodes;
80
extern const ia_huff_ipd_nodes_struct ixheaacd_huff_ipd_nodes;
81
extern const ia_huff_lav_nodes_struct ixheaacd_huff_lav_idx_nodes;
82
extern const ia_huff_pt0_nodes_struct ixheaacd_huff_pilot_nodes;
83
extern const ia_huff_cld_nodes_struct ixheaacd_huff_cld_nodes;
84
extern const ia_huff_icc_nodes_struct ixheaacd_huff_icc_nodes;
85
extern const ia_huff_cpc_nodes_struct ixheaacd_huff_cpc_nodes;
86
extern const ia_huff_res_nodes_struct ixheaacd_huff_reshape_nodes;
87
88
WORD32 ixheaacd_mps_create(ia_mps_dec_state_struct* self, WORD32 bs_frame_len,
89
                           WORD32 residual_coding,
90
3.59k
                           ia_usac_dec_mps_config_struct* mps212_config) {
91
3.59k
  WORD32 num_ch;
92
3.59k
  WORD32 err_code = 0;
93
94
3.59k
  ia_mps_bs_frame bs_frame;
95
96
3.59k
  self->num_parameter_sets = 1;
97
3.59k
  self->qmf_band_count = 64;
98
99
3.59k
  self->res_ch_count = 0;
100
101
3.59k
  if (mps212_config) {
102
3.59k
    self->config = mps212_config;
103
3.59k
    self->frame_length = bs_frame_len;
104
3.59k
    self->in_ch_count = 1;
105
3.59k
    self->out_ch_count = 2;
106
3.59k
    self->residual_coding = residual_coding;
107
3.59k
    if (self->residual_coding) {
108
1.24k
      self->bs_residual_present = 1;
109
1.24k
      self->bs_residual_bands = mps212_config->bs_residual_bands;
110
1.24k
      if (self->config->bs_phase_coding) {
111
696
        self->config->bs_phase_coding = 2;
112
696
      }
113
1.24k
    }
114
3.59k
  }
115
116
3.59k
  err_code = ixheaacd_mps_header_decode(self);
117
118
3.59k
  if (err_code != IA_NO_ERROR) {
119
14
    self->mps_init_done = 0;
120
14
    return err_code;
121
14
  }
122
123
3.57k
  if ((self->residual_coding) && (self->res_bands > 0)) self->res_ch_count++;
124
125
3.57k
  ixheaacd_mps_env_init(self);
126
127
3.57k
  self->resolution = self->qmf_band_count;
128
129
10.7k
  for (num_ch = 0; num_ch < self->out_ch_count; num_ch++) {
130
7.15k
    ixheaacd_mps_synt_init(self->qmf_filt_state[num_ch]);
131
7.15k
  }
132
133
3.57k
  ixheaacd_mps_qmf_hybrid_analysis_init(&self->hyb_filt_state[0]);
134
135
3.57k
  if ((self->residual_coding) && (self->res_bands > 0))
136
845
    ixheaacd_mps_qmf_hybrid_analysis_init(&self->hyb_filt_state[1]);
137
138
3.57k
  err_code = ixheaacd_mps_decor_init(&(self->mps_decor), self->hyb_band_count_max,
139
3.57k
                                     self->config->bs_decorr_config,
140
3.57k
                                     self->object_type);
141
142
3.57k
  if (err_code != IA_NO_ERROR) {
143
31
    self->mps_init_done = 0;
144
31
    return err_code;
145
31
  }
146
147
3.54k
  ixheaacd_mps_init_pre_and_post_matrix(self);
148
149
3.54k
  self->parse_nxt_frame = 1;
150
151
3.54k
  bs_frame = self->bs_frame;
152
3.54k
  memset(bs_frame.cld_idx_pre, 0, MAX_PARAMETER_BANDS * sizeof(WORD32));
153
3.54k
  memset(bs_frame.icc_idx_pre, 0, MAX_PARAMETER_BANDS * sizeof(WORD32));
154
3.54k
  memset(bs_frame.cmp_cld_idx_prev, 0, MAX_PARAMETER_BANDS * sizeof(WORD32));
155
3.54k
  memset(bs_frame.cmp_icc_idx_prev, 0, MAX_PARAMETER_BANDS * sizeof(WORD32));
156
157
3.54k
  self->subband_var.init_flag = 0;
158
3.54k
  self->subband_var.update_old_ener = 0;
159
3.54k
  self->subband_var.nrg_dir = 0;
160
3.54k
  memset(self->subband_var.nrg_diff, 0, 2 * sizeof(FLOAT32));
161
162
3.54k
  memset(self->opd_smooth.smooth_l_phase, 0,
163
3.54k
         MAX_PARAMETER_BANDS * sizeof(WORD32));
164
3.54k
  memset(self->opd_smooth.smooth_r_phase, 0,
165
3.54k
         MAX_PARAMETER_BANDS * sizeof(WORD32));
166
3.54k
  self->mps_init_done = 1;
167
168
3.54k
  return 0;
169
3.57k
}
170
171
static const FLOAT32 ixheaacd_tsd_mul_re[] = {
172
    1.0f,  0.707106781186548f,  0.0f, -0.707106781186548f,
173
    -1.0f, -0.707106781186548f, 0.0f, 0.707106781186548f};
174
175
static const FLOAT32 ixheaacd_tsd_mul_im[] = {
176
    0.0f, 0.707106781186548f,  1.0f,  0.707106781186548f,
177
    0.0f, -0.707106781186548f, -1.0f, -0.707106781186548f};
178
179
19.2k
VOID ixheaacd_mps_qmf_hyb_analysis(ia_mps_dec_state_struct* self) {
180
19.2k
  if (self->object_type == AOT_ER_AAC_ELD ||
181
19.2k
      self->object_type == AOT_ER_AAC_LD) {
182
3.29k
    WORD32 k, n;
183
184
60.8k
    for (n = 0; n < self->time_slots; n++) {
185
3.13M
      for (k = 0; k < self->qmf_band_count; k++) {
186
3.07M
        self->hyb_in[0][k][n].re = self->qmf_in[0][n][k].re;
187
3.07M
        self->hyb_in[0][k][n].im = self->qmf_in[0][n][k].im;
188
3.07M
      }
189
57.5k
    }
190
15.9k
  } else {
191
15.9k
      ixheaacd_mps_qmf_hybrid_analysis(&self->hyb_filt_state[0], self->qmf_in[0],
192
15.9k
                                   self->qmf_band_count, self->time_slots,
193
15.9k
                                   self->hyb_in[0]);
194
15.9k
  }
195
196
19.2k
  if ((self->residual_coding) && (self->res_bands > 0)) {
197
8.16k
    ixheaacd_mps_qmf_hybrid_analysis(&self->hyb_filt_state[self->in_ch_count],
198
8.16k
                                     self->qmf_in[1], self->band_count[1],
199
8.16k
                                     self->time_slots, self->hyb_res);
200
8.16k
  }
201
19.2k
}
202
203
107k
VOID ixheaacd_mps_qmf_hyb_synthesis(ia_mps_dec_state_struct* self) {
204
107k
  WORD32 ch;
205
206
107k
  if (self->object_type == AOT_ER_AAC_ELD ||
207
107k
      self->object_type == AOT_ER_AAC_LD) {
208
3.29k
    WORD32 k, n;
209
9.89k
    for (ch = 0; ch < self->out_ch_count; ch++) {
210
121k
      for (n = 0; n < self->time_slots; n++) {
211
6.26M
        for (k = 0; k < self->qmf_band_count; k++) {
212
6.14M
          self->qmf_out_dir[ch][n][k].re = self->hyb_dir_out[ch][n][k].re;
213
6.14M
          self->qmf_out_dir[ch][n][k].im = self->hyb_dir_out[ch][n][k].im;
214
6.14M
        }
215
115k
      }
216
6.59k
    }
217
104k
  } else {
218
312k
      for (ch = 0; ch < self->out_ch_count; ch++) {
219
208k
          ixheaacd_mps_qmf_hybrid_synthesis(self->hyb_dir_out[ch],
220
208k
                                      self->qmf_band_count, self->time_slots,
221
208k
                                      self->qmf_out_dir[ch]);
222
208k
      }
223
104k
  }
224
107k
}
225
226
19.2k
VOID ixheaacd_mps_decor(ia_mps_dec_state_struct* self) {
227
19.2k
  WORD32 k, sb_sample, idx;
228
229
19.2k
  ia_cmplx_flt_struct(*scratch)[MAX_HYBRID_BANDS_MPS];
230
231
19.2k
  ia_cmplx_flt_struct coeff;
232
19.2k
  WORD32 band_start = 7;
233
234
19.2k
  scratch = self->scratch;
235
236
38.4k
  for (k = self->dir_sig_count; k < self->dir_sig_count + self->decor_sig_count;
237
19.2k
       k++) {
238
19.2k
    if (self->bs_tsd_enable) {
239
457k
      for (sb_sample = 0; sb_sample < self->time_slots; sb_sample++) {
240
446k
        if (self->bs_tsd_sep_data[sb_sample]) {
241
1.92M
          for (idx = band_start; idx < self->mps_decor.num_bins; idx++) {
242
1.85M
            scratch[sb_sample][idx].re = self->v[k][sb_sample][idx].re;
243
1.85M
            scratch[sb_sample][idx].im = self->v[k][sb_sample][idx].im;
244
1.85M
            self->v[k][sb_sample][idx].re = 0.0f;
245
1.85M
            self->v[k][sb_sample][idx].im = 0.0f;
246
1.85M
          }
247
64.5k
        }
248
446k
      }
249
10.0k
    }
250
251
19.2k
    ixheaacd_mps_decor_apply(&self->mps_decor, self->v[k], self->w_diff[k],
252
19.2k
                             self->time_slots, NO_RES_BANDS,
253
19.2k
                             self->ldmps_config.ldmps_present_flag);
254
255
19.2k
    if (self->bs_tsd_enable) {
256
457k
      for (sb_sample = 0; sb_sample < self->time_slots; sb_sample++) {
257
446k
        if (self->bs_tsd_sep_data[sb_sample]) {
258
64.5k
          coeff.re = ixheaacd_tsd_mul_re[self->bs_tsd_tr_phase_data[sb_sample]];
259
64.5k
          coeff.im = ixheaacd_tsd_mul_im[self->bs_tsd_tr_phase_data[sb_sample]];
260
261
1.92M
          for (idx = band_start; idx < self->mps_decor.num_bins; idx++) {
262
1.85M
            self->w_diff[k][sb_sample][idx].re +=
263
1.85M
                coeff.re * scratch[sb_sample][idx].re -
264
1.85M
                coeff.im * scratch[sb_sample][idx].im;
265
1.85M
            self->w_diff[k][sb_sample][idx].im +=
266
1.85M
                coeff.im * scratch[sb_sample][idx].re +
267
1.85M
                coeff.re * scratch[sb_sample][idx].im;
268
1.85M
          }
269
64.5k
        }
270
446k
      }
271
10.0k
    }
272
19.2k
  }
273
19.2k
}
274
275
19.2k
VOID ixheaacd_mps_mix_res_decor(ia_mps_dec_state_struct* self) {
276
19.2k
  WORD32 ts, qs, row, indx;
277
278
730k
  for (ts = 0; ts < self->time_slots; ts++) {
279
29.9M
    for (qs = 0; qs < self->hyb_band_count_max; qs++) {
280
29.2M
      indx = self->hyb_band_to_processing_band_table[qs];
281
282
58.5M
      for (row = 0; row < self->dir_sig_count; row++) {
283
29.2M
        self->w_dir[row][ts][qs].re = self->v[row][ts][qs].re;
284
29.2M
        self->w_dir[row][ts][qs].im = self->v[row][ts][qs].im;
285
29.2M
      }
286
287
29.2M
      for (row = self->dir_sig_count;
288
58.5M
           row < (self->dir_sig_count + self->decor_sig_count); row++) {
289
29.2M
        if (indx < self->res_bands) {
290
9.64M
          self->w_dir[row][ts][qs].re = self->hyb_res[qs][ts].re;
291
9.64M
          self->w_dir[row][ts][qs].im = self->hyb_res[qs][ts].im;
292
19.6M
        } else {
293
19.6M
          self->w_dir[row][ts][qs].re = 0.0f;
294
19.6M
          self->w_dir[row][ts][qs].im = 0.0f;
295
19.6M
        }
296
29.2M
      }
297
298
58.5M
      for (row = 0; row < self->dir_sig_count; row++) {
299
29.2M
        self->w_diff[row][ts][qs].re = 0.0f;
300
29.2M
        self->w_diff[row][ts][qs].im = 0.0f;
301
29.2M
      }
302
303
29.2M
      for (row = self->dir_sig_count;
304
58.5M
           row < (self->dir_sig_count + self->decor_sig_count); row++) {
305
29.2M
        if (indx < self->res_bands) {
306
9.64M
          self->w_diff[row][ts][qs].re = 0.0f;
307
9.64M
          self->w_diff[row][ts][qs].im = 0.0f;
308
9.64M
        }
309
29.2M
      }
310
29.2M
    }
311
711k
  }
312
19.2k
}
313
314
33.9k
VOID ixheaacd_mps_mix_res_decor_residual_band(ia_mps_dec_state_struct* self) {
315
33.9k
  WORD32 ts, qs, indx;
316
1.65M
  for (qs = 0; qs < self->hyb_band_count_max; qs++) {
317
1.62M
    indx = self->hyb_band_to_processing_band_table[qs];
318
1.62M
    if (indx >= self->res_bands) {
319
1.00M
      if (qs < self->hyb_band_count[1]) {
320
18.5M
        for (ts = 0; ts < self->time_slots; ts++) {
321
18.0M
          self->w_dir[1][ts][qs].re = 0.0f;
322
18.0M
          self->w_dir[1][ts][qs].im = 0.0f;
323
18.0M
        }
324
555k
      }
325
1.00M
    } else {
326
30.0M
      for (ts = 0; ts < self->time_slots; ts++) {
327
29.4M
        self->w_diff[1][ts][qs].re = 0.0f;
328
29.4M
        self->w_diff[1][ts][qs].im = 0.0f;
329
29.4M
      }
330
619k
    }
331
1.62M
  }
332
33.9k
}
333
334
19.2k
VOID ixheaacd_mps_create_w(ia_mps_dec_state_struct* self) {
335
19.2k
  ixheaacd_mps_decor(self);
336
19.2k
  ixheaacd_mps_mix_res_decor(self);
337
19.2k
}
338
339
88.3k
VOID ixheaacd_mps_qmf_hyb_analysis_no_pre_mix(ia_mps_dec_state_struct* self) {
340
88.3k
  ixheaacd_mps_qmf_hybrid_analysis_no_pre_mix(
341
88.3k
      &self->hyb_filt_state[0], self->qmf_in[0], self->band_count[0],
342
88.3k
      self->time_slots, self->w_dir[0]);
343
344
88.3k
  if (self->res_bands) {
345
48.5k
    ixheaacd_mps_qmf_hybrid_analysis_no_pre_mix(
346
48.5k
        &self->hyb_filt_state[1], self->qmf_in[1], self->band_count[1],
347
48.5k
        self->time_slots, self->w_dir[1]);
348
349
48.5k
    if (self->res_bands != 28) {
350
33.9k
      ixheaacd_mps_decor_apply(&self->mps_decor, self->w_dir[0],
351
33.9k
                               self->w_diff[1], self->time_slots,
352
33.9k
                               self->res_bands,
353
33.9k
                               self->ldmps_config.ldmps_present_flag);
354
355
33.9k
      ixheaacd_mps_mix_res_decor_residual_band(self);
356
33.9k
    }
357
48.5k
  } else {
358
39.8k
    ixheaacd_mps_decor_apply(&self->mps_decor, self->w_dir[0], self->w_diff[1],
359
39.8k
                             self->time_slots, NO_RES_BANDS,
360
39.8k
                             self->ldmps_config.ldmps_present_flag);
361
39.8k
  }
362
88.3k
}
363
364
WORD32 ixheaacd_mps_apply(ia_mps_dec_state_struct* self,
365
                          FLOAT32** input_buffer[4],
366
104k
                          FLOAT32 (*output_buffer)[4096]) {
367
104k
  WORD32 ch, ts, qs;
368
104k
  WORD32 time_slots = self->time_slots;
369
104k
  WORD32 in_ch_count = self->in_ch_count + self->res_ch_count;
370
104k
  WORD32 err = 0;
371
104k
  self->hyb_band_count[0] = self->band_count[0] - QMF_BANDS_TO_HYBRID + 10;
372
104k
  self->hyb_band_count[1] = self->band_count[1] - QMF_BANDS_TO_HYBRID + 10;
373
104k
  self->hyb_band_count_max =
374
104k
      max(self->hyb_band_count[0], self->hyb_band_count[1]);
375
104k
  self->mps_decor.decor_nrg_smooth.num_bins = self->hyb_band_count_max;
376
104k
  self->mps_decor.num_bins = self->hyb_band_count_max;
377
104k
  self->output_buffer = output_buffer;
378
379
104k
  err = ixheaacd_mps_frame_decode(self);
380
381
104k
  if (err != IA_NO_ERROR) return err;
382
383
104k
  ixheaacd_pre_and_mix_matrix_calculation(self);
384
385
104k
  ixheaacd_mps_pre_matrix_mix_matrix_smoothing(self);
386
387
265k
  for (ch = 0; ch < in_ch_count; ch++) {
388
6.37M
    for (ts = 0; ts < time_slots; ts++) {
389
196M
      for (qs = 0; qs < self->band_count[ch]; qs++) {
390
190M
        self->qmf_in[ch][qs][ts].re =
391
190M
            self->input_gain * input_buffer[2 * ch][ts][qs];
392
190M
        self->qmf_in[ch][qs][ts].im =
393
190M
            self->input_gain * input_buffer[2 * ch + 1][ts][qs];
394
190M
      }
395
6.21M
    }
396
160k
  }
397
398
104k
  if (!(self->pre_mix_req | self->bs_tsd_enable)) {
399
88.3k
    ixheaacd_mps_qmf_hyb_analysis_no_pre_mix(self);
400
88.3k
  } else {
401
15.9k
    ixheaacd_mps_qmf_hyb_analysis(self);
402
403
15.9k
    ixheaacd_mps_apply_pre_matrix(self);
404
405
15.9k
    ixheaacd_mps_create_w(self);
406
15.9k
  }
407
408
104k
  if ((!(self->res_bands | self->pre_mix_req)) &&
409
104k
      (self->config->bs_phase_coding == 0)) {
410
14.2k
    ixheaacd_mps_apply_mix_matrix_type1(self);
411
412
90.0k
  } else if (self->pre_mix_req) {
413
8.45k
    ixheaacd_mps_apply_mix_matrix_type2(self);
414
415
81.5k
  } else {
416
81.5k
    ixheaacd_mps_apply_mix_matrix_type3(self);
417
81.5k
  }
418
419
104k
  if (self->config->bs_temp_shape_config == 2) {
420
10.5k
    ixheaacd_mps_time_env_shaping(self);
421
10.5k
  }
422
423
104k
  err = ixheaacd_mps_temp_process(self);
424
104k
  if (err) return err;
425
426
104k
  self->parse_nxt_frame = 1;
427
104k
  self->pre_mix_req = 0;
428
104k
  return 0;
429
104k
}
430
431
static VOID ixheaacd_mps_pcm_decode(ia_bit_buf_struct *it_bit_buff,
432
                                    WORD32* out_data_1, WORD32* out_data_2,
433
                                    WORD32 ixheaacd_drc_offset, WORD32 num_val,
434
23.4k
                                    WORD32 num_levels) {
435
23.4k
  WORD32 i = 0, j = 0, idx = 0;
436
23.4k
  WORD32 max_grp_len = 0, grp_len = 0, next_val = 0, grp_val = 0;
437
23.4k
  UWORD32 data = 0;
438
439
23.4k
  FLOAT32 ld_nlev = 0.f;
440
441
23.4k
  WORD32 pcm_chunk_size[7] = {0};
442
443
23.4k
  switch (num_levels) {
444
40
    case 3:
445
40
      max_grp_len = 5;
446
40
      break;
447
14
    case 7:
448
14
      max_grp_len = 6;
449
14
      break;
450
17
    case 11:
451
17
      max_grp_len = 2;
452
17
      break;
453
0
    case 13:
454
0
      max_grp_len = 4;
455
0
      break;
456
0
    case 19:
457
0
      max_grp_len = 4;
458
0
      break;
459
0
    case 25:
460
0
      max_grp_len = 3;
461
0
      break;
462
191
    case 51:
463
191
      max_grp_len = 4;
464
191
      break;
465
5.26k
    case 4:
466
9.85k
    case 8:
467
18.6k
    case 15:
468
19.4k
    case 16:
469
20.1k
    case 26:
470
23.1k
    case 31:
471
23.1k
      max_grp_len = 1;
472
23.1k
      break;
473
0
    default:
474
0
      return;
475
23.4k
  }
476
477
23.4k
  ld_nlev = (FLOAT32)(log((FLOAT32)num_levels) / log(2.f));
478
479
47.7k
  for (i = 1; i <= max_grp_len; i++) {
480
24.2k
    pcm_chunk_size[i] = (WORD32)ceil((FLOAT32)(i)*ld_nlev);
481
24.2k
  }
482
483
181k
  for (i = 0; i < num_val; i += max_grp_len) {
484
158k
    grp_len = min(max_grp_len, num_val - i);
485
158k
    data = ixheaacd_read_bits_buf(it_bit_buff, pcm_chunk_size[grp_len]);
486
487
158k
    grp_val = data;
488
489
318k
    for (j = 0; j < grp_len; j++) {
490
159k
      idx = i + (grp_len - j - 1);
491
159k
      next_val = grp_val % num_levels;
492
493
159k
      if (out_data_2 == NULL) {
494
105k
        out_data_1[idx] = next_val - ixheaacd_drc_offset;
495
105k
      } else if (out_data_1 == NULL) {
496
0
        out_data_2[idx] = next_val - ixheaacd_drc_offset;
497
54.1k
      } else {
498
54.1k
        if (idx % 2) {
499
27.0k
          out_data_2[idx / 2] = next_val - ixheaacd_drc_offset;
500
27.0k
        } else {
501
27.0k
          out_data_1[idx / 2] = next_val - ixheaacd_drc_offset;
502
27.0k
        }
503
54.1k
      }
504
505
159k
      grp_val = (grp_val - next_val) / num_levels;
506
159k
    }
507
158k
  }
508
509
23.4k
  return;
510
23.4k
}
511
512
static VOID ixheaacd_mps_huff_read(ia_bit_buf_struct *it_bit_buff,
513
                                   const WORD32 (*node_tab)[][2],
514
368k
                                   WORD32* out_data) {
515
368k
  WORD32 node = 0;
516
368k
  UWORD32 next_bit = 0;
517
518
896k
  do {
519
896k
    next_bit = ixheaacd_read_bits_buf(it_bit_buff, 1);
520
896k
    node = (*node_tab)[node][next_bit];
521
896k
  } while (node > 0);
522
523
368k
  *out_data = node;
524
525
368k
  return;
526
368k
}
527
528
static VOID ixheaacd_mps_huff_read_2d(ia_bit_buf_struct *it_bit_buff,
529
                                      const WORD32 (*node_tab)[][2],
530
                                      WORD32 out_data[2], WORD32* escape)
531
532
164k
{
533
164k
  WORD32 huff_2d_8bit = 0;
534
164k
  WORD32 node = 0;
535
536
164k
  ixheaacd_mps_huff_read(it_bit_buff, node_tab, &node);
537
164k
  *escape = (node == 0);
538
539
164k
  if (*escape) {
540
295
    out_data[0] = 0;
541
295
    out_data[1] = 1;
542
164k
  } else {
543
164k
    huff_2d_8bit = -(node + 1);
544
164k
    out_data[0] = huff_2d_8bit >> 4;
545
164k
    out_data[1] = huff_2d_8bit & 0xf;
546
164k
  }
547
548
164k
  return;
549
164k
}
550
551
static VOID ixheaacd_mps_sym_restore(ia_bit_buf_struct *it_bit_buff,
552
101k
                                     WORD32 lav, WORD32 data[2]) {
553
101k
  WORD32 tmp = 0;
554
101k
  UWORD32 sym_bit = 0;
555
556
101k
  WORD32 sum_val = data[0] + data[1];
557
101k
  WORD32 diff_val = data[0] - data[1];
558
559
101k
  if (sum_val > lav) {
560
26.7k
    data[0] = -sum_val + (2 * lav + 1);
561
26.7k
    data[1] = -diff_val;
562
74.2k
  } else {
563
74.2k
    data[0] = sum_val;
564
74.2k
    data[1] = diff_val;
565
74.2k
  }
566
567
101k
  if (data[0] + data[1] != 0) {
568
42.3k
    sym_bit = ixheaacd_read_bits_buf(it_bit_buff, 1);
569
42.3k
    if (sym_bit) {
570
15.8k
      data[0] = -data[0];
571
15.8k
      data[1] = -data[1];
572
15.8k
    }
573
42.3k
  }
574
575
101k
  if (data[0] - data[1] != 0) {
576
36.7k
    sym_bit = ixheaacd_read_bits_buf(it_bit_buff, 1);
577
36.7k
    if (sym_bit) {
578
11.8k
      tmp = data[0];
579
11.8k
      data[0] = data[1];
580
11.8k
      data[1] = tmp;
581
11.8k
    }
582
36.7k
  }
583
584
101k
  return;
585
101k
}
586
587
static VOID ixheaacd_mps_sym_restoreipd(ia_bit_buf_struct *it_bit_buff,
588
7.82k
                                        WORD32 lav, WORD32 data[2]) {
589
7.82k
  WORD32 tmp = 0;
590
7.82k
  UWORD32 sym_bit = 0;
591
592
7.82k
  WORD32 sum_val = data[0] + data[1];
593
7.82k
  WORD32 diff_val = data[0] - data[1];
594
595
7.82k
  if (sum_val > lav) {
596
1.72k
    data[0] = -sum_val + (2 * lav + 1);
597
1.72k
    data[1] = -diff_val;
598
6.10k
  } else {
599
6.10k
    data[0] = sum_val;
600
6.10k
    data[1] = diff_val;
601
6.10k
  }
602
603
7.82k
  if (data[0] - data[1] != 0) {
604
2.30k
    sym_bit = ixheaacd_read_bits_buf(it_bit_buff, 1);
605
2.30k
    if (sym_bit) {
606
1.41k
      tmp = data[0];
607
1.41k
      data[0] = data[1];
608
1.41k
      data[1] = tmp;
609
1.41k
    }
610
2.30k
  }
611
612
7.82k
  return;
613
7.82k
}
614
615
static VOID ixheaacd_mps_huff_dec_pilot(ia_bit_buf_struct *it_bit_buff,
616
                                        const WORD32 (*node_tab)[][2],
617
6.29k
                                        WORD32* pilot_data) {
618
6.29k
  WORD32 node = 0;
619
620
6.29k
  ixheaacd_mps_huff_read(it_bit_buff, node_tab, &node);
621
6.29k
  *pilot_data = -(node + 1);
622
623
6.29k
  return;
624
6.29k
}
625
626
static VOID ixheaacd_mps_huff_dec_cld_1d(
627
    ia_bit_buf_struct *it_bit_buff,
628
    const ia_huff_cld_node_1d_struct* huff_nodes, WORD32* out_data,
629
14.6k
    WORD32 num_val, WORD32 p0_flag) {
630
14.6k
  WORD32 i = 0, node = 0, ixheaacd_drc_offset = 0;
631
14.6k
  WORD32 od = 0, od_sign = 0;
632
14.6k
  UWORD32 data = 0;
633
634
14.6k
  if (p0_flag) {
635
9.93k
    ixheaacd_mps_huff_read(it_bit_buff,
636
9.93k
                           (ia_huff_node_struct)&ixheaacd_huff_part0_nodes.cld,
637
9.93k
                           &node);
638
9.93k
    out_data[0] = -(node + 1);
639
9.93k
    ixheaacd_drc_offset = 1;
640
9.93k
  }
641
642
95.1k
  for (i = ixheaacd_drc_offset; i < num_val; i++) {
643
80.5k
    ixheaacd_mps_huff_read(it_bit_buff,
644
80.5k
                           (ia_huff_node_struct)&huff_nodes->node_tab, &node);
645
80.5k
    od = -(node + 1);
646
647
80.5k
    if (od != 0) {
648
17.8k
      data = ixheaacd_read_bits_buf(it_bit_buff, 1);
649
17.8k
      od_sign = data;
650
651
17.8k
      if (od_sign) od = -od;
652
17.8k
    }
653
654
80.5k
    out_data[i] = od;
655
80.5k
  }
656
657
14.6k
  return;
658
14.6k
}
659
660
static VOID ixheaacd_mps_huff_dec_ipd_1d(
661
    ia_bit_buf_struct *it_bit_buff,
662
    const ia_huff_ipd_node_1d_struct* huff_nodes, WORD32* out_data,
663
1.97k
    WORD32 num_val, WORD32 p0_flag) {
664
1.97k
  WORD32 i = 0, node = 0, ixheaacd_drc_offset = 0;
665
1.97k
  WORD32 od = 0;
666
667
1.97k
  if (p0_flag) {
668
1.44k
    ixheaacd_mps_huff_read(
669
1.44k
        it_bit_buff, (ia_huff_node_struct)&ixheaacd_huff_ipd_nodes.hp0.node_tab,
670
1.44k
        &node);
671
1.44k
    out_data[0] = -(node + 1);
672
1.44k
    ixheaacd_drc_offset = 1;
673
1.44k
  }
674
675
19.2k
  for (i = ixheaacd_drc_offset; i < num_val; i++) {
676
17.2k
    ixheaacd_mps_huff_read(it_bit_buff,
677
17.2k
                           (ia_huff_node_struct)&huff_nodes->node_tab, &node);
678
17.2k
    od = -(node + 1);
679
17.2k
    out_data[i] = od;
680
17.2k
  }
681
682
1.97k
  return;
683
1.97k
}
684
685
static VOID ixheaacd_mps_huff_dec_icc_1d(
686
    ia_bit_buf_struct *it_bit_buff,
687
    const ia_huff_icc_node_1d_struct* huff_nodes, WORD32* out_data,
688
6.80k
    WORD32 num_val, WORD32 p0_flag) {
689
6.80k
  WORD32 i = 0, node = 0, ixheaacd_drc_offset = 0;
690
6.80k
  WORD32 od = 0, od_sign = 0;
691
6.80k
  UWORD32 data = 0;
692
693
6.80k
  if (p0_flag) {
694
3.77k
    ixheaacd_mps_huff_read(it_bit_buff,
695
3.77k
                           (ia_huff_node_struct)&ixheaacd_huff_part0_nodes.icc,
696
3.77k
                           &node);
697
3.77k
    out_data[0] = -(node + 1);
698
3.77k
    ixheaacd_drc_offset = 1;
699
3.77k
  }
700
701
42.6k
  for (i = ixheaacd_drc_offset; i < num_val; i++) {
702
35.8k
    ixheaacd_mps_huff_read(it_bit_buff,
703
35.8k
                           (ia_huff_node_struct)&huff_nodes->node_tab, &node);
704
35.8k
    od = -(node + 1);
705
706
35.8k
    if (od != 0) {
707
10.8k
      data = ixheaacd_read_bits_buf(it_bit_buff, 1);
708
10.8k
      od_sign = data;
709
710
10.8k
      if (od_sign) od = -od;
711
10.8k
    }
712
713
35.8k
    out_data[i] = od;
714
35.8k
  }
715
716
6.80k
  return;
717
6.80k
}
718
719
static VOID ia_mps_dec_huff_dec_cpc_1d(
720
    const ia_huff_cpc_node_1d_struct *huff_nodes, WORD32 *out_data,
721
706
    WORD32 num_val, WORD32 p0_flag, ia_bit_buf_struct *h_bit_buf) {
722
706
  WORD32 i = 0, node = 0, offset = 0;
723
706
  WORD32 od = 0, od_sign = 0;
724
706
  WORD32 data = 0;
725
726
706
  if (p0_flag) {
727
371
    ixheaacd_mps_huff_read(
728
371
        h_bit_buf, (ia_huff_node_struct) & (ixheaacd_huff_part0_nodes.cpc),
729
371
        &node);
730
371
    out_data[0] = -(node + 1);
731
371
    offset = 1;
732
371
  }
733
734
6.48k
  for (i = offset; i < num_val; i++) {
735
5.77k
    ixheaacd_mps_huff_read(h_bit_buf,
736
5.77k
                           (ia_huff_node_struct)&huff_nodes->node_tab, &node);
737
5.77k
    od = -(node + 1);
738
739
5.77k
    if (od != 0) {
740
3.93k
      data = ixheaacd_read_bits_buf(h_bit_buf, 1);
741
3.93k
      od_sign = data;
742
743
3.93k
      if (od_sign) od = -od;
744
3.93k
    }
745
746
5.77k
    out_data[i] = od;
747
5.77k
  }
748
706
}
749
750
static VOID ixheaacd_mps_huff_dec_cld_2d(
751
    ia_bit_buf_struct *it_bit_buff,
752
    const ia_huff_cld_node_2d_struct* huff_nodes, WORD32 out_data[][2],
753
18.5k
    WORD32 num_val, WORD32 ch_fac, WORD32* p0_data[2]) {
754
18.5k
  WORD32 i = 0, lav = 0, escape = 0, esc_contrl = 0;
755
18.5k
  WORD32 node = 0;
756
18.5k
  UWORD32 data = 0;
757
758
18.5k
  WORD32 esc_data[MAXBANDS][2] = {{0}};
759
18.5k
  WORD32 esc_idx[MAXBANDS] = {0};
760
761
18.5k
  ixheaacd_mps_huff_read(
762
18.5k
      it_bit_buff, (ia_huff_node_struct)&ixheaacd_huff_lav_idx_nodes.node_tab,
763
18.5k
      &node);
764
18.5k
  data = -(node + 1);
765
766
18.5k
  lav = 2 * data + 3;
767
768
18.5k
  if (p0_data[0] != NULL) {
769
7.90k
    ixheaacd_mps_huff_read(it_bit_buff,
770
7.90k
                           (ia_huff_node_struct)&ixheaacd_huff_part0_nodes.cld,
771
7.90k
                           &node);
772
7.90k
    *p0_data[0] = -(node + 1);
773
7.90k
  }
774
18.5k
  if (p0_data[1] != NULL) {
775
3.19k
    ixheaacd_mps_huff_read(it_bit_buff,
776
3.19k
                           (ia_huff_node_struct)&ixheaacd_huff_part0_nodes.cld,
777
3.19k
                           &node);
778
3.19k
    *p0_data[1] = -(node + 1);
779
3.19k
  }
780
781
91.9k
  for (i = 0; i < num_val; i += ch_fac) {
782
73.3k
    switch (lav) {
783
41.6k
      case 3:
784
41.6k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
785
41.6k
                                  (ia_huff_node_struct)&huff_nodes->lav3,
786
41.6k
                                  out_data[i], &escape);
787
41.6k
        break;
788
9.69k
      case 5:
789
9.69k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
790
9.69k
                                  (ia_huff_node_struct)&huff_nodes->lav5,
791
9.69k
                                  out_data[i], &escape);
792
9.69k
        break;
793
14.4k
      case 7:
794
14.4k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
795
14.4k
                                  (ia_huff_node_struct)&huff_nodes->lav7,
796
14.4k
                                  out_data[i], &escape);
797
14.4k
        break;
798
7.65k
      case 9:
799
7.65k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
800
7.65k
                                  (ia_huff_node_struct)&huff_nodes->lav9,
801
7.65k
                                  out_data[i], &escape);
802
7.65k
        break;
803
0
      default:
804
0
        break;
805
73.3k
    }
806
807
73.3k
    if (escape) {
808
0
      esc_idx[esc_contrl++] = i;
809
73.3k
    } else {
810
73.3k
      ixheaacd_mps_sym_restore(it_bit_buff, lav, out_data[i]);
811
73.3k
    }
812
73.3k
  }
813
814
18.5k
  if (esc_contrl > 0) {
815
0
    ixheaacd_mps_pcm_decode(it_bit_buff, esc_data[0], esc_data[1], 0,
816
0
                            2 * esc_contrl, (2 * lav + 1));
817
818
0
    for (i = 0; i < esc_contrl; i++) {
819
0
      out_data[esc_idx[i]][0] = esc_data[0][i] - lav;
820
0
      out_data[esc_idx[i]][1] = esc_data[1][i] - lav;
821
0
    }
822
0
  }
823
824
18.5k
  return;
825
18.5k
}
826
827
static VOID ixheaacd_mps_huff_dec_icc_2d(
828
    ia_bit_buf_struct *it_bit_buff,
829
    const ia_huff_icc_node_2d_struct* huff_nodes, WORD32 out_data[][2],
830
5.54k
    WORD32 num_val, WORD32 ch_fac, WORD32* p0_data[2]) {
831
5.54k
  WORD32 i = 0, lav = 0, escape = 0, esc_contrl = 0;
832
5.54k
  WORD32 node = 0;
833
5.54k
  UWORD32 data = 0;
834
835
5.54k
  WORD32 esc_data[2][MAXBANDS] = {{0}};
836
5.54k
  WORD32 esc_idx[MAXBANDS] = {0};
837
838
5.54k
  ixheaacd_mps_huff_read(
839
5.54k
      it_bit_buff, (ia_huff_node_struct)&ixheaacd_huff_lav_idx_nodes.node_tab,
840
5.54k
      &node);
841
5.54k
  data = -(node + 1);
842
843
5.54k
  lav = 2 * data + 1;
844
845
5.54k
  if (p0_data[0] != NULL) {
846
2.61k
    ixheaacd_mps_huff_read(it_bit_buff,
847
2.61k
                           (ia_huff_node_struct)&ixheaacd_huff_part0_nodes.icc,
848
2.61k
                           &node);
849
2.61k
    *p0_data[0] = -(node + 1);
850
2.61k
  }
851
5.54k
  if (p0_data[1] != NULL) {
852
1.95k
    ixheaacd_mps_huff_read(it_bit_buff,
853
1.95k
                           (ia_huff_node_struct)&ixheaacd_huff_part0_nodes.icc,
854
1.95k
                           &node);
855
1.95k
    *p0_data[1] = -(node + 1);
856
1.95k
  }
857
858
30.4k
  for (i = 0; i < num_val; i += ch_fac) {
859
24.9k
    switch (lav) {
860
15.2k
      case 1:
861
15.2k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
862
15.2k
                                  (ia_huff_node_struct)&huff_nodes->lav1,
863
15.2k
                                  out_data[i], &escape);
864
15.2k
        break;
865
6.31k
      case 3:
866
6.31k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
867
6.31k
                                  (ia_huff_node_struct)&huff_nodes->lav3,
868
6.31k
                                  out_data[i], &escape);
869
6.31k
        break;
870
1.55k
      case 5:
871
1.55k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
872
1.55k
                                  (ia_huff_node_struct)&huff_nodes->lav5,
873
1.55k
                                  out_data[i], &escape);
874
1.55k
        break;
875
1.75k
      case 7:
876
1.75k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
877
1.75k
                                  (ia_huff_node_struct)&huff_nodes->lav7,
878
1.75k
                                  out_data[i], &escape);
879
1.75k
        break;
880
24.9k
    }
881
882
24.9k
    if (escape) {
883
82
      esc_idx[esc_contrl++] = i;
884
24.8k
    } else {
885
24.8k
      ixheaacd_mps_sym_restore(it_bit_buff, lav, out_data[i]);
886
24.8k
    }
887
24.9k
  }
888
889
5.54k
  if (esc_contrl > 0) {
890
23
    ixheaacd_mps_pcm_decode(it_bit_buff, esc_data[0], esc_data[1], 0,
891
23
                            2 * esc_contrl, (2 * lav + 1));
892
893
105
    for (i = 0; i < esc_contrl; i++) {
894
82
      out_data[esc_idx[i]][0] = esc_data[0][i] - lav;
895
82
      out_data[esc_idx[i]][1] = esc_data[1][i] - lav;
896
82
    }
897
23
  }
898
899
5.54k
  return;
900
5.54k
}
901
902
static VOID ixheaacd_mps_huff_dec_ipd_2d(
903
    ia_bit_buf_struct *it_bit_buff,
904
    const ia_huff_ipd_node_2d_struct* huff_nodes, WORD32 out_data[][2],
905
977
    WORD32 num_val, WORD32 ch_fac, WORD32* p0_data[2]) {
906
977
  WORD32 i = 0, lav = 0, escape = 0, esc_contrl = 0;
907
977
  WORD32 node = 0;
908
977
  UWORD32 data = 0;
909
910
977
  WORD32 esc_data[2][MAXBANDS] = {{0}};
911
977
  WORD32 esc_idx[MAXBANDS] = {0};
912
913
977
  ixheaacd_mps_huff_read(
914
977
      it_bit_buff, (ia_huff_node_struct)&ixheaacd_huff_lav_idx_nodes.node_tab,
915
977
      &node);
916
917
977
  data = -(node + 1);
918
977
  if (data == 0)
919
309
    data = 3;
920
668
  else
921
668
    data--;
922
923
977
  lav = 2 * data + 1;
924
925
977
  if (p0_data[0] != NULL) {
926
324
    ixheaacd_mps_huff_read(
927
324
        it_bit_buff, (ia_huff_node_struct)&ixheaacd_huff_ipd_nodes.hp0.node_tab,
928
324
        &node);
929
324
    *p0_data[0] = -(node + 1);
930
324
  }
931
977
  if (p0_data[1] != NULL) {
932
258
    ixheaacd_mps_huff_read(
933
258
        it_bit_buff, (ia_huff_node_struct)&ixheaacd_huff_ipd_nodes.hp0.node_tab,
934
258
        &node);
935
258
    *p0_data[1] = -(node + 1);
936
258
  }
937
938
9.01k
  for (i = 0; i < num_val; i += ch_fac) {
939
8.03k
    switch (lav) {
940
2.80k
      case 1:
941
2.80k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
942
2.80k
                                  (ia_huff_node_struct)&huff_nodes->lav1,
943
2.80k
                                  out_data[i], &escape);
944
2.80k
        break;
945
1.17k
      case 3:
946
1.17k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
947
1.17k
                                  (ia_huff_node_struct)&huff_nodes->lav3,
948
1.17k
                                  out_data[i], &escape);
949
1.17k
        break;
950
1.07k
      case 5:
951
1.07k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
952
1.07k
                                  (ia_huff_node_struct)&huff_nodes->lav5,
953
1.07k
                                  out_data[i], &escape);
954
1.07k
        break;
955
2.97k
      case 7:
956
2.97k
        ixheaacd_mps_huff_read_2d(it_bit_buff,
957
2.97k
                                  (ia_huff_node_struct)&huff_nodes->lav7,
958
2.97k
                                  out_data[i], &escape);
959
2.97k
        break;
960
8.03k
    }
961
962
8.03k
    if (escape) {
963
213
      esc_idx[esc_contrl++] = i;
964
7.82k
    } else {
965
7.82k
      ixheaacd_mps_sym_restoreipd(it_bit_buff, lav, out_data[i]);
966
7.82k
    }
967
8.03k
  }
968
969
977
  if (esc_contrl > 0) {
970
71
    ixheaacd_mps_pcm_decode(it_bit_buff, esc_data[0], esc_data[1], 0,
971
71
                            2 * esc_contrl, (2 * lav + 1));
972
973
284
    for (i = 0; i < esc_contrl; i++) {
974
213
      out_data[esc_idx[i]][0] = esc_data[0][i] - lav;
975
213
      out_data[esc_idx[i]][1] = esc_data[1][i] - lav;
976
213
    }
977
71
  }
978
979
977
  return;
980
977
}
981
982
static VOID ia_mps_dec_huff_dec_cpc_2d(
983
    const ia_mps_dec_huff_cpc_nod_2d *huff_nodes, WORD32 out_data[][2],
984
    WORD32 num_val, WORD32 stride, WORD32 *p0_data[2],
985
409
    ia_bit_buf_struct *h_bit_buf) {
986
409
  WORD32 i = 0, lav = 0, escape = 0, esc_cntr = 0;
987
409
  WORD32 node = 0;
988
409
  WORD32 data = 0;
989
990
409
  WORD32 esc_data[2][MAXBANDS] = {{0}};
991
409
  WORD32 esc_idx[MAXBANDS] = {0};
992
993
409
  ixheaacd_mps_huff_read(
994
409
      h_bit_buf, (ia_huff_node_struct) & (ixheaacd_huff_lav_idx_nodes.node_tab),
995
409
      &node);
996
409
  data = -(node + 1);
997
998
409
  lav = 3 * data + 3;
999
1000
409
  if (p0_data[0] != NULL) {
1001
150
    ixheaacd_mps_huff_read(
1002
150
        h_bit_buf, (ia_huff_node_struct) & (ixheaacd_huff_part0_nodes.cpc),
1003
150
        &node);
1004
150
    *p0_data[0] = -(node + 1);
1005
150
  }
1006
409
  if (p0_data[1] != NULL) {
1007
104
    ixheaacd_mps_huff_read(
1008
104
        h_bit_buf, (ia_huff_node_struct) & (ixheaacd_huff_part0_nodes.cpc),
1009
104
        &node);
1010
104
    *p0_data[1] = -(node + 1);
1011
104
  }
1012
1013
3.21k
  for (i = 0; i < num_val; i += stride) {
1014
2.81k
    switch (lav) {
1015
808
      case LAV_3:
1016
808
        ixheaacd_mps_huff_read_2d(h_bit_buf,
1017
808
                                  (ia_huff_node_struct)&huff_nodes->lav3,
1018
808
                                  out_data[i], &escape);
1019
808
        break;
1020
437
      case LAV_6:
1021
437
        ixheaacd_mps_huff_read_2d(h_bit_buf,
1022
437
                                  (ia_huff_node_struct)&huff_nodes->lav6,
1023
437
                                  out_data[i], &escape);
1024
437
        break;
1025
499
      case LAV_9:
1026
499
        ixheaacd_mps_huff_read_2d(h_bit_buf,
1027
499
                                  (ia_huff_node_struct)&huff_nodes->lav9,
1028
499
                                  out_data[i], &escape);
1029
499
        break;
1030
1.06k
      case LAV_12:
1031
1.06k
        ixheaacd_mps_huff_read_2d(h_bit_buf,
1032
1.06k
                                  (ia_huff_node_struct)&huff_nodes->lav12,
1033
1.06k
                                  out_data[i], &escape);
1034
1.06k
        break;
1035
0
      default:
1036
0
        break;
1037
2.81k
    }
1038
1039
2.81k
    if (escape) {
1040
0
      esc_idx[esc_cntr++] = i;
1041
2.81k
    } else {
1042
2.81k
      ixheaacd_mps_sym_restore(h_bit_buf, lav, out_data[i]);
1043
2.81k
    }
1044
2.81k
  }
1045
1046
407
  if (esc_cntr > 0) {
1047
0
    ixheaacd_mps_pcm_decode(h_bit_buf, esc_data[0], esc_data[1], 0,
1048
0
                            (esc_cntr << 1), ((lav << 1) + 1));
1049
1050
0
    for (i = 0; i < esc_cntr; i++) {
1051
0
      out_data[esc_idx[i]][0] = esc_data[0][i] - lav;
1052
0
      out_data[esc_idx[i]][1] = esc_data[1][i] - lav;
1053
0
    }
1054
0
  }
1055
407
  return;
1056
409
}
1057
1058
static VOID ixheaacd_huff_decode(ia_bit_buf_struct *it_bit_buff, WORD32 *out_data_1,
1059
                                 WORD32 *out_data_2, WORD32 data_type, WORD32 diff_type_1,
1060
                                 WORD32 diff_type_2, WORD32 pilot_coding_flag, WORD32 *pilot_data,
1061
32.7k
                                 WORD32 num_val, WORD32 *cdg_scheme, WORD32 ld_mps_flag) {
1062
32.7k
  WORD32 diff_type;
1063
1064
32.7k
  WORD32 i = 0;
1065
32.7k
  UWORD32 data = 0;
1066
1067
32.7k
  WORD32 pair_vec[MAXBANDS][2];
1068
1069
32.7k
  WORD32* p0_data_1[2] = {NULL, NULL};
1070
32.7k
  WORD32* p0_data_2[2] = {NULL, NULL};
1071
1072
32.7k
  WORD32 p0_flag[2];
1073
1074
32.7k
  WORD32 num_val_1_int = num_val;
1075
32.7k
  WORD32 num_val_2_int = num_val;
1076
1077
32.7k
  WORD32* out_data_1_int = out_data_1;
1078
32.7k
  WORD32* out_data_2_int = out_data_2;
1079
1080
32.7k
  WORD32 df_rest_flag_1 = 0;
1081
32.7k
  WORD32 df_rest_flag_2 = 0;
1082
1083
32.7k
  WORD32 huff_yy_1;
1084
32.7k
  WORD32 huff_yy_2;
1085
32.7k
  WORD32 huff_yy;
1086
32.7k
  if (pilot_coding_flag) {
1087
6.29k
    switch (data_type) {
1088
5.12k
      case CLD:
1089
5.12k
        if (out_data_1 != NULL) {
1090
5.12k
          ixheaacd_mps_huff_dec_pilot(
1091
5.12k
              it_bit_buff, (ia_huff_node_struct)&ixheaacd_huff_pilot_nodes.cld,
1092
5.12k
              pilot_data);
1093
5.12k
        }
1094
5.12k
        break;
1095
1096
1.01k
      case ICC:
1097
1.01k
        if (out_data_1 != NULL) {
1098
1.01k
          ixheaacd_mps_huff_dec_pilot(
1099
1.01k
              it_bit_buff, (ia_huff_node_struct)&ixheaacd_huff_pilot_nodes.icc,
1100
1.01k
              pilot_data);
1101
1.01k
        }
1102
1.01k
        break;
1103
1104
155
      case CPC:
1105
155
        if (out_data_1 != NULL) {
1106
155
          ixheaacd_mps_huff_dec_pilot(
1107
155
              it_bit_buff,
1108
155
              (ia_huff_node_struct) & (ixheaacd_huff_pilot_nodes.cpc),
1109
155
              pilot_data);
1110
155
        }
1111
155
        break;
1112
1113
0
      default:
1114
0
        break;
1115
6.29k
    }
1116
6.29k
  }
1117
1118
32.7k
  data = ixheaacd_read_bits_buf(it_bit_buff, 1);
1119
32.7k
  *cdg_scheme = data << PAIR_SHIFT;
1120
1121
32.7k
  if (*cdg_scheme >> PAIR_SHIFT == HUFF_2D) {
1122
19.3k
    if ((out_data_1 != NULL) && (out_data_2 != NULL) && (ld_mps_flag != 1)) {
1123
11.0k
      data = ixheaacd_read_bits_buf(it_bit_buff, 1);
1124
11.0k
      *cdg_scheme |= data;
1125
11.0k
    } else {
1126
8.37k
      *cdg_scheme |= FREQ_PAIR;
1127
8.37k
    }
1128
19.3k
  }
1129
1130
32.7k
  if (pilot_coding_flag) {
1131
6.29k
    huff_yy_1 = PCM_PLT;
1132
6.29k
    huff_yy_2 = PCM_PLT;
1133
26.4k
  } else {
1134
26.4k
    huff_yy_1 = diff_type_1;
1135
26.4k
    huff_yy_2 = diff_type_2;
1136
26.4k
  }
1137
1138
32.7k
  switch (*cdg_scheme >> PAIR_SHIFT) {
1139
13.3k
    case HUFF_1D:
1140
1141
13.3k
      p0_flag[0] = (diff_type_1 == DIFF_FREQ) && !pilot_coding_flag;
1142
13.3k
      p0_flag[1] = (diff_type_2 == DIFF_FREQ) && !pilot_coding_flag;
1143
1144
13.3k
      switch (data_type) {
1145
8.33k
        case CLD:
1146
8.33k
          if (out_data_1 != NULL) {
1147
8.33k
            ixheaacd_mps_huff_dec_cld_1d(
1148
8.33k
                it_bit_buff, &ixheaacd_huff_cld_nodes.h_1_dim[huff_yy_1],
1149
8.33k
                out_data_1, num_val_1_int, p0_flag[0]);
1150
8.33k
          }
1151
8.33k
          if (out_data_2 != NULL) {
1152
3.27k
            ixheaacd_mps_huff_dec_cld_1d(
1153
3.27k
                it_bit_buff, &ixheaacd_huff_cld_nodes.h_1_dim[huff_yy_2],
1154
3.27k
                out_data_2, num_val_2_int, p0_flag[1]);
1155
3.27k
          }
1156
1157
8.33k
          break;
1158
1159
3.58k
        case ICC:
1160
3.58k
          if (out_data_1 != NULL) {
1161
3.58k
            ixheaacd_mps_huff_dec_icc_1d(
1162
3.58k
                it_bit_buff, &ixheaacd_huff_icc_nodes.h_1_dim[huff_yy_1],
1163
3.58k
                out_data_1, num_val_1_int, p0_flag[0]);
1164
3.58k
          }
1165
3.58k
          if (out_data_2 != NULL) {
1166
1.44k
            ixheaacd_mps_huff_dec_icc_1d(
1167
1.44k
                it_bit_buff, &ixheaacd_huff_icc_nodes.h_1_dim[huff_yy_2],
1168
1.44k
                out_data_2, num_val_2_int, p0_flag[1]);
1169
1.44k
          }
1170
1171
3.58k
          break;
1172
1173
1.08k
        case IPD:
1174
1.08k
          if (out_data_1 != NULL) {
1175
1.08k
            ixheaacd_mps_huff_dec_ipd_1d(
1176
1.08k
                it_bit_buff, &ixheaacd_huff_ipd_nodes.h_1_dim[huff_yy_1],
1177
1.08k
                out_data_1, num_val_1_int, p0_flag[0]);
1178
1.08k
          }
1179
1.08k
          if (out_data_2 != NULL) {
1180
612
            ixheaacd_mps_huff_dec_ipd_1d(
1181
612
                it_bit_buff, &ixheaacd_huff_ipd_nodes.h_1_dim[huff_yy_2],
1182
612
                out_data_2, num_val_2_int, p0_flag[1]);
1183
612
          }
1184
1185
1.08k
          break;
1186
376
        case CPC:
1187
376
          if (out_data_1 != NULL) {
1188
376
            ia_mps_dec_huff_dec_cpc_1d(
1189
376
                &(ixheaacd_huff_cpc_nodes.h_1_dim[huff_yy_1]), out_data_1,
1190
376
                num_val_1_int, p0_flag[0], it_bit_buff);
1191
376
          }
1192
376
          if (out_data_2 != NULL) {
1193
183
            ia_mps_dec_huff_dec_cpc_1d(
1194
183
                &(ixheaacd_huff_cpc_nodes.h_1_dim[huff_yy_2]), out_data_2,
1195
183
                num_val_2_int, p0_flag[1], it_bit_buff);
1196
183
          }
1197
1198
376
          break;
1199
0
        default:
1200
0
          break;
1201
13.3k
      }
1202
1203
13.3k
      break;
1204
1205
19.3k
    case HUFF_2D:
1206
1207
19.3k
      switch (*cdg_scheme & PAIR_MASK) {
1208
13.7k
        case FREQ_PAIR:
1209
1210
13.7k
          if (out_data_1 != NULL) {
1211
13.7k
            if (!pilot_coding_flag && diff_type_1 == DIFF_FREQ) {
1212
6.27k
              p0_data_1[0] = &out_data_1[0];
1213
6.27k
              p0_data_1[1] = NULL;
1214
1215
6.27k
              num_val_1_int -= 1;
1216
6.27k
              out_data_1_int += 1;
1217
6.27k
            }
1218
13.7k
            df_rest_flag_1 = num_val_1_int % 2;
1219
13.7k
            if (df_rest_flag_1) num_val_1_int -= 1;
1220
13.7k
          }
1221
13.7k
          if (out_data_2 != NULL) {
1222
6.07k
            if (!pilot_coding_flag && diff_type_2 == DIFF_FREQ) {
1223
797
              p0_data_2[0] = NULL;
1224
797
              p0_data_2[1] = &out_data_2[0];
1225
1226
797
              num_val_2_int -= 1;
1227
797
              out_data_2_int += 1;
1228
797
            }
1229
6.07k
            df_rest_flag_2 = num_val_2_int % 2;
1230
6.07k
            if (df_rest_flag_2) num_val_2_int -= 1;
1231
6.07k
          }
1232
1233
13.7k
          switch (data_type) {
1234
10.5k
            case CLD:
1235
1236
10.5k
              if (out_data_1 != NULL) {
1237
10.5k
                ixheaacd_mps_huff_dec_cld_2d(
1238
10.5k
                    it_bit_buff,
1239
10.5k
                    &ixheaacd_huff_cld_nodes.h_2_dim[huff_yy_1][FREQ_PAIR],
1240
10.5k
                    pair_vec, num_val_1_int, 2, p0_data_1);
1241
10.5k
                if (df_rest_flag_1) {
1242
2.57k
                  ixheaacd_mps_huff_dec_cld_1d(
1243
2.57k
                      it_bit_buff, &ixheaacd_huff_cld_nodes.h_1_dim[huff_yy_1],
1244
2.57k
                      out_data_1_int + num_val_1_int, 1, 0);
1245
2.57k
                }
1246
10.5k
              }
1247
10.5k
              if (out_data_2 != NULL) {
1248
4.96k
                ixheaacd_mps_huff_dec_cld_2d(
1249
4.96k
                    it_bit_buff,
1250
4.96k
                    &ixheaacd_huff_cld_nodes.h_2_dim[huff_yy_2][FREQ_PAIR],
1251
4.96k
                    pair_vec + 1, num_val_2_int, 2, p0_data_2);
1252
4.96k
                if (df_rest_flag_2) {
1253
437
                  ixheaacd_mps_huff_dec_cld_1d(
1254
437
                      it_bit_buff, &ixheaacd_huff_cld_nodes.h_1_dim[huff_yy_2],
1255
437
                      out_data_2_int + num_val_2_int, 1, 0);
1256
437
                }
1257
4.96k
              }
1258
10.5k
              break;
1259
1260
2.44k
            case ICC:
1261
2.44k
              if (out_data_1 != NULL) {
1262
2.44k
                ixheaacd_mps_huff_dec_icc_2d(
1263
2.44k
                    it_bit_buff,
1264
2.44k
                    &ixheaacd_huff_icc_nodes.h_2_dim[huff_yy_1][FREQ_PAIR],
1265
2.44k
                    pair_vec, num_val_1_int, 2, p0_data_1);
1266
2.44k
                if (df_rest_flag_1) {
1267
1.37k
                  ixheaacd_mps_huff_dec_icc_1d(
1268
1.37k
                      it_bit_buff, &ixheaacd_huff_icc_nodes.h_1_dim[huff_yy_1],
1269
1.37k
                      out_data_1_int + num_val_1_int, 1, 0);
1270
1.37k
                }
1271
2.44k
              }
1272
2.44k
              if (out_data_2 != NULL) {
1273
881
                ixheaacd_mps_huff_dec_icc_2d(
1274
881
                    it_bit_buff,
1275
881
                    &ixheaacd_huff_icc_nodes.h_2_dim[huff_yy_2][FREQ_PAIR],
1276
881
                    pair_vec + 1, num_val_2_int, 2, p0_data_2);
1277
881
                if (df_rest_flag_2) {
1278
397
                  ixheaacd_mps_huff_dec_icc_1d(
1279
397
                      it_bit_buff, &ixheaacd_huff_icc_nodes.h_1_dim[huff_yy_2],
1280
397
                      out_data_2_int + num_val_2_int, 1, 0);
1281
397
                }
1282
881
              }
1283
2.44k
              break;
1284
1285
520
            case IPD:
1286
520
              if (out_data_1 != NULL) {
1287
520
                ixheaacd_mps_huff_dec_ipd_2d(
1288
520
                    it_bit_buff,
1289
520
                    &ixheaacd_huff_ipd_nodes.h_2_dim[huff_yy_1][FREQ_PAIR],
1290
520
                    pair_vec, num_val_1_int, 2, p0_data_1);
1291
520
                if (df_rest_flag_1) {
1292
220
                  ixheaacd_mps_huff_dec_ipd_1d(
1293
220
                      it_bit_buff, &ixheaacd_huff_ipd_nodes.h_1_dim[huff_yy_1],
1294
220
                      out_data_1_int + num_val_1_int, 1, 0);
1295
220
                }
1296
520
              }
1297
520
              if (out_data_2 != NULL) {
1298
151
                ixheaacd_mps_huff_dec_ipd_2d(
1299
151
                    it_bit_buff,
1300
151
                    &ixheaacd_huff_ipd_nodes.h_2_dim[huff_yy_2][FREQ_PAIR],
1301
151
                    pair_vec + 1, num_val_2_int, 2, p0_data_2);
1302
151
                if (df_rest_flag_2) {
1303
55
                  ixheaacd_mps_huff_dec_ipd_1d(
1304
55
                      it_bit_buff, &ixheaacd_huff_ipd_nodes.h_1_dim[huff_yy_2],
1305
55
                      out_data_2_int + num_val_2_int, 1, 0);
1306
55
                }
1307
151
              }
1308
520
              break;
1309
228
            case CPC:
1310
228
              if (out_data_1 != NULL) {
1311
228
                ia_mps_dec_huff_dec_cpc_2d(
1312
228
                    &(ixheaacd_huff_cpc_nodes.h_2_dim[huff_yy_1][FREQ_PAIR]), pair_vec,
1313
228
                    num_val_1_int, 2, p0_data_1, it_bit_buff);
1314
228
                if (df_rest_flag_1) {
1315
120
                  ia_mps_dec_huff_dec_cpc_1d(&(ixheaacd_huff_cpc_nodes.h_1_dim[huff_yy_1]),
1316
120
                      out_data_1_int + num_val_1_int, 1, 0, it_bit_buff);
1317
120
                }
1318
228
              }
1319
228
              if (out_data_2 != NULL) {
1320
80
                ia_mps_dec_huff_dec_cpc_2d(
1321
80
                    &(ixheaacd_huff_cpc_nodes.h_2_dim[huff_yy_2][FREQ_PAIR]), pair_vec + 1,
1322
80
                    num_val_2_int, 2, p0_data_2, it_bit_buff);
1323
1324
80
                if (df_rest_flag_2) {
1325
27
                  ia_mps_dec_huff_dec_cpc_1d(
1326
27
                      &(ixheaacd_huff_cpc_nodes.h_1_dim[huff_yy_2]),
1327
27
                      out_data_2_int + num_val_2_int, 1, 0, it_bit_buff);
1328
27
                }
1329
80
              }
1330
228
              break;
1331
0
            default:
1332
0
              break;
1333
13.7k
          }
1334
1335
13.7k
          if (out_data_1 != NULL) {
1336
65.4k
            for (i = 0; i < num_val_1_int - 1; i += 2) {
1337
51.7k
              out_data_1_int[i] = pair_vec[i][0];
1338
51.7k
              out_data_1_int[i + 1] = pair_vec[i][1];
1339
51.7k
            }
1340
13.7k
          }
1341
13.7k
          if (out_data_2 != NULL) {
1342
34.5k
            for (i = 0; i < num_val_2_int - 1; i += 2) {
1343
28.4k
              out_data_2_int[i] = pair_vec[i + 1][0];
1344
28.4k
              out_data_2_int[i + 1] = pair_vec[i + 1][1];
1345
28.4k
            }
1346
6.06k
          }
1347
1348
13.7k
          break;
1349
1350
5.65k
        case TIME_PAIR:
1351
1352
5.65k
          if (!pilot_coding_flag &&
1353
5.65k
              ((diff_type_1 == DIFF_FREQ) || (diff_type_2 == DIFF_FREQ))) {
1354
4.71k
            p0_data_1[0] = &out_data_1[0];
1355
4.71k
            p0_data_1[1] = &out_data_2[0];
1356
1357
4.71k
            out_data_1_int += 1;
1358
4.71k
            out_data_2_int += 1;
1359
1360
4.71k
            num_val_1_int -= 1;
1361
4.71k
          }
1362
1363
5.65k
          if ((diff_type_1 == DIFF_TIME) || (diff_type_2 == DIFF_TIME)) {
1364
4.62k
            diff_type = DIFF_TIME;
1365
4.62k
          } else {
1366
1.02k
            diff_type = DIFF_FREQ;
1367
1.02k
          }
1368
5.65k
          if (pilot_coding_flag) {
1369
527
            huff_yy = PCM_PLT;
1370
5.12k
          } else {
1371
5.12k
            huff_yy = diff_type;
1372
5.12k
          }
1373
1374
5.65k
          switch (data_type) {
1375
3.02k
            case CLD:
1376
3.02k
              ixheaacd_mps_huff_dec_cld_2d(
1377
3.02k
                  it_bit_buff,
1378
3.02k
                  &ixheaacd_huff_cld_nodes.h_2_dim[huff_yy][TIME_PAIR],
1379
3.02k
                  pair_vec, num_val_1_int, 1, p0_data_1);
1380
3.02k
              break;
1381
1382
2.22k
            case ICC:
1383
2.22k
              ixheaacd_mps_huff_dec_icc_2d(
1384
2.22k
                  it_bit_buff,
1385
2.22k
                  &ixheaacd_huff_icc_nodes.h_2_dim[huff_yy][TIME_PAIR],
1386
2.22k
                  pair_vec, num_val_1_int, 1, p0_data_1);
1387
2.22k
              break;
1388
1389
306
            case IPD:
1390
306
              ixheaacd_mps_huff_dec_ipd_2d(
1391
306
                  it_bit_buff,
1392
306
                  &ixheaacd_huff_ipd_nodes.h_2_dim[huff_yy][TIME_PAIR],
1393
306
                  pair_vec, num_val_1_int, 1, p0_data_1);
1394
306
              break;
1395
101
            case CPC:
1396
101
              ia_mps_dec_huff_dec_cpc_2d(&(ixheaacd_huff_cpc_nodes.h_2_dim[huff_yy][TIME_PAIR]),
1397
101
                  pair_vec, num_val_1_int, 1, p0_data_1, it_bit_buff);
1398
101
              break;
1399
0
            default:
1400
0
              break;
1401
5.65k
          }
1402
1403
34.3k
          for (i = 0; i < num_val_1_int; i++) {
1404
28.7k
            out_data_1_int[i] = pair_vec[i][0];
1405
28.7k
            out_data_2_int[i] = pair_vec[i][1];
1406
28.7k
          }
1407
1408
5.63k
          break;
1409
1410
0
        default:
1411
0
          break;
1412
19.3k
      }
1413
1414
19.3k
      break;
1415
1416
19.3k
    default:
1417
0
      break;
1418
32.7k
  }
1419
1420
32.6k
  return;
1421
32.7k
}
1422
1423
static VOID ixheaacd_diff_freq_decode(WORD32* diff_data, WORD32* out_data,
1424
42.3k
                                      WORD32 num_val) {
1425
42.3k
  WORD32 i = 0;
1426
1427
42.3k
  out_data[0] = diff_data[0];
1428
1429
297k
  for (i = 1; i < num_val; i++) {
1430
255k
    out_data[i] = out_data[i - 1] + diff_data[i];
1431
255k
  }
1432
42.3k
}
1433
1434
static VOID ixheaacd_mps_diff_time_dec_bwd(WORD32* prev_data, WORD32* diff_data,
1435
                                           WORD32* out_data,
1436
                                           WORD32 mixed_diff_type,
1437
9.22k
                                           WORD32 num_val) {
1438
9.22k
  WORD32 i = 0;
1439
1440
9.22k
  if (mixed_diff_type) {
1441
3.70k
    out_data[0] = diff_data[0];
1442
17.5k
    for (i = 1; i < num_val; i++) {
1443
13.8k
      out_data[i] = prev_data[i] + diff_data[i];
1444
13.8k
    }
1445
5.51k
  } else {
1446
55.2k
    for (i = 0; i < num_val; i++) {
1447
49.7k
      out_data[i] = prev_data[i] + diff_data[i];
1448
49.7k
    }
1449
5.51k
  }
1450
9.22k
}
1451
1452
static VOID ixheaacd_mps_diff_time_dec_fwd(WORD32* prev_data, WORD32* diff_data,
1453
                                           WORD32* out_data,
1454
                                           WORD32 mixed_diff_type,
1455
1.14k
                                           WORD32 num_val) {
1456
1.14k
  WORD32 i = 0;
1457
1458
1.14k
  if (mixed_diff_type) {
1459
498
    out_data[0] = diff_data[0];
1460
4.44k
    for (i = 1; i < num_val; i++) {
1461
3.94k
      out_data[i] = prev_data[i] - diff_data[i];
1462
3.94k
    }
1463
646
  } else {
1464
5.15k
    for (i = 0; i < num_val; i++) {
1465
4.50k
      out_data[i] = prev_data[i] - diff_data[i];
1466
4.50k
    }
1467
646
  }
1468
1.14k
}
1469
1470
static VOID ixheaacd_attach_lsb(ia_bit_buf_struct *it_bit_buff,
1471
                                WORD32* in_data_msb, WORD32 ixheaacd_drc_offset,
1472
                                WORD32 num_lsb, WORD32 num_val,
1473
49.8k
                                WORD32* out_data) {
1474
49.8k
  WORD32 i = 0, lsb = 0, msb = 0;
1475
49.8k
  UWORD32 data = 0;
1476
1477
438k
  for (i = 0; i < num_val; i++) {
1478
388k
    msb = in_data_msb[i];
1479
1480
388k
    if (num_lsb > 0) {
1481
31.1k
      data = ixheaacd_read_bits_buf(it_bit_buff, num_lsb);
1482
31.1k
      lsb = data;
1483
1484
31.1k
      out_data[i] = ((msb << num_lsb) | lsb) - ixheaacd_drc_offset;
1485
31.1k
    } else
1486
357k
      out_data[i] = msb - ixheaacd_drc_offset;
1487
388k
  }
1488
1489
49.8k
  return;
1490
49.8k
}
1491
1492
WORD32 ixheaacd_mps_ecdatapairdec(ia_bit_buf_struct *it_bit_buff, WORD32 outdata[][MAXBANDS],
1493
                                  WORD32 history[MAXBANDS], WORD32 data_type, WORD32 set_idx,
1494
                                  WORD32 start_band, WORD32 data_bands, WORD32 pair_flag,
1495
                                  WORD32 coarse_flag, WORD32 diff_time_back_flag,
1496
56.5k
                                  WORD32 ld_mps_flag, WORD32 heaac_mps_present, WORD32 ec_flag) {
1497
56.5k
  WORD32 attach_lsb_flag = 0;
1498
56.5k
  WORD32 pcm_coding_flag = 0;
1499
56.5k
  WORD32 pilot_coding_flag = 0;
1500
56.5k
  WORD32 pilot_data[2] = {0, 0};
1501
56.5k
  WORD32 mixed_time_pair = 0, pcm_val = 0;
1502
56.5k
  WORD32 quant_levels = 0, quant_offset = 0;
1503
56.5k
  UWORD32 data = 0;
1504
56.5k
  WORD32 band_start = 0;
1505
1506
56.5k
  WORD32 data_pair[2][MAXBANDS] = {{0}};
1507
56.5k
  WORD32 data_diff[2][MAXBANDS] = {{0}};
1508
1509
56.5k
  WORD32 msb_state[MAXBANDS] = {0};
1510
1511
56.5k
  WORD32* data_array[2] = {NULL, NULL};
1512
1513
56.5k
  WORD32 diff_type[2] = {DIFF_FREQ, DIFF_FREQ};
1514
56.5k
  WORD32 cdg_scheme = HUFF_1D;
1515
56.5k
  WORD32 direction = BACKWARDS;
1516
1517
56.5k
  if (heaac_mps_present == 1) {
1518
25.9k
    band_start = start_band;
1519
25.9k
  }
1520
1521
56.5k
  switch (data_type) {
1522
34.1k
    case CLD:
1523
34.1k
      if (coarse_flag) {
1524
14.6k
        attach_lsb_flag = 0;
1525
14.6k
        quant_levels = 15;
1526
14.6k
        quant_offset = 7;
1527
19.4k
      } else {
1528
19.4k
        attach_lsb_flag = 0;
1529
19.4k
        quant_levels = 31;
1530
19.4k
        quant_offset = 15;
1531
19.4k
      }
1532
1533
34.1k
      break;
1534
1535
16.5k
    case ICC:
1536
16.5k
      if (coarse_flag) {
1537
7.80k
        attach_lsb_flag = 0;
1538
7.80k
        quant_levels = 4;
1539
7.80k
        quant_offset = 0;
1540
8.76k
      } else {
1541
8.76k
        attach_lsb_flag = 0;
1542
8.76k
        quant_levels = 8;
1543
8.76k
        quant_offset = 0;
1544
8.76k
      }
1545
1546
16.5k
      break;
1547
1548
4.34k
    case IPD:
1549
4.34k
      if (coarse_flag) {
1550
2.35k
        attach_lsb_flag = 0;
1551
2.35k
        quant_levels = 8;
1552
2.35k
        quant_offset = 0;
1553
2.35k
      } else {
1554
1.99k
        attach_lsb_flag = 1;
1555
1.99k
        quant_levels = 16;
1556
1.99k
        quant_offset = 0;
1557
1.99k
      }
1558
4.34k
      break;
1559
1560
1.54k
    case CPC:
1561
1.54k
      if (coarse_flag) {
1562
988
        attach_lsb_flag = 0;
1563
988
        quant_levels = 26;
1564
988
        quant_offset = 10;
1565
988
      } else {
1566
561
        attach_lsb_flag = 1;
1567
561
        quant_levels = 51;
1568
561
        quant_offset = 20;
1569
561
      }
1570
1.54k
      break;
1571
1572
0
    default:
1573
0
      break;
1574
56.5k
  }
1575
1576
56.5k
  data = ixheaacd_read_bits_buf(it_bit_buff, 1);
1577
56.5k
  pcm_coding_flag = data;
1578
1579
56.5k
  pilot_coding_flag = 0;
1580
1581
56.5k
  if (heaac_mps_present == 1) {
1582
25.9k
    if (pcm_coding_flag && data_bands > 4) {
1583
7.20k
      data = ixheaacd_read_bits_buf(it_bit_buff, 1);
1584
7.20k
      pilot_coding_flag = data;
1585
7.20k
    }
1586
25.9k
  }
1587
1588
56.5k
  if (pcm_coding_flag && !pilot_coding_flag) {
1589
23.3k
    if (pair_flag) {
1590
12.9k
      data_array[0] = data_pair[0];
1591
12.9k
      data_array[1] = data_pair[1];
1592
12.9k
      pcm_val = 2 * data_bands;
1593
12.9k
    } else {
1594
10.4k
      data_array[0] = data_pair[0];
1595
10.4k
      data_array[1] = NULL;
1596
10.4k
      pcm_val = data_bands;
1597
10.4k
    }
1598
1599
23.3k
    ixheaacd_mps_pcm_decode(it_bit_buff, data_array[0], data_array[1],
1600
23.3k
                            quant_offset, pcm_val, quant_levels);
1601
1602
33.1k
  } else {
1603
33.1k
    if (pair_flag) {
1604
17.6k
      data_array[0] = data_diff[0];
1605
17.6k
      data_array[1] = data_diff[1];
1606
17.6k
    } else {
1607
15.5k
      data_array[0] = data_diff[0];
1608
15.5k
      data_array[1] = NULL;
1609
15.5k
    }
1610
1611
33.1k
    diff_type[0] = DIFF_FREQ;
1612
33.1k
    diff_type[1] = DIFF_FREQ;
1613
1614
33.1k
    direction = BACKWARDS;
1615
1616
33.1k
    if (!pilot_coding_flag) {
1617
26.8k
      if (pair_flag || diff_time_back_flag) {
1618
20.1k
        data = ixheaacd_read_bits_buf(it_bit_buff, 1);
1619
20.1k
        diff_type[0] = data;
1620
20.1k
      }
1621
1622
26.8k
      if (pair_flag && ((diff_type[0] == DIFF_FREQ) || diff_time_back_flag)) {
1623
11.2k
        data = ixheaacd_read_bits_buf(it_bit_buff, 1);
1624
11.2k
        diff_type[1] = data;
1625
11.2k
      }
1626
26.8k
    }
1627
1628
33.1k
    if (data_bands <= 0) {
1629
418
      if (!ec_flag)
1630
418
        return -1;
1631
0
      else
1632
0
        longjmp(*(it_bit_buff->xaac_jmp_buf), IA_FATAL_ERROR);
1633
418
    }
1634
1635
32.7k
    ixheaacd_huff_decode(it_bit_buff, data_array[0], data_array[1], data_type, diff_type[0],
1636
32.7k
                         diff_type[1], pilot_coding_flag, pilot_data, data_bands, &cdg_scheme,
1637
32.7k
                         ld_mps_flag);
1638
1639
32.7k
    if (pilot_coding_flag && heaac_mps_present == 1) {
1640
6.27k
      WORD32 i;
1641
72.0k
      for (i = 0; i < data_bands; i++) {
1642
65.7k
        data_pair[0][i] = data_diff[0][i] + pilot_data[0];
1643
65.7k
      }
1644
1645
6.27k
      if (pair_flag) {
1646
61.2k
        for (i = 0; i < data_bands; i++) {
1647
55.8k
          data_pair[1][i] = data_diff[1][i] + pilot_data[0];
1648
55.8k
        }
1649
5.47k
      }
1650
26.4k
    } else {
1651
26.4k
      if ((diff_type[0] == DIFF_TIME) || (diff_type[1] == DIFF_TIME)) {
1652
9.29k
        if (pair_flag) {
1653
7.01k
          if ((diff_type[0] == DIFF_TIME) && !diff_time_back_flag) {
1654
874
            direction = FORWARDS;
1655
6.14k
          } else if (diff_type[1] == DIFF_TIME) {
1656
5.54k
            direction = BACKWARDS;
1657
5.54k
          } else {
1658
593
            data = ixheaacd_read_bits_buf(it_bit_buff, 1);
1659
593
            direction = data;
1660
593
          }
1661
7.01k
        } else {
1662
2.28k
          direction = BACKWARDS;
1663
2.28k
        }
1664
9.29k
      }
1665
1666
26.4k
      mixed_time_pair = (diff_type[0] != diff_type[1]) &&
1667
26.4k
                        ((cdg_scheme & PAIR_MASK) == TIME_PAIR);
1668
1669
26.4k
      if (direction == BACKWARDS) {
1670
25.2k
        if (diff_type[0] == DIFF_FREQ) {
1671
21.5k
          ixheaacd_diff_freq_decode(data_diff[0], data_pair[0], data_bands);
1672
21.5k
        } else {
1673
3.67k
          WORD32 i;
1674
36.3k
          for (i = 0; i < data_bands; i++) {
1675
32.7k
            msb_state[i] = history[i + band_start] + quant_offset;
1676
32.7k
            if (attach_lsb_flag) {
1677
6.52k
              msb_state[i] >>= 1;
1678
6.52k
            }
1679
32.7k
          }
1680
3.67k
          ixheaacd_mps_diff_time_dec_bwd(msb_state, data_diff[0], data_pair[0],
1681
3.67k
                                         mixed_time_pair, data_bands);
1682
3.67k
        }
1683
25.2k
        if (diff_type[1] == DIFF_FREQ) {
1684
19.6k
          ixheaacd_diff_freq_decode(data_diff[1], data_pair[1], data_bands);
1685
19.6k
        } else {
1686
5.54k
          ixheaacd_mps_diff_time_dec_bwd(data_pair[0], data_diff[1], data_pair[1],
1687
5.54k
                                         mixed_time_pair, data_bands);
1688
5.54k
        }
1689
25.2k
      } else {
1690
1.27k
        ixheaacd_diff_freq_decode(data_diff[1], data_pair[1], data_bands);
1691
1692
1.27k
        if (diff_type[0] == DIFF_FREQ) {
1693
0
          ixheaacd_diff_freq_decode(data_diff[0], data_pair[0], data_bands);
1694
1.27k
        } else {
1695
1.27k
          ixheaacd_mps_diff_time_dec_fwd(data_pair[1], data_diff[0], data_pair[0],
1696
1.27k
                                         mixed_time_pair, data_bands);
1697
1.27k
        }
1698
1.27k
      }
1699
26.4k
    }
1700
32.7k
    ixheaacd_attach_lsb(it_bit_buff, data_pair[0], quant_offset,
1701
32.7k
                        attach_lsb_flag ? 1 : 0, data_bands, data_pair[0]);
1702
32.7k
    if (pair_flag) {
1703
17.1k
      ixheaacd_attach_lsb(it_bit_buff, data_pair[1], quant_offset,
1704
17.1k
                          attach_lsb_flag ? 1 : 0, data_bands, data_pair[1]);
1705
17.1k
    }
1706
32.7k
  }
1707
1708
56.1k
  memcpy(outdata[set_idx] + band_start, data_pair[0],
1709
56.1k
         sizeof(WORD32) * data_bands);
1710
56.1k
  if (pair_flag) {
1711
30.0k
    memcpy(outdata[set_idx + 1] + band_start, data_pair[1],
1712
30.0k
           sizeof(WORD32) * data_bands);
1713
30.0k
  }
1714
1715
56.1k
  return IA_NO_ERROR;
1716
56.5k
}
1717
1718
VOID ixheaacd_mps_huff_decode(ia_bit_buf_struct *it_bit_buff,
1719
5.24k
                              WORD32* out_data, WORD32 num_val) {
1720
5.24k
  WORD32 val_rcvd = 0, dummy = 0, i = 0, val = 0, len = 0;
1721
5.24k
  WORD32 rl_data[2] = {0};
1722
1723
60.9k
  while (val_rcvd < num_val) {
1724
55.7k
    ixheaacd_mps_huff_read_2d(it_bit_buff,
1725
55.7k
                              (ia_huff_node_struct)&ixheaacd_huff_reshape_nodes,
1726
55.7k
                              rl_data, &dummy);
1727
55.7k
    val = rl_data[0];
1728
55.7k
    len = rl_data[1] + 1;
1729
193k
    for (i = val_rcvd; i < val_rcvd + len; i++) {
1730
137k
      out_data[i] = val;
1731
137k
    }
1732
55.7k
    val_rcvd += len;
1733
55.7k
  }
1734
1735
5.24k
  return;
1736
5.24k
}
1737
1738
VOID ixheaacd_update_out_buffer(ia_heaac_mps_state_struct *pstr_mps_state,
1739
15.5k
                                WORD16 *out_buf) {
1740
15.5k
  WORD32 ch, sam;
1741
15.5k
  WORD32 num_output_channels_at = pstr_mps_state->num_output_channels_at;
1742
15.5k
  WORD32 frame_length = pstr_mps_state->frame_length;
1743
1744
15.5k
  WORD32 *p_time_out = pstr_mps_state->array_struct->time_out;
1745
1746
135k
  for (ch = 0; ch < num_output_channels_at; ch++) {
1747
120k
    WORD32 *time_out = p_time_out;
1748
187M
    for (sam = 0; sam < frame_length; sam++) {
1749
187M
      out_buf[sam * num_output_channels_at + ch] = (*time_out++) >> 16;
1750
187M
    }
1751
120k
    p_time_out += QBXTS;
1752
120k
  }
1753
1754
15.5k
  return;
1755
15.5k
}
1756
1757
15.5k
VOID ixheaacd_update_time_out_buffer(ia_heaac_mps_state_struct *pstr_mps_state) {
1758
15.5k
  WORD32 n;
1759
15.5k
  WORD32 up_mix_type = pstr_mps_state->up_mix_type;
1760
15.5k
  WORD32 tree_config = pstr_mps_state->tree_config;
1761
15.5k
  WORD32 lfe_gain = pstr_mps_state->lfe_gain;
1762
15.5k
  WORD32 surround_gain = pstr_mps_state->surround_gain;
1763
1764
15.5k
  if (!pstr_mps_state->bs_config.arbitrary_tree && up_mix_type != 2 && up_mix_type != 3) {
1765
15.4k
    WORD32 frame_length = pstr_mps_state->frame_length;
1766
1767
15.4k
    WORD32 *time_out_3 = pstr_mps_state->array_struct->time_out + QBXTSX3;
1768
15.4k
    WORD32 *time_out_4 = time_out_3 + QBXTS;
1769
15.4k
    WORD32 *time_out_5 = time_out_4 + QBXTS;
1770
15.4k
    WORD32 *time_out_6 = time_out_5 + QBXTS;
1771
15.4k
    WORD32 *time_out_7 = time_out_6 + QBXTS;
1772
1773
23.8M
    for (n = 0; n < frame_length; n++) {
1774
23.8M
      *time_out_3 = ixheaacd_mps_mult32_shr_15(*time_out_3, lfe_gain);
1775
23.8M
      time_out_3++;
1776
23.8M
      *time_out_4 = ixheaacd_mps_mult32_shr_15(*time_out_4, surround_gain);
1777
23.8M
      time_out_4++;
1778
23.8M
      *time_out_5 = ixheaacd_mps_mult32_shr_15(*time_out_5, surround_gain);
1779
23.8M
      time_out_5++;
1780
23.8M
    }
1781
1782
15.4k
    if (tree_config == 4 || tree_config == 6) {
1783
21.5M
      for (n = 0; n < frame_length; n++) {
1784
21.5M
        *time_out_6 = ixheaacd_mps_mult32_shr_15(*time_out_6, surround_gain);
1785
21.5M
        time_out_6++;
1786
21.5M
        *time_out_7 = ixheaacd_mps_mult32_shr_15(*time_out_7, surround_gain);
1787
21.5M
        time_out_7++;
1788
21.5M
      }
1789
12.9k
    }
1790
15.4k
  }
1791
15.5k
}
1792
1793
static IA_ERRORCODE ixheaacd_apply_frame(ia_heaac_mps_state_struct *pstr_mps_state,
1794
                                         WORD32 in_time_slots,
1795
                                         WORD32 *m_qmf_real, WORD32 *m_qmf_imag,
1796
15.7k
                                         WORD16 *out_buf) {
1797
15.7k
  IA_ERRORCODE err_code = IA_NO_ERROR;
1798
15.7k
  WORD32 ch, ts, qs;
1799
15.7k
  WORD32 *pbuf_real, *pbuf_imag, *pbuf_re, *pbuf_im;
1800
15.7k
  WORD32 *buf_real, *buf_imag;
1801
15.7k
  WORD32 *qmf_input_delay_real_2 =
1802
15.7k
      pstr_mps_state->mps_persistent_mem.qmf_input_delay_real;
1803
15.7k
  WORD32 *qmf_input_delay_imag_2 =
1804
15.7k
      pstr_mps_state->mps_persistent_mem.qmf_input_delay_imag;
1805
15.7k
  WORD32 num_input_channels = pstr_mps_state->num_input_channels;
1806
15.7k
  WORD32 qmf_bands = pstr_mps_state->qmf_bands;
1807
15.7k
  WORD32 cur_time_slot = pstr_mps_state->cur_time_slot;
1808
15.7k
  WORD32 time_slots = pstr_mps_state->time_slots;
1809
15.7k
  WORD32 qmf_input_delay_index = pstr_mps_state->qmf_input_delay_index;
1810
15.7k
  WORD32 up_mix_type = pstr_mps_state->up_mix_type;
1811
15.7k
  WORD32 residual_coding = pstr_mps_state->residual_coding;
1812
15.7k
  WORD32 arbitrary_downmix = pstr_mps_state->arbitrary_downmix;
1813
1814
15.7k
  WORD32 *qmf_input_delay_real_1, *qmf_input_delay_imag_1;
1815
15.7k
  WORD32 *qmf_input_delay_real, *qmf_input_delay_imag;
1816
1817
15.7k
  WORD32 *p_qmf_real = m_qmf_real;
1818
15.7k
  WORD32 *p_qmf_imag = m_qmf_imag;
1819
15.7k
  WORD32 *p_qmf_re, *p_qmf_im, *qmf_real, *qmf_imag;
1820
1821
15.7k
  if (cur_time_slot + in_time_slots > time_slots) {
1822
0
    if (pstr_mps_state->ec_flag)
1823
0
      cur_time_slot = time_slots - in_time_slots;
1824
0
    else
1825
0
      return IA_FATAL_ERROR;
1826
0
  }
1827
15.7k
  if (time_slots % HOP_SLOTS != 0) {
1828
10
    if (pstr_mps_state->ec_flag)
1829
0
      time_slots = time_slots - (time_slots % HOP_SLOTS);
1830
10
    else
1831
10
      return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_TIMESLOTS;
1832
10
  }
1833
1834
15.7k
  pbuf_real = pstr_mps_state->array_struct->buf_real;
1835
15.7k
  pbuf_imag = pstr_mps_state->array_struct->buf_imag;
1836
1837
15.7k
  if (up_mix_type == 1) {
1838
0
    for (ch = 0; ch < num_input_channels; ch++) {
1839
0
      pbuf_re = pbuf_real;
1840
0
      pbuf_im = pbuf_imag;
1841
1842
0
      p_qmf_re = p_qmf_real;
1843
0
      p_qmf_im = p_qmf_imag;
1844
1845
0
      for (ts = 0; ts < in_time_slots; ts++) {
1846
0
        buf_real = pbuf_re + (cur_time_slot + ts);
1847
0
        buf_imag = pbuf_im + (cur_time_slot + ts);
1848
1849
0
        qmf_real = p_qmf_re;
1850
0
        qmf_imag = p_qmf_im;
1851
1852
0
        for (qs = 0; qs < qmf_bands; qs++) {
1853
0
          *buf_real++ = *qmf_real++;
1854
0
          *buf_imag++ = *qmf_imag++;
1855
0
        }
1856
0
        pbuf_re += MAX_HYBRID_BANDS;
1857
0
        pbuf_im += MAX_HYBRID_BANDS;
1858
1859
0
        p_qmf_re += MAX_NUM_QMF_BANDS;
1860
0
        p_qmf_im += MAX_NUM_QMF_BANDS;
1861
0
      }
1862
0
      pbuf_real += TSXHB;
1863
0
      pbuf_imag += TSXHB;
1864
1865
0
      p_qmf_real += QBXTS;
1866
0
      p_qmf_imag += QBXTS;
1867
0
    }
1868
15.7k
  } else {
1869
98.2k
    for (ch = 0; ch < num_input_channels; ch++) {
1870
82.5k
      WORD32 offset = ch * PCXQB;
1871
82.5k
      qmf_input_delay_index = pstr_mps_state->qmf_input_delay_index;
1872
82.5k
      qmf_input_delay_real_1 = qmf_input_delay_real_2 + offset;
1873
82.5k
      qmf_input_delay_imag_1 = qmf_input_delay_imag_2 + offset;
1874
1875
82.5k
      pbuf_re = pbuf_real + cur_time_slot * MAX_HYBRID_BANDS;
1876
82.5k
      pbuf_im = pbuf_imag + cur_time_slot * MAX_HYBRID_BANDS;
1877
1878
82.5k
      p_qmf_re = p_qmf_real;
1879
82.5k
      p_qmf_im = p_qmf_imag;
1880
1881
2.65M
      for (ts = 0; ts < in_time_slots; ts++) {
1882
2.57M
        WORD32 off_set = qmf_input_delay_index * MAX_NUM_QMF_BANDS;
1883
2.57M
        qmf_input_delay_real = qmf_input_delay_real_1 + off_set;
1884
2.57M
        qmf_input_delay_imag = qmf_input_delay_imag_1 + off_set;
1885
1886
2.57M
        buf_real = pbuf_re;
1887
2.57M
        buf_imag = pbuf_im;
1888
1889
2.57M
        qmf_real = p_qmf_re;
1890
2.57M
        qmf_imag = p_qmf_im;
1891
1892
136M
        for (qs = 0; qs < qmf_bands; qs++) {
1893
133M
          {
1894
133M
            *buf_real++ = *qmf_input_delay_real;
1895
133M
            *buf_imag++ = *qmf_input_delay_imag;
1896
1897
133M
            *qmf_input_delay_real++ = *qmf_real++;
1898
133M
            *qmf_input_delay_imag++ = *qmf_imag++;
1899
133M
          }
1900
133M
        }
1901
1902
2.57M
        qmf_input_delay_index++;
1903
1904
2.57M
        if (qmf_input_delay_index == PC_FILTERDELAY) {
1905
509k
          qmf_input_delay_index = 0;
1906
509k
        }
1907
2.57M
        pbuf_re += MAX_HYBRID_BANDS;
1908
2.57M
        pbuf_im += MAX_HYBRID_BANDS;
1909
1910
2.57M
        p_qmf_re += MAX_NUM_QMF_BANDS;
1911
2.57M
        p_qmf_im += MAX_NUM_QMF_BANDS;
1912
2.57M
      }
1913
82.5k
      pbuf_real += TSXHB;
1914
82.5k
      pbuf_imag += TSXHB;
1915
1916
82.5k
      p_qmf_real += QBXTS;
1917
82.5k
      p_qmf_imag += QBXTS;
1918
82.5k
    }
1919
15.7k
    pstr_mps_state->qmf_input_delay_index = qmf_input_delay_index;
1920
15.7k
  }
1921
1922
15.7k
  pstr_mps_state->cur_time_slot += in_time_slots;
1923
15.7k
  cur_time_slot = pstr_mps_state->cur_time_slot;
1924
1925
15.7k
  if (pstr_mps_state->cur_time_slot < time_slots) {
1926
0
    if (pstr_mps_state->ec_flag) {
1927
0
      pstr_mps_state->cur_time_slot = time_slots;
1928
0
    } else
1929
0
      return IA_FATAL_ERROR;
1930
0
  }
1931
1932
15.7k
  pstr_mps_state->cur_time_slot = 0;
1933
1934
15.7k
  err_code = ixheaacd_decode_frame(pstr_mps_state);
1935
15.7k
  if (err_code != IA_NO_ERROR) return err_code;
1936
1937
15.5k
  ixheaacd_mdct_2_qmf(pstr_mps_state);
1938
1939
15.5k
  ixheaacd_hybrid_qmf_analysis(pstr_mps_state);
1940
1941
15.5k
  if (residual_coding || (arbitrary_downmix == 2)) {
1942
340
    ixheaacd_update_buffers(pstr_mps_state);
1943
340
  }
1944
1945
15.5k
  if (up_mix_type == 1) {
1946
0
    ixheaacd_apply_blind(pstr_mps_state);
1947
0
  }
1948
1949
15.5k
  ixheaacd_calc_m1m2(pstr_mps_state);
1950
1951
15.5k
  ixheaacd_smooth_m1m2(pstr_mps_state);
1952
1953
15.5k
  ixheaacd_mps_apply_m1(pstr_mps_state);
1954
1955
15.5k
  ixheaacd_buffer_m1(pstr_mps_state);
1956
1957
15.5k
  if (up_mix_type != 2) {
1958
15.5k
    if (pstr_mps_state->temp_shape_config == 2) {
1959
6.59k
      ixheaacd_pre_reshape_bb_env(pstr_mps_state);
1960
6.59k
    }
1961
15.5k
  }
1962
1963
15.5k
  ixheaacd_create_w(pstr_mps_state);
1964
1965
15.5k
  ixheaacd_apply_m2(pstr_mps_state);
1966
1967
15.5k
  ixheaacd_buffer_m2(pstr_mps_state);
1968
1969
15.5k
  if (up_mix_type != 2) {
1970
15.5k
    if (pstr_mps_state->temp_shape_config == 2) {
1971
6.59k
      ixheaacd_reshape_bb_env(pstr_mps_state);
1972
6.59k
    }
1973
15.5k
  }
1974
1975
15.5k
  ixheaacd_tp_process(pstr_mps_state);
1976
1977
15.5k
  ixheaacd_update_time_out_buffer(pstr_mps_state);
1978
1979
15.5k
  ixheaacd_update_out_buffer(pstr_mps_state, out_buf);
1980
1981
15.5k
  pstr_mps_state->parse_next_bitstream_frame = 1;
1982
1983
15.5k
  return IA_NO_ERROR;
1984
15.7k
}
1985
1986
IA_ERRORCODE ixheaacd_heaac_mps_apply(ia_exhaacplus_dec_api_struct *self,
1987
                                      WORD16 *output_buf, UWORD8 *mps_buffer,
1988
16.4k
                                      WORD32 mps_bytes) {
1989
16.4k
  ia_heaac_mps_state_struct *pstr_mps_state =
1990
16.4k
      &self->p_state_aac->heaac_mps_handle;
1991
16.4k
  IA_ERRORCODE error_code = IA_NO_ERROR;
1992
16.4k
  WORD32 n_channels, n_time_slots, qmf_bands, channel;
1993
16.4k
  ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
1994
1995
16.4k
  WORD32 *p_qmf_real = pstr_mps_state->array_struct->m_qmf_real;
1996
16.4k
  WORD32 *p_qmf_imag = pstr_mps_state->array_struct->m_qmf_imag;
1997
16.4k
  WORD32 buffer_size = mps_bytes;
1998
1999
16.4k
  if (self->p_state_aac->heaac_mps_handle.is_first == 1) {
2000
12.1k
    self->p_state_aac->heaac_mps_handle.is_first = 1;
2001
12.1k
    if (pstr_mps_state->bytes_remaining != 0) {
2002
10.6k
      buffer_size = mps_bytes + pstr_mps_state->bytes_remaining;
2003
114k
      for (WORD32 ii = 0; ii < mps_bytes; ii++) {
2004
103k
        pstr_mps_state->temp_buf[ii + pstr_mps_state->bytes_remaining] =
2005
103k
            mps_buffer[ii];
2006
103k
      }
2007
2008
10.6k
      pstr_mps_state->ptr_mps_bit_buff = ixheaacd_create_bit_buf(
2009
10.6k
          &pstr_mps_state->mps_bit_buf, (UWORD8 *)pstr_mps_state->temp_buf,
2010
10.6k
          buffer_size);
2011
10.6k
      pstr_mps_state->ptr_mps_bit_buff->xaac_jmp_buf =
2012
10.6k
          &self->p_state_aac->xaac_jmp_buf;
2013
2014
10.6k
      pstr_mps_state->ptr_mps_bit_buff->cnt_bits += (8 * buffer_size);
2015
10.6k
    } else {
2016
1.56k
      memcpy(pstr_mps_state->temp_buf, mps_buffer, mps_bytes);
2017
1.56k
      buffer_size = mps_bytes;
2018
1.56k
      pstr_mps_state->ptr_mps_bit_buff = ixheaacd_create_bit_buf(
2019
1.56k
          &pstr_mps_state->mps_bit_buf, (UWORD8 *)mps_buffer, buffer_size);
2020
1.56k
      pstr_mps_state->ptr_mps_bit_buff->cnt_bits += (8 * buffer_size);
2021
2022
1.56k
      pstr_mps_state->ptr_mps_bit_buff->xaac_jmp_buf =
2023
1.56k
          &self->p_state_aac->xaac_jmp_buf;
2024
1.56k
    }
2025
12.1k
  }
2026
2027
16.4k
  if (curr_state->num_input_channels > 2 && pstr_mps_state->mps_with_sbr == 1) {
2028
2
    if (pstr_mps_state->ec_flag) {
2029
0
      curr_state->num_input_channels = 2;
2030
0
      pstr_mps_state->frame_ok = 0;
2031
2
    } else {
2032
2
      return IA_FATAL_ERROR;
2033
2
    }
2034
2
  }
2035
2036
16.4k
  n_channels = curr_state->num_input_channels;
2037
16.4k
  n_time_slots = curr_state->time_slots;
2038
16.4k
  qmf_bands = curr_state->qmf_bands;
2039
2040
16.4k
  if (pstr_mps_state->mps_decode == 1) {
2041
16.4k
    if (pstr_mps_state->mps_with_sbr) {
2042
930
      for (channel = 0; channel < n_channels; channel++) {
2043
572
        WORD32 kk = 0;
2044
572
        if (self->aac_config.ui_enh_sbr)
2045
572
        {
2046
11.8k
          for (WORD32 ii = 0; ii < n_time_slots; ii++) {
2047
11.2k
            FLOAT32 *qmf_re = self->p_state_aac->str_sbr_dec_info[0]
2048
11.2k
                ->pstr_sbr_channel[channel]->str_sbr_dec.pp_qmf_buf_real[ii];
2049
11.2k
            FLOAT32 *qmf_im = self->p_state_aac->str_sbr_dec_info[0]
2050
11.2k
                ->pstr_sbr_channel[channel]->str_sbr_dec.pp_qmf_buf_imag[ii];
2051
2052
377k
            for (WORD32 jj = 0; jj < qmf_bands; jj++) {
2053
366k
              p_qmf_real[kk] = ixheaacd_mps_mult32_shr_15(
2054
366k
                  curr_state->clip_protect_gain, (WORD32)(qmf_re[jj] * 1024));
2055
366k
              p_qmf_imag[kk++] = ixheaacd_mps_mult32_shr_15(
2056
366k
                  curr_state->clip_protect_gain, (WORD32)(qmf_im[jj] * 1024));
2057
366k
            }
2058
11.2k
          }
2059
572
        }
2060
0
        else
2061
0
        {
2062
0
          for (WORD32 ii = 0; ii < n_time_slots; ii++) {
2063
0
            WORD32 *qmf_re = self->p_state_aac->str_sbr_dec_info[0]
2064
0
                ->pstr_sbr_channel[channel]->str_sbr_dec.p_arr_qmf_buf_real[ii];
2065
0
            WORD32 *qmf_im = self->p_state_aac->str_sbr_dec_info[0]
2066
0
                ->pstr_sbr_channel[channel]->str_sbr_dec.p_arr_qmf_buf_imag[ii];
2067
2068
0
            for (WORD32 jj = 0; jj < qmf_bands; jj++) {
2069
0
              p_qmf_real[kk] = ixheaacd_mps_mult32_shr_15(
2070
0
                  curr_state->clip_protect_gain, qmf_re[jj] * 256);
2071
0
              p_qmf_imag[kk++] = ixheaacd_mps_mult32_shr_15(
2072
0
                  curr_state->clip_protect_gain, qmf_im[jj] * 256);
2073
0
            }
2074
0
          }
2075
0
        }
2076
572
        p_qmf_real += QBXTS;
2077
572
        p_qmf_imag += QBXTS;
2078
572
      }
2079
16.0k
    } else {
2080
99.5k
      for (channel = 0; channel < n_channels; channel++) {
2081
83.4k
        ixheaacd_calc_ana_filt_bank(pstr_mps_state, output_buf, p_qmf_real,
2082
83.4k
                                    p_qmf_imag, channel);
2083
2084
83.4k
        p_qmf_real += QBXTS;
2085
83.4k
        p_qmf_imag += QBXTS;
2086
83.4k
      }
2087
16.0k
    }
2088
16.4k
    if (!pstr_mps_state->ec_flag && pstr_mps_state->frame_ok) {
2089
16.4k
      error_code = ixheaacd_parse_frame(pstr_mps_state);
2090
16.4k
      if (error_code != IA_NO_ERROR) return error_code;
2091
16.4k
    }
2092
2093
16.2k
    if (!pstr_mps_state->first_frame || !pstr_mps_state->ec_flag) {
2094
15.7k
      error_code = ixheaacd_apply_frame(pstr_mps_state, n_time_slots,
2095
15.7k
                                        pstr_mps_state->array_struct->m_qmf_real,
2096
15.7k
                                        pstr_mps_state->array_struct->m_qmf_imag, output_buf);
2097
15.7k
      if (error_code != IA_NO_ERROR) return error_code;
2098
15.7k
    }
2099
15.9k
    if (error_code == 0 && pstr_mps_state->ec_flag && pstr_mps_state->frame_ok) {
2100
0
      error_code = ixheaacd_parse_frame(pstr_mps_state);
2101
0
      if (error_code != IA_NO_ERROR) {
2102
0
        pstr_mps_state->frame_ok = 0;
2103
0
      }
2104
0
    }
2105
2106
15.9k
    pstr_mps_state->i_bytes_consumed_mps =
2107
15.9k
        (WORD32)(pstr_mps_state->ptr_mps_bit_buff->ptr_read_next -
2108
15.9k
                 pstr_mps_state->ptr_mps_bit_buff->ptr_bit_buf_base);
2109
2110
15.9k
    pstr_mps_state->bytes_remaining =
2111
15.9k
        buffer_size - pstr_mps_state->i_bytes_consumed_mps;
2112
15.9k
    if (pstr_mps_state->bytes_remaining < 0)
2113
354
    {
2114
354
      if (pstr_mps_state->ec_flag)
2115
0
      {
2116
0
        pstr_mps_state->bytes_remaining = 0;
2117
0
        pstr_mps_state->frame_ok = 0;
2118
0
      }
2119
354
      else
2120
354
      {
2121
354
        return IA_FATAL_ERROR;
2122
354
      }
2123
354
    }
2124
2125
15.6k
    if (pstr_mps_state->bytes_remaining != 0) {
2126
423k
      for (WORD32 ii = 0; ii < pstr_mps_state->bytes_remaining; ii++) {
2127
410k
        pstr_mps_state->temp_buf[ii] =
2128
410k
            pstr_mps_state->temp_buf[ii + pstr_mps_state->i_bytes_consumed_mps];
2129
410k
      }
2130
12.9k
    }
2131
15.6k
  }
2132
15.6k
  self->p_state_aac->heaac_mps_handle.is_first = 1;
2133
15.6k
  self->p_state_aac->heaac_mps_handle.first_frame = 0;
2134
2135
15.6k
  return error_code;
2136
16.4k
}