/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 | 318k | WORD32 ixheaacd_complex_anal_filt(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer) { |
49 | 318k | WORD32 idx; |
50 | 318k | WORD32 anal_size = 2 * ptr_hbe_txposer->synth_size; |
51 | 318k | WORD32 N = (10 * anal_size); |
52 | 318k | WORD32 no_bins = ptr_hbe_txposer->no_bins >> 1; |
53 | | |
54 | 318k | 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.97M | for (idx = 0; idx < no_bins; idx++) { |
60 | 5.65M | WORD32 i, j, k, l; |
61 | 5.65M | FLOAT32 window_output[640]; |
62 | 5.65M | FLOAT32 u[128], u_in[256], u_out[256]; |
63 | 5.65M | FLOAT32 accu_r, accu_i; |
64 | 5.65M | const FLOAT32 *inp_signal; |
65 | 5.65M | FLOAT32 *anal_buf; |
66 | | |
67 | 5.65M | FLOAT32 *analy_cos_sin_tab = ptr_hbe_txposer->analy_cos_sin_tab; |
68 | 5.65M | const FLOAT32 *interp_window_coeff = ptr_hbe_txposer->analy_wind_coeff; |
69 | 5.65M | FLOAT32 *x = ptr_hbe_txposer->analy_buf; |
70 | 5.65M | 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.65M | } else { |
78 | 5.65M | memset(ptr_hbe_txposer->qmf_in_buf[idx + HBE_OPER_WIN_LEN - 1], 0, |
79 | 5.65M | TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32)); |
80 | | |
81 | 5.65M | inp_signal = ptr_hbe_txposer->ptr_input_buf + |
82 | 5.65M | idx * 2 * ptr_hbe_txposer->synth_size + 1; |
83 | 5.65M | anal_buf = &ptr_hbe_txposer->qmf_in_buf[idx + HBE_OPER_WIN_LEN - 1] |
84 | 5.65M | [4 * ptr_hbe_txposer->k_start]; |
85 | 5.65M | } |
86 | | |
87 | 1.17G | for (i = N - 1; i >= anal_size; i--) { |
88 | 1.16G | x[i] = x[i - anal_size]; |
89 | 1.16G | } |
90 | | |
91 | 135M | for (i = anal_size - 1; i >= 0; i--) { |
92 | 129M | x[i] = inp_signal[anal_size - 1 - i]; |
93 | 129M | } |
94 | | |
95 | 1.30G | for (i = 0; i < N; i++) { |
96 | 1.29G | window_output[i] = x[i] * interp_window_coeff[i]; |
97 | 1.29G | } |
98 | | |
99 | 265M | for (i = 0; i < 2 * anal_size; i++) { |
100 | 259M | accu_r = 0.0; |
101 | 1.55G | for (j = 0; j < 5; j++) { |
102 | 1.29G | accu_r = accu_r + window_output[i + j * 2 * anal_size]; |
103 | 1.29G | } |
104 | 259M | u[i] = accu_r; |
105 | 259M | } |
106 | 5.65M | if (anal_size == 40 || anal_size == 56) { |
107 | 28.2M | for (i = 1; i < anal_size; i++) { |
108 | 27.5M | FLOAT32 temp1 = u[i] + u[2 * anal_size - i]; |
109 | 27.5M | FLOAT32 temp2 = u[i] - u[2 * anal_size - i]; |
110 | 27.5M | u[i] = temp1; |
111 | 27.5M | u[2 * anal_size - i] = temp2; |
112 | 27.5M | } |
113 | | |
114 | 28.9M | for (k = 0; k < anal_size; k++) { |
115 | 28.2M | accu_r = u[anal_size]; |
116 | 28.2M | if (k & 1) |
117 | 14.1M | accu_i = u[0]; |
118 | 14.1M | else |
119 | 14.1M | accu_i = -u[0]; |
120 | 1.12G | for (l = 1; l < anal_size; l++) { |
121 | 1.10G | accu_r = accu_r + u[0 + l] * analy_cos_sin_tab[2 * l + 0]; |
122 | 1.10G | accu_i = accu_i + u[2 * anal_size - l] * analy_cos_sin_tab[2 * l + 1]; |
123 | 1.10G | } |
124 | 28.2M | analy_cos_sin_tab += (2 * anal_size); |
125 | 28.2M | *anal_buf++ = (FLOAT32)accu_r; |
126 | 28.2M | *anal_buf++ = (FLOAT32)accu_i; |
127 | 28.2M | } |
128 | 4.94M | } else { |
129 | 4.94M | FLOAT32 *ptr_u = u_in; |
130 | 4.94M | FLOAT32 *ptr_v = u_out; |
131 | 208M | for (k = 0; k < anal_size * 2; k++) { |
132 | 203M | *ptr_u++ = ((*analy_cos_sin_tab++) * u[k]); |
133 | 203M | *ptr_u++ = ((*analy_cos_sin_tab++) * u[k]); |
134 | 203M | } |
135 | 4.94M | if (ptr_hbe_txposer->ixheaacd_cmplx_anal_fft != NULL) |
136 | 4.94M | (*(ptr_hbe_txposer->ixheaacd_cmplx_anal_fft))(u_in, u_out, |
137 | 4.94M | anal_size * 2); |
138 | 0 | else |
139 | 0 | return -1; |
140 | | |
141 | 55.8M | for (k = 0; k < anal_size / 2; k++) { |
142 | 50.8M | *(anal_buf + 1) = -*ptr_v++; |
143 | 50.8M | *anal_buf = *ptr_v++; |
144 | | |
145 | 50.8M | anal_buf += 2; |
146 | | |
147 | 50.8M | *(anal_buf + 1) = *ptr_v++; |
148 | 50.8M | *anal_buf = -*ptr_v++; |
149 | | |
150 | 50.8M | anal_buf += 2; |
151 | 50.8M | } |
152 | 4.94M | } |
153 | 5.65M | } |
154 | 318k | return 0; |
155 | 318k | } |
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 | 318k | FLOAT32 qmf_buf_imag[][64]) { |
160 | 318k | WORD32 i, j, k, l, idx; |
161 | 318k | FLOAT32 g[640]; |
162 | 318k | FLOAT32 w[640]; |
163 | 318k | FLOAT32 synth_out[128]; |
164 | 318k | FLOAT32 accu_r; |
165 | 318k | WORD32 synth_size = ptr_hbe_txposer->synth_size; |
166 | 318k | FLOAT32 *ptr_cos_tab_trans_qmf = |
167 | 318k | (FLOAT32 *)&ixheaac_cos_table_trans_qmf[0][0] + |
168 | 318k | ptr_hbe_txposer->k_start * 32; |
169 | 318k | FLOAT32 *buffer = ptr_hbe_txposer->synth_buf; |
170 | 318k | FLOAT32 *ptr_inp_buf = ptr_hbe_txposer->ptr_input_buf + ptr_hbe_txposer->ana_fft_size[0]; |
171 | | |
172 | 11.6M | for (idx = 0; idx < num_columns; idx++) { |
173 | 11.3M | FLOAT32 loc_qmf_buf[64]; |
174 | 11.3M | FLOAT32 *synth_buf_r = loc_qmf_buf; |
175 | 11.3M | FLOAT32 *out_buf; |
176 | 11.3M | if (ptr_hbe_txposer->esbr_hq == 1) { |
177 | 0 | out_buf = ptr_inp_buf + |
178 | 0 | (idx - 1) * ptr_hbe_txposer->synth_size; |
179 | 11.3M | } else { |
180 | 11.3M | out_buf = ptr_hbe_txposer->ptr_input_buf + |
181 | 11.3M | (idx + 1) * ptr_hbe_txposer->synth_size; |
182 | 11.3M | } |
183 | 11.3M | FLOAT32 *synth_cos_tab = ptr_hbe_txposer->synth_cos_tab; |
184 | 11.3M | const FLOAT32 *interp_window_coeff = ptr_hbe_txposer->synth_wind_coeff; |
185 | 11.3M | if (ptr_hbe_txposer->k_start < 0) return -1; |
186 | 141M | for (k = 0; k < synth_size; k++) { |
187 | 129M | WORD32 ki = ptr_hbe_txposer->k_start + k; |
188 | 129M | synth_buf_r[k] = (FLOAT32)( |
189 | 129M | ptr_cos_tab_trans_qmf[(k << 1) + 0] * qmf_buf_real[idx][ki] + |
190 | 129M | ptr_cos_tab_trans_qmf[(k << 1) + 1] * qmf_buf_imag[idx][ki]); |
191 | | |
192 | 129M | synth_buf_r[k + ptr_hbe_txposer->synth_size] = 0; |
193 | 129M | } |
194 | | |
195 | 2.35G | for (l = (20 * synth_size - 1); l >= 2 * synth_size; l--) { |
196 | 2.33G | buffer[l] = buffer[l - 2 * synth_size]; |
197 | 2.33G | } |
198 | | |
199 | 11.3M | if (synth_size == 20) { |
200 | 1.41M | FLOAT32 *psynth_cos_tab = synth_cos_tab; |
201 | | |
202 | 31.0M | for (l = 0; l < (synth_size + 1); l++) { |
203 | 29.6M | accu_r = 0.0; |
204 | 622M | for (k = 0; k < synth_size; k++) { |
205 | 593M | accu_r += synth_buf_r[k] * psynth_cos_tab[k]; |
206 | 593M | } |
207 | 29.6M | buffer[0 + l] = accu_r; |
208 | 29.6M | buffer[synth_size - l] = accu_r; |
209 | 29.6M | psynth_cos_tab = psynth_cos_tab + synth_size; |
210 | 29.6M | } |
211 | 14.1M | for (l = (synth_size + 1); l < (2 * synth_size - synth_size / 2); l++) { |
212 | 12.7M | accu_r = 0.0; |
213 | 266M | for (k = 0; k < synth_size; k++) { |
214 | 254M | accu_r += synth_buf_r[k] * psynth_cos_tab[k]; |
215 | 254M | } |
216 | 12.7M | buffer[0 + l] = accu_r; |
217 | 12.7M | buffer[3 * synth_size - l] = -accu_r; |
218 | 12.7M | psynth_cos_tab = psynth_cos_tab + synth_size; |
219 | 12.7M | } |
220 | 1.41M | accu_r = 0.0; |
221 | 29.6M | for (k = 0; k < synth_size; k++) { |
222 | 28.2M | accu_r += synth_buf_r[k] * psynth_cos_tab[k]; |
223 | 28.2M | } |
224 | 1.41M | buffer[3 * synth_size >> 1] = accu_r; |
225 | 9.89M | } else { |
226 | 9.89M | FLOAT32 tmp; |
227 | 9.89M | FLOAT32 *ptr_u = synth_out; |
228 | 9.89M | WORD32 kmax = (synth_size >> 1); |
229 | 9.89M | FLOAT32 *syn_buf = &buffer[kmax]; |
230 | 9.89M | kmax += synth_size; |
231 | | |
232 | 9.89M | if (ptr_hbe_txposer->ixheaacd_real_synth_fft != NULL) |
233 | 9.89M | (*(ptr_hbe_txposer->ixheaacd_real_synth_fft))(synth_buf_r, synth_out, |
234 | 9.89M | synth_size * 2); |
235 | 5 | else |
236 | 5 | return -1; |
237 | | |
238 | 162M | for (k = 0; k < kmax; k++) { |
239 | 152M | tmp = ((*ptr_u++) * (*synth_cos_tab++)); |
240 | 152M | tmp -= ((*ptr_u++) * (*synth_cos_tab++)); |
241 | 152M | *syn_buf++ = tmp; |
242 | 152M | } |
243 | | |
244 | 9.89M | syn_buf = &buffer[0]; |
245 | 9.89M | kmax -= synth_size; |
246 | | |
247 | 60.7M | for (k = 0; k < kmax; k++) { |
248 | 50.8M | tmp = ((*ptr_u++) * (*synth_cos_tab++)); |
249 | 50.8M | tmp -= ((*ptr_u++) * (*synth_cos_tab++)); |
250 | 50.8M | *syn_buf++ = tmp; |
251 | 50.8M | } |
252 | 9.89M | } |
253 | | |
254 | 67.8M | for (i = 0; i < 5; i++) { |
255 | 56.5M | memcpy(&g[(2 * i + 0) * synth_size], &buffer[(4 * i + 0) * synth_size], |
256 | 56.5M | sizeof(FLOAT32) * synth_size); |
257 | 56.5M | memcpy(&g[(2 * i + 1) * synth_size], &buffer[(4 * i + 3) * synth_size], |
258 | 56.5M | sizeof(FLOAT32) * synth_size); |
259 | 56.5M | } |
260 | | |
261 | 1.31G | for (k = 0; k < 10 * synth_size; k++) { |
262 | 1.29G | w[k] = g[k] * interp_window_coeff[k]; |
263 | 1.29G | } |
264 | | |
265 | 141M | for (i = 0; i < synth_size; i++) { |
266 | 129M | accu_r = 0.0; |
267 | 1.42G | for (j = 0; j < 10; j++) { |
268 | 1.29G | accu_r = accu_r + w[synth_size * j + i]; |
269 | 1.29G | } |
270 | 129M | out_buf[i] = (FLOAT32)accu_r; |
271 | 129M | } |
272 | 11.3M | } |
273 | 318k | return 0; |
274 | 318k | } |
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 | } |