Coverage Report

Created: 2026-05-08 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_esbr_polyphase.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#include <string.h>
21
#include "ixheaac_type_def.h"
22
#include "ixheaacd_bitbuffer.h"
23
#include "ixheaacd_interface.h"
24
#include "ixheaacd_sbr_common.h"
25
#include "ixheaacd_drc_data_struct.h"
26
#include "ixheaacd_drc_dec.h"
27
28
#include "ixheaac_sbr_const.h"
29
#include "ixheaacd_sbrdecsettings.h"
30
#include "ixheaacd_sbrdecoder.h"
31
#include "ixheaacd_env_extr_part.h"
32
#include "ixheaacd_sbr_rom.h"
33
#include "ixheaacd_common_rom.h"
34
#include "ixheaacd_hybrid.h"
35
#include "ixheaacd_sbr_scale.h"
36
#include "ixheaacd_ps_dec.h"
37
#include "ixheaacd_freq_sca.h"
38
#include "ixheaacd_lpp_tran.h"
39
#include "ixheaacd_bitbuffer.h"
40
#include "ixheaacd_env_extr.h"
41
#include "ixheaacd_qmf_dec.h"
42
#include "ixheaacd_env_calc.h"
43
#include "ixheaacd_pvc_dec.h"
44
#include "ixheaacd_sbr_dec.h"
45
#include "ixheaacd_qmf_poly.h"
46
#include "ixheaac_esbr_rom.h"
47
48
297k
WORD32 ixheaacd_complex_anal_filt(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer) {
49
297k
  WORD32 idx;
50
297k
  WORD32 anal_size = 2 * ptr_hbe_txposer->synth_size;
51
297k
  WORD32 N = (10 * anal_size);
52
297k
  WORD32 no_bins = ptr_hbe_txposer->no_bins >> 1;
53
54
297k
  if (ptr_hbe_txposer->esbr_hq != 0) {
55
0
    anal_size = 2 * ptr_hbe_txposer->analy_size;
56
0
    no_bins = ptr_hbe_txposer->no_bins;
57
0
  }
58
59
5.69M
  for (idx = 0; idx < no_bins; idx++) {
60
5.39M
    WORD32 i, j, k, l;
61
5.39M
    FLOAT32 window_output[640];
62
5.39M
    FLOAT32 u[128], u_in[256], u_out[256];
63
5.39M
    FLOAT32 accu_r, accu_i;
64
5.39M
    const FLOAT32 *inp_signal;
65
5.39M
    FLOAT32 *anal_buf;
66
67
5.39M
    FLOAT32 *analy_cos_sin_tab = ptr_hbe_txposer->analy_cos_sin_tab;
68
5.39M
    const FLOAT32 *interp_window_coeff = ptr_hbe_txposer->analy_wind_coeff;
69
5.39M
    FLOAT32 *x = ptr_hbe_txposer->analy_buf;
70
5.39M
    if (ptr_hbe_txposer->esbr_hq != 0) {
71
0
      memset(ptr_hbe_txposer->qmf_in_buf[idx], 0,
72
0
          TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32));
73
0
      inp_signal = ptr_hbe_txposer->ptr_output_buf +
74
0
          idx * ptr_hbe_txposer->analy_size + 1;
75
0
      anal_buf = &ptr_hbe_txposer->qmf_in_buf[idx]
76
0
          [4 * ptr_hbe_txposer->a_start];
77
5.39M
    } else {
78
5.39M
    memset(ptr_hbe_txposer->qmf_in_buf[idx + HBE_OPER_WIN_LEN - 1], 0,
79
5.39M
           TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32));
80
81
5.39M
    inp_signal = ptr_hbe_txposer->ptr_input_buf +
82
5.39M
                 idx * 2 * ptr_hbe_txposer->synth_size + 1;
83
5.39M
    anal_buf = &ptr_hbe_txposer->qmf_in_buf[idx + HBE_OPER_WIN_LEN - 1]
84
5.39M
                                           [4 * ptr_hbe_txposer->k_start];
85
5.39M
    }
86
87
1.12G
    for (i = N - 1; i >= anal_size; i--) {
88
1.12G
      x[i] = x[i - anal_size];
89
1.12G
    }
90
91
130M
    for (i = anal_size - 1; i >= 0; i--) {
92
124M
      x[i] = inp_signal[anal_size - 1 - i];
93
124M
    }
94
95
1.25G
    for (i = 0; i < N; i++) {
96
1.24G
      window_output[i] = x[i] * interp_window_coeff[i];
97
1.24G
    }
98
99
254M
    for (i = 0; i < 2 * anal_size; i++) {
100
249M
      accu_r = 0.0;
101
1.49G
      for (j = 0; j < 5; j++) {
102
1.24G
        accu_r = accu_r + window_output[i + j * 2 * anal_size];
103
1.24G
      }
104
249M
      u[i] = accu_r;
105
249M
    }
106
5.39M
    if (anal_size == 40 || anal_size == 56) {
107
24.2M
      for (i = 1; i < anal_size; i++) {
108
23.6M
        FLOAT32 temp1 = u[i] + u[2 * anal_size - i];
109
23.6M
        FLOAT32 temp2 = u[i] - u[2 * anal_size - i];
110
23.6M
        u[i] = temp1;
111
23.6M
        u[2 * anal_size - i] = temp2;
112
23.6M
      }
113
114
24.8M
      for (k = 0; k < anal_size; k++) {
115
24.2M
        accu_r = u[anal_size];
116
24.2M
        if (k & 1)
117
12.1M
          accu_i = u[0];
118
12.1M
        else
119
12.1M
          accu_i = -u[0];
120
971M
        for (l = 1; l < anal_size; l++) {
121
946M
          accu_r = accu_r + u[0 + l] * analy_cos_sin_tab[2 * l + 0];
122
946M
          accu_i = accu_i + u[2 * anal_size - l] * analy_cos_sin_tab[2 * l + 1];
123
946M
        }
124
24.2M
        analy_cos_sin_tab += (2 * anal_size);
125
24.2M
        *anal_buf++ = (FLOAT32)accu_r;
126
24.2M
        *anal_buf++ = (FLOAT32)accu_i;
127
24.2M
      }
128
4.79M
    } else {
129
4.79M
      FLOAT32 *ptr_u = u_in;
130
4.79M
      FLOAT32 *ptr_v = u_out;
131
205M
      for (k = 0; k < anal_size * 2; k++) {
132
200M
        *ptr_u++ = ((*analy_cos_sin_tab++) * u[k]);
133
200M
        *ptr_u++ = ((*analy_cos_sin_tab++) * u[k]);
134
200M
      }
135
4.79M
      if (ptr_hbe_txposer->ixheaacd_cmplx_anal_fft != NULL)
136
4.79M
        (*(ptr_hbe_txposer->ixheaacd_cmplx_anal_fft))(u_in, u_out,
137
4.79M
                                                      anal_size * 2);
138
0
      else
139
0
        return -1;
140
141
55.0M
      for (k = 0; k < anal_size / 2; k++) {
142
50.2M
        *(anal_buf + 1) = -*ptr_v++;
143
50.2M
        *anal_buf = *ptr_v++;
144
145
50.2M
        anal_buf += 2;
146
147
50.2M
        *(anal_buf + 1) = *ptr_v++;
148
50.2M
        *anal_buf = -*ptr_v++;
149
150
50.2M
        anal_buf += 2;
151
50.2M
      }
152
4.79M
    }
153
5.39M
  }
154
297k
  return 0;
155
297k
}
156
157
WORD32 ixheaacd_real_synth_filt(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
158
                                WORD32 num_columns, FLOAT32 qmf_buf_real[][64],
159
297k
                                FLOAT32 qmf_buf_imag[][64]) {
160
297k
  WORD32 i, j, k, l, idx;
161
297k
  FLOAT32 g[640];
162
297k
  FLOAT32 w[640];
163
297k
  FLOAT32 synth_out[128];
164
297k
  FLOAT32 accu_r;
165
297k
  WORD32 synth_size = ptr_hbe_txposer->synth_size;
166
297k
  FLOAT32 *ptr_cos_tab_trans_qmf =
167
297k
      (FLOAT32 *)&ixheaac_cos_table_trans_qmf[0][0] +
168
297k
      ptr_hbe_txposer->k_start * 32;
169
297k
  FLOAT32 *buffer = ptr_hbe_txposer->synth_buf;
170
297k
  FLOAT32 *ptr_inp_buf = ptr_hbe_txposer->ptr_input_buf + ptr_hbe_txposer->ana_fft_size[0];
171
172
11.0M
  for (idx = 0; idx < num_columns; idx++) {
173
10.7M
    FLOAT32 loc_qmf_buf[64];
174
10.7M
    FLOAT32 *synth_buf_r = loc_qmf_buf;
175
10.7M
    FLOAT32 *out_buf;
176
10.7M
    if (ptr_hbe_txposer->esbr_hq == 1) {
177
0
        out_buf = ptr_inp_buf +
178
0
                  (idx - 1) * ptr_hbe_txposer->synth_size;
179
10.7M
    } else {
180
10.7M
      out_buf = ptr_hbe_txposer->ptr_input_buf +
181
10.7M
                       (idx + 1) * ptr_hbe_txposer->synth_size;
182
10.7M
    }
183
10.7M
    FLOAT32 *synth_cos_tab = ptr_hbe_txposer->synth_cos_tab;
184
10.7M
    const FLOAT32 *interp_window_coeff = ptr_hbe_txposer->synth_wind_coeff;
185
10.7M
    if (ptr_hbe_txposer->k_start < 0) return -1;
186
135M
    for (k = 0; k < synth_size; k++) {
187
124M
      WORD32 ki = ptr_hbe_txposer->k_start + k;
188
124M
      synth_buf_r[k] = (FLOAT32)(
189
124M
          ptr_cos_tab_trans_qmf[(k << 1) + 0] * qmf_buf_real[idx][ki] +
190
124M
          ptr_cos_tab_trans_qmf[(k << 1) + 1] * qmf_buf_imag[idx][ki]);
191
192
124M
      synth_buf_r[k + ptr_hbe_txposer->synth_size] = 0;
193
124M
    }
194
195
2.25G
    for (l = (20 * synth_size - 1); l >= 2 * synth_size; l--) {
196
2.24G
      buffer[l] = buffer[l - 2 * synth_size];
197
2.24G
    }
198
199
10.7M
    if (synth_size == 20) {
200
1.21M
      FLOAT32 *psynth_cos_tab = synth_cos_tab;
201
202
26.7M
      for (l = 0; l < (synth_size + 1); l++) {
203
25.4M
        accu_r = 0.0;
204
535M
        for (k = 0; k < synth_size; k++) {
205
509M
          accu_r += synth_buf_r[k] * psynth_cos_tab[k];
206
509M
        }
207
25.4M
        buffer[0 + l] = accu_r;
208
25.4M
        buffer[synth_size - l] = accu_r;
209
25.4M
        psynth_cos_tab = psynth_cos_tab + synth_size;
210
25.4M
      }
211
12.1M
      for (l = (synth_size + 1); l < (2 * synth_size - synth_size / 2); l++) {
212
10.9M
        accu_r = 0.0;
213
229M
        for (k = 0; k < synth_size; k++) {
214
218M
          accu_r += synth_buf_r[k] * psynth_cos_tab[k];
215
218M
        }
216
10.9M
        buffer[0 + l] = accu_r;
217
10.9M
        buffer[3 * synth_size - l] = -accu_r;
218
10.9M
        psynth_cos_tab = psynth_cos_tab + synth_size;
219
10.9M
      }
220
1.21M
      accu_r = 0.0;
221
25.4M
      for (k = 0; k < synth_size; k++) {
222
24.2M
        accu_r += synth_buf_r[k] * psynth_cos_tab[k];
223
24.2M
      }
224
1.21M
      buffer[3 * synth_size >> 1] = accu_r;
225
9.58M
    } else {
226
9.58M
      FLOAT32 tmp;
227
9.58M
      FLOAT32 *ptr_u = synth_out;
228
9.58M
      WORD32 kmax = (synth_size >> 1);
229
9.58M
      FLOAT32 *syn_buf = &buffer[kmax];
230
9.58M
      kmax += synth_size;
231
232
9.58M
      if (ptr_hbe_txposer->ixheaacd_real_synth_fft != NULL)
233
9.58M
        (*(ptr_hbe_txposer->ixheaacd_real_synth_fft))(synth_buf_r, synth_out,
234
9.58M
                                                      synth_size * 2);
235
4
      else
236
4
        return -1;
237
238
160M
      for (k = 0; k < kmax; k++) {
239
150M
        tmp = ((*ptr_u++) * (*synth_cos_tab++));
240
150M
        tmp -= ((*ptr_u++) * (*synth_cos_tab++));
241
150M
        *syn_buf++ = tmp;
242
150M
      }
243
244
9.58M
      syn_buf = &buffer[0];
245
9.58M
      kmax -= synth_size;
246
247
59.7M
      for (k = 0; k < kmax; k++) {
248
50.2M
        tmp = ((*ptr_u++) * (*synth_cos_tab++));
249
50.2M
        tmp -= ((*ptr_u++) * (*synth_cos_tab++));
250
50.2M
        *syn_buf++ = tmp;
251
50.2M
      }
252
9.58M
    }
253
254
64.7M
    for (i = 0; i < 5; i++) {
255
53.9M
      memcpy(&g[(2 * i + 0) * synth_size], &buffer[(4 * i + 0) * synth_size],
256
53.9M
             sizeof(FLOAT32) * synth_size);
257
53.9M
      memcpy(&g[(2 * i + 1) * synth_size], &buffer[(4 * i + 3) * synth_size],
258
53.9M
             sizeof(FLOAT32) * synth_size);
259
53.9M
    }
260
261
1.25G
    for (k = 0; k < 10 * synth_size; k++) {
262
1.24G
      w[k] = g[k] * interp_window_coeff[k];
263
1.24G
    }
264
265
135M
    for (i = 0; i < synth_size; i++) {
266
124M
      accu_r = 0.0;
267
1.37G
      for (j = 0; j < 10; j++) {
268
1.24G
        accu_r = accu_r + w[synth_size * j + i];
269
1.24G
      }
270
124M
      out_buf[i] = (FLOAT32)accu_r;
271
124M
    }
272
10.7M
  }
273
297k
  return 0;
274
297k
}
275
276
WORD32 ixheaacd_dft_hbe_cplx_anal_filt(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
277
                                       FLOAT32 qmf_buf_real[][64],
278
0
                                       FLOAT32 qmf_buf_imag[][64]) {
279
0
  WORD32 idx;
280
281
0
  WORD32 anal_size = ptr_hbe_txposer->analy_size;
282
283
0
  WORD32 N = (10 * ptr_hbe_txposer->analy_size);
284
285
0
  for (idx = 0; idx < ptr_hbe_txposer->no_bins; idx++) {
286
0
    WORD32 i, j, k, l;
287
0
    FLOAT32 window_output[640];
288
0
    FLOAT32 u[128];
289
0
    FLOAT32 accu_r, accu_i;
290
0
    const FLOAT32 *inp_signal;
291
0
    FLOAT32 *qmf_buf_r = &qmf_buf_real[idx][ptr_hbe_txposer->a_start];
292
0
    FLOAT32 *qmf_buf_i = &qmf_buf_imag[idx][ptr_hbe_txposer->a_start];
293
294
0
    const FLOAT32 *interp_window_coeff = ptr_hbe_txposer->analy_wind_coeff;
295
0
    FLOAT32 *x = ptr_hbe_txposer->analy_buf;
296
297
0
    memset(&qmf_buf_real[idx][ptr_hbe_txposer->a_start], 0,
298
0
        (NO_QMF_SYNTH_CHANNELS - ptr_hbe_txposer->a_start) *
299
0
        sizeof(qmf_buf_real[idx][ptr_hbe_txposer->a_start]));
300
0
    memset(&qmf_buf_imag[idx][ptr_hbe_txposer->a_start], 0,
301
0
        TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(qmf_buf_imag[idx][ptr_hbe_txposer->a_start]));
302
303
0
    inp_signal = ptr_hbe_txposer->ptr_output_buf +
304
0
        idx * ptr_hbe_txposer->analy_size + 1;
305
306
0
    for (i = N - 1; i >= anal_size; i--) {
307
0
        x[i] = x[i - anal_size];
308
0
    }
309
310
0
    for (i = anal_size - 1; i >= 0; i--) {
311
0
        x[i] = inp_signal[anal_size - 1 - i];
312
0
    }
313
314
0
    for (i = 0; i < N; i++) {
315
0
        window_output[i] = x[i] * interp_window_coeff[i];
316
0
    }
317
318
0
    for (i = 0; i < 2 * anal_size; i++) {
319
0
      accu_r = 0.0;
320
0
      for (j = 0; j < 5; j++) {
321
0
        accu_r = accu_r + window_output[i + j * 2 * anal_size];
322
0
      }
323
0
      u[i] = accu_r;
324
0
    }
325
326
0
    for (k = 0; k < anal_size; k++) {
327
0
      accu_r = 0;
328
0
      accu_i = 0;
329
0
      for (l = 0; l < 2 * anal_size; l++) {
330
0
        accu_r = accu_r + u[l] * ptr_hbe_txposer->str_dft_hbe_anal_coeff.real[k][l];
331
0
        accu_i = accu_i + u[l] * ptr_hbe_txposer->str_dft_hbe_anal_coeff.imag[k][l];
332
0
      }
333
0
      qmf_buf_r[k] = (FLOAT32)accu_r;
334
0
      qmf_buf_i[k] = (FLOAT32)accu_i;
335
0
    }
336
0
  }
337
0
  return 0;
338
0
}