Coverage Report

Created: 2026-08-13 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_acelp_bitparse.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 <string.h>
21
#include "ixheaac_type_def.h"
22
23
#include "ixheaacd_acelp_com.h"
24
#include "ixheaacd_bitbuffer.h"
25
26
#include "ixheaacd_interface.h"
27
#include "ixheaacd_cnst.h"
28
#include "ixheaacd_info.h"
29
#include "ixheaacd_sbr_common.h"
30
#include "ixheaacd_drc_data_struct.h"
31
#include "ixheaacd_defines.h"
32
#include "ixheaacd_aac_rom.h"
33
#include "ixheaacd_pulsedata.h"
34
#include "ixheaacd_pns.h"
35
#include "ixheaac_constants.h"
36
#include "ixheaacd_sbrdecsettings.h"
37
#include "ixheaacd_sbrdecoder.h"
38
#include "ixheaacd_acelp_info.h"
39
#include "ixheaacd_tns_usac.h"
40
#include "ixheaacd_ec_defines.h"
41
#include "ixheaacd_ec_struct_def.h"
42
#include "ixheaacd_main.h"
43
#include "ixheaacd_channelinfo.h"
44
#include "ixheaacd_ec.h"
45
#include "ixheaacd_arith_dec.h"
46
#include "ixheaacd_func_def.h"
47
#include "ixheaac_basic_ops32.h"
48
#include "ixheaac_error_standards.h"
49
#include "ixheaacd_error_codes.h"
50
51
extern const ia_usac_samp_rate_info ixheaacd_samp_rate_info[];
52
53
362k
WORD32 ixheaacd_get_mode_lpc(WORD32 lpc_set, ia_bit_buf_struct *it_bit_buff, WORD32 *nk_mode) {
54
362k
  WORD32 mode_lpc = 0;
55
362k
  switch (lpc_set) {
56
85.4k
    case 4:
57
85.4k
      mode_lpc = 0;
58
85.4k
      break;
59
54.0k
    case 0:
60
138k
    case 2:
61
138k
      mode_lpc = ixheaacd_read_bits_buf(it_bit_buff, 1);
62
138k
      if (mode_lpc == 1) *nk_mode = 3;
63
138k
      break;
64
58.9k
    case 1:
65
58.9k
      if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0)
66
38.7k
        mode_lpc = *nk_mode = 2;
67
20.2k
      else {
68
20.2k
        if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0)
69
16.2k
          mode_lpc = *nk_mode = 0;
70
3.98k
        else
71
3.98k
          mode_lpc = *nk_mode = 1;
72
20.2k
      }
73
58.9k
      break;
74
78.8k
    case 3:
75
78.8k
      if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0)
76
50.7k
        mode_lpc = *nk_mode = 1;
77
28.1k
      else {
78
28.1k
        if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0)
79
19.0k
          mode_lpc = *nk_mode = 0;
80
9.05k
        else {
81
9.05k
          if (ixheaacd_read_bits_buf(it_bit_buff, 1) == 0)
82
2.49k
            mode_lpc = 2;
83
6.56k
          else
84
6.56k
            mode_lpc = 3;
85
9.05k
          *nk_mode = 2;
86
9.05k
        }
87
28.1k
      }
88
78.8k
      break;
89
362k
  }
90
362k
  return mode_lpc;
91
362k
}
92
93
358k
VOID ixheaacd_qn_data(WORD32 nk_mode, WORD32 *qn, ia_bit_buf_struct *it_bit_buff) {
94
358k
  WORD32 k;
95
358k
  switch (nk_mode) {
96
50.7k
    case 1:
97
152k
      for (k = 0; k < 2; k++) {
98
143k
        while (ixheaacd_read_bits_buf(it_bit_buff, 1) == 1) {
99
41.9k
          qn[k] += 1;
100
41.9k
        }
101
101k
        if (qn[k] > 0) qn[k] += 1;
102
101k
      }
103
50.7k
      break;
104
201k
    case 0:
105
249k
    case 2:
106
307k
    case 3:
107
922k
      for (k = 0; k < 2; k++) qn[k] = 2 + ixheaacd_read_bits_buf(it_bit_buff, 2);
108
109
307k
      if (nk_mode == 2) {
110
143k
        for (k = 0; k < 2; k++) {
111
95.5k
          if (qn[k] > 4) {
112
15.1k
            qn[k] = 0;
113
114
41.3k
            while (ixheaacd_read_bits_buf(it_bit_buff, 1) == 1) qn[k] += 1;
115
116
15.1k
            if (qn[k] > 0) qn[k] += 4;
117
15.1k
          }
118
95.5k
        }
119
259k
      } else {
120
778k
        for (k = 0; k < 2; k++) {
121
519k
          if (qn[k] > 4) {
122
82.8k
            WORD32 qn_ext = 0;
123
237k
            while (ixheaacd_read_bits_buf(it_bit_buff, 1) == 1) qn_ext += 1;
124
125
82.8k
            switch (qn_ext) {
126
44.9k
              case 0:
127
44.9k
                qn[k] = 5;
128
44.9k
                break;
129
18.5k
              case 1:
130
18.5k
                qn[k] = 6;
131
18.5k
                break;
132
5.55k
              case 2:
133
5.55k
                qn[k] = 0;
134
5.55k
                break;
135
13.7k
              default:
136
13.7k
                qn[k] = qn_ext + 4;
137
13.7k
                break;
138
82.8k
            }
139
82.8k
          }
140
519k
        }
141
259k
      }
142
307k
      break;
143
358k
  }
144
358k
  return;
145
358k
}
146
147
VOID ixheaacd_code_book_indices(ia_td_frame_data_struct *pstr_td_frame_data, WORD32 nk_mode,
148
358k
                                WORD32 *pos, ia_bit_buf_struct *it_bit_buff) {
149
358k
  WORD32 k, qn[2] = {0, 0}, nk, n, i;
150
151
358k
  ixheaacd_qn_data(nk_mode, &qn[0], it_bit_buff);
152
153
358k
  pstr_td_frame_data->lpc_first_approx_idx[(*pos)++] = qn[0];
154
358k
  pstr_td_frame_data->lpc_first_approx_idx[(*pos)++] = qn[1];
155
156
1.07M
  for (k = 0; k < 2; k++) {
157
716k
    if (qn[k] > 0) {
158
627k
      if (qn[k] > 4) {
159
84.4k
        nk = (qn[k] - 3) / 2;
160
84.4k
        n = qn[k] - nk * 2;
161
543k
      } else {
162
543k
        nk = 0;
163
543k
        n = qn[k];
164
543k
      }
165
627k
      pstr_td_frame_data->lpc_first_approx_idx[(*pos)++] =
166
627k
          ixheaacd_read_bits_buf(it_bit_buff, 4 * n);
167
168
5.64M
      for (i = 0; i < 8; i++)
169
5.02M
        pstr_td_frame_data->lpc_first_approx_idx[(*pos)++] =
170
5.02M
            ixheaacd_read_bits_buf(it_bit_buff, nk);
171
627k
    }
172
716k
  }
173
358k
  return;
174
358k
}
175
176
VOID ixheaacd_lpc_data(WORD32 first_lpd_flag, WORD32 mod[],
177
                       ia_td_frame_data_struct *pstr_td_frame_data,
178
85.4k
                       ia_bit_buf_struct *it_bit_buff) {
179
85.4k
  WORD32 mode_lpc, nk_mode = 0, j = 0;
180
181
85.4k
  mode_lpc = ixheaacd_get_mode_lpc(4, it_bit_buff, &nk_mode);
182
183
85.4k
  pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8);
184
185
85.4k
  ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff);
186
85.4k
  if (first_lpd_flag) {
187
54.0k
    mode_lpc = ixheaacd_get_mode_lpc(0, it_bit_buff, &nk_mode);
188
54.0k
    pstr_td_frame_data->lpc_first_approx_idx[j++] = mode_lpc;
189
190
54.0k
    if (mode_lpc == 0)
191
35.6k
      pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8);
192
193
54.0k
    ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff);
194
54.0k
  }
195
85.4k
  if (mod[0] < 3) {
196
84.8k
    mode_lpc = ixheaacd_get_mode_lpc(2, it_bit_buff, &nk_mode);
197
84.8k
    pstr_td_frame_data->lpc_first_approx_idx[j++] = mode_lpc;
198
199
84.8k
    if (mode_lpc == 0)
200
58.9k
      pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8);
201
202
84.8k
    ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff);
203
84.8k
  }
204
85.4k
  if (mod[0] < 2) {
205
58.9k
    mode_lpc = ixheaacd_get_mode_lpc(1, it_bit_buff, &nk_mode);
206
58.9k
    pstr_td_frame_data->lpc_first_approx_idx[j++] = mode_lpc;
207
208
58.9k
    if (mode_lpc == 0)
209
16.2k
      pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8);
210
211
58.9k
    if (mode_lpc != 1) ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff);
212
58.9k
  }
213
85.4k
  if (mod[2] < 2) {
214
78.8k
    mode_lpc = ixheaacd_get_mode_lpc(3, it_bit_buff, &nk_mode);
215
78.8k
    pstr_td_frame_data->lpc_first_approx_idx[j++] = mode_lpc;
216
217
78.8k
    if (mode_lpc == 0)
218
19.0k
      pstr_td_frame_data->lpc_first_approx_idx[j++] = ixheaacd_read_bits_buf(it_bit_buff, 8);
219
220
78.8k
    ixheaacd_code_book_indices(pstr_td_frame_data, nk_mode, &j, it_bit_buff);
221
78.8k
  }
222
85.4k
  return;
223
85.4k
}
224
225
VOID ixheaacd_fac_decoding(WORD32 fac_length, WORD32 k, WORD32 *fac_prm,
226
219k
                           ia_bit_buf_struct *it_bit_buff) {
227
219k
  WORD32 i, j, n, qn, nk, kv[8];
228
219k
  long code_book_index;
229
230
3.31M
  for (i = 0; i < fac_length; i += 8) {
231
3.09M
    qn = 0;
232
5.29M
    while (ixheaacd_read_bits_buf(it_bit_buff, 1) == 1) {
233
2.20M
      qn += 1;
234
2.20M
    }
235
3.09M
    if (qn != 0) qn += 1;
236
237
3.09M
    nk = 0;
238
3.09M
    n = qn;
239
3.09M
    if (qn > 4) {
240
52.6k
      nk = (qn - 3) >> 1;
241
52.6k
      n = qn - nk * 2;
242
52.6k
    }
243
244
3.09M
    code_book_index = ixheaacd_read_bits_buf(it_bit_buff, 4 * n);
245
246
27.8M
    for (j = 0; j < 8; j++) {
247
24.7M
      kv[j] = ixheaacd_read_bits_buf(it_bit_buff, nk);
248
24.7M
    }
249
250
3.09M
    ixheaacd_rotated_gosset_mtx_dec(qn, code_book_index, kv, &fac_prm[k * FAC_LENGTH + i]);
251
3.09M
  }
252
219k
}
253
254
const UWORD8 ixheaacd_num_bites_celp_coding[8][4] = {
255
    {5, 5, 5, 5},     {9, 9, 5, 5},     {9, 9, 9, 9}, {13, 13, 9, 9},
256
    {13, 13, 13, 13}, {16, 16, 16, 16}, {1, 5, 1, 5}, {1, 5, 5, 5}};
257
258
VOID ixheaacd_acelp_decoding(WORD32 k, ia_usac_data_struct *usac_data,
259
                             ia_td_frame_data_struct *pstr_td_frame_data,
260
185k
                             ia_bit_buf_struct *it_bit_buff, WORD32 chan) {
261
185k
  WORD32 sfr, kk;
262
185k
  WORD32 nb_subfr = usac_data->num_subfrm;
263
185k
  const UWORD8 *ptr_num_bits =
264
185k
      &ixheaacd_num_bites_celp_coding[pstr_td_frame_data->acelp_core_mode][0];
265
266
185k
  chan = 0;
267
185k
  pstr_td_frame_data->mean_energy[k] = ixheaacd_read_bits_buf(it_bit_buff, 2);
268
269
873k
  for (sfr = 0; sfr < nb_subfr; sfr++) {
270
687k
    kk = k * 4 + sfr;
271
272
687k
    if ((sfr == 0) || ((nb_subfr == 4) && (sfr == 2)))
273
315k
      pstr_td_frame_data->acb_index[kk] = ixheaacd_read_bits_buf(it_bit_buff, 9);
274
275
371k
    else
276
371k
      pstr_td_frame_data->acb_index[kk] = ixheaacd_read_bits_buf(it_bit_buff, 6);
277
278
687k
    pstr_td_frame_data->ltp_filtering_flag[kk] = ixheaacd_read_bits_buf(it_bit_buff, 1);
279
280
687k
    if (pstr_td_frame_data->acelp_core_mode == 5) {
281
67.1k
      pstr_td_frame_data->icb_index[kk][0] =
282
67.1k
          ixheaacd_read_bits_buf(it_bit_buff, 2);
283
67.1k
      pstr_td_frame_data->icb_index[kk][1] =
284
67.1k
          ixheaacd_read_bits_buf(it_bit_buff, 2);
285
67.1k
      pstr_td_frame_data->icb_index[kk][2] =
286
67.1k
          ixheaacd_read_bits_buf(it_bit_buff, 2);
287
67.1k
      pstr_td_frame_data->icb_index[kk][3] =
288
67.1k
          ixheaacd_read_bits_buf(it_bit_buff, 2);
289
67.1k
      pstr_td_frame_data->icb_index[kk][4] =
290
67.1k
          ixheaacd_read_bits_buf(it_bit_buff, 14);
291
67.1k
      pstr_td_frame_data->icb_index[kk][5] =
292
67.1k
          ixheaacd_read_bits_buf(it_bit_buff, 14);
293
67.1k
      pstr_td_frame_data->icb_index[kk][6] =
294
67.1k
          ixheaacd_read_bits_buf(it_bit_buff, 14);
295
67.1k
      pstr_td_frame_data->icb_index[kk][7] =
296
67.1k
          ixheaacd_read_bits_buf(it_bit_buff, 14);
297
620k
    } else {
298
620k
      pstr_td_frame_data->icb_index[kk][0] =
299
620k
          ixheaacd_read_bits_buf(it_bit_buff, ptr_num_bits[0]);
300
620k
      pstr_td_frame_data->icb_index[kk][1] =
301
620k
          ixheaacd_read_bits_buf(it_bit_buff, ptr_num_bits[1]);
302
620k
      pstr_td_frame_data->icb_index[kk][2] =
303
620k
          ixheaacd_read_bits_buf(it_bit_buff, ptr_num_bits[2]);
304
620k
      pstr_td_frame_data->icb_index[kk][3] =
305
620k
          ixheaacd_read_bits_buf(it_bit_buff, ptr_num_bits[3]);
306
620k
    }
307
308
687k
    pstr_td_frame_data->gains[kk] = ixheaacd_read_bits_buf(it_bit_buff, 7);
309
687k
  }
310
185k
}
311
312
VOID ixheaacd_tcx_coding(ia_usac_data_struct *usac_data, pWORD32 quant, WORD32 k,
313
                         WORD32 first_tcx_flag, ia_td_frame_data_struct *pstr_td_frame_data,
314
123k
                         ia_bit_buf_struct *it_bit_buff) {
315
123k
  pstr_td_frame_data->noise_factor[k] = ixheaacd_read_bits_buf(it_bit_buff, 3);
316
317
123k
  pstr_td_frame_data->global_gain[k] = ixheaacd_read_bits_buf(it_bit_buff, 7);
318
319
123k
  switch (pstr_td_frame_data->mod[k]) {
320
91.3k
    case 1:
321
91.3k
      pstr_td_frame_data->tcx_lg[k] = usac_data->len_subfrm;
322
91.3k
      break;
323
31.9k
    case 2:
324
31.9k
      pstr_td_frame_data->tcx_lg[k] = 2 * (usac_data->len_subfrm);
325
31.9k
      break;
326
613
    case 3:
327
613
      pstr_td_frame_data->tcx_lg[k] = 4 * (usac_data->len_subfrm);
328
613
      break;
329
123k
  }
330
331
123k
  if (first_tcx_flag) {
332
76.8k
    if (usac_data->usac_independency_flg) {
333
29.8k
      pstr_td_frame_data->arith_reset_flag = 1;
334
46.9k
    } else {
335
46.9k
      pstr_td_frame_data->arith_reset_flag = ixheaacd_read_bits_buf(it_bit_buff, 1);
336
46.9k
    }
337
76.8k
  }
338
339
123k
  ixheaacd_arith_data(pstr_td_frame_data, quant, usac_data, it_bit_buff, (first_tcx_flag), k);
340
341
123k
  return;
342
123k
}
343
344
WORD32 ixheaacd_lpd_channel_stream(ia_usac_data_struct *usac_data,
345
                                   ia_td_frame_data_struct *pstr_td_frame_data,
346
93.8k
                                   ia_bit_buf_struct *it_bit_buff, FLOAT32 *synth) {
347
93.8k
  WORD32 lpd_mode, k, cnt, ii;
348
93.8k
  WORD32 first_tcx_flag;
349
93.8k
  WORD32 *quant;
350
93.8k
  WORD32 core_mode_last = 0, fac_data_present;
351
93.8k
  WORD32 *fac_data;
352
93.8k
  WORD32 first_lpd_flag = 0;
353
93.8k
  WORD32 short_fac_flag;
354
93.8k
  WORD32 bpf_control_info = 0;
355
93.8k
  WORD32 chan = usac_data->present_chan;
356
93.8k
  WORD32 last_lpd_mode = usac_data->str_tddec[chan]->mode_prev;
357
93.8k
  WORD32 err = 0;
358
93.8k
  short_fac_flag = 0;
359
360
93.8k
  jmp_buf local;
361
362
93.8k
  if (usac_data->ec_flag) {
363
0
    err = setjmp(local);
364
0
  }
365
366
93.8k
  if (usac_data->sampling_rate_idx <= 5 && usac_data->ec_flag) {
367
0
    usac_data->frame_ok = 0;
368
0
  }
369
370
93.8k
  if (err == 0 && usac_data->frame_ok == 1) {
371
93.8k
    if (usac_data->ec_flag) {
372
0
      it_bit_buff->xaac_jmp_buf = &local;
373
0
    }
374
93.8k
    pstr_td_frame_data->acelp_core_mode = ixheaacd_read_bits_buf(it_bit_buff, 3);
375
376
93.8k
    lpd_mode = ixheaacd_read_bits_buf(it_bit_buff, 5);
377
378
93.8k
    if ((lpd_mode > 25 || lpd_mode < 0)) {
379
7.78k
      if (usac_data->ec_flag) {
380
0
        longjmp(*(it_bit_buff->xaac_jmp_buf),
381
0
                IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
382
7.78k
      } else {
383
7.78k
        return IA_FATAL_ERROR;
384
7.78k
      }
385
7.78k
    }
386
387
86.0k
    if (lpd_mode == 25) {
388
613
      pstr_td_frame_data->mod[0] = pstr_td_frame_data->mod[1] = pstr_td_frame_data->mod[2] =
389
613
          pstr_td_frame_data->mod[3] = 3;
390
85.4k
    } else if (lpd_mode == 24) {
391
815
      pstr_td_frame_data->mod[0] = pstr_td_frame_data->mod[1] = pstr_td_frame_data->mod[2] =
392
815
          pstr_td_frame_data->mod[3] = 2;
393
84.6k
    } else {
394
84.6k
      if (lpd_mode >= 20) {
395
5.19k
        pstr_td_frame_data->mod[0] = lpd_mode & 1;
396
5.19k
        pstr_td_frame_data->mod[1] = (lpd_mode >> 1) & 1;
397
5.19k
        pstr_td_frame_data->mod[2] = pstr_td_frame_data->mod[3] = 2;
398
79.4k
      } else if (lpd_mode >= 16) {
399
25.1k
        pstr_td_frame_data->mod[0] = pstr_td_frame_data->mod[1] = 2;
400
25.1k
        pstr_td_frame_data->mod[2] = lpd_mode & 1;
401
25.1k
        pstr_td_frame_data->mod[3] = (lpd_mode >> 1) & 1;
402
54.3k
      } else {
403
54.3k
        pstr_td_frame_data->mod[0] = lpd_mode & 1;
404
54.3k
        pstr_td_frame_data->mod[1] = (lpd_mode >> 1) & 1;
405
54.3k
        pstr_td_frame_data->mod[2] = (lpd_mode >> 2) & 1;
406
54.3k
        pstr_td_frame_data->mod[3] = (lpd_mode >> 3) & 1;
407
54.3k
      }
408
84.6k
    }
409
410
86.0k
    bpf_control_info = ixheaacd_read_bits_buf(it_bit_buff, 1);
411
412
86.0k
    core_mode_last = ixheaacd_read_bits_buf(it_bit_buff, 1);
413
414
86.0k
    fac_data_present = ixheaacd_read_bits_buf(it_bit_buff, 1);
415
416
86.0k
    first_lpd_flag = (core_mode_last == 0) ? 1 : 0;
417
418
86.0k
    quant = pstr_td_frame_data->x_tcx_invquant;
419
86.0k
    first_tcx_flag = 1;
420
86.0k
    k = 0;
421
395k
    while (k < 4) {
422
309k
      if (k == 0) {
423
86.0k
        if ((core_mode_last == 1) && (fac_data_present == 1))
424
12.3k
          ixheaacd_fac_decoding((usac_data->len_subfrm) / 2, k, pstr_td_frame_data->fac,
425
12.3k
                                it_bit_buff);
426
223k
      } else {
427
223k
        if (((last_lpd_mode == 0) && (pstr_td_frame_data->mod[k] > 0)) ||
428
193k
            ((last_lpd_mode > 0) && (pstr_td_frame_data->mod[k] == 0)))
429
95.6k
          ixheaacd_fac_decoding((usac_data->len_subfrm) / 2, k, pstr_td_frame_data->fac,
430
95.6k
                                it_bit_buff);
431
223k
      }
432
433
309k
      if (pstr_td_frame_data->mod[k] == 0) {
434
185k
        ixheaacd_acelp_decoding(k, usac_data, pstr_td_frame_data, it_bit_buff, chan);
435
185k
        last_lpd_mode = 0;
436
185k
        pstr_td_frame_data->tcx_lg[k] = 0;
437
185k
        k += 1;
438
185k
      } else {
439
123k
        ixheaacd_tcx_coding(usac_data, quant, k, first_tcx_flag, pstr_td_frame_data, it_bit_buff);
440
123k
        last_lpd_mode = pstr_td_frame_data->mod[k];
441
123k
        quant += pstr_td_frame_data->tcx_lg[k];
442
443
123k
        cnt = 1 << (pstr_td_frame_data->mod[k] - 1);
444
445
157k
        for (ii = 0; ii < cnt - 1; ii++) pstr_td_frame_data->tcx_lg[k + 1 + ii] = 0;
446
447
123k
        k += cnt;
448
123k
        first_tcx_flag = 0;
449
123k
      }
450
309k
    }
451
452
86.0k
    ixheaacd_lpc_data(first_lpd_flag, pstr_td_frame_data->mod, pstr_td_frame_data, it_bit_buff);
453
454
86.0k
    if ((core_mode_last == 0) && (fac_data_present == 1)) {
455
11.5k
      WORD32 fac_length;
456
11.5k
      short_fac_flag = ixheaacd_read_bits_buf(it_bit_buff, 1);
457
458
11.5k
      fac_length = (short_fac_flag) ? ((usac_data->ccfl) / 16) : ((usac_data->ccfl) / 8);
459
460
11.5k
      fac_data = pstr_td_frame_data->fac_data;
461
11.5k
      fac_data[0] = ixheaacd_read_bits_buf(it_bit_buff, 7);
462
11.5k
      if ((pstr_td_frame_data->fac_data[0] < 0) || (pstr_td_frame_data->fac_data[0] > 128)) {
463
0
        if (usac_data->ec_flag) {
464
0
          longjmp(*(it_bit_buff->xaac_jmp_buf),
465
0
                  IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
466
0
        } else {
467
0
          return IA_FATAL_ERROR;
468
0
        }
469
0
      }
470
11.5k
      ixheaacd_fac_decoding(fac_length, 0, &fac_data[1], it_bit_buff);
471
11.5k
    }
472
86.0k
    if (fac_data_present == 0) {
473
61.5k
      memset(&pstr_td_frame_data->fac_data[0], 0, sizeof(pstr_td_frame_data->fac_data));
474
61.5k
    }
475
86.0k
    if (usac_data->ec_flag && usac_data->frame_ok) {
476
0
      usac_data->bpf_control_info = bpf_control_info;
477
0
      usac_data->core_mode_last = core_mode_last;
478
0
      usac_data->first_lpd_flag = first_lpd_flag;
479
0
    }
480
86.0k
  } else {
481
0
    usac_data->frame_ok = 0;
482
0
  }
483
484
86.0k
  if (usac_data->ec_flag) {
485
0
    usac_data->str_error_concealment[chan].pstr_ec_scratch =
486
0
        (ia_ec_scratch_str *)&usac_data->str_error_concealment[chan].str_ec_scratch;
487
488
0
    ixheaacd_usac_apply_ec(usac_data, &ixheaacd_samp_rate_info[0], chan);
489
490
0
    if (usac_data->frame_ok == 0) {
491
0
      bpf_control_info = usac_data->bpf_control_info;
492
0
      core_mode_last = usac_data->core_mode_last;
493
0
      first_lpd_flag = usac_data->first_lpd_flag;
494
0
    }
495
0
  }
496
86.0k
  if (usac_data->frame_ok) {
497
85.3k
    err = ixheaacd_lpd_dec(usac_data, usac_data->str_tddec[chan], pstr_td_frame_data, synth,
498
85.3k
                           first_lpd_flag, short_fac_flag, bpf_control_info);
499
85.3k
  } else {
500
774
    if (usac_data->ec_flag) {
501
0
      usac_data->fac_data_present[chan] = 0;
502
0
      err = ixheaacd_lpd_dec(usac_data, usac_data->str_tddec[chan],
503
0
                             &usac_data->td_frame_data_prev[chan], synth, first_lpd_flag,
504
0
                             short_fac_flag, bpf_control_info);
505
0
    }
506
774
  }
507
508
86.0k
  return (err);
509
93.8k
}
510
511
WORD32 ixheaacd_tw_buff_update(ia_usac_data_struct *usac_data, WORD32 i,
512
93.8k
                               ia_usac_lpd_decoder_handle st) {
513
93.8k
  WORD32 *p_ioverlap = usac_data->overlap_data_ptr[i];
514
93.8k
  WORD32 td_frame_prev = usac_data->td_frame_prev[i];
515
93.8k
  WORD32 window_sequence_last = usac_data->window_sequence_last[i];
516
93.8k
  WORD32 tw_mdct = usac_data->tw_mdct[0];
517
518
93.8k
  if (!td_frame_prev) {
519
22.3k
    if (tw_mdct) {
520
0
      if (usac_data->ec_flag == 0) {
521
0
        return -1;
522
0
      } else {
523
0
        tw_mdct = 0;
524
0
      }
525
22.3k
    } else {
526
22.3k
      ixheaacd_reset_acelp_data_fix(usac_data, st, p_ioverlap,
527
22.3k
                                    (window_sequence_last == EIGHT_SHORT_SEQUENCE), 0);
528
22.3k
    }
529
22.3k
  }
530
93.8k
  return 0;
531
93.8k
}
532
533
93.0k
VOID ixheaacd_td_frm_dec(ia_usac_data_struct *usac_data, WORD32 k, WORD32 mod0) {
534
93.0k
  WORD32 i;
535
93.0k
  WORD32 lfac = 0;
536
537
93.0k
  WORD32 *p_out_idata = usac_data->output_data_ptr[k];
538
93.0k
  WORD32 *p_ioverlap = usac_data->overlap_data_ptr[k];
539
93.0k
  WORD32 nlong = usac_data->ccfl;
540
93.0k
  WORD32 window_sequence_last = usac_data->window_sequence_last[k];
541
93.0k
  WORD32 td_frame_prev = usac_data->td_frame_prev[k];
542
93.0k
  WORD32 tw_mdct = usac_data->tw_mdct[0];
543
93.0k
  WORD32 nshort = nlong / 8;
544
93.0k
  WORD32 *p_in_idata = p_out_idata;
545
546
93.0k
  if (!td_frame_prev) {
547
21.8k
    if (window_sequence_last == EIGHT_SHORT_SEQUENCE) {
548
8.67k
      lfac = nshort / 2;
549
13.1k
    } else {
550
13.1k
      lfac = nshort;
551
13.1k
    }
552
21.8k
  }
553
554
93.0k
  if (!td_frame_prev && (mod0 == 0)) {
555
2.76M
    for (i = 0; i < (nlong / 2) - lfac - (LEN_SUBFR); i++) {
556
2.75M
      p_in_idata[i] = 0;
557
2.75M
    }
558
84.6k
  } else if (!td_frame_prev && (mod0 > 0)) {
559
5.31M
    for (i = 0; i < (nlong / 2) - lfac; i++) {
560
5.30M
      p_in_idata[i] = 0;
561
5.30M
    }
562
13.4k
  }
563
564
93.0k
  if (tw_mdct) {
565
0
    if (!td_frame_prev && (mod0 == 0)) {
566
0
      for (i = (nlong / 2) - lfac - (LEN_SUBFR); i < nlong / 2; i++) {
567
0
        p_ioverlap[i + (nlong / 2)] = 0;
568
0
      }
569
0
    }
570
0
    for (i = 0; i < nlong / 2; i++) {
571
0
      p_out_idata[i] = p_ioverlap[i] << 1;
572
0
      p_out_idata[i + nlong / 2] =
573
0
          ixheaac_add32_sat(p_ioverlap[i + nlong / 2] << 1, p_in_idata[i]);
574
0
      p_ioverlap[i] = ixheaac_add32_sat(p_in_idata[i + (nlong / 2)] >> 1, p_ioverlap[i + nlong]);
575
0
      p_ioverlap[i + (nlong / 2)] = 0;
576
0
      p_ioverlap[i + nlong] = 0;
577
0
      p_ioverlap[i + nlong + (nlong / 2)] = 0;
578
0
    }
579
93.0k
  } else {
580
93.0k
    if (!td_frame_prev && (mod0 == 0)) {
581
1.37M
      for (i = (nlong / 2) - lfac - (LEN_SUBFR); i < nlong / 2; i++) {
582
1.36M
        p_ioverlap[i] = 0;
583
1.36M
      }
584
84.6k
    } else if (!td_frame_prev) {
585
7.95M
      for (i = (nlong / 2) - lfac; i < nlong; i++) {
586
7.94M
        p_ioverlap[i] = 0;
587
7.94M
      }
588
13.4k
    }
589
87.4M
    for (i = 0; i < nlong; i++) {
590
87.3M
      p_out_idata[i] = ixheaac_add32_sat(p_ioverlap[i] << 1, p_in_idata[i]);
591
87.3M
      p_ioverlap[i] = 0;
592
87.3M
    }
593
93.0k
  }
594
93.0k
}