Coverage Report

Created: 2025-08-24 07:17

/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
36.5M
#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
70.2M
                                                     WORD32 c) {
86
70.2M
  WORD32 result;
87
88
70.2M
  result = a + ixheaac_mult32x16hin32(b, c);
89
90
70.2M
  return (result);
91
70.2M
}
92
93
static PLATFORM_INLINE WORD32 ixheaacd_macn32x16hin32(WORD32 a, WORD32 b,
94
17.8M
                                                      WORD32 c) {
95
17.8M
  WORD32 result;
96
97
17.8M
  result = a - ixheaac_mult32x16hin32(b, c);
98
99
17.8M
  return (result);
100
17.8M
}
101
102
VOID ixheaacd_filterstep3(WORD16 a0r, WORD16 a0i, WORD16 a1r, WORD16 a1i,
103
                          WORD32 start_indx, WORD32 stop_idx, WORD32 low_band,
104
393k
                          WORD32 high_band, WORD32 *qmf_buffer) {
105
393k
  WORD32 i;
106
393k
  WORD32 prev1r, prev1i;
107
393k
  WORD32 prev2r, prev2i;
108
393k
  WORD16 coef1r = (a0r);
109
393k
  WORD16 coef1i = (a0i);
110
393k
  WORD16 coef2r = (a1r);
111
393k
  WORD16 coef2i = (a1i);
112
393k
  WORD32 *p_src, *p_dst;
113
393k
  WORD32 qmf_real, qmf_imag;
114
115
393k
  WORD32 curr, curi;
116
393k
  p_src = qmf_buffer + low_band + ((start_indx) << 7);
117
393k
  prev2r = *p_src;
118
393k
  p_src += 64;
119
120
393k
  prev2i = *p_src;
121
393k
  p_src += 64;
122
123
393k
  prev1r = *p_src;
124
393k
  p_src += 64;
125
126
393k
  prev1i = *p_src;
127
393k
  p_src += 64;
128
129
393k
  p_dst = qmf_buffer + high_band + ((start_indx + 2) << 7);
130
131
6.54M
  for (i = stop_idx - start_indx; i != 0; i--) {
132
6.15M
    WORD32 accu;
133
134
6.15M
    curr = *p_src;
135
6.15M
    p_src += 64;
136
137
6.15M
    curi = *p_src;
138
6.15M
    p_src += 64;
139
140
6.15M
    qmf_real = (curr >> LPC_SCALE_FACTOR);
141
6.15M
    qmf_imag = (curi >> LPC_SCALE_FACTOR);
142
143
6.15M
    accu = ixheaac_sub32(
144
6.15M
        ixheaac_add32(ixheaac_sub32(ixheaac_mult32x16in32(prev1r, coef1r),
145
6.15M
                                      ixheaac_mult32x16in32(prev1i, coef1i)),
146
6.15M
                       ixheaac_mult32x16in32(prev2r, coef2r)),
147
6.15M
        ixheaac_mult32x16in32(prev2i, coef2i));
148
149
6.15M
    *p_dst = ixheaac_add32(qmf_real, (accu << 1));
150
6.15M
    p_dst += 64;
151
152
6.15M
    accu = ixheaac_add32(
153
6.15M
        ixheaac_add32_sat(
154
6.15M
            ixheaac_add32_sat(ixheaac_mult32x16in32(prev1r, coef1i),
155
6.15M
                               ixheaac_mult32x16in32(prev1i, coef1r)),
156
6.15M
            ixheaac_mult32x16in32(prev2r, coef2i)),
157
6.15M
        ixheaac_mult32x16in32(prev2i, coef2r));
158
159
6.15M
    *p_dst = ixheaac_add32(qmf_imag, (accu << 1));
160
6.15M
    p_dst += 64;
161
162
6.15M
    prev2r = prev1r;
163
6.15M
    prev1r = curr;
164
6.15M
    prev2i = prev1i;
165
6.15M
    prev1i = curi;
166
6.15M
  }
167
393k
}
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.7k
    WORD32 *real_buffer, WORD32 num_bands, WORD16 slots) {
378
53.7k
  WORD32 k;
379
53.7k
  WORD32 *img_buffer;
380
53.7k
  WORD32 *ptr_real = real_buffer;
381
53.7k
  ia_lpp_trans_cov_matrix *pac_arr = cov_matrix;
382
383
609k
  for (k = 0; k < num_bands; k++) {
384
556k
    WORD32 t_phi_11 = 0, t_phi_01 = 0, t_phi_01_i = 0;
385
556k
    WORD32 prev_real, prev_imag, curr_real, curr_imag;
386
387
556k
    real_buffer = ptr_real;
388
556k
    img_buffer = real_buffer + 64;
389
556k
    cov_matrix = pac_arr;
390
391
556k
    prev_real = real_buffer[-128];
392
556k
    prev_imag = img_buffer[-128];
393
394
556k
    curr_real = real_buffer[0];
395
556k
    curr_imag = img_buffer[0];
396
397
556k
    curr_real = ixheaac_shr32(curr_real, 3);
398
556k
    curr_imag = ixheaac_shr32(curr_imag, 3);
399
556k
    prev_real = ixheaac_shr32(prev_real, 3);
400
556k
    prev_imag = ixheaac_shr32(prev_imag, 3);
401
402
556k
    t_phi_01 = ixheaac_mult32x16hin32(curr_real, prev_real);
403
556k
    t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_imag, prev_imag);
404
405
556k
    t_phi_01_i = ixheaac_mult32x16hin32(curr_imag, prev_real);
406
556k
    t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i, curr_real, prev_imag);
407
408
556k
    t_phi_11 = ixheaac_mult32x16hin32(prev_real, prev_real);
409
556k
    t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_imag, prev_imag);
410
411
556k
    {
412
556k
      WORD n;
413
556k
      WORD32 *real1 = &real_buffer[128];
414
556k
      WORD32 *imag1 = &img_buffer[128];
415
416
556k
      prev_real = curr_real;
417
556k
      prev_imag = curr_imag;
418
419
4.19M
      for (n = ((slots - 2) >> 1); n; n--) {
420
3.63M
        curr_real = *real1;
421
3.63M
        real1 += 128;
422
3.63M
        curr_imag = *imag1;
423
3.63M
        imag1 += 128;
424
425
3.63M
        curr_real = ixheaac_shr32(curr_real, 3);
426
3.63M
        curr_imag = ixheaac_shr32(curr_imag, 3);
427
428
3.63M
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_real, prev_real);
429
3.63M
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_imag, prev_imag);
430
431
3.63M
        t_phi_01_i = ixheaacd_mac32x16hin32(t_phi_01_i, curr_imag, prev_real);
432
3.63M
        t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i, curr_real, prev_imag);
433
434
3.63M
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_real, prev_real);
435
3.63M
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_imag, prev_imag);
436
437
3.63M
        prev_real = *real1;
438
3.63M
        real1 += 128;
439
3.63M
        prev_imag = *imag1;
440
3.63M
        imag1 += 128;
441
442
3.63M
        prev_real = ixheaac_shr32(prev_real, 3);
443
3.63M
        prev_imag = ixheaac_shr32(prev_imag, 3);
444
445
3.63M
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, prev_real, curr_real);
446
3.63M
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, prev_imag, curr_imag);
447
448
3.63M
        t_phi_01_i = ixheaacd_mac32x16hin32(t_phi_01_i, prev_imag, curr_real);
449
3.63M
        t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i, prev_real, curr_imag);
450
451
3.63M
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, curr_real, curr_real);
452
3.63M
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, curr_imag, curr_imag);
453
3.63M
      }
454
455
556k
      if (slots & 0x01) {
456
253k
        curr_real = *real1;
457
253k
        curr_imag = *imag1;
458
459
253k
        curr_real = ixheaac_shr32(curr_real, 3);
460
253k
        curr_imag = ixheaac_shr32(curr_imag, 3);
461
462
253k
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_real, prev_real);
463
253k
        t_phi_01 = ixheaacd_mac32x16hin32(t_phi_01, curr_imag, prev_imag);
464
465
253k
        t_phi_01_i = ixheaacd_mac32x16hin32(t_phi_01_i, curr_imag, prev_real);
466
253k
        t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i, curr_real, prev_imag);
467
468
253k
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_real, prev_real);
469
253k
        t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, prev_imag, prev_imag);
470
253k
      }
471
556k
    }
472
473
556k
    {
474
556k
      WORD32 t_phi_22 = t_phi_11;
475
556k
      WORD32 curr_real = real_buffer[-2 * 128];
476
556k
      WORD32 curr_imag = img_buffer[-2 * 128];
477
478
556k
      curr_real = ixheaac_shr32(curr_real, 3);
479
556k
      curr_imag = ixheaac_shr32(curr_imag, 3);
480
481
556k
      t_phi_22 = ixheaacd_mac32x16hin32(t_phi_22, curr_real, curr_real);
482
556k
      t_phi_22 = ixheaacd_mac32x16hin32(t_phi_22, curr_imag, curr_imag);
483
484
556k
      curr_real = real_buffer[(slots - 2) * 128];
485
556k
      curr_imag = img_buffer[(slots - 2) * 128];
486
487
556k
      curr_real = ixheaac_shr32(curr_real, 3);
488
556k
      curr_imag = ixheaac_shr32(curr_imag, 3);
489
490
556k
      t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, curr_real, curr_real);
491
556k
      t_phi_11 = ixheaacd_mac32x16hin32(t_phi_11, curr_imag, curr_imag);
492
493
556k
      cov_matrix->phi_11 = t_phi_11;
494
556k
      cov_matrix->phi_22 = t_phi_22;
495
556k
    }
496
497
556k
    {
498
556k
      WORD32 t_phi_12 = t_phi_01;
499
500
556k
      t_phi_12 = ixheaacd_mac32x16hin32(t_phi_12, real_buffer[-128] >> 3,
501
556k
                                        real_buffer[-2 * 128] >> 3);
502
556k
      t_phi_12 = ixheaacd_mac32x16hin32(t_phi_12, img_buffer[-128] >> 3,
503
556k
                                        img_buffer[-2 * 128] >> 3);
504
556k
      t_phi_01 =
505
556k
          ixheaacd_mac32x16hin32(t_phi_01, real_buffer[(slots - 1) * 128] >> 3,
506
556k
                                 real_buffer[(slots - 2) * 128] >> 3);
507
556k
      t_phi_01 =
508
556k
          ixheaacd_mac32x16hin32(t_phi_01, img_buffer[(slots - 1) * 128] >> 3,
509
556k
                                 img_buffer[(slots - 2) * 128] >> 3);
510
511
556k
      cov_matrix->phi_01 = t_phi_01;
512
556k
      cov_matrix->phi_12 = t_phi_12;
513
556k
    }
514
515
556k
    {
516
556k
      WORD32 t_phi_12_i = t_phi_01_i;
517
518
556k
      t_phi_12_i = ixheaacd_mac32x16hin32(t_phi_12_i, img_buffer[-128] >> 3,
519
556k
                                          real_buffer[-2 * 128] >> 3);
520
556k
      t_phi_12_i = ixheaacd_macn32x16hin32(t_phi_12_i, real_buffer[-128] >> 3,
521
556k
                                           img_buffer[-2 * 128] >> 3);
522
556k
      t_phi_01_i =
523
556k
          ixheaacd_mac32x16hin32(t_phi_01_i, img_buffer[(slots - 1) * 128] >> 3,
524
556k
                                 real_buffer[(slots - 2) * 128] >> 3);
525
556k
      t_phi_01_i = ixheaacd_macn32x16hin32(t_phi_01_i,
526
556k
                                           real_buffer[(slots - 1) * 128] >> 3,
527
556k
                                           img_buffer[(slots - 2) * 128] >> 3);
528
529
556k
      cov_matrix->phi_01_im = t_phi_01_i;
530
556k
      cov_matrix->phi_12_im = t_phi_12_i;
531
556k
    }
532
533
556k
    {
534
556k
      WORD16 n, len_by_4, p;
535
556k
      WORD32 t_phi_02 = 0x00, t_phi_02_i = 0x00;
536
537
556k
      len_by_4 = (slots >> 2);
538
556k
      p = 0;
539
2.52M
      for (n = 0; n < len_by_4; n++) {
540
1.97M
        WORD32 real1, real2, imag1, imag2;
541
1.97M
        real1 = real_buffer[p * 128];
542
1.97M
        real2 = real_buffer[(p - 2) * 128];
543
1.97M
        imag1 = img_buffer[p * 128];
544
1.97M
        imag2 = img_buffer[(p - 2) * 128];
545
546
1.97M
        real1 = ixheaac_shr32(real1, 3);
547
1.97M
        real2 = ixheaac_shr32(real2, 3);
548
1.97M
        imag1 = ixheaac_shr32(imag1, 3);
549
1.97M
        imag2 = ixheaac_shr32(imag2, 3);
550
551
1.97M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
552
1.97M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
553
1.97M
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
554
1.97M
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
555
556
1.97M
        real1 = real_buffer[(p + 1) * 128];
557
1.97M
        real2 = real_buffer[(p - 1) * 128];
558
1.97M
        imag1 = img_buffer[(p + 1) * 128];
559
1.97M
        imag2 = img_buffer[(p - 1) * 128];
560
561
1.97M
        real1 = ixheaac_shr32(real1, 3);
562
1.97M
        real2 = ixheaac_shr32(real2, 3);
563
1.97M
        imag1 = ixheaac_shr32(imag1, 3);
564
1.97M
        imag2 = ixheaac_shr32(imag2, 3);
565
566
1.97M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
567
1.97M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
568
1.97M
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
569
1.97M
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
570
571
1.97M
        real1 = real_buffer[(p + 2) * 128];
572
1.97M
        real2 = real_buffer[p * 128];
573
1.97M
        imag1 = img_buffer[(p + 2) * 128];
574
1.97M
        imag2 = img_buffer[p * 128];
575
576
1.97M
        real1 = ixheaac_shr32(real1, 3);
577
1.97M
        real2 = ixheaac_shr32(real2, 3);
578
1.97M
        imag1 = ixheaac_shr32(imag1, 3);
579
1.97M
        imag2 = ixheaac_shr32(imag2, 3);
580
581
1.97M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
582
1.97M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
583
1.97M
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
584
1.97M
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
585
586
1.97M
        real1 = real_buffer[(p + 3) * 128];
587
1.97M
        real2 = real_buffer[(p + 1) * 128];
588
1.97M
        imag1 = img_buffer[(p + 3) * 128];
589
1.97M
        imag2 = img_buffer[(p + 1) * 128];
590
591
1.97M
        real1 = ixheaac_shr32(real1, 3);
592
1.97M
        real2 = ixheaac_shr32(real2, 3);
593
1.97M
        imag1 = ixheaac_shr32(imag1, 3);
594
1.97M
        imag2 = ixheaac_shr32(imag2, 3);
595
596
1.97M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
597
1.97M
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
598
1.97M
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
599
1.97M
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
600
1.97M
        p += 4;
601
1.97M
      }
602
556k
      n = ixheaac_shl16(len_by_4, 2);
603
1.31M
      for (; n < slots; n++) {
604
759k
        WORD32 real1, real2, imag1, imag2;
605
759k
        real1 = real_buffer[(n * 128)];
606
759k
        real2 = real_buffer[(n - 2) * 128];
607
759k
        imag1 = img_buffer[n * 128];
608
759k
        imag2 = img_buffer[(n - 2) * 128];
609
610
759k
        real1 = ixheaac_shr32(real1, 3);
611
759k
        real2 = ixheaac_shr32(real2, 3);
612
759k
        imag1 = ixheaac_shr32(imag1, 3);
613
759k
        imag2 = ixheaac_shr32(imag2, 3);
614
615
759k
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, real1, real2);
616
759k
        t_phi_02 = ixheaacd_mac32x16hin32(t_phi_02, imag1, imag2);
617
759k
        t_phi_02_i = ixheaacd_mac32x16hin32(t_phi_02_i, imag1, real2);
618
759k
        t_phi_02_i = ixheaacd_macn32x16hin32(t_phi_02_i, real1, imag2);
619
759k
      }
620
621
556k
      cov_matrix->phi_02 = t_phi_02;
622
556k
      cov_matrix->phi_02_im = t_phi_02_i;
623
556k
    }
624
556k
    ptr_real++;
625
556k
    pac_arr++;
626
556k
  }
627
53.7k
}
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
60.2k
VOID ixheaacd_clr_subsamples(WORD32 *ptr_qmf_buf, WORD32 num, WORD32 size) {
836
60.2k
  WORD32 i;
837
1.93M
  for (i = num; i >= 0; i--) {
838
1.87M
    memset(ptr_qmf_buf, 0, sizeof(WORD32) * (size));
839
1.87M
    ptr_qmf_buf += 64;
840
1.87M
  }
841
60.2k
}
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.7k
                           WORD32 *sub_sig_x, WORD audio_object_type) {
963
53.7k
  WORD32 bw_index[MAX_NUM_PATCHES];
964
53.7k
  WORD32 bw_array[MAX_NUM_PATCHES];
965
966
53.7k
  WORD32 i, j;
967
53.7k
  WORD32 start_patch, stop_patch, low_band, high_band;
968
53.7k
  ia_patch_param_struct *patch_param =
969
53.7k
      hf_generator->pstr_settings->str_patch_param;
970
53.7k
  WORD32 patch;
971
972
53.7k
  WORD16 alpha_real[LPC_ORDER];
973
53.7k
  WORD16 a0r, a1r;
974
53.7k
  WORD16 alpha_imag[LPC_ORDER];
975
53.7k
  WORD16 a0i = 0, a1i = 0;
976
977
53.7k
  WORD16 bw = 0;
978
979
53.7k
  ia_lpp_trans_cov_matrix cov_matrix;
980
53.7k
  ia_lpp_trans_cov_matrix cov_matrix_seq[MAX_COLS];
981
982
53.7k
  WORD32 common_scale;
983
53.7k
  WORD32 actual_stop_band;
984
53.7k
  WORD32 num_patches = hf_generator->pstr_settings->num_patches;
985
986
53.7k
  WORD32  auto_corr_length = hf_generator->pstr_settings->num_columns + 6;
987
988
53.7k
  start_idx = (start_idx * factor);
989
990
53.7k
  stop_idx = (hf_generator->pstr_settings->num_columns + (stop_idx * factor));
991
992
53.7k
  ixheaacd_invfilt_level_emphasis(hf_generator, num_if_bands, sbr_invf_mode,
993
53.7k
                                  sbr_invf_mode_prev, bw_array);
994
995
53.7k
  actual_stop_band =
996
53.7k
      ixheaac_add16(patch_param[num_patches - 1].dst_start_band,
997
53.7k
                     patch_param[num_patches - 1].num_bands_in_patch);
998
999
891k
  for (i = start_idx; i < stop_idx; i++) {
1000
837k
    WORD32 *p_qmf_real = &qmf_real[i][actual_stop_band];
1001
837k
    WORD32 *p_qmf_imag = &qmf_imag[i][actual_stop_band];
1002
1003
22.6M
    for (j = NO_SYNTHESIS_CHANNELS - actual_stop_band; j != 0; j--) {
1004
21.7M
      *p_qmf_real++ = 0;
1005
21.7M
      *p_qmf_imag++ = 0;
1006
21.7M
    }
1007
837k
  }
1008
1009
53.7k
  memset(bw_index, 0, sizeof(WORD32) * num_patches);
1010
1011
53.7k
  common_scale =
1012
53.7k
      ixheaac_min32(scale_factor->ov_lb_scale, scale_factor->lb_scale);
1013
1014
53.7k
  start_patch = hf_generator->pstr_settings->start_patch;
1015
53.7k
  stop_patch = hf_generator->pstr_settings->stop_patch;
1016
1017
53.7k
  {
1018
53.7k
    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.7k
  }
1027
53.7k
  if (audio_object_type != AOT_ER_AAC_ELD &&
1028
53.7k
      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.7k
  } else {
1041
53.7k
    if (hf_generator->pstr_settings->num_columns == 15) {
1042
22.9k
      (*ixheaacd_covariance_matrix_calc_2)(
1043
22.9k
          &cov_matrix_seq[start_patch],
1044
22.9k
          (sub_sig_x + start_patch + LPC_ORDER * 128),
1045
22.9k
          (stop_patch - start_patch),
1046
22.9k
          hf_generator->pstr_settings->num_columns);
1047
30.8k
     } else {
1048
30.8k
      (*ixheaacd_covariance_matrix_calc_2)(
1049
30.8k
          &cov_matrix_seq[start_patch],
1050
30.8k
          (sub_sig_x + start_patch + LPC_ORDER * 128),
1051
30.8k
          (stop_patch - start_patch), 16);
1052
30.8k
    }
1053
53.7k
  }
1054
1055
609k
  for (low_band = start_patch; low_band < stop_patch; low_band++) {
1056
556k
    FLAG reset_lpc_coeff = 0;
1057
556k
    WORD32 max_val;
1058
556k
    WORD32 q_shift;
1059
556k
    WORD32 v;
1060
556k
    max_val = ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_01);
1061
556k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_02);
1062
556k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_12);
1063
1064
556k
    max_val = max_val | (cov_matrix_seq[low_band].phi_11);
1065
556k
    max_val = max_val | (cov_matrix_seq[low_band].phi_22);
1066
556k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_01_im);
1067
556k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_02_im);
1068
556k
    max_val = max_val | ixheaac_abs32_nrm(cov_matrix_seq[low_band].phi_12_im);
1069
1070
556k
    q_shift = ixheaac_pnorm32(max_val);
1071
1072
556k
    cov_matrix.phi_11 = (cov_matrix_seq[low_band].phi_11 << q_shift);
1073
556k
    cov_matrix.phi_22 = (cov_matrix_seq[low_band].phi_22 << q_shift);
1074
556k
    cov_matrix.phi_01 = (cov_matrix_seq[low_band].phi_01 << q_shift);
1075
556k
    cov_matrix.phi_02 = (cov_matrix_seq[low_band].phi_02 << q_shift);
1076
556k
    cov_matrix.phi_12 = (cov_matrix_seq[low_band].phi_12 << q_shift);
1077
556k
    cov_matrix.phi_01_im = (cov_matrix_seq[low_band].phi_01_im << q_shift);
1078
556k
    cov_matrix.phi_02_im = (cov_matrix_seq[low_band].phi_02_im << q_shift);
1079
556k
    cov_matrix.phi_12_im = (cov_matrix_seq[low_band].phi_12_im << q_shift);
1080
1081
556k
    max_val = ixheaac_mult32(cov_matrix.phi_12, cov_matrix.phi_12);
1082
556k
    max_val = ixheaac_add32_sat(
1083
556k
        max_val, ixheaac_mult32(cov_matrix.phi_12_im, cov_matrix.phi_12_im));
1084
1085
556k
    v = ixheaac_sub32_sat(
1086
556k
            ixheaac_mult32(cov_matrix.phi_11, cov_matrix.phi_22), max_val)
1087
556k
        << 1;
1088
556k
    cov_matrix.d = v;
1089
1090
556k
    alpha_real[1] = 0;
1091
556k
    alpha_imag[1] = 0;
1092
1093
556k
    if (cov_matrix.d != 0) {
1094
405k
      WORD32 tmp_r, temp_real, modulus_d;
1095
405k
      WORD32 tmp_i, temp_imag;
1096
405k
      WORD16 inverse_d;
1097
405k
      WORD32 norm_d;
1098
1099
405k
      norm_d = ixheaac_norm32(cov_matrix.d);
1100
1101
405k
      inverse_d =
1102
405k
          (WORD16)(*ixheaacd_fix_div)(0x40000000, (cov_matrix.d << norm_d));
1103
1104
405k
      modulus_d = ixheaac_abs32_sat(cov_matrix.d);
1105
405k
      tmp_r =
1106
405k
          (ixheaac_sub32_sat(
1107
405k
              ixheaac_sub32_sat(
1108
405k
                  ixheaac_mult32(cov_matrix.phi_01, cov_matrix.phi_12),
1109
405k
                  ixheaac_mult32(cov_matrix.phi_01_im, cov_matrix.phi_12_im)),
1110
405k
              ixheaac_mult32(cov_matrix.phi_02, cov_matrix.phi_11))) >>
1111
405k
          (LPC_SCALE_FACTOR - 1);
1112
405k
      tmp_i = (ixheaac_sub32_sat(
1113
405k
                  ixheaac_add32_sat(
1114
405k
                      ixheaac_mult32(cov_matrix.phi_01_im, cov_matrix.phi_12),
1115
405k
                      ixheaac_mult32(cov_matrix.phi_01, cov_matrix.phi_12_im)),
1116
405k
                  ixheaac_mult32(cov_matrix.phi_02_im, cov_matrix.phi_11))) >>
1117
405k
              (LPC_SCALE_FACTOR - 1);
1118
405k
      temp_imag = ixheaac_abs32(tmp_i);
1119
405k
      temp_real = ixheaac_abs32(tmp_r);
1120
1121
405k
      if (temp_real >= modulus_d) {
1122
1.34k
        reset_lpc_coeff = 1;
1123
404k
      } else {
1124
404k
        alpha_real[1] = (WORD16)(
1125
404k
            (ixheaac_mult32x16in32(tmp_r, inverse_d) << (norm_d + 1)) >> 15);
1126
404k
      }
1127
1128
405k
      if (temp_imag >= modulus_d) {
1129
3.06k
        reset_lpc_coeff = 1;
1130
402k
      } else {
1131
402k
        alpha_imag[1] = (WORD16)(
1132
402k
            (ixheaac_mult32x16in32(tmp_i, inverse_d) << (norm_d + 1)) >> 15);
1133
402k
      }
1134
405k
    }
1135
1136
556k
    alpha_real[0] = 0;
1137
556k
    alpha_imag[0] = 0;
1138
1139
556k
    if (cov_matrix.phi_11 != 0) {
1140
402k
      WORD32 tmp_r, temp_real;
1141
402k
      WORD32 tmp_i = 0, temp_imag = 0;
1142
402k
      WORD16 inverse_r11;
1143
402k
      WORD32 norm_r11;
1144
1145
402k
      norm_r11 = ixheaac_norm32(cov_matrix.phi_11);
1146
1147
402k
      inverse_r11 = (WORD16)(*ixheaacd_fix_div)(
1148
402k
          0x40000000, (cov_matrix.phi_11 << norm_r11));
1149
1150
402k
      tmp_r = ixheaac_add32_sat(
1151
402k
          ixheaac_add32(
1152
402k
              (cov_matrix.phi_01 >> (LPC_SCALE_FACTOR + 1)),
1153
402k
              ixheaac_mult32x16in32(cov_matrix.phi_12, alpha_real[1])),
1154
402k
          ixheaac_mult32x16in32(cov_matrix.phi_12_im, alpha_imag[1]));
1155
402k
      tmp_i = ixheaac_sub32_sat(
1156
402k
          ixheaac_add32(
1157
402k
              (cov_matrix.phi_01_im >> (LPC_SCALE_FACTOR + 1)),
1158
402k
              ixheaac_mult32x16in32(cov_matrix.phi_12, alpha_imag[1])),
1159
402k
          ixheaac_mult32x16in32(cov_matrix.phi_12_im, alpha_real[1]));
1160
1161
402k
      tmp_r = tmp_r << 1;
1162
402k
      tmp_i = tmp_i << 1;
1163
1164
402k
      temp_imag = ixheaac_abs32(tmp_i);
1165
402k
      temp_real = ixheaac_abs32(tmp_r);
1166
1167
402k
      if (temp_real >= cov_matrix.phi_11) {
1168
417
        reset_lpc_coeff = 1;
1169
401k
      } else {
1170
401k
        alpha_real[0] = (WORD16)(
1171
401k
            (ixheaac_mult32x16in32(ixheaac_sub32_sat(0, tmp_r), inverse_r11)
1172
401k
             << (norm_r11 + 1)) >>
1173
401k
            15);
1174
401k
      }
1175
1176
402k
      if (temp_imag >= cov_matrix.phi_11) {
1177
306
        reset_lpc_coeff = 1;
1178
402k
      } else {
1179
402k
        alpha_imag[0] = (WORD16)(
1180
402k
            (ixheaac_mult32x16in32(ixheaac_sub32_sat(0, tmp_i), inverse_r11)
1181
402k
             << (norm_r11 + 1)) >>
1182
402k
            15);
1183
402k
      }
1184
402k
    }
1185
1186
556k
    if (ixheaac_add32_sat((alpha_real[0] * alpha_real[0]),
1187
556k
                           (alpha_imag[0] * alpha_imag[0])) >= 0x40000000L) {
1188
141
      reset_lpc_coeff = 1;
1189
141
    }
1190
1191
556k
    if (ixheaac_add32_sat((alpha_real[1] * alpha_real[1]),
1192
556k
                           (alpha_imag[1] * alpha_imag[1])) >= 0x40000000L) {
1193
240
      reset_lpc_coeff = 1;
1194
240
    }
1195
1196
556k
    if (reset_lpc_coeff) {
1197
4.14k
      alpha_real[0] = 0;
1198
4.14k
      alpha_real[1] = 0;
1199
4.14k
      alpha_imag[0] = 0;
1200
4.14k
      alpha_imag[1] = 0;
1201
4.14k
    }
1202
1203
556k
    patch = 0;
1204
1205
1.97M
    while (patch < num_patches) {
1206
1.42M
      high_band = (low_band + patch_param[patch].dst_end_band);
1207
1208
1.42M
      if ((low_band < patch_param[patch].src_start_band) ||
1209
1.42M
          (low_band >= patch_param[patch].src_end_band)) {
1210
305k
        patch++;
1211
305k
        continue;
1212
305k
      }
1213
1214
1.11M
      if (high_band < max_qmf_subband) {
1215
0
        patch++;
1216
0
        continue;
1217
0
      }
1218
1219
1.30M
      while ((bw_index[patch] < MAX_NUM_PATCHES - 1) &&
1220
1.30M
             (bw_index[patch] < MAX_NUM_NOISE_VALUES) &&
1221
1.30M
             (high_band >=
1222
1.30M
              hf_generator->pstr_settings->bw_borders[bw_index[patch]])) {
1223
187k
        bw_index[patch]++;
1224
187k
      }
1225
1226
1.11M
      bw = ixheaac_extract16h(bw_array[bw_index[patch]]);
1227
1.11M
      a0r = ixheaac_mult16_shl_sat(bw, alpha_real[0]);
1228
1.11M
      a0i = ixheaac_mult16_shl_sat(bw, alpha_imag[0]);
1229
1.11M
      bw = ixheaac_mult16_shl_sat(bw, bw);
1230
1.11M
      a1r = ixheaac_mult16_shl_sat(bw, alpha_real[1]);
1231
1.11M
      a1i = ixheaac_mult16_shl_sat(bw, alpha_imag[1]);
1232
1233
1.11M
      if (bw > 0) {
1234
393k
        ixheaacd_filterstep3(a0r, a0i, a1r, a1i, start_idx, stop_idx, low_band,
1235
393k
                             high_band, sub_sig_x);
1236
1237
725k
      } else {
1238
725k
        WORD32 *p_src = sub_sig_x + low_band + ((start_idx + 2) << 7);
1239
725k
        WORD32 *p_dst = sub_sig_x + high_band + ((start_idx + 2) << 7);
1240
1241
11.9M
        for (i = stop_idx - start_idx; i != 0; i--) {
1242
11.2M
          *(p_dst) = *(p_src) >> LPC_SCALE_FACTOR;
1243
11.2M
          p_src += 64;
1244
11.2M
          p_dst += 64;
1245
11.2M
          *(p_dst) = *(p_src) >> LPC_SCALE_FACTOR;
1246
11.2M
          p_src += 64;
1247
11.2M
          p_dst += 64;
1248
11.2M
        }
1249
725k
      }
1250
1251
1.11M
      patch++;
1252
1.11M
    }
1253
556k
  }
1254
1255
53.7k
  memcpy(hf_generator->bw_array_prev, bw_array, sizeof(WORD32) * num_if_bands);
1256
1257
53.7k
  scale_factor->hb_scale = (WORD16)(common_scale - LPC_SCALE_FACTOR);
1258
53.7k
}