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