Coverage Report

Created: 2025-12-10 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_imdct.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 <math.h>
21
#include <stdio.h>
22
#include <stdlib.h>
23
#include <string.h>
24
25
#include "ixheaac_type_def.h"
26
#include "ixheaacd_interface.h"
27
28
#include "ixheaacd_defines.h"
29
#include "ixheaacd_aac_rom.h"
30
31
#include "ixheaacd_bitbuffer.h"
32
33
#include "ixheaacd_tns_usac.h"
34
#include "ixheaacd_cnst.h"
35
#include "ixheaacd_acelp_info.h"
36
37
#include "ixheaacd_td_mdct.h"
38
39
#include "ixheaacd_sbrdecsettings.h"
40
#include "ixheaacd_info.h"
41
#include "ixheaacd_sbr_common.h"
42
#include "ixheaacd_drc_data_struct.h"
43
#include "ixheaacd_drc_dec.h"
44
#include "ixheaacd_sbrdecoder.h"
45
#include "ixheaacd_mps_polyphase.h"
46
#include "ixheaac_sbr_const.h"
47
48
#include "ixheaacd_pulsedata.h"
49
#include "ixheaacd_pns.h"
50
#include "ixheaacd_lt_predict.h"
51
#include "ixheaacd_ec_defines.h"
52
#include "ixheaacd_ec_struct_def.h"
53
#include "ixheaacd_main.h"
54
#include "ixheaacd_channelinfo.h"
55
#include "ixheaacd_ec.h"
56
#include "ixheaacd_arith_dec.h"
57
#include "ixheaacd_windows.h"
58
59
#include "ixheaacd_vec_baisc_ops.h"
60
#include "ixheaac_constants.h"
61
#include "ixheaacd_function_selector.h"
62
#include "ixheaac_basic_ops32.h"
63
#include "ixheaac_basic_ops40.h"
64
65
#include "ixheaacd_func_def.h"
66
67
#include "ixheaacd_windows.h"
68
69
extern const WORD32 ixheaacd_pre_post_twid_cos_512[512];
70
extern const WORD32 ixheaacd_pre_post_twid_sin_512[512];
71
extern const WORD32 ixheaacd_pre_post_twid_cos_384[384];
72
extern const WORD32 ixheaacd_pre_post_twid_sin_384[384];
73
extern const WORD32 ixheaacd_pre_post_twid_cos_64[64];
74
extern const WORD32 ixheaacd_pre_post_twid_sin_64[64];
75
extern const WORD32 ixheaacd_pre_post_twid_cos_48[48];
76
extern const WORD32 ixheaacd_pre_post_twid_sin_48[48];
77
extern const FLOAT64 ixheaacd_power_10_table[28];
78
extern const ia_usac_samp_rate_info ixheaacd_samp_rate_info[];
79
80
27.3M
#define ABS(A) ((A) < 0 ? (-A) : (A))
81
82
715k
static WORD32 ixheaacd_calc_max_spectralline(WORD32 *p_in_ibuffer, WORD32 n) {
83
715k
  WORD32 k, shiftp, itemp = 0;
84
716M
  for (k = 0; k < n; k++) {
85
716M
    if (ixheaac_abs32_sat(p_in_ibuffer[k]) > itemp)
86
2.98M
      itemp = ixheaac_abs32_sat(p_in_ibuffer[k]);
87
716M
  }
88
89
715k
  shiftp = ixheaac_norm32(itemp);
90
91
715k
  return (shiftp);
92
715k
}
93
94
715k
static void ixheaacd_normalize(WORD32 *buff, WORD32 shift, WORD len) {
95
715k
  WORD32 i;
96
97
716M
  for (i = 0; i < len; i++) {
98
716M
    buff[i] = buff[i] << shift;
99
716M
  }
100
715k
}
101
102
97.6k
static FLOAT32 ixheaacd_pow10(WORD32 input) {
103
97.6k
  FLOAT32 output = 1;
104
214k
  while (input > 0) {
105
116k
    output *= 10;
106
116k
    input--;
107
116k
  }
108
97.6k
  return (output);
109
97.6k
}
110
111
void ixheaacd_calc_pre_twid_dec(WORD32 *ptr_x, WORD32 *r_ptr, WORD32 *i_ptr,
112
                                WORD32 nlength, const WORD32 *cos_ptr,
113
1.13M
                                const WORD32 *sin_ptr) {
114
1.13M
  WORD32 i;
115
1.13M
  WORD32 *ptr_y;
116
117
1.13M
  ptr_y = &ptr_x[2 * nlength - 1];
118
119
180M
  for (i = 0; i < nlength; i++) {
120
179M
    *r_ptr++ = ((ixheaac_mult32(ixheaac_negate32_sat(*ptr_x), (*cos_ptr)) -
121
179M
                 ixheaac_mult32((*ptr_y), (*sin_ptr))));
122
179M
    *i_ptr++ = ((ixheaac_mult32((*ptr_y), (*cos_ptr++)) -
123
179M
                 ixheaac_mult32((*ptr_x), (*sin_ptr++))));
124
179M
    ptr_x += 2;
125
179M
    ptr_y -= 2;
126
179M
  }
127
1.13M
}
128
129
void ixheaacd_calc_post_twid_dec(WORD32 *xptr, WORD32 *r_ptr, WORD32 *i_ptr,
130
                                 WORD32 nlength, const WORD32 *cos_ptr,
131
                                 const WORD32 *sin_ptr
132
133
1.13M
                                 ) {
134
1.13M
  WORD32 i;
135
1.13M
  WORD32 *yptr;
136
137
1.13M
  yptr = &xptr[2 * nlength - 1];
138
139
180M
  for (i = 0; i < nlength; i++) {
140
179M
    *xptr = (-(ixheaac_mult32((r_ptr[i]), (*cos_ptr)) -
141
179M
               ixheaac_mult32((i_ptr[i]), (*sin_ptr))));
142
179M
    *yptr = (-(ixheaac_mult32((i_ptr[i]), (*cos_ptr++)) +
143
179M
               ixheaac_mult32((r_ptr[i]), (*sin_ptr++))));
144
179M
    xptr += 2;
145
179M
    yptr -= 2;
146
179M
  }
147
1.13M
}
148
149
static VOID ixheaacd_fft_based_imdct(WORD32 *data, WORD32 npoints, WORD32 *preshift,
150
1.13M
                                     WORD32 *tmp_data) {
151
1.13M
  WORD32 *data_r;
152
1.13M
  WORD32 *data_i;
153
1.13M
  WORD32 nlength = npoints >> 1;
154
1.13M
  const WORD32 *cos_ptr;
155
1.13M
  const WORD32 *sin_ptr;
156
157
1.13M
  data_r = tmp_data;
158
1.13M
  data_i = tmp_data + 512;
159
160
1.13M
  if (nlength == 512) {
161
220k
    cos_ptr = ixheaacd_pre_post_twid_cos_512;
162
220k
    sin_ptr = ixheaacd_pre_post_twid_sin_512;
163
917k
  } else if (nlength == 384) {
164
25.7k
    cos_ptr = ixheaacd_pre_post_twid_cos_384;
165
25.7k
    sin_ptr = ixheaacd_pre_post_twid_sin_384;
166
891k
  } else if (nlength == 64) {
167
838k
    cos_ptr = ixheaacd_pre_post_twid_cos_64;
168
838k
    sin_ptr = ixheaacd_pre_post_twid_sin_64;
169
838k
  } else if (nlength == 48) {
170
53.2k
    cos_ptr = ixheaacd_pre_post_twid_cos_48;
171
53.2k
    sin_ptr = ixheaacd_pre_post_twid_sin_48;
172
53.2k
  } else {
173
0
    cos_ptr = ixheaacd_pre_post_twid_cos_48;
174
0
    sin_ptr = ixheaacd_pre_post_twid_sin_48;
175
0
  }
176
177
1.13M
  (*ixheaacd_calc_pre_twid)(data, data_r, data_i, nlength, cos_ptr, sin_ptr);
178
1.13M
  ixheaacd_complex_fft(data_r, data_i, nlength, 1, preshift);
179
180
1.13M
  (*ixheaacd_calc_post_twid)(data, data_r, data_i, nlength, cos_ptr, sin_ptr);
181
1.13M
  return;
182
1.13M
}
183
184
#define N_LONG_LEN_MAX 1024
185
186
VOID ixheaacd_acelp_imdct(WORD32 *imdct_in, WORD32 npoints, WORD8 *qshift,
187
1.13M
                            WORD32 *tmp_data) {
188
1.13M
  WORD32 preshift = 0;
189
1.13M
  WORD32 i;
190
1.13M
  WORD32 k = (npoints / 2);
191
192
9.68M
  while (((k & 1) == 0) & (k != 1)) {
193
8.54M
    k = k >> 1;
194
8.54M
    preshift++;
195
8.54M
  }
196
197
1.13M
  if ((k != 1)) {
198
24.9M
    for (i = 0; i < (npoints / 2); i++) {
199
24.8M
      imdct_in[i] = (imdct_in[i] / 3) << 1;
200
24.8M
    }
201
78.9k
    preshift++;
202
78.9k
  }
203
204
1.13M
  ixheaacd_fft_based_imdct(imdct_in, npoints / 2, &preshift, tmp_data);
205
1.13M
  preshift += 2;
206
1.13M
  *qshift -= preshift;
207
1.13M
  return;
208
1.13M
}
209
210
IA_ERRORCODE ixheaacd_cal_fac_data(ia_usac_data_struct *usac_data, WORD32 i_ch,
211
                                   WORD32 n_long, WORD32 lfac,
212
97.6k
                                   WORD32 *fac_idata, WORD8 *q_fac) {
213
97.6k
  WORD32 gain_fac, scale, k, *i_aq, itemp = 0, *izir;
214
97.6k
  WORD32 int_aq[ORDER + 1] = {0};
215
97.6k
  WORD32 intzir[2 * LEN_FRAME] = {0};
216
97.6k
  WORD32 x_in[FAC_LENGTH] = {0};
217
97.6k
  FLOAT32 gain, ztemp, ftemp, pow10, rem10;
218
97.6k
  FLOAT32 qfac1;
219
97.6k
  WORD8 qshift1 = 0;
220
97.6k
  WORD8 qshift2 = 0;
221
97.6k
  WORD8 qshift3 = 0;
222
97.6k
  WORD32 preshift = 0;
223
224
97.6k
  FLOAT32 *last_lpc = usac_data->lpc_prev[i_ch];
225
97.6k
  FLOAT32 *acelp_in = usac_data->acelp_in[i_ch];
226
97.6k
  WORD32 *fac_data = usac_data->fac_data[i_ch];
227
97.6k
  WORD32 *ptr_scratch = &usac_data->scratch_buffer[0];
228
229
97.6k
  WORD32 quo = fac_data[0] / 28;
230
97.6k
  WORD32 rem = fac_data[0] % 28;
231
97.6k
  pow10 = ixheaacd_pow10(quo);
232
97.6k
  rem10 = (FLOAT32)ixheaacd_power_10_table[rem];
233
234
97.6k
  gain = pow10 * rem10;
235
97.6k
  scale = (WORD32)(ixheaac_norm32((WORD32)((ABS(gain) + 1))));
236
97.6k
  gain_fac = (WORD32)(gain * (FLOAT32)((WORD64)1 << scale));
237
97.6k
  scale += 4;
238
97.6k
  qfac1 = 1.0f / (gain);
239
240
97.6k
  if (acelp_in != NULL) {
241
97.6k
    izir = intzir;
242
97.6k
    ftemp = 0.0;
243
25.0M
    for (k = 0; k < n_long / 4; k++) {
244
24.9M
      ztemp = acelp_in[k] * (qfac1);
245
24.9M
      if (ABS(ztemp) > ftemp) ftemp = ABS(ztemp);
246
24.9M
    }
247
248
97.6k
    itemp = (WORD32)(ftemp);
249
97.6k
    qshift3 = ixheaac_norm32(itemp);
250
251
25.0M
    for (k = 0; k < n_long / 4; k++) {
252
24.9M
      izir[k] =
253
24.9M
          (WORD32)((acelp_in[k] * (qfac1)) * (FLOAT32)((WORD64)1 << qshift3));
254
24.9M
    }
255
97.6k
  } else
256
0
    izir = NULL;
257
258
97.6k
  if (last_lpc != NULL) {
259
97.6k
    ftemp = 0.0;
260
97.6k
    i_aq = int_aq;
261
1.75M
    for (k = 0; k < ORDER + 1; k++) {
262
1.65M
      if (ABS(last_lpc[k]) > ftemp) ftemp = ABS(last_lpc[k]);
263
1.65M
    }
264
265
97.6k
    itemp = (WORD32)(ftemp);
266
97.6k
    qshift2 = ixheaac_norm32(itemp);
267
268
1.75M
    for (k = 0; k < ORDER + 1; k++) {
269
1.65M
      i_aq[k] = (WORD32)(last_lpc[k] * (FLOAT32)((WORD64)1 << qshift2));
270
1.65M
    }
271
97.6k
  } else
272
0
    i_aq = NULL;
273
274
12.2M
  for (k = 0; k < lfac; k++) {
275
12.1M
    if (ixheaac_abs32_sat(fac_data[k + 1]) > itemp)
276
175k
      itemp = ixheaac_abs32_sat(fac_data[k + 1]);
277
12.1M
  }
278
279
97.6k
  qshift1 = ixheaac_norm32(itemp);
280
281
12.2M
  for (k = 0; k < lfac; k++) {
282
12.1M
    fac_data[k + 1] =
283
12.1M
        (WORD32)(fac_data[k + 1] * (FLOAT32)((WORD64)1 << qshift1));
284
12.1M
  }
285
286
6.15M
  for (k = 0; k < lfac / 2; k++) {
287
6.05M
    x_in[k] = fac_data[2 * k + 1];
288
6.05M
    x_in[lfac / 2 + k] = fac_data[lfac - 2 * k];
289
6.05M
  }
290
291
97.6k
  if (FAC_LENGTH < lfac) {
292
0
    if (usac_data->ec_flag == 0)
293
0
      return -1;
294
0
    else
295
0
      lfac = FAC_LENGTH;
296
0
  }
297
298
97.6k
  if ((n_long / 8) < lfac) {
299
123
    if (usac_data->ec_flag == 0)
300
123
      return -1;
301
0
    else
302
0
      lfac = (n_long / 8);
303
123
  }
304
305
97.4k
  if ((n_long / 8 + 1) > (2 * LEN_FRAME - lfac - 1)) {
306
0
    if (usac_data->ec_flag == 0)
307
0
      return -1;
308
0
    else
309
0
      lfac = (2 * LEN_FRAME) - (n_long / 8);
310
0
  }
311
312
97.4k
  if (lfac & (lfac - 1)) {
313
1.12k
    if ((lfac != 48) && (lfac != 96) && (lfac != 192) && (lfac != 384) && (lfac != 768)) {
314
0
      if (usac_data->ec_flag == 0)
315
0
        return -1;
316
0
      else
317
0
        lfac = 48;
318
0
    }
319
1.12k
  }
320
321
97.4k
  ixheaacd_fr_alias_cnx_fix(x_in, n_long / 4, lfac, i_aq, izir, fac_idata + 16, &qshift1, qshift2,
322
97.4k
                            qshift3, &preshift, ptr_scratch);
323
324
97.4k
  preshift += 4;
325
97.4k
  *q_fac = (qshift1 - preshift);
326
327
97.4k
  if (acelp_in != NULL) {
328
24.2M
    for (k = 0; k < 2 * lfac; k++) {
329
24.1M
      fac_idata[k] =
330
24.1M
          ixheaac_mul32_sh(fac_idata[k + 16], gain_fac, (WORD8)(scale));
331
24.1M
    }
332
97.4k
  }
333
97.4k
  return IA_NO_ERROR;
334
97.4k
}
335
336
static IA_ERRORCODE ixheaacd_fd_imdct_short(ia_usac_data_struct *usac_data,
337
                                            WORD32 i_ch, WORD32 *fac_data_out,
338
                                            offset_lengths *ixheaacd_drc_offset,
339
111k
                                            WORD8 fac_q) {
340
111k
  FLOAT32 qfac;
341
111k
  WORD32 overlap_data_buf[2 * N_LONG_LEN_MAX] = {0};
342
111k
  WORD32 *window_short, k, *window_short_prev_ptr;
343
111k
  WORD32 *overlap_data, *fp;
344
345
111k
  WORD32 *p_overlap_ibuffer = usac_data->overlap_data_ptr[i_ch];
346
111k
  WORD32 *p_in_ibuffer = usac_data->coef_fix[i_ch];
347
111k
  FLOAT32 *p_out_buffer = usac_data->time_sample_vector[i_ch];
348
111k
  WORD32 *p_out_ibuffer = usac_data->output_data_ptr[i_ch];
349
111k
  WORD32 *scratch_mem = usac_data->scratch_buffer;
350
111k
  WORD32 td_frame_prev = usac_data->td_frame_prev[i_ch];
351
111k
  WORD32 fac_apply = usac_data->fac_data_present[i_ch];
352
111k
  WORD8 shiftp, input_q, output_q, shift_olap = 14;
353
111k
  WORD32 max_shift;
354
355
111k
  WORD32 window_select = usac_data->window_shape[i_ch];
356
111k
  WORD32 window_select_prev = usac_data->window_shape_prev[i_ch];
357
111k
  ia_usac_lpd_decoder_handle st = usac_data->str_tddec[i_ch];
358
111k
  WORD32 err_code = 0;
359
360
111k
  if (usac_data->ec_flag) {
361
0
    td_frame_prev = usac_data->td_frame_prev_ec[i_ch];
362
111k
  } else {
363
111k
    if (ixheaacd_drc_offset->n_short & (ixheaacd_drc_offset->n_short - 1)) {
364
6.65k
      if ((ixheaacd_drc_offset->n_short != 48) && (ixheaacd_drc_offset->n_short != 96) &&
365
0
          (ixheaacd_drc_offset->n_short != 192) && (ixheaacd_drc_offset->n_short != 384) &&
366
0
          (ixheaacd_drc_offset->n_short != 768)) {
367
0
        return -1;
368
0
      }
369
6.65k
    }
370
111k
  }
371
372
111k
  max_shift = ixheaacd_calc_max_spectralline(p_in_ibuffer, ixheaacd_drc_offset->n_long);
373
111k
  ixheaacd_normalize(p_in_ibuffer, max_shift, ixheaacd_drc_offset->n_long);
374
111k
  shiftp = max_shift + 6;
375
111k
  input_q = shiftp;
376
377
111k
  memcpy(overlap_data_buf, p_overlap_ibuffer,
378
111k
         sizeof(WORD32) * ixheaacd_drc_offset->n_long);
379
111k
  overlap_data = overlap_data_buf;
380
381
111k
  fp = overlap_data + ixheaacd_drc_offset->n_flat_ls;
382
383
1.00M
  for (k = 0; k < 8; k++) {
384
891k
    shiftp = input_q;
385
891k
    ixheaacd_acelp_imdct(
386
891k
        p_in_ibuffer + (k * ixheaacd_drc_offset->n_short),
387
891k
        2 * ixheaacd_drc_offset->n_short, &shiftp, scratch_mem);
388
891k
  }
389
390
111k
  max_shift =
391
111k
      ixheaacd_calc_max_spectralline(p_in_ibuffer, ixheaacd_drc_offset->n_long);
392
111k
  ixheaacd_normalize(p_in_ibuffer, max_shift - 1, ixheaacd_drc_offset->n_long);
393
111k
  shiftp += max_shift - 1;
394
395
111k
  if ((shiftp - shift_olap) > 31) {
396
46.2k
    shiftp = 31 + shift_olap;
397
46.2k
  }
398
111k
  err_code = ixheaacd_calc_window(&window_short, ixheaacd_drc_offset->n_short,
399
111k
                                  window_select, usac_data->ec_flag);
400
111k
  if (err_code == -1) return err_code;
401
111k
  err_code = ixheaacd_calc_window(&window_short_prev_ptr, ixheaacd_drc_offset->n_trans_ls,
402
111k
                                  window_select_prev, usac_data->ec_flag);
403
111k
  if (err_code == -1) return err_code;
404
405
111k
  if (fac_apply)
406
34.9k
    ixheaacd_windowing_short1(p_in_ibuffer + ixheaacd_drc_offset->n_short / 2,
407
34.9k
                              window_short_prev_ptr, fp, ixheaacd_drc_offset,
408
34.9k
                              shiftp, shift_olap);
409
410
76.5k
  else
411
76.5k
    ixheaacd_windowing_short2(p_in_ibuffer + ixheaacd_drc_offset->n_short / 2,
412
76.5k
                              window_short_prev_ptr, fp, ixheaacd_drc_offset,
413
76.5k
                              shiftp, shift_olap);
414
415
111k
  output_q = ixheaacd_windowing_short3(
416
111k
      p_in_ibuffer, window_short + ixheaacd_drc_offset->n_short - 1,
417
111k
      fp + ixheaacd_drc_offset->n_short, ixheaacd_drc_offset->n_short, shiftp,
418
111k
      shift_olap);
419
111k
  p_in_ibuffer += ixheaacd_drc_offset->n_short;
420
111k
  fp += ixheaacd_drc_offset->n_short;
421
111k
  window_short_prev_ptr = window_short;
422
423
780k
  for (k = 1; k < 7; k++) {
424
668k
    output_q = ixheaacd_windowing_short4(
425
668k
        p_in_ibuffer, window_short_prev_ptr, fp,
426
668k
        window_short_prev_ptr + ixheaacd_drc_offset->n_short - 1,
427
668k
        ixheaacd_drc_offset->n_short, 1, shiftp, shift_olap, output_q);
428
668k
    p_in_ibuffer += ixheaacd_drc_offset->n_short;
429
668k
    fp += ixheaacd_drc_offset->n_short;
430
668k
    window_short_prev_ptr = window_short;
431
668k
  }
432
433
111k
  output_q = ixheaacd_windowing_short4(
434
111k
      p_in_ibuffer, window_short_prev_ptr, fp,
435
111k
      window_short_prev_ptr + ixheaacd_drc_offset->n_short - 1,
436
111k
      ixheaacd_drc_offset->n_short, 0, shiftp, shift_olap, output_q);
437
111k
  p_in_ibuffer += ixheaacd_drc_offset->n_short;
438
111k
  fp += ixheaacd_drc_offset->n_short;
439
440
111k
  if (fac_apply) {
441
34.9k
    ixheaacd_combine_fac(overlap_data + ixheaacd_drc_offset->n_flat_ls +
442
34.9k
                             ixheaacd_drc_offset->lfac,
443
34.9k
                         fac_data_out,
444
34.9k
                         overlap_data + ixheaacd_drc_offset->n_flat_ls +
445
34.9k
                             ixheaacd_drc_offset->lfac,
446
34.9k
                         2 * ixheaacd_drc_offset->lfac, output_q, fac_q);
447
34.9k
  }
448
111k
  memset(overlap_data + 2 * ixheaacd_drc_offset->n_long -
449
111k
             ixheaacd_drc_offset->n_flat_ls,
450
111k
         0, sizeof(WORD32) * ixheaacd_drc_offset->n_flat_ls);
451
111k
  ixheaacd_scale_down(overlap_data, overlap_data,
452
111k
                      ixheaacd_drc_offset->n_flat_ls, shift_olap, output_q);
453
454
111k
  ixheaacd_scale_down(p_overlap_ibuffer,
455
111k
                      overlap_data + ixheaacd_drc_offset->n_long,
456
111k
                      ixheaacd_drc_offset->n_long, output_q, shift_olap);
457
111k
  ixheaacd_scale_down(p_out_ibuffer, overlap_data, ixheaacd_drc_offset->n_long,
458
111k
                      output_q, 15);
459
460
111k
  if (td_frame_prev) {
461
16.4k
    qfac = 1.0f / (FLOAT32)(1 << 15);
462
463
15.4M
    for (k = 0; k < ixheaacd_drc_offset->n_long; k++) {
464
15.4M
      p_out_buffer[k] = ((FLOAT32)p_out_ibuffer[k]) * qfac;
465
15.4M
    }
466
16.4k
    err_code = ixheaacd_lpd_bpf_fix(usac_data, 1, p_out_buffer, st);
467
16.4k
    if (err_code != 0) return err_code;
468
469
15.4M
    for (k = 0; k < ixheaacd_drc_offset->n_long; k++) {
470
15.4M
      p_out_ibuffer[k] = (WORD32)(p_out_buffer[k] * (1 << 15));
471
15.4M
    }
472
16.4k
  }
473
474
111k
  return 0;
475
111k
}
476
477
static IA_ERRORCODE ixheaacd_fd_imdct_long(ia_usac_data_struct *usac_data,
478
                                           WORD32 i_ch, WORD32 *fac_idata,
479
                                           offset_lengths *ixheaacd_drc_offset,
480
246k
                                           WORD8 fac_q) {
481
246k
  FLOAT32 qfac;
482
246k
  WORD32 *window_long_prev = NULL, k, i, *window_short_prev_ptr = NULL;
483
484
246k
  WORD32 *p_in_ibuffer = usac_data->coef_fix[i_ch];
485
246k
  WORD32 *p_overlap_ibuffer = usac_data->overlap_data_ptr[i_ch];
486
246k
  WORD32 *p_out_ibuffer = usac_data->output_data_ptr[i_ch];
487
246k
  FLOAT32 *p_out_buffer = usac_data->time_sample_vector[i_ch];
488
246k
  WORD32 *scratch_mem = usac_data->scratch_buffer;
489
246k
  WORD32 n_long = usac_data->ccfl;
490
246k
  WORD32 td_frame_prev = usac_data->td_frame_prev[i_ch];
491
246k
  WORD32 fac_apply = usac_data->fac_data_present[i_ch];
492
246k
  WORD8 shiftp, output_q = 0, shift_olap = 14;
493
246k
  WORD32 max_shift;
494
495
246k
  WORD32 window_sequence = usac_data->window_sequence[i_ch];
496
246k
  WORD32 window_select_prev = usac_data->window_shape_prev[i_ch];
497
246k
  ia_usac_lpd_decoder_handle st = usac_data->str_tddec[i_ch];
498
499
246k
  WORD32 err_code = 0;
500
246k
  if (usac_data->ec_flag) {
501
0
    td_frame_prev = usac_data->td_frame_prev_ec[i_ch];
502
246k
  } else {
503
246k
    if (ixheaacd_drc_offset->n_long & (ixheaacd_drc_offset->n_long - 1)) {
504
25.7k
      if ((ixheaacd_drc_offset->n_long != 48) && (ixheaacd_drc_offset->n_long != 96) &&
505
25.7k
          (ixheaacd_drc_offset->n_long != 192) && (ixheaacd_drc_offset->n_long != 384) &&
506
25.7k
          (ixheaacd_drc_offset->n_long != 768)) {
507
0
        return -1;
508
0
      }
509
25.7k
    }
510
246k
  }
511
512
246k
  max_shift =
513
246k
      ixheaacd_calc_max_spectralline(p_in_ibuffer, ixheaacd_drc_offset->n_long);
514
246k
  ixheaacd_normalize(p_in_ibuffer, max_shift, ixheaacd_drc_offset->n_long);
515
246k
  shiftp = max_shift + 6;
516
517
246k
  ixheaacd_acelp_imdct(p_in_ibuffer, 2 * ixheaacd_drc_offset->n_long,
518
246k
                                  &shiftp, scratch_mem);
519
520
246k
  max_shift =
521
246k
      ixheaacd_calc_max_spectralline(p_in_ibuffer, ixheaacd_drc_offset->n_long);
522
246k
  ixheaacd_normalize(p_in_ibuffer, max_shift - 1, ixheaacd_drc_offset->n_long);
523
246k
  shiftp += max_shift - 1;
524
246k
  if ((shiftp - shift_olap) > 31) {
525
203k
    shiftp = 31 + shift_olap;
526
203k
  }
527
528
246k
  switch (window_sequence) {
529
169k
    case ONLY_LONG_SEQUENCE:
530
173k
    case LONG_START_SEQUENCE:
531
173k
      err_code = ixheaacd_calc_window(
532
173k
          &window_long_prev, ixheaacd_drc_offset->n_long, window_select_prev, usac_data->ec_flag);
533
173k
      if (err_code == -1) return err_code;
534
173k
      output_q = ixheaacd_windowing_long1(
535
173k
          p_in_ibuffer + n_long / 2, p_overlap_ibuffer, window_long_prev,
536
173k
          window_long_prev + ixheaacd_drc_offset->n_long - 1, p_out_ibuffer,
537
173k
          ixheaacd_drc_offset->n_long, shiftp, shift_olap);
538
173k
      break;
539
540
55.5k
    case STOP_START_SEQUENCE:
541
72.6k
    case LONG_STOP_SEQUENCE:
542
72.6k
      err_code = ixheaacd_calc_window(&window_short_prev_ptr,
543
72.6k
                                      ixheaacd_drc_offset->n_trans_ls,
544
72.6k
                                      window_select_prev, usac_data->ec_flag);
545
72.6k
      if (err_code == -1) return err_code;
546
72.6k
      if (fac_apply) {
547
35.4k
        output_q = ixheaacd_windowing_long2(
548
35.4k
            p_in_ibuffer + n_long / 2, window_short_prev_ptr, fac_idata,
549
35.4k
            p_overlap_ibuffer, p_out_ibuffer, ixheaacd_drc_offset, shiftp,
550
35.4k
            shift_olap, fac_q);
551
37.2k
      } else {
552
37.2k
        output_q = ixheaacd_windowing_long3(
553
37.2k
            p_in_ibuffer + n_long / 2, window_short_prev_ptr, p_overlap_ibuffer,
554
37.2k
            p_out_ibuffer,
555
37.2k
            window_short_prev_ptr + ixheaacd_drc_offset->n_trans_ls - 1,
556
37.2k
            ixheaacd_drc_offset, shiftp, shift_olap);
557
37.2k
      }
558
72.6k
      break;
559
246k
  }
560
561
123M
  for (i = 0; i < ixheaacd_drc_offset->n_long / 2; i++) {
562
122M
    if (shiftp > shift_olap) {
563
108M
      p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 + i] =
564
108M
        ixheaac_negate32_sat(p_in_ibuffer[i]) >> (shiftp - shift_olap);
565
108M
      p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 - i - 1] =
566
108M
        ixheaac_negate32_sat(p_in_ibuffer[i]) >> (shiftp - shift_olap);
567
108M
    }
568
14.0M
    else {
569
14.0M
      p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 + i] =
570
14.0M
        ixheaac_negate32_sat(p_in_ibuffer[i]) >> (shift_olap - shiftp);
571
14.0M
      p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 - i - 1] =
572
14.0M
        ixheaac_negate32_sat(p_in_ibuffer[i]) >> (shift_olap - shiftp);
573
14.0M
    }
574
122M
  }
575
576
246k
  ixheaacd_scale_down_adj(p_out_ibuffer, p_out_ibuffer,
577
246k
                          ixheaacd_drc_offset->n_long, output_q, 15);
578
579
246k
  if (td_frame_prev) {
580
24.9k
    qfac = 1.0f / (FLOAT32)(1 << 15);
581
582
24.0M
    for (k = 0; k < ixheaacd_drc_offset->n_long; k++) {
583
23.9M
      p_out_buffer[k] = ((FLOAT32)p_out_ibuffer[k]) * qfac;
584
23.9M
    }
585
24.9k
    err_code = ixheaacd_lpd_bpf_fix(usac_data, 0, p_out_buffer, st);
586
24.9k
    if (err_code != 0) return err_code;
587
588
23.9M
    for (k = 0; k < ixheaacd_drc_offset->n_long; k++) {
589
23.9M
      p_out_ibuffer[k] = (WORD32)(p_out_buffer[k] * (1 << 15));
590
23.9M
    }
591
24.9k
  }
592
593
246k
  return 0;
594
246k
}
595
596
357k
WORD32 ixheaacd_fd_frm_dec(ia_usac_data_struct *usac_data, WORD32 i_ch) {
597
357k
  WORD32 fac_idata[2 * FAC_LENGTH + 16];
598
357k
  offset_lengths ixheaacd_drc_offset;
599
357k
  WORD8 fac_q = 0;
600
357k
  IA_ERRORCODE err = IA_NO_ERROR;
601
357k
  WORD32 td_frame_prev, fac_apply, window_sequence;
602
357k
  if (usac_data->ec_flag) {
603
0
    usac_data->str_error_concealment[i_ch].pstr_ec_scratch =
604
0
        (ia_ec_scratch_str *)&usac_data->str_error_concealment[i_ch].str_ec_scratch;
605
0
    usac_data->core_mode = 0;
606
0
    ixheaacd_usac_apply_ec(usac_data, &ixheaacd_samp_rate_info[0], i_ch);
607
0
  }
608
357k
  if (usac_data->ec_flag) {
609
0
    td_frame_prev = usac_data->td_frame_prev_ec[i_ch];
610
357k
  } else {
611
357k
    td_frame_prev = usac_data->td_frame_prev[i_ch];
612
357k
  }
613
357k
  fac_apply = usac_data->fac_data_present[i_ch];
614
357k
  window_sequence = usac_data->window_sequence[i_ch];
615
357k
  ixheaacd_drc_offset.n_long = usac_data->ccfl;
616
357k
  ixheaacd_drc_offset.n_short = ixheaacd_drc_offset.n_long >> 3;
617
618
357k
  memset(fac_idata, 0, sizeof(fac_idata));
619
620
357k
  if (td_frame_prev) {
621
41.4k
    if (window_sequence == EIGHT_SHORT_SEQUENCE) {
622
16.4k
      ixheaacd_drc_offset.lfac = ixheaacd_drc_offset.n_long >> 4;
623
24.9k
    } else {
624
24.9k
      ixheaacd_drc_offset.lfac = ixheaacd_drc_offset.n_long >> 3;
625
24.9k
    }
626
41.4k
    ixheaacd_drc_offset.n_flat_ls =
627
41.4k
        (ixheaacd_drc_offset.n_long - (ixheaacd_drc_offset.lfac) * 2) >> 1;
628
629
41.4k
    ixheaacd_drc_offset.n_trans_ls = (ixheaacd_drc_offset.lfac) << 1;
630
316k
  } else {
631
316k
    ixheaacd_drc_offset.lfac = FAC_LENGTH;
632
316k
    ixheaacd_drc_offset.n_flat_ls =
633
316k
        (ixheaacd_drc_offset.n_long - ixheaacd_drc_offset.n_short) >> 1;
634
316k
    ixheaacd_drc_offset.n_trans_ls = ixheaacd_drc_offset.n_short;
635
316k
  }
636
637
357k
  if (fac_apply && usac_data->frame_ok == 1) {
638
97.6k
    err = ixheaacd_cal_fac_data(usac_data, i_ch, ixheaacd_drc_offset.n_long,
639
97.6k
                                ixheaacd_drc_offset.lfac, fac_idata, &fac_q);
640
97.6k
    if (err) return err;
641
97.6k
  }
642
643
357k
  if (window_sequence != EIGHT_SHORT_SEQUENCE) {
644
246k
    err = ixheaacd_fd_imdct_long(usac_data, i_ch, fac_idata,
645
246k
                                 &ixheaacd_drc_offset, fac_q);
646
246k
    if (err) return err;
647
246k
  } else {
648
111k
    err = ixheaacd_fd_imdct_short(usac_data, i_ch, fac_idata,
649
111k
                                  &ixheaacd_drc_offset, fac_q);
650
111k
    if (err) return err;
651
111k
  }
652
653
357k
  return err;
654
357k
}