Coverage Report

Created: 2026-08-31 07:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_sbr_hbe_polyphase.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2023 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 "ixheaac_type_def.h"
21
#include "ixheaace_bitbuffer.h"
22
#include "ixheaac_error_standards.h"
23
#include "ixheaace_error_codes.h"
24
25
#include "iusace_tns_usac.h"
26
#include "iusace_cnst.h"
27
#include "ixheaace_sbr_def.h"
28
#include "ixheaace_resampler.h"
29
#include "ixheaace_sbr_hbe.h"
30
#include "ixheaace_sbr_hbe_fft.h"
31
#include "ixheaac_esbr_rom.h"
32
#include <string.h>
33
34
123k
IA_ERRORCODE ixheaace_complex_anal_filt(ixheaace_str_esbr_hbe_txposer *ptr_hbe_txposer) {
35
123k
  WORD32 idx;
36
123k
  WORD32 anal_size = 2 * ptr_hbe_txposer->synth_size;
37
123k
  WORD32 N = (10 * anal_size);
38
39
123k
  WORD32 no_bins = ptr_hbe_txposer->no_bins >> 1;
40
41
123k
  if (ptr_hbe_txposer->esbr_hq != 0) {
42
0
    anal_size = 2 * ptr_hbe_txposer->analy_size;
43
0
    no_bins = ptr_hbe_txposer->no_bins;
44
0
  }
45
46
123k
  idx = 0;
47
2.81M
  while (idx < no_bins) {
48
2.68M
    WORD32 i, j, k, l;
49
2.68M
    FLOAT32 window_output[640] = {0};
50
2.68M
    FLOAT32 u[128] = {0}, u_in[256] = {0}, u_out[256] = {0};
51
2.68M
    FLOAT32 accu_r, accu_i;
52
2.68M
    const FLOAT32 *ptr_inp_signal;
53
2.68M
    FLOAT32 *ptr_anal_buf;
54
55
2.68M
    FLOAT32 *ptr_analy_cos_sin_tab = ptr_hbe_txposer->ptr_analy_cos_sin_tab;
56
2.68M
    const FLOAT32 *ptr_interp_window_coeff = ptr_hbe_txposer->ptr_ana_win_coeff;
57
2.68M
    FLOAT32 *ptr_x = ptr_hbe_txposer->analy_buf;
58
59
2.68M
    if (ptr_hbe_txposer->esbr_hq != 0) {
60
0
      memset(ptr_hbe_txposer->qmf_in_buf[idx], 0, sizeof(ptr_hbe_txposer->qmf_in_buf[idx]));
61
0
      ptr_inp_signal = ptr_hbe_txposer->ptr_output_buf + idx * ptr_hbe_txposer->analy_size + 1;
62
0
      ptr_anal_buf = &ptr_hbe_txposer->qmf_in_buf[idx][4 * ptr_hbe_txposer->a_start];
63
2.68M
    } else {
64
2.68M
      memset(ptr_hbe_txposer->qmf_in_buf[idx + IXHEAACE_HBE_OPER_WIN_LEN - 1], 0,
65
2.68M
             sizeof(ptr_hbe_txposer->qmf_in_buf[idx + IXHEAACE_HBE_OPER_WIN_LEN - 1]));
66
67
2.68M
      ptr_inp_signal = ptr_hbe_txposer->ptr_input_buf + idx * 2 * ptr_hbe_txposer->synth_size + 1;
68
2.68M
      ptr_anal_buf =
69
2.68M
          &ptr_hbe_txposer
70
2.68M
               ->qmf_in_buf[idx + IXHEAACE_HBE_OPER_WIN_LEN - 1][4 * ptr_hbe_txposer->k_start];
71
2.68M
    }
72
73
690M
    for (i = N - 1; i >= anal_size; i--) {
74
687M
      ptr_x[i] = ptr_x[i - anal_size];
75
687M
    }
76
77
79.0M
    for (i = anal_size - 1; i >= 0; i--) {
78
76.3M
      ptr_x[i] = ptr_inp_signal[anal_size - 1 - i];
79
76.3M
    }
80
81
766M
    for (i = 0; i < N; i++) {
82
763M
      window_output[i] = ptr_x[i] * ptr_interp_window_coeff[i];
83
763M
    }
84
85
155M
    for (i = 0; i < 2 * anal_size; i++) {
86
152M
      accu_r = 0.0;
87
916M
      for (j = 0; j < 5; j++) {
88
763M
        accu_r = accu_r + window_output[i + j * 2 * anal_size];
89
763M
      }
90
152M
      u[i] = accu_r;
91
152M
    }
92
2.68M
    if (anal_size == 40 || anal_size == 56) {
93
11.3M
      for (i = 1; i < anal_size; i++) {
94
11.0M
        FLOAT32 temp1 = u[i] + u[2 * anal_size - i];
95
11.0M
        FLOAT32 temp2 = u[i] - u[2 * anal_size - i];
96
11.0M
        u[i] = temp1;
97
11.0M
        u[2 * anal_size - i] = temp2;
98
11.0M
      }
99
100
283k
      k = 0;
101
11.6M
      while (k < anal_size) {
102
11.3M
        accu_r = u[anal_size];
103
11.3M
        if (k & 1)
104
5.66M
          accu_i = u[0];
105
5.66M
        else
106
5.66M
          accu_i = -u[0];
107
452M
        for (l = 1; l < anal_size; l++) {
108
441M
          accu_r = accu_r + u[0 + l] * ptr_analy_cos_sin_tab[2 * l + 0];
109
441M
          accu_i = accu_i + u[2 * anal_size - l] * ptr_analy_cos_sin_tab[2 * l + 1];
110
441M
        }
111
11.3M
        ptr_analy_cos_sin_tab += (2 * anal_size);
112
11.3M
        *ptr_anal_buf++ = (FLOAT32)accu_r;
113
11.3M
        *ptr_anal_buf++ = (FLOAT32)accu_i;
114
11.3M
        k++;
115
11.3M
      }
116
2.40M
    } else {
117
2.40M
      FLOAT32 *ptr_u = u_in;
118
2.40M
      FLOAT32 *ptr_v = u_out;
119
132M
      for (k = 0; k < anal_size * 2; k++) {
120
130M
        *ptr_u++ = ((*ptr_analy_cos_sin_tab++) * u[k]);
121
130M
        *ptr_u++ = ((*ptr_analy_cos_sin_tab++) * u[k]);
122
130M
      }
123
2.40M
      if (ptr_hbe_txposer->ixheaace_cmplx_anal_fft != NULL) {
124
2.40M
        (*(ptr_hbe_txposer->ixheaace_cmplx_anal_fft))(u_in, u_out, anal_size * 2);
125
2.40M
      } else {
126
0
        return IA_EXHEAACE_EXE_NONFATAL_ESBR_INVALID_FFT;
127
0
      }
128
129
34.9M
      for (k = 0; k < anal_size / 2; k++) {
130
32.5M
        *(ptr_anal_buf + 1) = -*ptr_v++;
131
32.5M
        *ptr_anal_buf = *ptr_v++;
132
133
32.5M
        ptr_anal_buf += 2;
134
135
32.5M
        *(ptr_anal_buf + 1) = *ptr_v++;
136
32.5M
        *ptr_anal_buf = -*ptr_v++;
137
138
32.5M
        ptr_anal_buf += 2;
139
32.5M
      }
140
2.40M
    }
141
2.68M
    idx++;
142
2.68M
  }
143
123k
  return IA_NO_ERROR;
144
123k
}
145
146
IA_ERRORCODE ixheaace_real_synth_filt(ixheaace_str_esbr_hbe_txposer *ptr_hbe_txposer,
147
                                      WORD32 num_columns, FLOAT32 qmf_buf_real[][64],
148
150k
                                      FLOAT32 qmf_buf_imag[][64]) {
149
150k
  WORD32 i, j, k, l, idx;
150
150k
  FLOAT32 g[640];
151
150k
  FLOAT32 w[640];
152
150k
  FLOAT32 synth_out[128];
153
150k
  FLOAT32 accu_r;
154
150k
  WORD32 synth_size = ptr_hbe_txposer->synth_size;
155
150k
  FLOAT32 *ptr_cos_tab_trans_qmf =
156
150k
      (FLOAT32 *)&ixheaac_cos_table_trans_qmf[0][0] + ptr_hbe_txposer->k_start * 32;
157
150k
  FLOAT32 *ptr_buffer = ptr_hbe_txposer->synth_buf;
158
150k
  FLOAT32 *ptr_inp_buf = ptr_hbe_txposer->ptr_input_buf + ptr_hbe_txposer->ana_fft_size[0];
159
160
6.47M
  for (idx = 0; idx < num_columns; idx++) {
161
6.32M
    FLOAT32 loc_qmf_buf[64];
162
6.32M
    FLOAT32 *ptr_synth_buf_r = loc_qmf_buf;
163
6.32M
    FLOAT32 *ptr_out_buf;
164
6.32M
    if (ptr_hbe_txposer->esbr_hq == 1) {
165
0
      ptr_out_buf = ptr_inp_buf + (idx - 1) * ptr_hbe_txposer->synth_size;
166
6.32M
    } else {
167
6.32M
      ptr_out_buf = ptr_hbe_txposer->ptr_input_buf + (idx + 1) * ptr_hbe_txposer->synth_size;
168
6.32M
    }
169
170
6.32M
    FLOAT32 *ptr_synth_cos_tab = ptr_hbe_txposer->ptr_syn_cos_tab;
171
6.32M
    const FLOAT32 *ptr_interp_window_coeff = ptr_hbe_txposer->ptr_syn_win_coeff;
172
6.32M
    if (ptr_hbe_txposer->k_start < 0) {
173
0
      return IA_EXHEAACE_EXE_NONFATAL_ESBR_INVALID_START_BAND;
174
0
    }
175
176
6.32M
    k = 0;
177
96.4M
    while (k < synth_size) {
178
90.1M
      WORD32 ki = ptr_hbe_txposer->k_start + k;
179
90.1M
      ptr_synth_buf_r[k] = (FLOAT32)(ptr_cos_tab_trans_qmf[(k << 1) + 0] * qmf_buf_real[idx][ki] +
180
90.1M
                                     ptr_cos_tab_trans_qmf[(k << 1) + 1] * qmf_buf_imag[idx][ki]);
181
182
90.1M
      ptr_synth_buf_r[k + ptr_hbe_txposer->synth_size] = 0;
183
90.1M
      k++;
184
90.1M
    }
185
186
1.62G
    for (l = (20 * synth_size - 1); l >= 2 * synth_size; l--) {
187
1.62G
      ptr_buffer[l] = ptr_buffer[l - 2 * synth_size];
188
1.62G
    }
189
190
6.32M
    if (synth_size == 20) {
191
678k
      FLOAT32 *ptr_psynth_cos_tab = ptr_synth_cos_tab;
192
193
14.9M
      for (l = 0; l < (synth_size + 1); l++) {
194
14.2M
        accu_r = 0.0;
195
299M
        for (k = 0; k < synth_size; k++) {
196
284M
          accu_r += ptr_synth_buf_r[k] * ptr_psynth_cos_tab[k];
197
284M
        }
198
14.2M
        ptr_buffer[0 + l] = accu_r;
199
14.2M
        ptr_buffer[synth_size - l] = accu_r;
200
14.2M
        ptr_psynth_cos_tab = ptr_psynth_cos_tab + synth_size;
201
14.2M
      }
202
6.78M
      for (l = (synth_size + 1); l < (2 * synth_size - synth_size / 2); l++) {
203
6.10M
        accu_r = 0.0;
204
128M
        for (k = 0; k < synth_size; k++) {
205
122M
          accu_r += ptr_synth_buf_r[k] * ptr_psynth_cos_tab[k];
206
122M
        }
207
6.10M
        ptr_buffer[0 + l] = accu_r;
208
6.10M
        ptr_buffer[3 * synth_size - l] = -accu_r;
209
6.10M
        ptr_psynth_cos_tab = ptr_psynth_cos_tab + synth_size;
210
6.10M
      }
211
678k
      accu_r = 0.0;
212
14.2M
      for (k = 0; k < synth_size; k++) {
213
13.5M
        accu_r += ptr_synth_buf_r[k] * ptr_psynth_cos_tab[k];
214
13.5M
      }
215
678k
      ptr_buffer[3 * synth_size >> 1] = accu_r;
216
5.64M
    } else {
217
5.64M
      FLOAT32 tmp;
218
5.64M
      FLOAT32 *ptr_u = synth_out;
219
5.64M
      WORD32 kmax = (synth_size >> 1);
220
5.64M
      FLOAT32 *ptr_syn_buf = &ptr_buffer[kmax];
221
5.64M
      kmax += synth_size;
222
223
5.64M
      if (ptr_hbe_txposer->ixheaace_real_synth_fft != NULL) {
224
5.64M
        (*(ptr_hbe_txposer->ixheaace_real_synth_fft))(ptr_synth_buf_r, synth_out, synth_size * 2);
225
5.64M
      } else {
226
0
        return IA_EXHEAACE_EXE_NONFATAL_ESBR_INVALID_FFT;
227
0
      }
228
229
120M
      for (k = 0; k < kmax; k++) {
230
114M
        tmp = ((*ptr_u++) * (*ptr_synth_cos_tab++));
231
114M
        tmp -= ((*ptr_u++) * (*ptr_synth_cos_tab++));
232
114M
        *ptr_syn_buf++ = tmp;
233
114M
      }
234
235
5.64M
      ptr_syn_buf = &ptr_buffer[0];
236
5.64M
      kmax -= synth_size;
237
238
43.9M
      for (k = 0; k < kmax; k++) {
239
38.2M
        tmp = ((*ptr_u++) * (*ptr_synth_cos_tab++));
240
38.2M
        tmp -= ((*ptr_u++) * (*ptr_synth_cos_tab++));
241
38.2M
        *ptr_syn_buf++ = tmp;
242
38.2M
      }
243
5.64M
    }
244
245
37.9M
    for (i = 0; i < 5; i++) {
246
31.6M
      memcpy(&g[(2 * i + 0) * synth_size], &ptr_buffer[(4 * i + 0) * synth_size],
247
31.6M
             sizeof(g[0]) * synth_size);
248
31.6M
      memcpy(&g[(2 * i + 1) * synth_size], &ptr_buffer[(4 * i + 3) * synth_size],
249
31.6M
             sizeof(g[0]) * synth_size);
250
31.6M
    }
251
252
907M
    for (k = 0; k < 10 * synth_size; k++) {
253
901M
      w[k] = g[k] * ptr_interp_window_coeff[k];
254
901M
    }
255
256
96.4M
    for (i = 0; i < synth_size; i++) {
257
90.1M
      accu_r = 0.0;
258
991M
      for (j = 0; j < 10; j++) {
259
901M
        accu_r = accu_r + w[synth_size * j + i];
260
901M
      }
261
90.1M
      ptr_out_buf[i] = (FLOAT32)accu_r;
262
90.1M
    }
263
6.32M
  }
264
150k
  return IA_NO_ERROR;
265
150k
}
266
267
VOID ixheaace_dft_hbe_cplx_anal_filt(ixheaace_str_esbr_hbe_txposer *ptr_hbe_txposer,
268
19.5k
                                     FLOAT32 qmf_buf_real[][64], FLOAT32 qmf_buf_imag[][64]) {
269
19.5k
  WORD32 idx;
270
271
19.5k
  WORD32 anal_size = ptr_hbe_txposer->analy_size;
272
273
19.5k
  WORD32 N = (10 * ptr_hbe_txposer->analy_size);
274
275
19.5k
  idx = 0;
276
646k
  while (idx < ptr_hbe_txposer->no_bins) {
277
626k
    WORD32 i, j, k, l;
278
626k
    FLOAT32 window_output[640] = {0};
279
626k
    FLOAT32 u[128] = {0};
280
626k
    FLOAT32 accu_r, accu_i;
281
626k
    const FLOAT32 *ptr_inp_signal;
282
626k
    FLOAT32 *ptr_qmf_buf_r = &qmf_buf_real[idx][ptr_hbe_txposer->a_start];
283
626k
    FLOAT32 *ptr_qmf_buf_i = &qmf_buf_imag[idx][ptr_hbe_txposer->a_start];
284
285
626k
    const FLOAT32 *ptr_interp_window_coeff = ptr_hbe_txposer->ptr_ana_win_coeff;
286
626k
    FLOAT32 *ptr_x = ptr_hbe_txposer->analy_buf;
287
288
626k
    memset(&qmf_buf_real[idx][ptr_hbe_txposer->a_start], 0,
289
626k
           (IXHEAACE_NUM_QMF_SYNTH_CHANNELS - ptr_hbe_txposer->a_start) *
290
626k
               sizeof(qmf_buf_real[idx][ptr_hbe_txposer->a_start]));
291
626k
    memset(&qmf_buf_imag[idx][ptr_hbe_txposer->a_start], 0,
292
626k
           IXHEAACE_TWICE_QMF_SYNTH_CH_NUM * sizeof(qmf_buf_imag[idx][ptr_hbe_txposer->a_start]));
293
294
626k
    ptr_inp_signal = ptr_hbe_txposer->ptr_output_buf + idx * ptr_hbe_txposer->analy_size + 1;
295
296
176M
    for (i = N - 1; i >= anal_size; i--) {
297
175M
      ptr_x[i] = ptr_x[i - anal_size];
298
175M
    }
299
300
20.1M
    for (i = anal_size - 1; i >= 0; i--) {
301
19.5M
      ptr_x[i] = ptr_inp_signal[anal_size - 1 - i];
302
19.5M
    }
303
304
196M
    for (i = 0; i < N; i++) {
305
195M
      window_output[i] = ptr_x[i] * ptr_interp_window_coeff[i];
306
195M
    }
307
308
39.7M
    for (i = 0; i < 2 * anal_size; i++) {
309
39.0M
      accu_r = 0.0;
310
234M
      for (j = 0; j < 5; j++) {
311
195M
        accu_r = accu_r + window_output[i + j * 2 * anal_size];
312
195M
      }
313
39.0M
      u[i] = accu_r;
314
39.0M
    }
315
316
20.1M
    for (k = 0; k < anal_size; k++) {
317
19.5M
      accu_r = 0;
318
19.5M
      accu_i = 0;
319
1.24G
      for (l = 0; l < 2 * anal_size; l++) {
320
1.22G
        accu_r = accu_r + u[l] * ptr_hbe_txposer->str_dft_hbe_anal_coeff.real[k][l];
321
1.22G
        accu_i = accu_i + u[l] * ptr_hbe_txposer->str_dft_hbe_anal_coeff.imag[k][l];
322
1.22G
      }
323
19.5M
      ptr_qmf_buf_r[k] = (FLOAT32)accu_r;
324
19.5M
      ptr_qmf_buf_i[k] = (FLOAT32)accu_i;
325
19.5M
    }
326
327
626k
    idx++;
328
626k
  }
329
19.5k
}