Coverage Report

Created: 2026-06-13 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_ext_ch_ele.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#include <stdio.h>
21
#include <string.h>
22
#include <stdlib.h>
23
#include <setjmp.h>
24
25
#include "ixheaac_type_def.h"
26
27
#include "ixheaacd_cnst.h"
28
29
#include "ixheaacd_bitbuffer.h"
30
31
#include "ixheaacd_interface.h"
32
#include "ixheaacd_acelp_info.h"
33
34
#include "ixheaacd_tns_usac.h"
35
#include "ixheaacd_acelp_info.h"
36
37
#include "ixheaacd_sbrdecsettings.h"
38
#include "ixheaacd_info.h"
39
#include "ixheaacd_sbr_common.h"
40
#include "ixheaacd_drc_data_struct.h"
41
#include "ixheaacd_drc_dec.h"
42
43
#include "ixheaacd_sbrdecoder.h"
44
#include "ixheaacd_mps_polyphase.h"
45
#include "ixheaac_sbr_const.h"
46
47
#include "ixheaacd_ec_defines.h"
48
#include "ixheaacd_ec_rom.h"
49
#include "ixheaacd_ec_struct_def.h"
50
#include "ixheaacd_main.h"
51
#include "ixheaacd_arith_dec.h"
52
#include "ixheaacd_tns_usac.h"
53
54
#include "ixheaacd_bit_extract.h"
55
56
#include "ixheaac_constants.h"
57
#include "ixheaac_basic_ops32.h"
58
#include "ixheaac_basic_ops40.h"
59
60
#include "ixheaacd_func_def.h"
61
62
#include "ixheaacd_defines.h"
63
#include "ixheaacd_windows.h"
64
65
#include "ixheaacd_vec_baisc_ops.h"
66
#include "ixheaacd_config.h"
67
#include "ixheaacd_defines.h"
68
#include "ixheaacd_aac_rom.h"
69
#include "ixheaacd_pulsedata.h"
70
#include "ixheaacd_pns.h"
71
#include "ixheaacd_channelinfo.h"
72
#include "ixheaacd_ec.h"
73
#include "ixheaacd_error_codes.h"
74
75
const WORD16 ixheaacd_mdst_fcoeff_long_sin[] = {0, 0, -16384, 0, 16384, 0, 0};
76
const WORD16 ixheaacd_mdst_fcoeff_long_kbd[] = {-2998, 0, -19052, 0,
77
                                                19052, 0, 2998};
78
const WORD16 ixheaacd_mdst_fcoeff_long_sin_kbd[] = {-1499, -1876, -17718, 0,
79
                                                    17718, 1876,  1499};
80
const WORD16 ixheaacd_mdst_fcoeff_long_kbd_sin[] = {-1499, 1876,  -17718, 0,
81
                                                    17718, -1876, 1499};
82
83
const WORD16 *const ixheaacd_mdst_fcoeff_longshort_curr[2][2] = {
84
    {ixheaacd_mdst_fcoeff_long_sin, ixheaacd_mdst_fcoeff_long_sin_kbd},
85
    {ixheaacd_mdst_fcoeff_long_kbd_sin, ixheaacd_mdst_fcoeff_long_kbd}};
86
87
const WORD16 ixheaacd_mdst_fcoeff_start_sin[] = {-3364, -3401, -18584, 0,
88
                                                 18584, 3401,  3364};
89
const WORD16 ixheaacd_mdst_fcoeff_start_kbd[] = {-4932, -1572, -19942, 0,
90
                                                 19942, 1572,  4932};
91
const WORD16 ixheaacd_mdst_fcoeff_start_sin_kbd[] = {-3433, -3447, -18608, 0,
92
                                                     18608, 3447,  3433};
93
const WORD16 ixheaacd_mdst_fcoeff_start_kbd_sin[] = {-4863, -1525, -19918, 0,
94
                                                     19918, 1525,  4863};
95
96
const WORD16 *const ixheaacd_mdst_fcoeff_start_curr[2][2] = {
97
    {ixheaacd_mdst_fcoeff_start_sin, ixheaacd_mdst_fcoeff_start_sin_kbd},
98
    {ixheaacd_mdst_fcoeff_start_kbd_sin, ixheaacd_mdst_fcoeff_start_kbd}};
99
100
const WORD16 ixheaacd_mdst_fcoeff_stop_sin[] = {-3364, 3401,  -18584, 0,
101
                                                18584, -3401, 3364};
102
const WORD16 ixheaacd_mdst_fcoeff_stop_kbd[] = {-4932, 1572,  -19942, 0,
103
                                                19942, -1572, 4932};
104
const WORD16 ixheaacd_mdst_fcoeff_stop_sin_kbd[] = {-4863, 1525,  -19918, 0,
105
                                                    19918, -1525, 4863};
106
const WORD16 ixheaacd_mdst_fcoeff_stop_kbd_sin[] = {-3433, 3447,  -18608, 0,
107
                                                    18608, -3447, 3433};
108
109
const WORD16 *const ixheaacd_mdst_fcoeff_stop_cur[2][2] = {
110
    {ixheaacd_mdst_fcoeff_stop_sin, ixheaacd_mdst_fcoeff_stop_sin_kbd},
111
    {ixheaacd_mdst_fcoeff_stop_kbd_sin, ixheaacd_mdst_fcoeff_stop_kbd}};
112
113
const WORD16 ixheaacd_mdst_fcoeff_stopstart_sin[] = {-6728, 0, -20785, 0,
114
                                                     20785, 0, 6728};
115
const WORD16 ixheaacd_mdst_fcoeff_stopstart_kbd[] = {-6866, -0, -20831, 0,
116
                                                     20831, 0,  6866};
117
const WORD16 ixheaacd_mdst_fcoeff_stopstart_sin_kbd[] = {-6797, -46, -20808, 0,
118
                                                         20808, 46,  6797};
119
const WORD16 ixheaacd_mdst_fcoeff_stopstart_kbd_sin[] = {-6797, 46, -20808, 0,
120
                                                         20808, 46, 6797};
121
122
const WORD16 *const ixheaacd_mdst_fcoeff_stopstart_cur[2][2] = {
123
    {ixheaacd_mdst_fcoeff_stopstart_sin,
124
     ixheaacd_mdst_fcoeff_stopstart_sin_kbd},
125
    {ixheaacd_mdst_fcoeff_stopstart_kbd_sin,
126
     ixheaacd_mdst_fcoeff_stopstart_kbd}};
127
128
const WORD16 ixheaacd_mdst_fcoeff_l_s_start_left_sin[] = {
129
    -0, 3477, 8192, 10430, 8192, 3477, -0};
130
const WORD16 ixheaacd_mdst_fcoeff_l_s_start_left_kbd[] = {
131
    1950, 4054, 6114, 6982, 6114, 4054, 1950};
132
133
const WORD16 ixheaacd_mdst_fcoeff_stop_stopstart_left_sin[] = {
134
    1262, 1285, 1299, 1304, 1299, 1285, 1262};
135
const WORD16 ixheaacd_mdst_fcoeff_stop_stopstart_left_kbd[] = {
136
    857, 866, 871, 873, 871, 866, 857};
137
138
const WORD16 *const ixheaacd_mdst_fcoeff_l_s_start_left_prev[2] = {
139
    ixheaacd_mdst_fcoeff_l_s_start_left_sin,
140
    ixheaacd_mdst_fcoeff_l_s_start_left_kbd};
141
const WORD16 *const ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[2] = {
142
    ixheaacd_mdst_fcoeff_stop_stopstart_left_sin,
143
    ixheaacd_mdst_fcoeff_stop_stopstart_left_kbd};
144
145
#define ONE_BY_TWO_POW_14 0.00006103515625
146
369M
#define ONE_BY_TWO_POW_15 0.000030517578125
147
148
void ixheaacd_usac_cplx_save_prev(ia_sfb_info_struct *info, WORD32 *l_spec,
149
                                  WORD32 *r_spec, WORD32 *l_spec_prev,
150
70.9k
                                  WORD32 *r_spec_prev) {
151
70.9k
  WORD32 ixheaacd_drc_offset;
152
153
70.9k
  ixheaacd_drc_offset = info->samp_per_bk - info->bins_per_sbk;
154
155
70.9k
  memcpy(l_spec_prev + ixheaacd_drc_offset, l_spec + ixheaacd_drc_offset,
156
70.9k
         sizeof(WORD32) * info->bins_per_sbk);
157
70.9k
  memcpy(r_spec_prev + ixheaacd_drc_offset, r_spec + ixheaacd_drc_offset,
158
70.9k
         sizeof(WORD32) * info->bins_per_sbk);
159
70.9k
}
160
161
static VOID ixheaacd_cplx_pred_data(
162
    ia_usac_data_struct *usac_data,
163
    ia_usac_tmp_core_coder_struct *pstr_core_coder, WORD32 num_window_groups,
164
14.1k
    ia_bit_buf_struct *it_bit_buff) {
165
14.1k
  ia_huff_code_book_struct *ptr_huff_code_book = &ixheaacd_book;
166
14.1k
  const ia_huff_code_word_struct *ptr_huff_code_word =
167
14.1k
      ptr_huff_code_book->pstr_huff_code_word;
168
14.1k
  WORD32 cplx_pred_all;
169
14.1k
  WORD32 delta_code_time;
170
14.1k
  WORD32 g, sfb;
171
14.1k
  WORD32 dpcm_alpha, last_alpha_q_re, last_alpha_q_im;
172
14.1k
  UWORD8 max_sfb_ste = pstr_core_coder->max_sfb_ste;
173
174
14.1k
  WORD32(*alpha_q_re)[SFB_NUM_MAX] = usac_data->alpha_q_re;
175
14.1k
  WORD32(*alpha_q_im)[SFB_NUM_MAX] = usac_data->alpha_q_im;
176
14.1k
  WORD32 *alpha_q_re_prev = usac_data->alpha_q_re_prev;
177
14.1k
  WORD32 *alpha_q_im_prev = usac_data->alpha_q_im_prev;
178
14.1k
  UWORD8(*cplx_pred_used)[SFB_NUM_MAX] = usac_data->cplx_pred_used;
179
180
14.1k
  cplx_pred_all = ixheaacd_read_bits_buf(it_bit_buff, 1);
181
182
14.1k
  if (cplx_pred_all == 0) {
183
59.2k
    for (g = 0; g < num_window_groups; g++) {
184
138k
      for (sfb = 0; sfb < max_sfb_ste; sfb += SFB_PER_PRED_BAND) {
185
88.1k
        cplx_pred_used[g][sfb] = ixheaacd_read_bits_buf(it_bit_buff, 1);
186
187
88.1k
        if (sfb + 1 < max_sfb_ste)
188
38.6k
          cplx_pred_used[g][sfb + 1] = cplx_pred_used[g][sfb];
189
88.1k
      }
190
6.72M
      for (sfb = max_sfb_ste; sfb < SFB_NUM_MAX; sfb++)
191
6.67M
        cplx_pred_used[g][sfb] = 0;
192
50.0k
    }
193
9.18k
  } else {
194
13.7k
    for (g = 0; g < num_window_groups; g++) {
195
90.2k
      for (sfb = 0; sfb < max_sfb_ste; sfb++) cplx_pred_used[g][sfb] = 1;
196
197
1.11M
      for (sfb = max_sfb_ste; sfb < SFB_NUM_MAX; sfb++)
198
1.10M
        cplx_pred_used[g][sfb] = 0;
199
8.72k
    }
200
4.98k
  }
201
202
14.1k
  pstr_core_coder->pred_dir = ixheaacd_read_bits_buf(it_bit_buff, 1);
203
204
14.1k
  pstr_core_coder->complex_coef = ixheaacd_read_bits_buf(it_bit_buff, 1);
205
206
14.1k
  if (pstr_core_coder->complex_coef) {
207
6.93k
    if (usac_data->usac_independency_flg)
208
6.29k
      pstr_core_coder->use_prev_frame = 0;
209
632
    else
210
632
      pstr_core_coder->use_prev_frame = ixheaacd_read_bits_buf(it_bit_buff, 1);
211
6.93k
  }
212
213
14.1k
  if (usac_data->usac_independency_flg)
214
7.20k
    delta_code_time = 0;
215
6.96k
  else
216
6.96k
    delta_code_time = ixheaacd_read_bits_buf(it_bit_buff, 1);
217
218
72.9k
  for (g = 0; g < num_window_groups; g++) {
219
191k
    for (sfb = 0; sfb < max_sfb_ste; sfb += SFB_PER_PRED_BAND) {
220
132k
      if (delta_code_time == 1) {
221
1.21k
        last_alpha_q_re = alpha_q_re_prev[sfb];
222
1.21k
        last_alpha_q_im = alpha_q_im_prev[sfb];
223
131k
      } else {
224
131k
        if (sfb > 0) {
225
73.6k
          last_alpha_q_re = alpha_q_re[g][sfb - 1];
226
73.6k
          last_alpha_q_im = alpha_q_im[g][sfb - 1];
227
73.6k
        } else {
228
57.8k
          last_alpha_q_re = last_alpha_q_im = 0;
229
57.8k
        }
230
131k
      }
231
232
132k
      if (cplx_pred_used[g][sfb] == 1) {
233
86.5k
        dpcm_alpha =
234
86.5k
            -ixheaacd_huff_codeword(ptr_huff_code_word, 0, it_bit_buff) + 60;
235
86.5k
        alpha_q_re[g][sfb] = dpcm_alpha + last_alpha_q_re;
236
237
86.5k
        if (pstr_core_coder->complex_coef) {
238
61.8k
          dpcm_alpha =
239
61.8k
              -ixheaacd_huff_codeword(ptr_huff_code_word, 0, it_bit_buff) + 60;
240
61.8k
          alpha_q_im[g][sfb] = dpcm_alpha + last_alpha_q_im;
241
61.8k
        } else {
242
24.7k
          alpha_q_im[g][sfb] = 0;
243
24.7k
        }
244
86.5k
      } else {
245
46.1k
        alpha_q_re[g][sfb] = 0;
246
46.1k
        alpha_q_im[g][sfb] = 0;
247
46.1k
      }
248
249
132k
      if ((sfb + 1) < max_sfb_ste) {
250
75.4k
        alpha_q_re[g][sfb + 1] = alpha_q_re[g][sfb];
251
75.4k
        alpha_q_im[g][sfb + 1] = alpha_q_im[g][sfb];
252
75.4k
      }
253
254
132k
      alpha_q_re_prev[sfb] = alpha_q_re[g][sfb];
255
132k
      alpha_q_im_prev[sfb] = alpha_q_im[g][sfb];
256
132k
    }
257
7.83M
    for (sfb = max_sfb_ste; sfb < SFB_NUM_MAX; sfb++) {
258
7.78M
      alpha_q_re[g][sfb] = 0;
259
7.78M
      alpha_q_im[g][sfb] = 0;
260
7.78M
      alpha_q_re_prev[sfb] = 0;
261
7.78M
      alpha_q_im_prev[sfb] = 0;
262
7.78M
    }
263
58.7k
  }
264
265
14.1k
  return;
266
14.1k
}
267
268
static WORD32 ixheaacd_read_ms_mask(
269
    ia_usac_data_struct *usac_data,
270
    ia_usac_tmp_core_coder_struct *pstr_core_coder,
271
34.2k
    ia_bit_buf_struct *it_bit_buff, WORD32 chn) {
272
34.2k
  WORD32 g, sfb;
273
34.2k
  WORD32 ms_mask_present;
274
275
34.2k
  UWORD8 *sfb_group = usac_data->group_dis[chn];
276
34.2k
  UWORD8 max_sfb = pstr_core_coder->max_sfb_ste;
277
34.2k
  UWORD8 *ms_used = usac_data->ms_used[chn];
278
34.2k
  ia_sfb_info_struct *info = usac_data->pstr_sfb_info[chn];
279
280
34.2k
  ms_mask_present = ixheaacd_read_bits_buf(it_bit_buff, 2);
281
282
34.2k
  switch (ms_mask_present) {
283
11.0k
    case 0:
284
285
11.0k
      break;
286
287
714
    case 1:
288
3.77k
      for (g = 0; g < info->max_win_len; g = *sfb_group++) {
289
20.5k
        for (sfb = 0; sfb < max_sfb; sfb++) {
290
17.4k
          *ms_used = ixheaacd_read_bits_buf(it_bit_buff, 1);
291
17.4k
          ms_used++;
292
17.4k
        }
293
32.6k
        for (; sfb < info->sfb_per_sbk; sfb++) {
294
29.5k
          *ms_used = 0;
295
29.5k
          ms_used++;
296
29.5k
        }
297
3.05k
      }
298
299
714
      break;
300
8.31k
    case 2:
301
18.5k
      for (g = 0; g < info->max_win_len; g = *sfb_group++)
302
380k
        for (sfb = 0; sfb < info->sfb_per_sbk; sfb++) *ms_used++ = 1;
303
8.31k
      break;
304
305
14.1k
    case 3:
306
307
14.1k
      ixheaacd_cplx_pred_data(usac_data, pstr_core_coder, info->num_groups,
308
14.1k
                              it_bit_buff);
309
14.1k
      return 3;
310
34.2k
  }
311
312
2.75M
  for (sfb = 0; sfb < SFB_NUM_MAX; sfb++) {
313
2.73M
    usac_data->alpha_q_re_prev[sfb] = 0;
314
2.73M
    usac_data->alpha_q_im_prev[sfb] = 0;
315
2.73M
  }
316
20.1k
  return ms_mask_present;
317
34.2k
}
318
319
VOID ixheaacd_ms_stereo(ia_usac_data_struct *usac_data, WORD32 *r_spec,
320
9.00k
                        WORD32 *l_spec, WORD32 chn, WORD32 nband) {
321
9.00k
  WORD32 temp_r, temp_l;
322
9.00k
  WORD32 sfb, k, grp, grp_len;
323
9.00k
  ia_sfb_info_struct *ptr_sfb_info = usac_data->pstr_sfb_info[chn];
324
9.00k
  UWORD8 *ms_used = usac_data->ms_used[chn];
325
9.00k
  WORD32 ixheaacd_drc_offset = 0;
326
327
22.2k
  for (grp = 0; grp < ptr_sfb_info->num_groups; grp++) {
328
29.7k
    for (grp_len = 0; grp_len < ptr_sfb_info->group_len[grp]; grp_len++) {
329
16.4k
      ixheaacd_drc_offset = 0;
330
86.2k
      for (sfb = 0; sfb < nband; sfb++) {
331
69.7k
        ixheaacd_drc_offset += ptr_sfb_info->sfb_width[sfb];
332
69.7k
        if (ms_used[sfb]) {
333
694k
          for (k = 0; k < ptr_sfb_info->sfb_width[sfb]; k++) {
334
640k
            temp_r = *r_spec;
335
640k
            temp_l = *l_spec;
336
640k
            *l_spec = ixheaac_add32_sat(temp_r, temp_l);
337
640k
            *r_spec = ixheaac_sub32_sat(temp_l, temp_r);
338
640k
            r_spec++;
339
640k
            l_spec++;
340
640k
          }
341
54.1k
        } else {
342
15.6k
          r_spec += ptr_sfb_info->sfb_width[sfb];
343
15.6k
          l_spec += ptr_sfb_info->sfb_width[sfb];
344
15.6k
        }
345
69.7k
      }
346
347
16.4k
      l_spec = l_spec + ptr_sfb_info->bins_per_sbk - ixheaacd_drc_offset;
348
16.4k
      r_spec = r_spec + ptr_sfb_info->bins_per_sbk - ixheaacd_drc_offset;
349
16.4k
    }
350
351
13.2k
    ms_used += ptr_sfb_info->sfb_per_sbk;
352
13.2k
  }
353
9.00k
}
354
355
static VOID ixheaacd_filter_and_add(const WORD32 *in, const WORD32 length,
356
                                    const WORD16 *filter, WORD32 *out,
357
                                    const WORD32 factor_even,
358
99.0k
                                    const WORD32 factor_odd) {
359
99.0k
  WORD32 i;
360
99.0k
  WORD64 sum;
361
362
99.0k
  sum = ixheaac_mult32x32in64(in[2], filter[0]);
363
99.0k
  sum = ixheaac_mac32x32in64(sum, in[1], filter[1]);
364
99.0k
  sum = ixheaac_mac32x32in64(sum, in[0], filter[2]);
365
99.0k
  sum = ixheaac_mac32x32in64_n(sum, &in[0], &filter[3], 4);
366
99.0k
  *out = ixheaac_add32_sat(
367
99.0k
      *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15)));
368
99.0k
  out++;
369
370
99.0k
  sum = ixheaac_mult32x32in64(in[1], filter[0]);
371
99.0k
  sum = ixheaac_mac32x32in64(sum, in[0], filter[1]);
372
99.0k
  sum = ixheaac_mac32x32in64_n(sum, &in[0], &filter[2], 5);
373
99.0k
  *out = ixheaac_add32_sat(
374
99.0k
      *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15)));
375
99.0k
  out++;
376
377
99.0k
  sum = ixheaac_mult32x32in64(in[0], filter[0]);
378
99.0k
  sum = ixheaac_mac32x32in64_n(sum, &in[0], &filter[1], 6);
379
99.0k
  *out = ixheaac_add32_sat(
380
99.0k
      *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15)));
381
99.0k
  out++;
382
383
6.24M
  for (i = 3; i < length - 4; i += 2) {
384
6.14M
    sum = 0;
385
6.14M
    sum = ixheaac_mac32x32in64_7(&in[i - 3], filter);
386
6.14M
    *out = ixheaac_add32_sat(
387
6.14M
        *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15)));
388
6.14M
    out++;
389
390
6.14M
    sum = 0;
391
6.14M
    sum = ixheaac_mac32x32in64_7(&in[i - 2], filter);
392
6.14M
    *out = ixheaac_add32_sat(
393
6.14M
        *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15)));
394
6.14M
    out++;
395
6.14M
  }
396
99.0k
  i = length - 3;
397
99.0k
  sum = 0;
398
99.0k
  sum = ixheaac_mac32x32in64_n(sum, &in[i - 3], filter, 6);
399
99.0k
  sum = ixheaac_mac32x32in64(sum, in[i + 2], filter[6]);
400
99.0k
  *out = ixheaac_add32_sat(
401
99.0k
      *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15)));
402
403
99.0k
  out++;
404
99.0k
  i = length - 2;
405
99.0k
  sum = 0;
406
99.0k
  sum = ixheaac_mac32x32in64_n(sum, &in[i - 3], filter, 5);
407
99.0k
  sum = ixheaac_mac32x32in64(sum, in[i + 1], filter[5]);
408
99.0k
  sum = ixheaac_mac32x32in64(sum, in[i], filter[6]);
409
410
99.0k
  *out = ixheaac_add32_sat(
411
99.0k
      *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15)));
412
99.0k
  out++;
413
414
99.0k
  i = length - 1;
415
99.0k
  sum = 0;
416
99.0k
  sum = ixheaac_mac32x32in64_n(sum, &in[i - 3], filter, 4);
417
99.0k
  sum = ixheaac_mac32x32in64(sum, in[i], filter[4]);
418
99.0k
  sum = ixheaac_mac32x32in64(sum, in[i - 1], filter[5]);
419
99.0k
  sum = ixheaac_mac32x32in64(sum, in[i - 2], filter[6]);
420
421
99.0k
  *out = ixheaac_add32_sat(
422
99.0k
      *out, ixheaac_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15)));
423
99.0k
}
424
425
static VOID ixheaacd_estimate_dmx_im(const WORD32 *dmx_re,
426
                                     const WORD32 *dmx_re_prev, WORD32 *dmx_im,
427
                                     ia_sfb_info_struct *pstr_sfb_info,
428
                                     WORD32 window, const WORD32 w_shape,
429
6.76k
                                     const WORD32 prev_w_shape) {
430
6.76k
  WORD32 i;
431
6.76k
  const WORD16 *mdst_fcoeff_curr, *mdst_fcoeff_prev;
432
433
6.76k
  switch (window) {
434
51
    case ONLY_LONG_SEQUENCE:
435
6.60k
    case EIGHT_SHORT_SEQUENCE:
436
6.60k
      mdst_fcoeff_curr =
437
6.60k
          ixheaacd_mdst_fcoeff_longshort_curr[prev_w_shape][w_shape];
438
6.60k
      mdst_fcoeff_prev = ixheaacd_mdst_fcoeff_l_s_start_left_prev[prev_w_shape];
439
6.60k
      break;
440
20
    case LONG_START_SEQUENCE:
441
20
      mdst_fcoeff_curr = ixheaacd_mdst_fcoeff_start_curr[prev_w_shape][w_shape];
442
20
      mdst_fcoeff_prev = ixheaacd_mdst_fcoeff_l_s_start_left_prev[prev_w_shape];
443
20
      break;
444
40
    case LONG_STOP_SEQUENCE:
445
40
      mdst_fcoeff_curr = ixheaacd_mdst_fcoeff_stop_cur[prev_w_shape][w_shape];
446
40
      mdst_fcoeff_prev =
447
40
          ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[prev_w_shape];
448
40
      break;
449
94
    case STOP_START_SEQUENCE:
450
94
      mdst_fcoeff_curr =
451
94
          ixheaacd_mdst_fcoeff_stopstart_cur[prev_w_shape][w_shape];
452
94
      mdst_fcoeff_prev =
453
94
          ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[prev_w_shape];
454
94
      break;
455
0
    default:
456
0
      mdst_fcoeff_curr =
457
0
          ixheaacd_mdst_fcoeff_stopstart_cur[prev_w_shape][w_shape];
458
0
      mdst_fcoeff_prev =
459
0
          ixheaacd_mdst_fcoeff_stop_stopstart_left_prev[prev_w_shape];
460
0
      break;
461
6.76k
  }
462
463
59.4k
  for (i = 0; i < pstr_sfb_info->max_win_len; i++) {
464
52.6k
    ixheaacd_filter_and_add(dmx_re, pstr_sfb_info->bins_per_sbk,
465
52.6k
                            mdst_fcoeff_curr, dmx_im, 1, 1);
466
467
52.6k
    if (dmx_re_prev)
468
46.4k
      ixheaacd_filter_and_add(dmx_re_prev, pstr_sfb_info->bins_per_sbk,
469
46.4k
                              mdst_fcoeff_prev, dmx_im, -1, 1);
470
471
52.6k
    dmx_re_prev = dmx_re;
472
52.6k
    dmx_re += pstr_sfb_info->bins_per_sbk;
473
52.6k
    dmx_im += pstr_sfb_info->bins_per_sbk;
474
52.6k
  }
475
6.76k
  return;
476
6.76k
}
477
478
static VOID ixheaacd_cplx_pred_upmixing(
479
    ia_usac_data_struct *usac_data, WORD32 *l_spec, WORD32 *r_spec,
480
13.9k
    ia_usac_tmp_core_coder_struct *pstr_core_coder, WORD32 chn) {
481
13.9k
  ia_sfb_info_struct *pstr_sfb_info = usac_data->pstr_sfb_info[chn];
482
13.9k
  WORD32 *dmx_re = &usac_data->scratch_buffer[0];
483
13.9k
  WORD32 *dmx_im = &usac_data->x_ac_dec[0];
484
485
13.9k
  WORD32 grp, sfb, grp_len, i = 0, k;
486
13.9k
  WORD32 *dmx_re_prev = usac_data->dmx_re_prev;
487
13.9k
  WORD32(*alpha_q_re)[SFB_NUM_MAX] = usac_data->alpha_q_re;
488
13.9k
  WORD32(*alpha_q_im)[SFB_NUM_MAX] = usac_data->alpha_q_im;
489
490
13.9k
  UWORD8(*cplx_pred_used)[SFB_NUM_MAX] = usac_data->cplx_pred_used;
491
492
13.9k
  WORD32 alpha_q_re_temp;
493
13.9k
  WORD32 alpha_q_im_temp;
494
13.9k
  WORD32 factor = 1;
495
496
13.9k
  if (pstr_core_coder->pred_dir) factor = -1;
497
498
72.2k
  for (grp = 0; grp < pstr_sfb_info->num_groups; grp++) {
499
168k
    for (grp_len = 0; grp_len < pstr_sfb_info->group_len[grp]; grp_len++) {
500
1.76M
      for (sfb = 0; sfb < pstr_sfb_info->sfb_per_sbk; sfb++) {
501
1.65M
        if (cplx_pred_used[grp][sfb] == 1) {
502
608k
          memcpy(&dmx_re[i], &l_spec[i],
503
608k
                 pstr_sfb_info->sfb_width[sfb] * sizeof(WORD32));
504
608k
          i += pstr_sfb_info->sfb_width[sfb];
505
608k
        }
506
507
1.04M
        else {
508
10.6M
          for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) {
509
9.62M
            dmx_re[i] = (WORD32)(
510
9.62M
                ((WORD64)l_spec[i] + ((WORD64)factor * (WORD64)r_spec[i])) >>
511
9.62M
                1);
512
9.62M
          }
513
1.04M
        }
514
1.65M
      }
515
109k
    }
516
58.2k
  }
517
518
13.9k
  memset(dmx_im, 0, sizeof(WORD32) * BLOCK_LEN_LONG);
519
520
13.9k
  if (pstr_core_coder->complex_coef) {
521
6.76k
    WORD32 *p_dmx_re_prev =
522
6.76k
        pstr_core_coder->use_prev_frame ? dmx_re_prev : NULL;
523
6.76k
    ixheaacd_estimate_dmx_im(dmx_re, p_dmx_re_prev, dmx_im, pstr_sfb_info,
524
6.76k
                             usac_data->window_sequence[chn],
525
6.76k
                             usac_data->window_shape[chn],
526
6.76k
                             usac_data->window_shape_prev[chn]);
527
528
23.1k
    for (grp = 0, i = 0; grp < pstr_sfb_info->num_groups; grp++) {
529
69.0k
      for (grp_len = 0; grp_len < pstr_sfb_info->group_len[grp]; grp_len++) {
530
847k
        for (sfb = 0; sfb < pstr_sfb_info->sfb_per_sbk; sfb++) {
531
794k
          alpha_q_re_temp = ixheaac_sat64_32(ixheaac_mult32x32in64(alpha_q_re[grp][sfb], 1677722));
532
794k
          alpha_q_im_temp = ixheaac_sat64_32(ixheaac_mult32x32in64(alpha_q_im[grp][sfb], 1677722));
533
794k
          if (cplx_pred_used[grp][sfb]) {
534
4.91M
            for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) {
535
4.36M
              WORD32 mid_side = ixheaac_sub32_sat(
536
4.36M
                  ixheaac_sub32_sat(r_spec[i],
537
4.36M
                                     (WORD32)((WORD64)ixheaac_mult32x32in64(
538
4.36M
                                                  alpha_q_re_temp, l_spec[i]) >>
539
4.36M
                                              24)),
540
4.36M
                  (WORD32)((WORD64)ixheaac_mult32x32in64(alpha_q_im_temp,
541
4.36M
                                                          dmx_im[i]) >>
542
4.36M
                           24));
543
4.36M
              r_spec[i] = ixheaac_sat64_32((WORD64)factor) *
544
4.36M
                          (WORD64)(ixheaac_sub32_sat(l_spec[i], mid_side));
545
4.36M
              l_spec[i] = ixheaac_add32_sat(l_spec[i], mid_side);
546
4.36M
            }
547
552k
          } else {
548
241k
            i += pstr_sfb_info->sfb_width[sfb];
549
241k
          }
550
794k
        }
551
52.6k
      }
552
16.3k
    }
553
7.21k
  } else {
554
49.0k
    for (grp = 0, i = 0; grp < pstr_sfb_info->num_groups; grp++) {
555
99.1k
      for (grp_len = 0; grp_len < pstr_sfb_info->group_len[grp]; grp_len++) {
556
917k
        for (sfb = 0; sfb < pstr_sfb_info->sfb_per_sbk; sfb++) {
557
860k
          alpha_q_re_temp = ixheaac_sat64_32(ixheaac_mult32x32in64(alpha_q_re[grp][sfb], 1677722));
558
860k
          if (cplx_pred_used[grp][sfb]) {
559
373k
            for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) {
560
317k
              WORD32 mid_side = ixheaac_sub32_sat(
561
317k
                  r_spec[i], (WORD32)((WORD64)ixheaac_mult32x32in64(
562
317k
                                          alpha_q_re_temp, l_spec[i]) >>
563
317k
                                      24));
564
565
317k
              r_spec[i] = ixheaac_sat64_32((WORD64)factor) *
566
317k
                          (WORD64)(ixheaac_sub32_sat(l_spec[i], mid_side));
567
317k
              l_spec[i] = ixheaac_add32_sat(l_spec[i], mid_side);
568
317k
            }
569
804k
          } else {
570
804k
            i += pstr_sfb_info->sfb_width[sfb];
571
804k
          }
572
860k
        }
573
57.2k
      }
574
41.8k
    }
575
7.21k
  }
576
577
13.9k
  return;
578
13.9k
}
579
580
static VOID ixheaacd_cplx_prev_mdct_dmx(ia_sfb_info_struct *pstr_sfb_info,
581
                                        WORD32 *l_spec, WORD32 *r_spec,
582
70.9k
                                        WORD32 *dmx_re_prev, WORD32 pred_dir) {
583
70.9k
  WORD32 offs, i;
584
70.9k
  WORD32 factor = 1;
585
70.9k
  if (pred_dir) factor = -1;
586
587
70.9k
  offs = pstr_sfb_info->samp_per_bk - pstr_sfb_info->bins_per_sbk;
588
589
44.2M
  for (i = 0; i < pstr_sfb_info->bins_per_sbk; i++)
590
44.1M
    dmx_re_prev[i] = (WORD32)(((WORD64)l_spec[i + offs] +
591
44.1M
                               ((WORD64)factor * (WORD64)r_spec[i + offs])) >>
592
44.1M
                              1);
593
70.9k
}
594
595
WORD32 ixheaacd_ics_info(ia_usac_data_struct *usac_data, WORD32 chn,
596
                         UWORD8 *max_sfb, ia_bit_buf_struct *it_bit_buff,
597
                         WORD32 window_sequence_last
598
599
                         )
600
601
196k
{
602
196k
  WORD32 win;
603
196k
  WORD32 mask = 0x40;
604
605
196k
  UWORD8 *scf_group_ptr = usac_data->group_dis[chn];
606
607
196k
  win = ixheaacd_read_bits_buf(it_bit_buff, 2);
608
609
196k
  win = usac_data->window_sequence[chn] =
610
196k
      ixheaacd_win_seq_select(win, window_sequence_last);
611
196k
  if (win == -1) return -1;
612
613
196k
  usac_data->pstr_sfb_info[chn] =
614
196k
      usac_data->pstr_usac_winmap[usac_data->window_sequence[chn]];
615
616
196k
  usac_data->window_shape[chn] = ixheaacd_read_bits_buf(it_bit_buff, 1);
617
618
196k
  if (usac_data->pstr_usac_winmap[win]->islong) {
619
137k
    *max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 6);
620
137k
    *scf_group_ptr = 1;
621
137k
  } else {
622
58.5k
    WORD32 i, scale_factor_grouping;
623
624
58.5k
    *max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 4);
625
626
58.5k
    scale_factor_grouping = ixheaacd_read_bits_buf(it_bit_buff, 7);
627
628
468k
    for (i = 1; i < 8; i++) {
629
409k
      if (!(scale_factor_grouping & mask)) *scf_group_ptr++ = i;
630
631
409k
      mask = mask >> 1;
632
409k
    }
633
58.5k
    *scf_group_ptr++ = i;
634
635
58.5k
    ixheaacd_calc_grp_offset(usac_data->pstr_usac_winmap[win],
636
58.5k
                             &usac_data->group_dis[chn][0]);
637
58.5k
  }
638
639
196k
  if (*max_sfb > usac_data->pstr_sfb_info[chn]->sfb_per_sbk) {
640
266
    *max_sfb = usac_data->pstr_sfb_info[chn]->sfb_per_sbk;
641
266
    return -1;
642
266
  }
643
644
195k
  return 0;
645
196k
}
646
647
WORD32 ixheaacd_core_coder_data(WORD32 id, ia_usac_data_struct *usac_data,
648
                                WORD32 elem_idx, WORD32 chan_offset,
649
                                ia_bit_buf_struct *it_bit_buff,
650
199k
                                WORD32 nr_core_coder_channels) {
651
199k
  WORD32 err_code = 0;
652
199k
  WORD32 k = 0, ch = 0, chn = 0, left = 0, right = 0;
653
654
199k
  ia_usac_tmp_core_coder_struct str_tmp_core_coder = {0};
655
199k
  ia_usac_tmp_core_coder_struct *pstr_core_coder = &str_tmp_core_coder;
656
199k
  ia_td_frame_data_struct td_frame;
657
199k
  jmp_buf local;
658
659
199k
  if (usac_data->ec_flag) {
660
0
    err_code = setjmp(local);
661
0
    it_bit_buff->xaac_jmp_buf = &local;
662
0
  }
663
199k
  if (err_code == 0 &&
664
199k
      ((usac_data->ec_flag == 0) || (usac_data->frame_ok == 1 && usac_data->ec_flag == 1))) {
665
199k
    memset(&td_frame, 0, sizeof(td_frame));
666
199k
    pstr_core_coder->tns_on_lr = 0;
667
199k
    pstr_core_coder->pred_dir = 0;
668
199k
    if (id != ID_USAC_LFE) {
669
501k
      for (ch = 0; ch < nr_core_coder_channels; ch++)
670
304k
        pstr_core_coder->core_mode[ch] = ixheaacd_read_bits_buf(it_bit_buff, 1);
671
197k
    } else {
672
3.30k
      for (ch = 0; ch < nr_core_coder_channels; ch++) pstr_core_coder->core_mode[ch] = 0;
673
1.65k
    }
674
675
199k
    if (nr_core_coder_channels == 2 && pstr_core_coder->core_mode[0] == 0 &&
676
88.4k
        pstr_core_coder->core_mode[1] == 0) {
677
71.4k
      pstr_core_coder->tns_active = ixheaacd_read_bits_buf(it_bit_buff, 1);
678
71.4k
      pstr_core_coder->common_window = ixheaacd_read_bits_buf(it_bit_buff, 1);
679
680
71.4k
      if (pstr_core_coder->common_window) {
681
34.2k
        left = chan_offset;
682
34.2k
        right = chan_offset + 1;
683
684
34.2k
        err_code = ixheaacd_ics_info(usac_data, left, &pstr_core_coder->max_sfb[left],
685
34.2k
                                     it_bit_buff, usac_data->window_sequence_last[left]);
686
687
34.2k
        if (err_code == -1) {
688
12
          if (usac_data->ec_flag) {
689
0
            memcpy(usac_data->max_sfb, pstr_core_coder->max_sfb,
690
0
                   sizeof(pstr_core_coder->max_sfb));
691
0
            longjmp(*(it_bit_buff->xaac_jmp_buf),
692
0
                    IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
693
12
          } else {
694
12
            return err_code;
695
12
          }
696
12
        }
697
698
34.2k
        pstr_core_coder->common_max_sfb = ixheaacd_read_bits_buf(it_bit_buff, 1);
699
700
34.2k
        if (pstr_core_coder->common_max_sfb == 0) {
701
11.6k
          if (usac_data->window_sequence[left] == EIGHT_SHORT_SEQUENCE)
702
9.96k
            pstr_core_coder->max_sfb[right] = ixheaacd_read_bits_buf(it_bit_buff, 4);
703
1.64k
          else
704
1.64k
            pstr_core_coder->max_sfb[right] = ixheaacd_read_bits_buf(it_bit_buff, 6);
705
22.6k
        } else {
706
22.6k
          pstr_core_coder->max_sfb[right] = pstr_core_coder->max_sfb[left];
707
22.6k
        }
708
709
34.2k
        pstr_core_coder->max_sfb_ste =
710
34.2k
            max(pstr_core_coder->max_sfb[left], pstr_core_coder->max_sfb[right]);
711
712
34.2k
        usac_data->window_sequence[right] = usac_data->window_sequence[left];
713
34.2k
        usac_data->window_shape[right] = usac_data->window_shape[left];
714
34.2k
        memcpy(&usac_data->group_dis[right][0], &usac_data->group_dis[left][0], 8);
715
34.2k
        usac_data->pstr_sfb_info[right] = usac_data->pstr_sfb_info[left];
716
34.2k
        if (pstr_core_coder->max_sfb[right] > usac_data->pstr_sfb_info[right]->sfb_per_sbk)
717
767
          pstr_core_coder->max_sfb[right] = usac_data->pstr_sfb_info[right]->sfb_per_sbk;
718
719
34.2k
        pstr_core_coder->ms_mask_present[0] =
720
34.2k
            ixheaacd_read_ms_mask(usac_data, pstr_core_coder, it_bit_buff, left);
721
37.2k
      } else {
722
37.2k
        left = chan_offset;
723
37.2k
        right = chan_offset + 1;
724
725
37.2k
        pstr_core_coder->ms_mask_present[0] = 0;
726
37.2k
        pstr_core_coder->ms_mask_present[1] = 0;
727
728
5.09M
        for (k = 0; k < SFB_NUM_MAX; k++) {
729
5.06M
          usac_data->alpha_q_re_prev[k] = 0;
730
5.06M
          usac_data->alpha_q_im_prev[k] = 0;
731
5.06M
        }
732
37.2k
      }
733
734
71.4k
      if (usac_data->tw_mdct[elem_idx] == 1) {
735
0
        pstr_core_coder->common_tw = ixheaacd_read_bits_buf(it_bit_buff, 1);
736
737
0
        if (pstr_core_coder->common_tw == 1) {
738
0
          usac_data->tw_data_present[left] = ixheaacd_read_bits_buf(it_bit_buff, 1);
739
0
          usac_data->tw_data_present[right] = usac_data->tw_data_present[left];
740
0
          if (usac_data->tw_data_present[left]) {
741
0
            for (k = 0; k < NUM_TW_NODES; k++) {
742
0
              usac_data->tw_ratio[left][k] = ixheaacd_read_bits_buf(it_bit_buff, 3);
743
0
              usac_data->tw_ratio[right][k] = usac_data->tw_ratio[left][k];
744
0
            }
745
0
          }
746
0
        }
747
0
      }
748
749
71.4k
      if (pstr_core_coder->tns_active) {
750
17.8k
        if (pstr_core_coder->common_window) {
751
16.7k
          pstr_core_coder->common_tns = ixheaacd_read_bits_buf(it_bit_buff, 1);
752
753
16.7k
        } else {
754
1.18k
          pstr_core_coder->common_tns = 0;
755
1.18k
        }
756
757
17.8k
        pstr_core_coder->tns_on_lr = ixheaacd_read_bits_buf(it_bit_buff, 1);
758
759
17.8k
        if (pstr_core_coder->common_tns) {
760
3.64k
          ixheaacd_read_tns_u(usac_data->pstr_sfb_info[0], &usac_data->pstr_tns[left][0],
761
3.64k
                              it_bit_buff);
762
3.64k
          memcpy(&usac_data->pstr_tns[right][0], &usac_data->pstr_tns[left][0],
763
3.64k
                 sizeof(ia_tns_frame_info_struct));
764
765
3.64k
          pstr_core_coder->tns_data_present[0] = 2;
766
3.64k
          pstr_core_coder->tns_data_present[1] = 2;
767
14.2k
        } else {
768
14.2k
          pstr_core_coder->tns_present_both = ixheaacd_read_bits_buf(it_bit_buff, 1);
769
770
14.2k
          if (pstr_core_coder->tns_present_both) {
771
11.6k
            pstr_core_coder->tns_data_present[0] = 1;
772
11.6k
            pstr_core_coder->tns_data_present[1] = 1;
773
11.6k
          } else {
774
2.56k
            pstr_core_coder->tns_data_present[1] = ixheaacd_read_bits_buf(it_bit_buff, 1);
775
2.56k
            pstr_core_coder->tns_data_present[0] = 1 - pstr_core_coder->tns_data_present[1];
776
2.56k
          }
777
14.2k
        }
778
53.5k
      } else {
779
53.5k
        pstr_core_coder->common_tns = 0;
780
53.5k
        pstr_core_coder->tns_data_present[0] = 0;
781
53.5k
        pstr_core_coder->tns_data_present[1] = 0;
782
53.5k
      }
783
784
127k
    } else {
785
127k
      pstr_core_coder->common_window = 0;
786
127k
      pstr_core_coder->common_tw = 0;
787
127k
      left = chan_offset;
788
127k
      right = chan_offset;
789
127k
      if (nr_core_coder_channels == 2) right = chan_offset + 1;
790
127k
    }
791
792
504k
    for (ch = 0, chn = chan_offset; ch < nr_core_coder_channels; ch++, chn++) {
793
305k
      if (pstr_core_coder->core_mode[chn] == CORE_MODE_LPD &&
794
56.6k
          usac_data->td_frame_prev[chn] == CORE_MODE_FD && usac_data->ec_flag) {
795
0
        memcpy(usac_data->coef_fix[chn], usac_data->str_error_concealment[chn].spectral_coeff,
796
0
               sizeof(usac_data->str_error_concealment[chn].spectral_coeff));
797
0
        memcpy(usac_data->spec_scale[chn], usac_data->str_error_concealment[chn].q_spec_coeff,
798
0
               sizeof(usac_data->spec_scale[chn]));
799
0
        err_code = ixheaacd_fd_frm_dec(usac_data, chn);
800
0
        if (err_code == -1) return err_code;
801
0
        for (k = 0; k < usac_data->ccfl; k++) {
802
0
          usac_data->time_sample_vector[chn][k] = (FLOAT32)(
803
0
              (FLOAT32)usac_data->output_data_ptr[chn][k] * (FLOAT32)(ONE_BY_TWO_POW_15));
804
0
        }
805
0
        memcpy(usac_data->time_sample_vector_prev[chn], usac_data->time_sample_vector[chn],
806
0
               usac_data->ccfl * sizeof(usac_data->time_sample_vector_prev[chn][0]));
807
808
0
        usac_data->window_sequence[ch] = usac_data->str_error_concealment[ch].win_seq;
809
0
        usac_data->window_shape[ch] = usac_data->str_error_concealment[ch].win_shape;
810
0
        usac_data->window_shape_prev[ch] = usac_data->window_shape[ch];
811
0
        usac_data->window_sequence_last[ch] = usac_data->window_sequence[ch];
812
0
      }
813
305k
      if (pstr_core_coder->core_mode[ch] == 1) {
814
75.0k
        err_code = ixheaacd_tw_buff_update(usac_data, chn, usac_data->str_tddec[chn]);
815
75.0k
        if (err_code == -1) return err_code;
816
817
75.0k
        if (!usac_data->td_frame_prev[chn]) {
818
15.3k
          ixheaacd_fix2flt_data(usac_data, usac_data->str_tddec[chn], chn);
819
15.3k
        }
820
821
69.7M
        for (k = 0; k < usac_data->ccfl; k++) {
822
69.6M
          usac_data->time_sample_vector[chn][k] = (FLOAT32)(
823
69.6M
              (FLOAT32)usac_data->output_data_ptr[chn][k] * (FLOAT32)(ONE_BY_TWO_POW_15));
824
69.6M
        }
825
75.0k
        usac_data->present_chan = chn;
826
75.0k
        err_code = ixheaacd_lpd_channel_stream(usac_data, &td_frame, it_bit_buff,
827
75.0k
                                               usac_data->time_sample_vector[chn]);
828
75.0k
        if (err_code == -1) return err_code;
829
75.0k
        if (usac_data->ec_flag) {
830
0
          it_bit_buff->xaac_jmp_buf = &local;
831
0
        }
832
75.0k
        if (usac_data->ec_flag && usac_data->frame_ok) {
833
0
          memcpy(&usac_data->td_frame_data_prev[chn], &td_frame, sizeof(td_frame));
834
0
          usac_data->core_mode = CORE_MODE_LPD;
835
0
        }
836
69.2M
        for (k = 0; k < usac_data->ccfl; k++) {
837
69.1M
          usac_data->output_data_ptr[chn][k] =
838
69.1M
              (WORD32)(usac_data->time_sample_vector[chn][k] * (FLOAT32)((WORD64)1 << 15));
839
69.1M
        }
840
841
75.0k
        usac_data->window_shape[chn] = WIN_SEL_0;
842
843
75.0k
        ixheaacd_td_frm_dec(usac_data, chn, td_frame.mod[0]);
844
845
75.0k
        usac_data->window_shape_prev[chn] = usac_data->window_shape[chn];
846
75.0k
        usac_data->window_sequence_last[chn] = EIGHT_SHORT_SEQUENCE;
847
848
230k
      } else {
849
230k
        memset(usac_data->coef_fix[chn], 0, LN2 * sizeof(*usac_data->coef_fix[0]));
850
851
230k
        if (usac_data->str_tddec[chn] && usac_data->td_frame_prev[chn]) {
852
13.5k
          if (usac_data->ec_flag) {
853
0
            memcpy(usac_data->time_sample_vector[chn], usac_data->time_sample_vector_prev[chn],
854
0
                   usac_data->ccfl * sizeof(usac_data->time_sample_vector[chn][0]));
855
0
          }
856
13.5k
          ixheaacd_lpd_dec_update(usac_data->str_tddec[chn], usac_data, chn);
857
13.5k
        }
858
859
230k
        if (id != ID_USAC_LFE) {
860
228k
          if ((nr_core_coder_channels == 1) ||
861
161k
              (pstr_core_coder->core_mode[0] != pstr_core_coder->core_mode[1]))
862
85.9k
            pstr_core_coder->tns_data_present[ch] = ixheaacd_read_bits_buf(it_bit_buff, 1);
863
228k
        }
864
865
230k
        err_code = ixheaacd_fd_channel_stream(
866
230k
            usac_data, pstr_core_coder, &pstr_core_coder->max_sfb[ch],
867
230k
            usac_data->window_sequence_last[chn], chn, usac_data->noise_filling_config[elem_idx],
868
230k
            ch, it_bit_buff);
869
230k
        if (err_code == -1) return err_code;
870
230k
      }
871
305k
    }
872
873
198k
    if (pstr_core_coder->core_mode[0] == CORE_MODE_FD &&
874
156k
        pstr_core_coder->core_mode[1] == CORE_MODE_FD && nr_core_coder_channels == 2) {
875
70.9k
      ixheaacd_cplx_prev_mdct_dmx(usac_data->pstr_sfb_info[left], usac_data->coef_save[left],
876
70.9k
                                  usac_data->coef_save[right], usac_data->dmx_re_prev,
877
70.9k
                                  pstr_core_coder->pred_dir);
878
70.9k
    }
879
880
198k
    if (pstr_core_coder->tns_on_lr == 0 && (id != ID_USAC_LFE)) {
881
454k
      for (ch = 0, chn = left; chn <= right; ch++, chn++) {
882
273k
        if (pstr_core_coder->core_mode[ch] == CORE_MODE_FD) {
883
198k
          err_code = ixheaacd_tns_apply(usac_data, usac_data->coef_fix[chn],
884
198k
                                        pstr_core_coder->max_sfb[ch],
885
198k
                                        usac_data->pstr_sfb_info[chn], usac_data->pstr_tns[chn]);
886
198k
          if (err_code) return err_code;
887
198k
        }
888
273k
      }
889
181k
    }
890
891
198k
    if (nr_core_coder_channels == 2 && pstr_core_coder->core_mode[0] == 0 &&
892
87.8k
        pstr_core_coder->core_mode[1] == 0) {
893
70.9k
      if (pstr_core_coder->ms_mask_present[0] == 3) {
894
13.9k
        ixheaacd_cplx_pred_upmixing(usac_data, usac_data->coef_fix[left],
895
13.9k
                                    usac_data->coef_fix[right], pstr_core_coder, left);
896
897
56.9k
      } else if (pstr_core_coder->ms_mask_present[0] > 0) {
898
9.00k
        ixheaacd_ms_stereo(usac_data, usac_data->coef_fix[right], usac_data->coef_fix[left], left,
899
9.00k
                           pstr_core_coder->max_sfb[right] > pstr_core_coder->max_sfb[left]
900
9.00k
                               ? pstr_core_coder->max_sfb[right]
901
9.00k
                               : pstr_core_coder->max_sfb[left]);
902
9.00k
      }
903
904
70.9k
      if (pstr_core_coder->tns_on_lr) {
905
42.7k
        for (ch = 0, chn = left; chn <= right; ch++, chn++) {
906
28.4k
          if (pstr_core_coder->core_mode[ch] == CORE_MODE_FD) {
907
28.4k
            err_code = ixheaacd_tns_apply(
908
28.4k
                usac_data, usac_data->coef_fix[chn], pstr_core_coder->max_sfb[ch],
909
28.4k
                usac_data->pstr_sfb_info[chn], usac_data->pstr_tns[chn]);
910
28.4k
            if (err_code) return err_code;
911
28.4k
          }
912
28.4k
        }
913
14.2k
      }
914
915
70.9k
      ixheaacd_usac_cplx_save_prev(usac_data->pstr_sfb_info[left], usac_data->coef_fix[left],
916
70.9k
                                   usac_data->coef_fix[right], usac_data->coef_save[left],
917
70.9k
                                   usac_data->coef_save[right]);
918
70.9k
    }
919
198k
    if (usac_data->ec_flag) {
920
0
      for (chn = left; chn <= right; chn++) {
921
0
        if (pstr_core_coder->core_mode[chn] == CORE_MODE_FD &&
922
0
            usac_data->td_frame_prev[chn] == CORE_MODE_LPD) {
923
0
          memcpy(usac_data->str_error_concealment[chn].spectral_coeff, usac_data->coef_fix[chn],
924
0
                 sizeof(usac_data->str_error_concealment[chn].spectral_coeff));
925
0
          memcpy(usac_data->str_error_concealment[chn].q_spec_coeff, usac_data->spec_scale[chn],
926
0
                 sizeof(usac_data->spec_scale[chn]));
927
0
          usac_data->str_error_concealment[chn].win_seq = usac_data->window_sequence[chn];
928
0
          usac_data->str_error_concealment[chn].win_shape = usac_data->window_shape[chn];
929
0
          usac_data->str_error_concealment[chn].win_shape_prev =
930
0
              usac_data->window_shape_prev[chn];
931
0
          usac_data->str_error_concealment[chn].td_frame_prev = usac_data->td_frame_prev[chn];
932
0
          usac_data->str_error_concealment[chn].fac_data_present =
933
0
              usac_data->fac_data_present[chn];
934
0
        }
935
0
      }
936
0
      if (usac_data->frame_ok && usac_data->ec_flag) {
937
0
        memcpy(usac_data->max_sfb, pstr_core_coder->max_sfb, sizeof(pstr_core_coder->max_sfb));
938
0
      }
939
0
    }
940
198k
  } else {
941
0
    left = chan_offset;
942
0
    right = chan_offset;
943
0
    if (nr_core_coder_channels == 2) right = chan_offset + 1;
944
0
    if (usac_data->ec_flag == 1) {
945
0
      WORD32 err = 0;
946
0
      usac_data->frame_ok = 0;
947
0
      for (ch = left; ch <= right; ch++) {
948
0
        if (usac_data->td_frame_prev[ch] == CORE_MODE_LPD) {
949
0
          usac_data->fac_data_present[ch] = 0;
950
0
          usac_data->str_error_concealment[ch].pstr_ec_scratch =
951
0
              (ia_ec_scratch_str *)&usac_data->str_error_concealment[ch].str_ec_scratch;
952
0
          usac_data->core_mode = usac_data->td_frame_prev[ch];
953
0
          usac_data->present_chan = ch;
954
0
          ixheaacd_usac_apply_ec(usac_data, NULL, ch);
955
0
          err = ixheaacd_lpd_dec(usac_data, usac_data->str_tddec[ch],
956
0
                                 &usac_data->td_frame_data_prev[ch],
957
0
                                 usac_data->time_sample_vector[ch], usac_data->first_lpd_flag, 0,
958
0
                                 usac_data->bpf_control_info);
959
960
0
          if (err) return err;
961
962
0
          for (k = 0; k < usac_data->ccfl; k++) {
963
0
            usac_data->output_data_ptr[ch][k] =
964
0
                (WORD32)(usac_data->time_sample_vector[ch][k] * (FLOAT32)((WORD64)1 << 15));
965
0
          }
966
967
0
          usac_data->window_shape[ch] = WIN_SEL_0;
968
0
          usac_data->window_shape_prev[ch] = usac_data->window_shape[ch];
969
0
          usac_data->window_sequence_last[ch] = EIGHT_SHORT_SEQUENCE;
970
0
        } else {
971
0
          pstr_core_coder->core_mode[ch] = CORE_MODE_FD;
972
0
        }
973
0
      }
974
0
    }
975
0
  }
976
977
502k
  for (ch = left; ch <= right; ch++) {
978
303k
    FLOAT32 *ptr_scratch =
979
303k
        (FLOAT32 *)usac_data->str_error_concealment[ch].str_ec_scratch.spec_coeff;
980
303k
    if ((pstr_core_coder->core_mode[ch] != CORE_MODE_LPD &&
981
247k
         usac_data->td_frame_prev[ch] != CORE_MODE_LPD && usac_data->ec_flag) ||
982
303k
        (pstr_core_coder->core_mode[ch] == CORE_MODE_FD && usac_data->ec_flag == 0)) {
983
247k
      if (usac_data->tw_mdct[elem_idx]) {
984
0
        err_code = -1;
985
0
        return err_code;
986
987
247k
      } else {
988
247k
        if (usac_data->frame_ok == 0) {
989
0
          usac_data->fac_data_present[ch] = 0;
990
0
        }
991
247k
        err_code = ixheaacd_fd_frm_dec(usac_data, ch);
992
247k
        if (err_code == -1) return err_code;
993
247k
        if (usac_data->ec_flag) {
994
0
          if (usac_data->str_error_concealment[ch].fade_idx < MAX_FADE_FRAMES) {
995
0
            FLOAT32 fade_fac = (FLOAT32)(ONE_BY_TWO_POW_15)*ia_ec_fade_factors
996
0
                [usac_data->str_error_concealment[ch].fade_idx];
997
0
            for (k = 0; k < usac_data->ccfl; k++) {
998
0
              usac_data->time_sample_vector[ch][k] =
999
0
                  (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] * fade_fac);
1000
0
            }
1001
0
          } else {
1002
0
            memset(&usac_data->time_sample_vector[ch][0], 0,
1003
0
                   usac_data->ccfl * sizeof(usac_data->time_sample_vector[ch][0]));
1004
0
          }
1005
247k
        } else {
1006
249M
          for (k = 0; k < usac_data->ccfl; k++) {
1007
248M
            usac_data->time_sample_vector[ch][k] =
1008
248M
                (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] *
1009
248M
                          (FLOAT32)(ONE_BY_TWO_POW_15));
1010
248M
          }
1011
247k
        }
1012
247k
      }
1013
247k
      usac_data->window_shape_prev[ch] = usac_data->window_shape[ch];
1014
247k
      usac_data->window_sequence_last[ch] = usac_data->window_sequence[ch];
1015
247k
    } else {
1016
55.9k
      if (usac_data->ec_flag) {
1017
0
        usac_data->str_error_concealment[ch].prev_frame_ok[0] =
1018
0
            usac_data->str_error_concealment[ch].prev_frame_ok[1];
1019
0
        usac_data->str_error_concealment[ch].prev_frame_ok[1] = usac_data->frame_ok;
1020
1021
0
        if (usac_data->str_error_concealment[ch].fade_idx < MAX_FADE_FRAMES) {
1022
0
          FLOAT32 fade_fac =
1023
0
              (FLOAT32)(ONE_BY_TWO_POW_15)*ia_ec_fade_factors[usac_data->str_error_concealment[ch]
1024
0
                                                                  .fade_idx];
1025
0
          for (k = 0; k < usac_data->ccfl; k++) {
1026
0
            usac_data->time_sample_vector[ch][k] =
1027
0
                (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] * fade_fac);
1028
0
          }
1029
0
        } else {
1030
0
          memset(&usac_data->time_sample_vector[ch][0], 0,
1031
0
                 usac_data->ccfl * sizeof(usac_data->time_sample_vector[ch][0]));
1032
0
        }
1033
1034
0
        memcpy(ptr_scratch, usac_data->time_sample_vector[ch],
1035
0
               usac_data->ccfl * sizeof(ptr_scratch[0]));
1036
0
        memcpy(usac_data->time_sample_vector[ch], usac_data->time_sample_vector_prev[ch],
1037
0
               usac_data->ccfl * sizeof(usac_data->time_sample_vector[ch][0]));
1038
0
        memcpy(usac_data->time_sample_vector_prev[ch], ptr_scratch,
1039
0
               usac_data->ccfl * sizeof(ptr_scratch[0]));
1040
55.9k
      } else {
1041
51.1M
        for (k = 0; k < usac_data->ccfl; k++) {
1042
51.1M
          usac_data->time_sample_vector[ch][k] =
1043
51.1M
              (FLOAT32)((FLOAT32)usac_data->output_data_ptr[ch][k] *
1044
51.1M
                        (FLOAT32)(ONE_BY_TWO_POW_15));
1045
51.1M
        }
1046
55.9k
      }
1047
55.9k
    }
1048
303k
    if (usac_data->ec_flag) {
1049
0
      usac_data->window_sequence[ch] = usac_data->str_error_concealment[ch].win_seq;
1050
0
      usac_data->window_shape[ch] = usac_data->str_error_concealment[ch].win_shape;
1051
0
      if (usac_data->first_frame == 0) {
1052
0
        usac_data->window_shape_prev[ch] = usac_data->window_shape[ch];
1053
0
        usac_data->window_sequence_last[ch] = usac_data->window_sequence[ch];
1054
0
      }
1055
0
    }
1056
303k
  }
1057
198k
  if (usac_data->ec_flag) {
1058
0
    usac_data->first_frame = 0;
1059
0
    if (usac_data->frame_ok == 1) {
1060
0
      for (ch = 0, chn = left; chn <= right; chn++, ch++)
1061
0
        usac_data->td_frame_prev[chn] = pstr_core_coder->core_mode[ch];
1062
0
    }
1063
198k
  } else {
1064
501k
    for (ch = 0, chn = left; chn <= right; chn++, ch++)
1065
303k
      usac_data->td_frame_prev[chn] = pstr_core_coder->core_mode[ch];
1066
198k
  }
1067
1068
198k
  return 0;
1069
198k
}