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 "ixheaacd_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 "ixheaacd_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 "ixheaacd_esbr_rom.h"
47
ixheaacd_complex_anal_filt(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer)48 WORD32 ixheaacd_complex_anal_filt(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer) {
49 WORD32 idx;
50 WORD32 anal_size = 2 * ptr_hbe_txposer->synth_size;
51 WORD32 N = (10 * anal_size);
52
53 for (idx = 0; idx < (ptr_hbe_txposer->no_bins >> 1); idx++) {
54 WORD32 i, j, k, l;
55 FLOAT32 window_output[640];
56 FLOAT32 u[128], u_in[256], u_out[256];
57 FLOAT32 accu_r, accu_i;
58 const FLOAT32 *inp_signal;
59 FLOAT32 *anal_buf;
60
61 FLOAT32 *analy_cos_sin_tab = ptr_hbe_txposer->analy_cos_sin_tab;
62 const FLOAT32 *interp_window_coeff = ptr_hbe_txposer->analy_wind_coeff;
63 FLOAT32 *x = ptr_hbe_txposer->analy_buf;
64
65 memset(ptr_hbe_txposer->qmf_in_buf[idx + HBE_OPER_WIN_LEN - 1], 0,
66 TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32));
67
68 inp_signal = ptr_hbe_txposer->ptr_input_buf +
69 idx * 2 * ptr_hbe_txposer->synth_size + 1;
70 anal_buf = &ptr_hbe_txposer->qmf_in_buf[idx + HBE_OPER_WIN_LEN - 1]
71 [4 * ptr_hbe_txposer->k_start];
72
73 for (i = N - 1; i >= anal_size; i--) {
74 x[i] = x[i - anal_size];
75 }
76
77 for (i = anal_size - 1; i >= 0; i--) {
78 x[i] = inp_signal[anal_size - 1 - i];
79 }
80
81 for (i = 0; i < N; i++) {
82 window_output[i] = x[i] * interp_window_coeff[i];
83 }
84
85 for (i = 0; i < 2 * anal_size; i++) {
86 accu_r = 0.0;
87 for (j = 0; j < 5; j++) {
88 accu_r = accu_r + window_output[i + j * 2 * anal_size];
89 }
90 u[i] = accu_r;
91 }
92
93 if (anal_size == 40) {
94 for (i = 1; i < anal_size; i++) {
95 FLOAT32 temp1 = u[i] + u[2 * anal_size - i];
96 FLOAT32 temp2 = u[i] - u[2 * anal_size - i];
97 u[i] = temp1;
98 u[2 * anal_size - i] = temp2;
99 }
100
101 for (k = 0; k < anal_size; k++) {
102 accu_r = u[anal_size];
103 if (k & 1)
104 accu_i = u[0];
105 else
106 accu_i = -u[0];
107 for (l = 1; l < anal_size; l++) {
108 accu_r = accu_r + u[0 + l] * analy_cos_sin_tab[2 * l + 0];
109 accu_i = accu_i + u[2 * anal_size - l] * analy_cos_sin_tab[2 * l + 1];
110 }
111 analy_cos_sin_tab += (2 * anal_size);
112 *anal_buf++ = (FLOAT32)accu_r;
113 *anal_buf++ = (FLOAT32)accu_i;
114 }
115 } else {
116 FLOAT32 *ptr_u = u_in;
117 FLOAT32 *ptr_v = u_out;
118 for (k = 0; k < anal_size * 2; k++) {
119 *ptr_u++ = ((*analy_cos_sin_tab++) * u[k]);
120 *ptr_u++ = ((*analy_cos_sin_tab++) * u[k]);
121 }
122 if (ptr_hbe_txposer->ixheaacd_cmplx_anal_fft != NULL)
123 (*(ptr_hbe_txposer->ixheaacd_cmplx_anal_fft))(u_in, u_out,
124 anal_size * 2);
125 else
126 return -1;
127
128 for (k = 0; k < anal_size / 2; k++) {
129 *(anal_buf + 1) = -*ptr_v++;
130 *anal_buf = *ptr_v++;
131
132 anal_buf += 2;
133
134 *(anal_buf + 1) = *ptr_v++;
135 *anal_buf = -*ptr_v++;
136
137 anal_buf += 2;
138 }
139 }
140 }
141 return 0;
142 }
143
ixheaacd_real_synth_filt(ia_esbr_hbe_txposer_struct * ptr_hbe_txposer,WORD32 num_columns,FLOAT32 qmf_buf_real[][64],FLOAT32 qmf_buf_imag[][64])144 WORD32 ixheaacd_real_synth_filt(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
145 WORD32 num_columns, FLOAT32 qmf_buf_real[][64],
146 FLOAT32 qmf_buf_imag[][64]) {
147 WORD32 i, j, k, l, idx;
148 FLOAT32 g[640];
149 FLOAT32 w[640];
150 FLOAT32 synth_out[128];
151 FLOAT32 accu_r;
152 WORD32 synth_size = ptr_hbe_txposer->synth_size;
153 FLOAT32 *ptr_cos_tab_trans_qmf =
154 (FLOAT32 *)&ixheaacd_cos_table_trans_qmf[0][0] +
155 ptr_hbe_txposer->k_start * 32;
156 FLOAT32 *buffer = ptr_hbe_txposer->synth_buf;
157
158 for (idx = 0; idx < num_columns; idx++) {
159 FLOAT32 loc_qmf_buf[64];
160 FLOAT32 *synth_buf_r = loc_qmf_buf;
161 FLOAT32 *out_buf = ptr_hbe_txposer->ptr_input_buf +
162 (idx + 1) * ptr_hbe_txposer->synth_size;
163 FLOAT32 *synth_cos_tab = ptr_hbe_txposer->synth_cos_tab;
164 const FLOAT32 *interp_window_coeff = ptr_hbe_txposer->synth_wind_coeff;
165 if (ptr_hbe_txposer->k_start < 0) return -1;
166 for (k = 0; k < synth_size; k++) {
167 WORD32 ki = ptr_hbe_txposer->k_start + k;
168 synth_buf_r[k] = (FLOAT32)(
169 ptr_cos_tab_trans_qmf[(k << 1) + 0] * qmf_buf_real[idx][ki] +
170 ptr_cos_tab_trans_qmf[(k << 1) + 1] * qmf_buf_imag[idx][ki]);
171
172 synth_buf_r[k + ptr_hbe_txposer->synth_size] = 0;
173 }
174
175 for (l = (20 * synth_size - 1); l >= 2 * synth_size; l--) {
176 buffer[l] = buffer[l - 2 * synth_size];
177 }
178
179 if (synth_size == 20) {
180 FLOAT32 *psynth_cos_tab = synth_cos_tab;
181
182 for (l = 0; l < (synth_size + 1); l++) {
183 accu_r = 0.0;
184 for (k = 0; k < synth_size; k++) {
185 accu_r += synth_buf_r[k] * psynth_cos_tab[k];
186 }
187 buffer[0 + l] = accu_r;
188 buffer[synth_size - l] = accu_r;
189 psynth_cos_tab = psynth_cos_tab + synth_size;
190 }
191 for (l = (synth_size + 1); l < (2 * synth_size - synth_size / 2); l++) {
192 accu_r = 0.0;
193 for (k = 0; k < synth_size; k++) {
194 accu_r += synth_buf_r[k] * psynth_cos_tab[k];
195 }
196 buffer[0 + l] = accu_r;
197 buffer[3 * synth_size - l] = -accu_r;
198 psynth_cos_tab = psynth_cos_tab + synth_size;
199 }
200 accu_r = 0.0;
201 for (k = 0; k < synth_size; k++) {
202 accu_r += synth_buf_r[k] * psynth_cos_tab[k];
203 }
204 buffer[3 * synth_size >> 1] = accu_r;
205 } else {
206 FLOAT32 tmp;
207 FLOAT32 *ptr_u = synth_out;
208 WORD32 kmax = (synth_size >> 1);
209 FLOAT32 *syn_buf = &buffer[kmax];
210 kmax += synth_size;
211
212 if (ptr_hbe_txposer->ixheaacd_real_synth_fft != NULL)
213 (*(ptr_hbe_txposer->ixheaacd_real_synth_fft))(synth_buf_r, synth_out,
214 synth_size * 2);
215 else
216 return -1;
217
218 for (k = 0; k < kmax; k++) {
219 tmp = ((*ptr_u++) * (*synth_cos_tab++));
220 tmp -= ((*ptr_u++) * (*synth_cos_tab++));
221 *syn_buf++ = tmp;
222 }
223
224 syn_buf = &buffer[0];
225 kmax -= synth_size;
226
227 for (k = 0; k < kmax; k++) {
228 tmp = ((*ptr_u++) * (*synth_cos_tab++));
229 tmp -= ((*ptr_u++) * (*synth_cos_tab++));
230 *syn_buf++ = tmp;
231 }
232 }
233
234 for (i = 0; i < 5; i++) {
235 memcpy(&g[(2 * i + 0) * synth_size], &buffer[(4 * i + 0) * synth_size],
236 sizeof(FLOAT32) * synth_size);
237 memcpy(&g[(2 * i + 1) * synth_size], &buffer[(4 * i + 3) * synth_size],
238 sizeof(FLOAT32) * synth_size);
239 }
240
241 for (k = 0; k < 10 * synth_size; k++) {
242 w[k] = g[k] * interp_window_coeff[k];
243 }
244
245 for (i = 0; i < synth_size; i++) {
246 accu_r = 0.0;
247 for (j = 0; j < 10; j++) {
248 accu_r = accu_r + w[synth_size * j + i];
249 }
250 out_buf[i] = (FLOAT32)accu_r;
251 }
252 }
253 return 0;
254 }