Coverage Report

Created: 2025-07-18 06:38

/src/libxaac/decoder/ixheaacd_lpp_tran.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#include <stdio.h>
21
#include <string.h>
22
#include "ixheaacd_sbr_common.h"
23
#include "ixheaac_type_def.h"
24
25
#include "ixheaac_constants.h"
26
#include "ixheaac_basic_ops32.h"
27
#include "ixheaac_basic_ops16.h"
28
#include "ixheaac_basic_ops40.h"
29
#include "ixheaac_basic_ops.h"
30
31
#include "ixheaac_basic_op.h"
32
#include "ixheaacd_intrinsics.h"
33
#include "ixheaacd_common_rom.h"
34
#include "ixheaacd_basic_funcs.h"
35
#include "ixheaacd_sbr_scale.h"
36
#include "ixheaacd_sbrdecsettings.h"
37
#include "ixheaacd_lpp_tran.h"
38
#include "ixheaacd_bitbuffer.h"
39
#include "ixheaacd_defines.h"
40
41
#include "ixheaacd_pns.h"
42
43
#include "ixheaacd_aac_rom.h"
44
#include "ixheaacd_pulsedata.h"
45
46
#include "ixheaacd_drc_data_struct.h"
47
48
#include "ixheaacd_lt_predict.h"
49
#include "ixheaacd_cnst.h"
50
#include "ixheaacd_ec_defines.h"
51
#include "ixheaacd_ec_struct_def.h"
52
#include "ixheaacd_channelinfo.h"
53
#include "ixheaacd_drc_dec.h"
54
55
#include "ixheaacd_sbrdecoder.h"
56
#include "ixheaacd_sbr_scale.h"
57
#include "ixheaacd_lpp_tran.h"
58
#include "ixheaacd_env_extr_part.h"
59
#include "ixheaacd_sbr_rom.h"
60
#include "ixheaacd_hybrid.h"
61
#include "ixheaacd_ps_dec.h"
62
#include "ixheaacd_env_extr.h"
63
64
#include "ixheaacd_intrinsics.h"
65
#include "ixheaacd_basic_funcs.h"
66
67
#include "ixheaacd_qmf_dec.h"
68
#include "ixheaacd_env_calc.h"
69
#include "ixheaac_sbr_const.h"
70
71
#include "ixheaacd_pvc_dec.h"
72
#include "ixheaacd_sbr_dec.h"
73
#include "ixheaacd_function_selector.h"
74
75
#include "ixheaacd_audioobjtypes.h"
76
77
35.7M
#define LPC_SCALE_FACTOR 2
78
79
0
#define AUTO_CORR_LEN_1024 38
80
0
#define AUTO_CORR_LEN_960  36
81
82
#define SHIFT 5
83
84
static PLATFORM_INLINE WORD32 ixheaacd_mac32x16hin32(WORD32 a, WORD32 b,
85
72.3M
                                                     WORD32 c) {
86
72.3M
  WORD32 result;
87
88
72.3M
  result = a + ixheaac_mult32x16hin32(b, c);
89
90
72.3M
  return (result);
91
72.3M
}
92
93
static PLATFORM_INLINE WORD32 ixheaacd_macn32x16hin32(WORD32 a, WORD32 b,
94
18.3M
                                                      WORD32 c) {
95
18.3M
  WORD32 result;
96
97
18.3M
  result = a - ixheaac_mult32x16hin32(b, c);
98
99
18.3M
  return (result);
100
18.3M
}
101
102
VOID ixheaacd_filterstep3(WORD16 a0r, WORD16 a0i, WORD16 a1r, WORD16 a1i,
103
                          WORD32 start_indx, WORD32 stop_idx, WORD32 low_band,
104
402k
                          WORD32 high_band, WORD32 *qmf_buffer) {
105
402k
  WORD32 i;
106
402k
  WORD32 prev1r, prev1i;
107
402k
  WORD32 prev2r, prev2i;
108
402k
  WORD16 coef1r = (a0r);
109
402k
  WORD16 coef1i = (a0i);
110
402k
  WORD16 coef2r = (a1r);
111
402k
  WORD16 coef2i = (a1i);
112
402k
  WORD32 *p_src, *p_dst;
113
402k
  WORD32 qmf_real, qmf_imag;
114
115
402k
  WORD32 curr, curi;
116
402k
  p_src = qmf_buffer + low_band + ((start_indx) << 7);
117
402k
  prev2r = *p_src;
118
402k
  p_src += 64;
119
120
402k
  prev2i = *p_src;
121
402k
  p_src += 64;
122
123
402k
  prev1r = *p_src;
124
402k
  p_src += 64;
125
126
402k
  prev1i = *p_src;
127
402k
  p_src += 64;
128
129
402k
  p_dst = qmf_buffer + high_band + ((start_indx + 2) << 7);
130
131
6.70M
  for (i = stop_idx - start_indx; i != 0; i--) {
132
6.29M
    WORD32 accu;
133
134
6.29M
    curr = *p_src;
135
6.29M
    p_src += 64;
136
137
6.29M
    curi = *p_src;
138
6.29M
    p_src += 64;
139
140
6.29M
    qmf_real = (curr >> LPC_SCALE_FACTOR);
141
6.29M
    qmf_imag = (curi >> LPC_SCALE_FACTOR);
142
143
6.29M
    accu = ixheaac_sub32(
144
6.29M
        ixheaac_add32(ixheaac_sub32(ixheaac_mult32x16in32(prev1r, coef1r),
145
6.29M
                                      ixheaac_mult32x16in32(prev1i, coef1i)),
146
6.29M
                       ixheaac_mult32x16in32(prev2r, coef2r)),
147
6.29M
        ixheaac_mult32x16in32(prev2i, coef2i));
148
149
6.29M
    *p_dst = ixheaac_add32(qmf_real, (accu << 1));
150
6.29M
    p_dst += 64;
151
152
6.29M
    accu = ixheaac_add32(
153
6.29M
        ixheaac_add32_sat(
154
6.29M
            ixheaac_add32_sat(ixheaac_mult32x16in32(prev1r, coef1i),
155
6.29M
                               ixheaac_mult32x16in32(prev1i, coef1r)),
156
6.29M
            ixheaac_mult32x16in32(prev2r, coef2i)),
157
6.29M
        ixheaac_mult32x16in32(prev2i, coef2r));
158
159
6.29M
    *p_dst = ixheaac_add32(qmf_imag, (accu << 1));
160
6.29M
    p_dst += 64;
161
162
6.29M
    prev2r = prev1r;
163
6.29M
    prev1r = curr;
164
6.29M
    prev2i = prev1i;
165
6.29M
    prev1i = curi;
166
6.29M
  }
167
402k
}
168
169
VOID ixheaacd_covariance_matrix_calc_dec_960(
170
    WORD32 *sub_sign_xlow, ia_lpp_trans_cov_matrix *cov_matrix,
171
0
    WORD32 count, WORD32 len) {
172
0
  WORD32 j, k;
173
0
  WORD32 ixheaacd_drc_offset = 2;
174
0
  WORD32 factor;
175
0
  WORD32 max_val, q_factor;
176
0
  WORD32 temp1, temp2, temp3, temp4;
177
0
  WORD32 *temp_buf_ptr = sub_sign_xlow;
178
179
0
  temp3 = 0;
180
0
  for (k = count; k > 0; k--) {
181
0
    WORD32 t_phi_01 = 0, t_phi_02 = 0, t_phi_11 = 0;
182
0
    WORD32 t_phi_12 = 0, t_phi_22 = 0;
183
184
0
    factor = -3;
185
0
    j = ixheaacd_drc_offset;
186
0
    sub_sign_xlow = temp_buf_ptr;
187
188
0
    temp1 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
189
0
    sub_sign_xlow += 64;
190
191
0
    temp2 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
192
0
    sub_sign_xlow += 64;
193
194
0
    for (; (j = j + 3) <= ixheaacd_drc_offset + len;) {
195
0
      temp3 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
196
0
      sub_sign_xlow += 64;
197
198
0
      t_phi_01 += ixheaac_mult32x16hin32(temp3, temp2);
199
0
      t_phi_02 += ixheaac_mult32x16hin32(temp3, temp1);
200
0
      t_phi_11 += ixheaac_mult32x16hin32(temp2, temp2);
201
202
0
      temp1 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
203
0
      sub_sign_xlow += 64;
204
205
0
      t_phi_01 += ixheaac_mult32x16hin32(temp1, temp3);
206
0
      t_phi_02 += ixheaac_mult32x16hin32(temp1, temp2);
207
0
      t_phi_11 += ixheaac_mult32x16hin32(temp3, temp3);
208
209
0
      temp2 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
210
0
      sub_sign_xlow += 64;
211
212
0
      t_phi_01 += ixheaac_mult32x16hin32(temp2, temp1);
213
0
      t_phi_02 += ixheaac_mult32x16hin32(temp2, temp3);
214
0
      t_phi_11 += ixheaac_mult32x16hin32(temp1, temp1);
215
0
    }
216
217
0
    if (AUTO_CORR_LEN_1024 == len) {
218
0
      temp3 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
219
0
      sub_sign_xlow += 64;
220
221
0
      t_phi_01 += ixheaac_mult32x16hin32(temp3, temp2);
222
0
      t_phi_02 += ixheaac_mult32x16hin32(temp3, temp1);
223
0
      t_phi_11 += ixheaac_mult32x16hin32(temp2, temp2);
224
225
0
      temp1 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
226
0
      sub_sign_xlow += 64;
227
228
0
      t_phi_01 += ixheaac_mult32x16hin32(temp1, temp3);
229
0
      t_phi_02 += ixheaac_mult32x16hin32(temp1, temp2);
230
0
      t_phi_11 += ixheaac_mult32x16hin32(temp3, temp3);
231
0
    }
232
233
0
    temp2 = ixheaac_shl32_dir(*temp_buf_ptr, factor);
234
0
    temp4 = ixheaac_shl32_dir(*(temp_buf_ptr + 64), factor);
235
236
0
    if (AUTO_CORR_LEN_960 == len) {
237
0
      temp3 = ixheaac_shl32_dir(sub_sign_xlow[-128], factor);
238
0
      temp1 = ixheaac_shl32_dir(sub_sign_xlow[-64], factor);
239
0
    }
240
241
0
    t_phi_12 = (t_phi_01 - ixheaac_mult32x16hin32(temp1, temp3) +
242
0
        ixheaac_mult32x16hin32(temp4, temp2));
243
244
0
    t_phi_22 = (t_phi_11 - ixheaac_mult32x16hin32(temp3, temp3) +
245
0
        ixheaac_mult32x16hin32(temp2, temp2));
246
247
0
    max_val = ixheaac_abs32_nrm(t_phi_01);
248
0
    max_val = max_val | ixheaac_abs32_nrm(t_phi_02);
249
0
    max_val = max_val | ixheaac_abs32_nrm(t_phi_12);
250
0
    max_val = max_val | (t_phi_11);
251
0
    max_val = max_val | (t_phi_22);
252
253
0
    q_factor = ixheaac_pnorm32(max_val);
254
255
0
    cov_matrix->phi_11 = (t_phi_11 << q_factor);
256
0
    cov_matrix->phi_22 = (t_phi_22 << q_factor);
257
0
    cov_matrix->phi_01 = (t_phi_01 << q_factor);
258
0
    cov_matrix->phi_02 = (t_phi_02 << q_factor);
259
0
    cov_matrix->phi_12 = (t_phi_12 << q_factor);
260
261
0
    cov_matrix->d = ixheaac_sub32_sat(
262
0
        ixheaac_mult32(cov_matrix->phi_22, cov_matrix->phi_11),
263
0
        ixheaac_mult32(cov_matrix->phi_12, cov_matrix->phi_12));
264
265
0
    cov_matrix++;
266
0
    temp_buf_ptr++;
267
0
  }
268
0
  return;
269
0
}
270
271
VOID ixheaacd_covariance_matrix_calc_dec(
272
    WORD32 *sub_sign_xlow, ia_lpp_trans_cov_matrix *cov_matrix,
273
0
    WORD32 count, WORD32 len) {
274
0
  WORD32 j, k;
275
0
  WORD32 ixheaacd_drc_offset = 2;
276
0
  WORD32 factor;
277
0
  WORD32 max_val, q_factor;
278
0
  WORD32 temp1, temp2, temp3, temp4;
279
0
  WORD32 *temp_buf_ptr = sub_sign_xlow;
280
281
0
  for (k = count; k > 0; k--) {
282
0
    WORD32 t_phi_01 = 0, t_phi_02 = 0, t_phi_11 = 0;
283
0
    WORD32 t_phi_12 = 0, t_phi_22 = 0;
284
285
0
    factor = -3;
286
0
    j = ixheaacd_drc_offset;
287
0
    sub_sign_xlow = temp_buf_ptr;
288
289
0
    temp1 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
290
0
    sub_sign_xlow += 64;
291
292
0
    temp2 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
293
0
    sub_sign_xlow += 64;
294
295
0
    for (; (j = j + 3) <= ixheaacd_drc_offset + len;) {
296
0
      temp3 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
297
0
      sub_sign_xlow += 64;
298
299
0
      t_phi_01 += ixheaac_mult32x16hin32(temp3, temp2);
300
0
      t_phi_02 += ixheaac_mult32x16hin32(temp3, temp1);
301
0
      t_phi_11 += ixheaac_mult32x16hin32(temp2, temp2);
302
303
0
      temp1 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
304
0
      sub_sign_xlow += 64;
305
306
0
      t_phi_01 += ixheaac_mult32x16hin32(temp1, temp3);
307
0
      t_phi_02 += ixheaac_mult32x16hin32(temp1, temp2);
308
0
      t_phi_11 += ixheaac_mult32x16hin32(temp3, temp3);
309
310
0
      temp2 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
311
0
      sub_sign_xlow += 64;
312
313
0
      t_phi_01 += ixheaac_mult32x16hin32(temp2, temp1);
314
0
      t_phi_02 += ixheaac_mult32x16hin32(temp2, temp3);
315
0
      t_phi_11 += ixheaac_mult32x16hin32(temp1, temp1);
316
0
    }
317
318
0
    if (AUTO_CORR_LEN_960 != len) {
319
0
      temp3 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
320
0
      sub_sign_xlow += 64;
321
322
0
      t_phi_01 += ixheaac_mult32x16hin32(temp3, temp2);
323
0
      t_phi_02 += ixheaac_mult32x16hin32(temp3, temp1);
324
0
      t_phi_11 += ixheaac_mult32x16hin32(temp2, temp2);
325
326
0
      temp1 = ixheaac_shl32_dir(*sub_sign_xlow, factor);
327
0
      sub_sign_xlow += 64;
328
329
0
      t_phi_01 += ixheaac_mult32x16hin32(temp1, temp3);
330
0
      t_phi_02 += ixheaac_mult32x16hin32(temp1, temp2);
331
0
      t_phi_11 += ixheaac_mult32x16hin32(temp3, temp3);
332
0
    }
333
0
    if (AUTO_CORR_LEN_960 == len) {
334
0
      temp3 = ixheaac_shl32_dir(sub_sign_xlow[-128], factor);
335
336
0
      temp3 = ixheaac_shl32_dir(sub_sign_xlow[-64], factor);
337
338
0
    }
339
340
0
    temp2 = ixheaac_shl32_dir(*temp_buf_ptr, factor);
341
0
    temp4 = ixheaac_shl32_dir(*(temp_buf_ptr + 64), factor);
342
343
0
    t_phi_12 = (t_phi_01 - ixheaac_mult32x16hin32(temp1, temp3) +
344
0
                ixheaac_mult32x16hin32(temp4, temp2));
345
346
0
    t_phi_22 = (t_phi_11 - ixheaac_mult32x16hin32(temp3, temp3) +
347
0
                ixheaac_mult32x16hin32(temp2, temp2));
348
349
0
    max_val = ixheaac_abs32_nrm(t_phi_01);
350
0
    max_val = max_val | ixheaac_abs32_nrm(t_phi_02);
351
0
    max_val = max_val | ixheaac_abs32_nrm(t_phi_12);
352
0
    max_val = max_val | (t_phi_11);
353
0
    max_val = max_val | (t_phi_22);
354
355
0
    q_factor = ixheaac_pnorm32(max_val);
356
357
0
    cov_matrix->phi_11 = (t_phi_11 << q_factor);
358
0
    cov_matrix->phi_22 = (t_phi_22 << q_factor);
359
0
    cov_matrix->phi_01 = (t_phi_01 << q_factor);
360
0
    cov_matrix->phi_02 = (t_phi_02 << q_factor);
361
0
    cov_matrix->phi_12 = (t_phi_12 << q_factor);
362
363
0
    cov_matrix->d = ixheaac_sub32_sat(
364
0
        ixheaac_mult32(cov_matrix->phi_22, cov_matrix->phi_11),
365
0
        ixheaac_mult32(cov_matrix->phi_12, cov_matrix->phi_12));
366
367
0
    cov_matrix++;
368
0
    temp_buf_ptr++;
369
0
  }
370
371
0
  return;
372
0
}
373
374
VOID ixheaacd_covariance_matrix_calc_2_dec(
375
    ia_lpp_trans_cov_matrix *cov_matrix,
376
377
53.9k
    WORD32 *real_buffer, WORD32 num_bands, WORD16 slots) {
378
53.9k
  WORD32 k;
379
53.9k
  WORD32 *img_buffer;
380
53.9k
  WORD32 *ptr_real = real_buffer;
381
53.9k
  ia_lpp_trans_cov_matrix *pac_arr = cov_matrix;
382
383
627k
  for (k = 0; k < num_bands; k++) {
384
573k
    WORD32 t_phi_11 = 0, t_phi_01 = 0, t_phi_01_i = 0;
385
573k
    WORD32 prev_real, prev_imag, curr_real, curr_imag;
386
387
573k
    real_buffer = ptr_real;
388
573k
    img_buffer = real_buffer + 64;
389
573k
    cov_matrix = pac_arr;
390
391
573k
    prev_real = real_buffer[-128];
392
573k
    prev_imag = img_buffer[-128];
393
394
573k
    curr_real = real_buffer[0];
395
573k
    curr_imag = img_buffer[0];
396
397
573k
    curr_real = ixheaac_shr32(curr_real, 3);
398
573k
    curr_imag = ixheaac_shr32(curr_imag, 3);
399
573k
    prev_real = ixheaac_shr32(prev_real, 3);
400
573k
    prev_imag = ixheaac_shr32(prev_imag, 3);
401
402
573k
    t_phi_01 = ixheaac_mult32x16hin32(curr_real, prev_real);
403
573k
    t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_imag, prev_imag);
404
405
573k
    t_phi_01_i = ixheaac_mult32x16hin32(curr_imag, prev_real);
406
573k
    t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i, curr_real, prev_imag);
407
408
573k
    t_phi_11 = ixheaac_mult32x16hin32(prev_real, prev_real);
409
573k
    t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_imag, prev_imag);
410
411
573k
    {
412
573k
      WORD n;
413
573k
      WORD32 *real1 = &real_buffer[128];
414
573k
      WORD32 *imag1 = &img_buffer[128];
415
416
573k
      prev_real = curr_real;
417
573k
      prev_imag = curr_imag;
418
419
4.31M
      for (n = ((slots - 2) >> 1); n; n--) {
420
3.74M
        curr_real = *real1;
421
3.74M
        real1 += 128;
422
3.74M
        curr_imag = *imag1;
423
3.74M
        imag1 += 128;
424
425
3.74M
        curr_real = ixheaac_shr32(curr_real, 3);
426
3.74M
        curr_imag = ixheaac_shr32(curr_imag, 3);
427
428
3.74M
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_real, prev_real);
429
3.74M
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_imag, prev_imag);
430
431
3.74M
        t_phi_01_i = ixheaacd_mac32x16hin32(t_phi_01_i, curr_imag, prev_real);
432
3.74M
        t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i, curr_real, prev_imag);
433
434
3.74M
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_real, prev_real);
435
3.74M
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_imag, prev_imag);
436
437
3.74M
        prev_real = *real1;
438
3.74M
        real1 += 128;
439
3.74M
        prev_imag = *imag1;
440
3.74M
        imag1 += 128;
441
442
3.74M
        prev_real = ixheaac_shr32(prev_real, 3);
443
3.74M
        prev_imag = ixheaac_shr32(prev_imag, 3);
444
445
3.74M
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, prev_real, curr_real);
446
3.74M
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, prev_imag, curr_imag);
447
448
3.74M
        t_phi_01_i = ixheaacd_mac32x16hin32(t_phi_01_i, prev_imag, curr_real);
449
3.74M
        t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i, prev_real, curr_imag);
450
451
3.74M
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, curr_real, curr_real);
452
3.74M
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, curr_imag, curr_imag);
453
3.74M
      }
454
455
573k
      if (slots & 0x01) {
456
266k
        curr_real = *real1;
457
266k
        curr_imag = *imag1;
458
459
266k
        curr_real = ixheaac_shr32(curr_real, 3);
460
266k
        curr_imag = ixheaac_shr32(curr_imag, 3);
461
462
266k
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_real, prev_real);
463
266k
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_imag, prev_imag);
464
465
266k
        t_phi_01_i = ixheaacd_mac32x16hin32(t_phi_01_i, curr_imag, prev_real);
466
266k
        t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i, curr_real, prev_imag);
467
468
266k
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_real, prev_real);
469
266k
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_imag, prev_imag);
470
266k
      }
471
573k
    }
472
473
573k
    {
474
573k
      WORD32 t_phi_22 = t_phi_11;
475
573k
      WORD32 curr_real = real_buffer[-2 * 128];
476
573k
      WORD32 curr_imag = img_buffer[-2 * 128];
477
478
573k
      curr_real = ixheaac_shr32(curr_real, 3);
479
573k
      curr_imag = ixheaac_shr32(curr_imag, 3);
480
481
573k
      t_phi_22 = ixheaacd_mac32x16hin32(t_phi_22, curr_real, curr_real);
482
573k
      t_phi_22 = ixheaacd_mac32x16hin32(t_phi_22, curr_imag, curr_imag);
483
484
573k
      curr_real = real_buffer[(slots - 2) * 128];
485
573k
      curr_imag = img_buffer[(slots - 2) * 128];
486
487
573k
      curr_real = ixheaac_shr32(curr_real, 3);
488
573k
      curr_imag = ixheaac_shr32(curr_imag, 3);
489
490
573k
      t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, curr_real, curr_real);
491
573k
      t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, curr_imag, curr_imag);
492
493
573k
      cov_matrix->phi_11 = t_phi_11;
494
573k
      cov_matrix->phi_22 = t_phi_22;
495
573k
    }
496
497
573k
    {
498
573k
      WORD32 t_phi_12 = t_phi_01;
499
500
573k
      t_phi_12 = ixheaacd_mac32x16hin32(t_phi_12, real_buffer[-128] >> 3,
501
573k
                                        real_buffer[-2 * 128] >> 3);
502
573k
      t_phi_12 = ixheaacd_mac32x16hin32(t_phi_12, img_buffer[-128] >> 3,
503
573k
                                        img_buffer[-2 * 128] >> 3);
504
573k
      t_phi_01 =
505
573k
          ixheaacd_mac32x16hin32(t_phi_01, real_buffer[(slots - 1) * 128] >> 3,
506
573k
                                 real_buffer[(slots - 2) * 128] >> 3);
507
573k
      t_phi_01 =
508
573k
          ixheaacd_mac32x16hin32(t_phi_01, img_buffer[(slots - 1) * 128] >> 3,
509
573k
                                 img_buffer[(slots - 2) * 128] >> 3);
510
511
573k
      cov_matrix->phi_01 = t_phi_01;
512
573k
      cov_matrix->phi_12 = t_phi_12;
513
573k
    }
514
515
573k
    {
516
573k
      WORD32 t_phi_12_i = t_phi_01_i;
517
518
573k
      t_phi_12_i = ixheaacd_mac32x16hin32(t_phi_12_i, img_buffer[-128] >> 3,
519
573k
                                          real_buffer[-2 * 128] >> 3);
520
573k
      t_phi_12_i = ixheaacd_macn32x16hin32(t_phi_12_i, real_buffer[-128] >> 3,
521
573k
                                           img_buffer[-2 * 128] >> 3);
522
573k
      t_phi_01_i =
523
573k
          ixheaacd_mac32x16hin32(t_phi_01_i, img_buffer[(slots - 1) * 128] >> 3,
524
573k
                                 real_buffer[(slots - 2) * 128] >> 3);
525
573k
      t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i,
526
573k
                                           real_buffer[(slots - 1) * 128] >> 3,
527
573k
                                           img_buffer[(slots - 2) * 128] >> 3);
528
529
573k
      cov_matrix->phi_01_im = t_phi_01_i;
530
573k
      cov_matrix->phi_12_im = t_phi_12_i;
531
573k
    }
532
533
573k
    {
534
573k
      WORD16 n, len_by_4, p;
535
573k
      WORD32 t_phi_02 = 0x00, t_phi_02_i = 0x00;
536
537
573k
      len_by_4 = (slots >> 2);
538
573k
      p = 0;
539
2.60M
      for (n = 0; n < len_by_4; n++) {
540
2.02M
        WORD32 real1, real2, imag1, imag2;
541
2.02M
        real1 = real_buffer[p * 128];
542
2.02M
        real2 = real_buffer[(p - 2) * 128];
543
2.02M
        imag1 = img_buffer[p * 128];
544
2.02M
        imag2 = img_buffer[(p - 2) * 128];
545
546
2.02M
        real1 = ixheaac_shr32(real1, 3);
547
2.02M
        real2 = ixheaac_shr32(real2, 3);
548
2.02M
        imag1 = ixheaac_shr32(imag1, 3);
549
2.02M
        imag2 = ixheaac_shr32(imag2, 3);
550
551
2.02M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
552
2.02M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
553
2.02M
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
554
2.02M
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
555
556
2.02M
        real1 = real_buffer[(p + 1) * 128];
557
2.02M
        real2 = real_buffer[(p - 1) * 128];
558
2.02M
        imag1 = img_buffer[(p + 1) * 128];
559
2.02M
        imag2 = img_buffer[(p - 1) * 128];
560
561
2.02M
        real1 = ixheaac_shr32(real1, 3);
562
2.02M
        real2 = ixheaac_shr32(real2, 3);
563
2.02M
        imag1 = ixheaac_shr32(imag1, 3);
564
2.02M
        imag2 = ixheaac_shr32(imag2, 3);
565
566
2.02M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
567
2.02M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
568
2.02M
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
569
2.02M
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
570
571
2.02M
        real1 = real_buffer[(p + 2) * 128];
572
2.02M
        real2 = real_buffer[p * 128];
573
2.02M
        imag1 = img_buffer[(p + 2) * 128];
574
2.02M
        imag2 = img_buffer[p * 128];
575
576
2.02M
        real1 = ixheaac_shr32(real1, 3);
577
2.02M
        real2 = ixheaac_shr32(real2, 3);
578
2.02M
        imag1 = ixheaac_shr32(imag1, 3);
579
2.02M
        imag2 = ixheaac_shr32(imag2, 3);
580
581
2.02M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
582
2.02M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
583
2.02M
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
584
2.02M
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
585
586
2.02M
        real1 = real_buffer[(p + 3) * 128];
587
2.02M
        real2 = real_buffer[(p + 1) * 128];
588
2.02M
        imag1 = img_buffer[(p + 3) * 128];
589
2.02M
        imag2 = img_buffer[(p + 1) * 128];
590
591
2.02M
        real1 = ixheaac_shr32(real1, 3);
592
2.02M
        real2 = ixheaac_shr32(real2, 3);
593
2.02M
        imag1 = ixheaac_shr32(imag1, 3);
594
2.02M
        imag2 = ixheaac_shr32(imag2, 3);
595
596
2.02M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
597
2.02M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
598
2.02M
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
599
2.02M
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
600
2.02M
        p += 4;
601
2.02M
      }
602
573k
      n = ixheaac_shl16(len_by_4, 2);
603
1.37M
      for (; n < slots; n++) {
604
798k
        WORD32 real1, real2, imag1, imag2;
605
798k
        real1 = real_buffer[(n * 128)];
606
798k
        real2 = real_buffer[(n - 2) * 128];
607
798k
        imag1 = img_buffer[n * 128];
608
798k
        imag2 = img_buffer[(n - 2) * 128];
609
610
798k
        real1 = ixheaac_shr32(real1, 3);
611
798k
        real2 = ixheaac_shr32(real2, 3);
612
798k
        imag1 = ixheaac_shr32(imag1, 3);
613
798k
        imag2 = ixheaac_shr32(imag2, 3);
614
615
798k
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
616
798k
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
617
798k
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
618
798k
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
619
798k
      }
620
621
573k
      cov_matrix->phi_02 = t_phi_02;
622
573k
      cov_matrix->phi_02_im = t_phi_02_i;
623
573k
    }
624
573k
    ptr_real++;
625
573k
    pac_arr++;
626
573k
  }
627
53.9k
}
628
629
static PLATFORM_INLINE VOID ixheaacd_filt_step3_lp(WORD len, WORD32 coef1,
630
                                                   WORD32 coef2,
631
                                                   WORD32 *pqmf_real_low,
632
0
                                                   WORD32 *pqmf_real_high) {
633
0
  WORD32 prev1;
634
0
  WORD32 prev2;
635
0
  WORD32 i;
636
637
0
  prev2 = *pqmf_real_low;
638
0
  pqmf_real_low += 64;
639
640
0
  prev1 = *pqmf_real_low;
641
0
  pqmf_real_low += 64;
642
643
0
  for (i = len; i >= 0; i -= 2) {
644
0
    WORD32 curr = *pqmf_real_low;
645
0
    WORD32 temp = ixheaac_mult32x16hin32(prev2, coef2);
646
0
    pqmf_real_low += 64;
647
648
0
    *pqmf_real_high = ixheaac_add32_sat((curr >> LPC_SCALE_FACTOR),
649
0
                                         ((ixheaacd_mac32x16hin32(temp, prev1, coef1)) << 1));
650
0
    pqmf_real_high += 64;
651
652
0
    prev2 = *pqmf_real_low;
653
0
    temp = ixheaac_mult32x16hin32(prev1, coef2);
654
0
    pqmf_real_low += 64;
655
656
0
    *pqmf_real_high = ixheaac_add32_sat((prev2 >> LPC_SCALE_FACTOR),
657
0
                                         ((ixheaacd_mac32x16hin32(temp, curr, coef1)) << 1));
658
0
    pqmf_real_high += 64;
659
660
0
    prev1 = prev2;
661
0
    prev2 = curr;
662
0
  }
663
0
}
664
665
VOID ixheaacd_filter1_lp(ia_sbr_hf_generator_struct *hf_generator,
666
                         ia_lpp_trans_cov_matrix *cov_matrix_seq,
667
                         WORD32 *bw_array, WORD16 *degree_alias,
668
                         WORD32 start_idx, WORD32 stop_idx,
669
                         WORD32 max_qmf_subband, WORD32 start_patch,
670
0
                         WORD32 stop_patch, WORD32 *sub_sig_x) {
671
0
  WORD16 k1, k1_below = 0, k1_below2 = 0;
672
0
  WORD32 i;
673
0
  WORD16 alpha_real[LPC_ORDER];
674
0
  WORD32 low_band, high_band;
675
0
  WORD32 patch;
676
0
  WORD16 bw = 0;
677
0
  WORD32 a0r, a1r;
678
679
0
  WORD num_patches = hf_generator->pstr_settings->num_patches;
680
0
  ia_patch_param_struct *patch_param =
681
0
      hf_generator->pstr_settings->str_patch_param;
682
0
  WORD32 bw_index[MAX_NUM_PATCHES];
683
684
0
  memset(bw_index, 0, sizeof(WORD32) * num_patches);
685
686
0
  for (low_band = start_patch; low_band < stop_patch; low_band++) {
687
0
    ia_lpp_trans_cov_matrix *p_cov_matrix = &cov_matrix_seq[low_band];
688
689
0
    alpha_real[1] = 0;
690
0
    alpha_real[0] = 0;
691
692
0
    if (p_cov_matrix->d != 0) {
693
0
      WORD32 tmp_r, temp_real, modulus_d;
694
0
      WORD16 inverse_d;
695
0
      WORD32 norm_d;
696
697
0
      norm_d = ixheaac_norm32(p_cov_matrix->d);
698
699
0
      inverse_d =
700
0
          (WORD16)(*ixheaacd_fix_div)(0x40000000, (p_cov_matrix->d << norm_d));
701
0
      modulus_d = ixheaac_abs32(p_cov_matrix->d);
702
703
0
      tmp_r =
704
0
          (ixheaac_sub32_sat(
705
0
               ixheaac_mult32(p_cov_matrix->phi_01, p_cov_matrix->phi_12),
706
0
               ixheaac_mult32(p_cov_matrix->phi_02, p_cov_matrix->phi_11)) >>
707
0
           LPC_SCALE_FACTOR);
708
0
      temp_real = ixheaac_abs32(tmp_r);
709
710
0
      if (temp_real < modulus_d) {
711
0
        alpha_real[1] = (WORD16)(
712
0
            (ixheaac_mult32x16in32_shl_sat(tmp_r, inverse_d) << norm_d) >> 15);
713
0
      }
714
715
0
      tmp_r =
716
0
          (ixheaac_sub32_sat(
717
0
               ixheaac_mult32(p_cov_matrix->phi_02, p_cov_matrix->phi_12),
718
0
               ixheaac_mult32(p_cov_matrix->phi_01, p_cov_matrix->phi_22)) >>
719
0
           LPC_SCALE_FACTOR);
720
0
      temp_real = ixheaac_abs32(tmp_r);
721
722
0
      if (temp_real < modulus_d) {
723
0
        alpha_real[0] = (WORD16)(
724
0
            (ixheaac_mult32x16in32_shl_sat(tmp_r, inverse_d) << norm_d) >> 15);
725
0
      }
726
0
    }
727
728
0
    if (p_cov_matrix->phi_11 == 0) {
729
0
      k1 = 0;
730
0
    } else {
731
0
      if (ixheaac_abs32_sat(p_cov_matrix->phi_01) >= p_cov_matrix->phi_11) {
732
0
        if (p_cov_matrix->phi_01 < 0) {
733
0
          k1 = 0x7fff;
734
0
        } else {
735
0
          k1 = (WORD16)-0x8000;
736
0
        }
737
0
      } else {
738
0
        k1 = -((WORD16)(
739
0
            (*ixheaacd_fix_div)(p_cov_matrix->phi_01, p_cov_matrix->phi_11)));
740
0
      }
741
0
    }
742
743
0
    if (low_band > 1) {
744
0
      WORD16 deg = ixheaac_sub16_sat(
745
0
          0x7fff, ixheaac_mult16_shl_sat(k1_below, k1_below));
746
0
      degree_alias[low_band] = 0;
747
748
0
      if (((low_band & 1) == 0) && (k1 < 0)) {
749
0
        if (k1_below < 0) {
750
0
          degree_alias[low_band] = 0x7fff;
751
752
0
          if (k1_below2 > 0) {
753
0
            degree_alias[low_band - 1] = deg;
754
0
          }
755
0
        } else {
756
0
          if (k1_below2 > 0) {
757
0
            degree_alias[low_band] = deg;
758
0
          }
759
0
        }
760
0
      }
761
762
0
      if (((low_band & 1) != 0) && (k1 > 0)) {
763
0
        if (k1_below > 0) {
764
0
          degree_alias[low_band] = 0x7fff;
765
766
0
          if (k1_below2 < 0) {
767
0
            degree_alias[low_band - 1] = deg;
768
0
          }
769
0
        } else {
770
0
          if (k1_below2 < 0) {
771
0
            degree_alias[low_band] = deg;
772
0
          }
773
0
        }
774
0
      }
775
0
    }
776
777
0
    k1_below2 = k1_below;
778
0
    k1_below = k1;
779
780
0
    patch = 0;
781
0
    while (patch < num_patches) {
782
0
      ia_patch_param_struct *p_loc_patch_param = &patch_param[patch];
783
0
      WORD32 bw_vec, bw_idx;
784
0
      WORD16 alpha1, alpha2;
785
786
0
      high_band = (((low_band + p_loc_patch_param->dst_end_band) << 8) >> 8);
787
788
0
      if ((low_band < p_loc_patch_param->src_start_band) ||
789
0
          (low_band >= p_loc_patch_param->src_end_band) ||
790
0
          (high_band < max_qmf_subband)) {
791
0
        patch++;
792
0
        continue;
793
0
      }
794
795
0
      bw_idx = bw_index[patch];
796
0
      while (high_band >= hf_generator->pstr_settings->bw_borders[bw_idx]) {
797
0
        bw_idx++;
798
0
        bw_index[patch] = bw_idx;
799
0
      }
800
801
0
      bw_vec = bw_array[bw_idx];
802
0
      alpha1 = alpha_real[0];
803
0
      alpha2 = alpha_real[1];
804
805
0
      bw = ixheaac_extract16h(bw_vec);
806
0
      a0r = ixheaac_mult16x16in32_shl(bw, alpha1);
807
0
      bw = ixheaac_mult16_shl_sat(bw, bw);
808
0
      a1r = ixheaac_mult16x16in32_shl(bw, alpha2);
809
810
0
      {
811
0
        WORD32 *p_sub_signal_xlow = sub_sig_x + low_band + ((start_idx) << 6);
812
0
        WORD32 *p_sub_signal_xhigh =
813
0
            sub_sig_x + high_band + ((start_idx + 2) << 6);
814
0
        WORD32 len = stop_idx - start_idx - 1;
815
816
0
        if (bw > 0) {
817
0
          ixheaacd_filt_step3_lp(len, a0r, a1r, p_sub_signal_xlow,
818
0
                                 p_sub_signal_xhigh);
819
820
0
        } else {
821
0
          p_sub_signal_xlow += 128;
822
0
          for (i = len; i >= 0; i--) {
823
0
            *p_sub_signal_xhigh = *p_sub_signal_xlow >> LPC_SCALE_FACTOR;
824
0
            p_sub_signal_xlow += 64;
825
0
            p_sub_signal_xhigh += 64;
826
0
          }
827
0
        }
828
0
      }
829
830
0
      patch++;
831
0
    }
832
0
  }
833
0
}
834
835
58.8k
VOID ixheaacd_clr_subsamples(WORD32 *ptr_qmf_buf, WORD32 num, WORD32 size) {
836
58.8k
  WORD32 i;
837
1.88M
  for (i = num; i >= 0; i--) {
838
1.83M
    memset(ptr_qmf_buf, 0, sizeof(WORD32) * (size));
839
1.83M
    ptr_qmf_buf += 64;
840
1.83M
  }
841
58.8k
}
842
843
VOID ixheaacd_low_pow_hf_generator(ia_sbr_hf_generator_struct *hf_generator,
844
                                   WORD32 **qmf_real, WORD16 *degree_alias,
845
                                   WORD32 start_idx, WORD32 stop_idx,
846
                                   WORD32 num_if_bands, WORD32 max_qmf_subband,
847
                                   WORD32 *sbr_invf_mode,
848
                                   WORD32 *sbr_invf_mode_prev, WORD32 norm_max,
849
0
                                   WORD32 *sub_sig_x) {
850
0
  WORD32 bw_array[MAX_NUM_PATCHES];
851
0
  WORD32 i;
852
0
  WORD32 start_patch, stop_patch, low_band, high_band;
853
0
  ia_patch_param_struct *patch_param =
854
0
      hf_generator->pstr_settings->str_patch_param;
855
0
  WORD32 patch;
856
0
  ia_lpp_trans_cov_matrix cov_matrix_seq[MAX_COLS];
857
858
0
  WORD32 actual_stop_band;
859
0
  WORD32 num_patches = hf_generator->pstr_settings->num_patches;
860
0
  WORD32 auto_corr_length = hf_generator->pstr_settings->num_columns + 6;
861
862
0
  stop_idx = (hf_generator->pstr_settings->num_columns + stop_idx);
863
864
0
  ixheaacd_invfilt_level_emphasis(hf_generator, num_if_bands, sbr_invf_mode,
865
0
                                  sbr_invf_mode_prev, bw_array);
866
867
0
  actual_stop_band =
868
0
      ixheaac_add16(patch_param[num_patches - 1].dst_start_band,
869
0
                     patch_param[num_patches - 1].num_bands_in_patch);
870
871
0
  {
872
0
    WORD32 *p_qmf_real;
873
0
    WORD32 len = 6, num;
874
875
0
    if (len > stop_idx) len = stop_idx;
876
877
0
    p_qmf_real = &qmf_real[start_idx][actual_stop_band];
878
0
    num = (len - start_idx - 1);
879
0
    ixheaacd_clr_subsamples(p_qmf_real, num,
880
0
                            (NO_SYNTHESIS_CHANNELS - actual_stop_band));
881
882
0
    if (actual_stop_band < 32) {
883
0
      num = (stop_idx - len - 1);
884
0
      p_qmf_real = &qmf_real[len][actual_stop_band];
885
0
      ixheaacd_clr_subsamples(p_qmf_real, num,
886
0
                              (NO_ANALYSIS_CHANNELS - actual_stop_band));
887
0
    }
888
0
  }
889
890
0
  start_patch = ixheaac_max16(
891
0
      1, ixheaac_sub16(hf_generator->pstr_settings->start_patch, 2));
892
0
  stop_patch = patch_param[0].dst_start_band;
893
894
0
  {
895
0
    WORD32 *ptr = &sub_sig_x[0];
896
0
    WORD32 *plpc_filt_states_real = &hf_generator->lpc_filt_states_real[0][0];
897
0
    for (i = LPC_ORDER; i != 0; i--) {
898
0
      memcpy(ptr, plpc_filt_states_real, sizeof(WORD32) * (stop_patch));
899
0
      ptr += NO_SYNTHESIS_CHANNELS;
900
0
      plpc_filt_states_real += 32;
901
0
    }
902
0
  }
903
0
  if (norm_max != 30) {
904
0
    if (30 == hf_generator->pstr_settings->num_columns) {
905
0
      (*ixheaacd_covariance_matrix_calc_960)(sub_sig_x + start_patch,
906
0
                                             &cov_matrix_seq[start_patch],
907
0
                                             (stop_patch - start_patch),
908
0
                                             auto_corr_length);
909
0
     } else
910
0
      (*ixheaacd_covariance_matrix_calc)(sub_sig_x + start_patch,
911
0
                                         &cov_matrix_seq[start_patch],
912
0
                                         (stop_patch - start_patch),
913
0
                                         auto_corr_length);
914
0
  } else {
915
0
    memset(&cov_matrix_seq[0], 0,
916
0
           sizeof(ia_lpp_trans_cov_matrix) * stop_patch);
917
0
  }
918
919
0
  ixheaacd_filter1_lp(hf_generator, cov_matrix_seq, bw_array, degree_alias,
920
0
                      start_idx, stop_idx, max_qmf_subband, start_patch,
921
0
                      stop_patch, sub_sig_x);
922
923
0
  start_patch = hf_generator->pstr_settings->start_patch;
924
0
  stop_patch = hf_generator->pstr_settings->stop_patch;
925
926
0
  for (low_band = start_patch; low_band < stop_patch; low_band++) {
927
0
    WORD32 src_start_band, src_end_band, dst_start_band;
928
0
    patch = 0;
929
930
0
    while (patch < num_patches) {
931
0
      ia_patch_param_struct *ptr_loc_patch_param = &patch_param[patch];
932
933
0
      src_start_band = ptr_loc_patch_param->src_start_band;
934
0
      src_end_band = ptr_loc_patch_param->src_end_band;
935
0
      dst_start_band = ptr_loc_patch_param->dst_start_band;
936
937
0
      high_band = (low_band + ptr_loc_patch_param->dst_end_band);
938
939
0
      if ((low_band < src_start_band) || (low_band >= src_end_band) ||
940
0
          (high_band >= NO_SYNTHESIS_CHANNELS)) {
941
0
        patch++;
942
0
        continue;
943
0
      }
944
945
0
      if ((high_band != dst_start_band)) {
946
0
        degree_alias[high_band] = degree_alias[low_band];
947
0
      }
948
949
0
      patch++;
950
0
    }
951
0
  }
952
953
0
  memcpy(hf_generator->bw_array_prev, bw_array, sizeof(WORD32) * num_if_bands);
954
0
}
955
956
VOID ixheaacd_hf_generator(ia_sbr_hf_generator_struct *hf_generator,
957
                           ia_sbr_scale_fact_struct *scale_factor,
958
                           WORD32 **qmf_real, WORD32 **qmf_imag, WORD32 factor,
959
                           WORD32 start_idx, WORD32 stop_idx,
960
                           WORD32 num_if_bands, WORD32 max_qmf_subband,
961
                           WORD32 *sbr_invf_mode, WORD32 *sbr_invf_mode_prev,
962
53.9k
                           WORD32 *sub_sig_x, WORD audio_object_type) {
963
53.9k
  WORD32 bw_index[MAX_NUM_PATCHES];
964
53.9k
  WORD32 bw_array[MAX_NUM_PATCHES];
965
966
53.9k
  WORD32 i, j;
967
53.9k
  WORD32 start_patch, stop_patch, low_band, high_band;
968
53.9k
  ia_patch_param_struct *patch_param =
969
53.9k
      hf_generator->pstr_settings->str_patch_param;
970
53.9k
  WORD32 patch;
971
972
53.9k
  WORD16 alpha_real[LPC_ORDER];
973
53.9k
  WORD16 a0r, a1r;
974
53.9k
  WORD16 alpha_imag[LPC_ORDER];
975
53.9k
  WORD16 a0i = 0, a1i = 0;
976
977
53.9k
  WORD16 bw = 0;
978
979
53.9k
  ia_lpp_trans_cov_matrix cov_matrix;
980
53.9k
  ia_lpp_trans_cov_matrix cov_matrix_seq[MAX_COLS];
981
982
53.9k
  WORD32 common_scale;
983
53.9k
  WORD32 actual_stop_band;
984
53.9k
  WORD32 num_patches = hf_generator->pstr_settings->num_patches;
985
986
53.9k
  WORD32  auto_corr_length = hf_generator->pstr_settings->num_columns + 6;
987
988
53.9k
  start_idx = (start_idx * factor);
989
990
53.9k
  stop_idx = (hf_generator->pstr_settings->num_columns + (stop_idx * factor));
991
992
53.9k
  ixheaacd_invfilt_level_emphasis(hf_generator, num_if_bands, sbr_invf_mode,
993
53.9k
                                  sbr_invf_mode_prev, bw_array);
994
995
53.9k
  actual_stop_band =
996
53.9k
      ixheaac_add16(patch_param[num_patches - 1].dst_start_band,
997
53.9k
                     patch_param[num_patches - 1].num_bands_in_patch);
998
999
891k
  for (i = start_idx; i < stop_idx; i++) {
1000
838k
    WORD32 *p_qmf_real = &qmf_real[i][actual_stop_band];
1001
838k
    WORD32 *p_qmf_imag = &qmf_imag[i][actual_stop_band];
1002
1003
22.7M
    for (j = NO_SYNTHESIS_CHANNELS - actual_stop_band; j != 0; j--) {
1004
21.8M
      *p_qmf_real++ = 0;
1005
21.8M
      *p_qmf_imag++ = 0;
1006
21.8M
    }
1007
838k
  }
1008
1009
53.9k
  memset(bw_index, 0, sizeof(WORD32) * num_patches);
1010
1011
53.9k
  common_scale =
1012
53.9k
      ixheaac_min32(scale_factor->ov_lb_scale, scale_factor->lb_scale);
1013
1014
53.9k
  start_patch = hf_generator->pstr_settings->start_patch;
1015
53.9k
  stop_patch = hf_generator->pstr_settings->stop_patch;
1016
1017
53.9k
  {
1018
53.9k
    WORD32 *ptr;
1019
161k
    for (i = 0; i < LPC_ORDER; i++) {
1020
107k
      ptr = sub_sig_x + (start_patch) + i * 128;
1021
107k
      memcpy(ptr, &hf_generator->lpc_filt_states_real[i][start_patch],
1022
107k
             sizeof(WORD32) * (stop_patch - start_patch));
1023
107k
      memcpy(ptr + 64, &hf_generator->lpc_filt_states_imag[i][start_patch],
1024
107k
             sizeof(WORD32) * (stop_patch - start_patch));
1025
107k
    }
1026
53.9k
  }
1027
53.9k
  if (audio_object_type != AOT_ER_AAC_ELD &&
1028
53.9k
      audio_object_type != AOT_ER_AAC_LD) {
1029
0
    if (auto_corr_length == 36) {
1030
0
      (*ixheaacd_covariance_matrix_calc_2)(
1031
0
          &cov_matrix_seq[start_patch],
1032
0
          (sub_sig_x + start_patch + LPC_ORDER * 128),
1033
0
          (stop_patch - start_patch), auto_corr_length);
1034
0
     } else {
1035
0
      (*ixheaacd_covariance_matrix_calc_2)(
1036
0
          &cov_matrix_seq[start_patch],
1037
0
          (sub_sig_x + start_patch + LPC_ORDER * 128),
1038
0
          (stop_patch - start_patch), 38);
1039
0
    }
1040
53.9k
  } else {
1041
53.9k
    if (hf_generator->pstr_settings->num_columns == 15) {
1042
24.6k
      (*ixheaacd_covariance_matrix_calc_2)(
1043
24.6k
          &cov_matrix_seq[start_patch],
1044
24.6k
          (sub_sig_x + start_patch + LPC_ORDER * 128),
1045
24.6k
          (stop_patch - start_patch),
1046
24.6k
          hf_generator->pstr_settings->num_columns);
1047
29.3k
     } else {
1048
29.3k
      (*ixheaacd_covariance_matrix_calc_2)(
1049
29.3k
          &cov_matrix_seq[start_patch],
1050
29.3k
          (sub_sig_x + start_patch + LPC_ORDER * 128),
1051
29.3k
          (stop_patch - start_patch), 16);
1052
29.3k
    }
1053
53.9k
  }
1054
1055
627k
  for (low_band = start_patch; low_band < stop_patch; low_band++) {
1056
573k
    FLAG reset_lpc_coeff = 0;
1057
573k
    WORD32 max_val;
1058
573k
    WORD32 q_shift;
1059
573k
    WORD32 v;
1060
573k
    max_val = ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_01);
1061
573k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_02);
1062
573k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_12);
1063
1064
573k
    max_val = max_val | (cov_matrix_seq[low_band].phi_11);
1065
573k
    max_val = max_val | (cov_matrix_seq[low_band].phi_22);
1066
573k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_01_im);
1067
573k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_02_im);
1068
573k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_12_im);
1069
1070
573k
    q_shift = ixheaac_pnorm32(max_val);
1071
1072
573k
    cov_matrix.phi_11 = (cov_matrix_seq[low_band].phi_11 << q_shift);
1073
573k
    cov_matrix.phi_22 = (cov_matrix_seq[low_band].phi_22 << q_shift);
1074
573k
    cov_matrix.phi_01 = (cov_matrix_seq[low_band].phi_01 << q_shift);
1075
573k
    cov_matrix.phi_02 = (cov_matrix_seq[low_band].phi_02 << q_shift);
1076
573k
    cov_matrix.phi_12 = (cov_matrix_seq[low_band].phi_12 << q_shift);
1077
573k
    cov_matrix.phi_01_im = (cov_matrix_seq[low_band].phi_01_im << q_shift);
1078
573k
    cov_matrix.phi_02_im = (cov_matrix_seq[low_band].phi_02_im << q_shift);
1079
573k
    cov_matrix.phi_12_im = (cov_matrix_seq[low_band].phi_12_im << q_shift);
1080
1081
573k
    max_val = ixheaac_mult32(cov_matrix.phi_12, cov_matrix.phi_12);
1082
573k
    max_val = ixheaac_add32_sat(
1083
573k
        max_val, ixheaac_mult32(cov_matrix.phi_12_im, cov_matrix.phi_12_im));
1084
1085
573k
    v = ixheaac_sub32_sat(
1086
573k
            ixheaac_mult32(cov_matrix.phi_11, cov_matrix.phi_22), max_val)
1087
573k
        << 1;
1088
573k
    cov_matrix.d = v;
1089
1090
573k
    alpha_real[1] = 0;
1091
573k
    alpha_imag[1] = 0;
1092
1093
573k
    if (cov_matrix.d != 0) {
1094
448k
      WORD32 tmp_r, temp_real, modulus_d;
1095
448k
      WORD32 tmp_i, temp_imag;
1096
448k
      WORD16 inverse_d;
1097
448k
      WORD32 norm_d;
1098
1099
448k
      norm_d = ixheaac_norm32(cov_matrix.d);
1100
1101
448k
      inverse_d =
1102
448k
          (WORD16)(*ixheaacd_fix_div)(0x40000000, (cov_matrix.d << norm_d));
1103
1104
448k
      modulus_d = ixheaac_abs32_sat(cov_matrix.d);
1105
448k
      tmp_r =
1106
448k
          (ixheaac_sub32_sat(
1107
448k
              ixheaac_sub32_sat(
1108
448k
                  ixheaac_mult32(cov_matrix.phi_01, cov_matrix.phi_12),
1109
448k
                  ixheaac_mult32(cov_matrix.phi_01_im, cov_matrix.phi_12_im)),
1110
448k
              ixheaac_mult32(cov_matrix.phi_02, cov_matrix.phi_11))) >>
1111
448k
          (LPC_SCALE_FACTOR - 1);
1112
448k
      tmp_i = (ixheaac_sub32_sat(
1113
448k
                  ixheaac_add32_sat(
1114
448k
                      ixheaac_mult32(cov_matrix.phi_01_im, cov_matrix.phi_12),
1115
448k
                      ixheaac_mult32(cov_matrix.phi_01, cov_matrix.phi_12_im)),
1116
448k
                  ixheaac_mult32(cov_matrix.phi_02_im, cov_matrix.phi_11))) >>
1117
448k
              (LPC_SCALE_FACTOR - 1);
1118
448k
      temp_imag = ixheaac_abs32(tmp_i);
1119
448k
      temp_real = ixheaac_abs32(tmp_r);
1120
1121
448k
      if (temp_real >= modulus_d) {
1122
1.87k
        reset_lpc_coeff = 1;
1123
447k
      } else {
1124
447k
        alpha_real[1] = (WORD16)(
1125
447k
            (ixheaac_mult32x16in32(tmp_r, inverse_d) << (norm_d + 1)) >> 15);
1126
447k
      }
1127
1128
448k
      if (temp_imag >= modulus_d) {
1129
4.33k
        reset_lpc_coeff = 1;
1130
444k
      } else {
1131
444k
        alpha_imag[1] = (WORD16)(
1132
444k
            (ixheaac_mult32x16in32(tmp_i, inverse_d) << (norm_d + 1)) >> 15);
1133
444k
      }
1134
448k
    }
1135
1136
573k
    alpha_real[0] = 0;
1137
573k
    alpha_imag[0] = 0;
1138
1139
573k
    if (cov_matrix.phi_11 != 0) {
1140
445k
      WORD32 tmp_r, temp_real;
1141
445k
      WORD32 tmp_i = 0, temp_imag = 0;
1142
445k
      WORD16 inverse_r11;
1143
445k
      WORD32 norm_r11;
1144
1145
445k
      norm_r11 = ixheaac_norm32(cov_matrix.phi_11);
1146
1147
445k
      inverse_r11 = (WORD16)(*ixheaacd_fix_div)(
1148
445k
          0x40000000, (cov_matrix.phi_11 << norm_r11));
1149
1150
445k
      tmp_r = ixheaac_add32_sat(
1151
445k
          ixheaac_add32(
1152
445k
              (cov_matrix.phi_01 >> (LPC_SCALE_FACTOR + 1)),
1153
445k
              ixheaac_mult32x16in32(cov_matrix.phi_12, alpha_real[1])),
1154
445k
          ixheaac_mult32x16in32(cov_matrix.phi_12_im, alpha_imag[1]));
1155
445k
      tmp_i = ixheaac_sub32_sat(
1156
445k
          ixheaac_add32(
1157
445k
              (cov_matrix.phi_01_im >> (LPC_SCALE_FACTOR + 1)),
1158
445k
              ixheaac_mult32x16in32(cov_matrix.phi_12, alpha_imag[1])),
1159
445k
          ixheaac_mult32x16in32(cov_matrix.phi_12_im, alpha_real[1]));
1160
1161
445k
      tmp_r = tmp_r << 1;
1162
445k
      tmp_i = tmp_i << 1;
1163
1164
445k
      temp_imag = ixheaac_abs32(tmp_i);
1165
445k
      temp_real = ixheaac_abs32(tmp_r);
1166
1167
445k
      if (temp_real >= cov_matrix.phi_11) {
1168
572
        reset_lpc_coeff = 1;
1169
444k
      } else {
1170
444k
        alpha_real[0] = (WORD16)(
1171
444k
            (ixheaac_mult32x16in32(ixheaac_sub32_sat(0, tmp_r), inverse_r11)
1172
444k
             << (norm_r11 + 1)) >>
1173
444k
            15);
1174
444k
      }
1175
1176
445k
      if (temp_imag >= cov_matrix.phi_11) {
1177
414
        reset_lpc_coeff = 1;
1178
444k
      } else {
1179
444k
        alpha_imag[0] = (WORD16)(
1180
444k
            (ixheaac_mult32x16in32(ixheaac_sub32_sat(0, tmp_i), inverse_r11)
1181
444k
             << (norm_r11 + 1)) >>
1182
444k
            15);
1183
444k
      }
1184
445k
    }
1185
1186
573k
    if (ixheaac_add32_sat((alpha_real[0] * alpha_real[0]),
1187
573k
                           (alpha_imag[0] * alpha_imag[0])) >= 0x40000000L) {
1188
148
      reset_lpc_coeff = 1;
1189
148
    }
1190
1191
573k
    if (ixheaac_add32_sat((alpha_real[1] * alpha_real[1]),
1192
573k
                           (alpha_imag[1] * alpha_imag[1])) >= 0x40000000L) {
1193
230
      reset_lpc_coeff = 1;
1194
230
    }
1195
1196
573k
    if (reset_lpc_coeff) {
1197
5.82k
      alpha_real[0] = 0;
1198
5.82k
      alpha_real[1] = 0;
1199
5.82k
      alpha_imag[0] = 0;
1200
5.82k
      alpha_imag[1] = 0;
1201
5.82k
    }
1202
1203
573k
    patch = 0;
1204
1205
1.94M
    while (patch < num_patches) {
1206
1.36M
      high_band = (low_band + patch_param[patch].dst_end_band);
1207
1208
1.36M
      if ((low_band < patch_param[patch].src_start_band) ||
1209
1.36M
          (low_band >= patch_param[patch].src_end_band)) {
1210
279k
        patch++;
1211
279k
        continue;
1212
279k
      }
1213
1214
1.08M
      if (high_band < max_qmf_subband) {
1215
0
        patch++;
1216
0
        continue;
1217
0
      }
1218
1219
1.25M
      while ((bw_index[patch] < MAX_NUM_PATCHES - 1) &&
1220
1.25M
             (bw_index[patch] < MAX_NUM_NOISE_VALUES) &&
1221
1.25M
             (high_band >=
1222
1.25M
              hf_generator->pstr_settings->bw_borders[bw_index[patch]])) {
1223
171k
        bw_index[patch]++;
1224
171k
      }
1225
1226
1.08M
      bw = ixheaac_extract16h(bw_array[bw_index[patch]]);
1227
1.08M
      a0r = ixheaac_mult16_shl_sat(bw, alpha_real[0]);
1228
1.08M
      a0i = ixheaac_mult16_shl_sat(bw, alpha_imag[0]);
1229
1.08M
      bw = ixheaac_mult16_shl_sat(bw, bw);
1230
1.08M
      a1r = ixheaac_mult16_shl_sat(bw, alpha_real[1]);
1231
1.08M
      a1i = ixheaac_mult16_shl_sat(bw, alpha_imag[1]);
1232
1233
1.08M
      if (bw > 0) {
1234
402k
        ixheaacd_filterstep3(a0r, a0i, a1r, a1i, start_idx, stop_idx, low_band,
1235
402k
                             high_band, sub_sig_x);
1236
1237
685k
      } else {
1238
685k
        WORD32 *p_src = sub_sig_x + low_band + ((start_idx + 2) << 7);
1239
685k
        WORD32 *p_dst = sub_sig_x + high_band + ((start_idx + 2) << 7);
1240
1241
11.3M
        for (i = stop_idx - start_idx; i != 0; i--) {
1242
10.6M
          *(p_dst) = *(p_src) >> LPC_SCALE_FACTOR;
1243
10.6M
          p_src += 64;
1244
10.6M
          p_dst += 64;
1245
10.6M
          *(p_dst) = *(p_src) >> LPC_SCALE_FACTOR;
1246
10.6M
          p_src += 64;
1247
10.6M
          p_dst += 64;
1248
10.6M
        }
1249
685k
      }
1250
1251
1.08M
      patch++;
1252
1.08M
    }
1253
573k
  }
1254
1255
53.9k
  memcpy(hf_generator->bw_array_prev, bw_array, sizeof(WORD32) * num_if_bands);
1256
1257
53.9k
  scale_factor->hb_scale = (WORD16)(common_scale - LPC_SCALE_FACTOR);
1258
53.9k
}