10725
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
|
|
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
|
|
4 **
|
|
5 ** This program is free software; you can redistribute it and/or modify
|
|
6 ** it under the terms of the GNU General Public License as published by
|
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
|
8 ** (at your option) any later version.
|
|
9 **
|
|
10 ** This program is distributed in the hope that it will be useful,
|
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ** GNU General Public License for more details.
|
|
14 **
|
|
15 ** You should have received a copy of the GNU General Public License
|
|
16 ** along with this program; if not, write to the Free Software
|
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 **
|
|
19 ** Any non-GPL usage of this software or parts of this software is strictly
|
|
20 ** forbidden.
|
|
21 **
|
|
22 ** Commercial non-GPL licensing of this software is possible.
|
|
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
|
|
24 **
|
10989
|
25 ** $Id: sbr_qmf.c,v 1.13 2003/09/30 12:43:05 menno Exp $
|
10725
|
26 **/
|
|
27
|
|
28 #include "common.h"
|
|
29 #include "structs.h"
|
|
30
|
|
31 #ifdef SBR_DEC
|
|
32
|
|
33
|
|
34 #include <stdlib.h>
|
|
35 #include <string.h>
|
|
36 #include "sbr_dct.h"
|
|
37 #include "sbr_qmf.h"
|
10989
|
38 #include "sbr_qmf_c.h"
|
10725
|
39 #include "sbr_syntax.h"
|
|
40
|
|
41
|
|
42 qmfa_info *qmfa_init(uint8_t channels)
|
|
43 {
|
|
44 qmfa_info *qmfa = (qmfa_info*)malloc(sizeof(qmfa_info));
|
|
45 qmfa->x = (real_t*)malloc(channels * 10 * sizeof(real_t));
|
|
46 memset(qmfa->x, 0, channels * 10 * sizeof(real_t));
|
|
47
|
|
48 qmfa->channels = channels;
|
|
49
|
|
50 return qmfa;
|
|
51 }
|
|
52
|
|
53 void qmfa_end(qmfa_info *qmfa)
|
|
54 {
|
|
55 if (qmfa)
|
|
56 {
|
|
57 if (qmfa->x) free(qmfa->x);
|
|
58 free(qmfa);
|
|
59 }
|
|
60 }
|
|
61
|
10989
|
62 void sbr_qmf_analysis_32(sbr_info *sbr, qmfa_info *qmfa, const real_t *input,
|
|
63 qmf_t *X, uint8_t offset, uint8_t kx)
|
10725
|
64 {
|
|
65 uint8_t l;
|
|
66 real_t u[64];
|
|
67 #ifndef SBR_LOW_POWER
|
|
68 real_t x[64], y[64];
|
|
69 #else
|
|
70 real_t y[32];
|
|
71 #endif
|
|
72 const real_t *inptr = input;
|
|
73
|
|
74 /* qmf subsample l */
|
10989
|
75 for (l = 0; l < sbr->numTimeSlotsRate; l++)
|
10725
|
76 {
|
|
77 int16_t n;
|
|
78
|
|
79 /* shift input buffer x */
|
|
80 memmove(qmfa->x + 32, qmfa->x, (320-32)*sizeof(real_t));
|
|
81
|
|
82 /* add new samples to input buffer x */
|
|
83 for (n = 32 - 1; n >= 0; n--)
|
|
84 {
|
|
85 #ifdef FIXED_POINT
|
|
86 qmfa->x[n] = (*inptr++) >> 5;
|
|
87 #else
|
|
88 qmfa->x[n] = *inptr++;
|
|
89 #endif
|
|
90 }
|
|
91
|
|
92 /* window and summation to create array u */
|
|
93 for (n = 0; n < 64; n++)
|
|
94 {
|
10989
|
95 u[n] = MUL_R_C(qmfa->x[n], qmf_c[2*n]) +
|
|
96 MUL_R_C(qmfa->x[n + 64], qmf_c[2*(n + 64)]) +
|
|
97 MUL_R_C(qmfa->x[n + 128], qmf_c[2*(n + 128)]) +
|
|
98 MUL_R_C(qmfa->x[n + 192], qmf_c[2*(n + 192)]) +
|
|
99 MUL_R_C(qmfa->x[n + 256], qmf_c[2*(n + 256)]);
|
10725
|
100 }
|
|
101
|
|
102 /* calculate 32 subband samples by introducing X */
|
|
103 #ifdef SBR_LOW_POWER
|
|
104 y[0] = u[48];
|
|
105 for (n = 1; n < 16; n++)
|
|
106 y[n] = u[n+48] + u[48-n];
|
|
107 for (n = 16; n < 32; n++)
|
|
108 y[n] = -u[n-16] + u[48-n];
|
|
109
|
|
110 DCT3_32_unscaled(u, y);
|
|
111
|
|
112 for (n = 0; n < 32; n++)
|
|
113 {
|
10989
|
114 if (n < kx)
|
|
115 {
|
10725
|
116 #ifdef FIXED_POINT
|
|
117 QMF_RE(X[((l + offset)<<5) + n]) = u[n] << 1;
|
|
118 #else
|
|
119 QMF_RE(X[((l + offset)<<5) + n]) = 2. * u[n];
|
|
120 #endif
|
10989
|
121 } else {
|
|
122 QMF_RE(X[((l + offset)<<5) + n]) = 0;
|
10725
|
123 }
|
|
124 }
|
|
125 #else
|
|
126 x[0] = u[0];
|
|
127 x[63] = u[32];
|
|
128 for (n = 2; n < 64; n += 2)
|
|
129 {
|
|
130 x[n-1] = u[(n>>1)];
|
|
131 x[n] = -u[64-(n>>1)];
|
|
132 }
|
|
133
|
|
134 DCT4_64(y, x);
|
|
135
|
|
136 for (n = 0; n < 32; n++)
|
|
137 {
|
10989
|
138 if (n < kx)
|
|
139 {
|
10725
|
140 #ifdef FIXED_POINT
|
|
141 QMF_RE(X[((l + offset)<<5) + n]) = y[n] << 1;
|
|
142 QMF_IM(X[((l + offset)<<5) + n]) = -y[63-n] << 1;
|
|
143 #else
|
|
144 QMF_RE(X[((l + offset)<<5) + n]) = 2. * y[n];
|
|
145 QMF_IM(X[((l + offset)<<5) + n]) = -2. * y[63-n];
|
|
146 #endif
|
10989
|
147 } else {
|
|
148 QMF_RE(X[((l + offset)<<5) + n]) = 0;
|
|
149 QMF_IM(X[((l + offset)<<5) + n]) = 0;
|
10725
|
150 }
|
|
151 }
|
|
152 #endif
|
|
153 }
|
|
154 }
|
|
155
|
|
156 qmfs_info *qmfs_init(uint8_t channels)
|
|
157 {
|
|
158 int size = 0;
|
|
159 qmfs_info *qmfs = (qmfs_info*)malloc(sizeof(qmfs_info));
|
10989
|
160
|
|
161 qmfs->v[0] = (real_t*)malloc(channels * 10 * sizeof(real_t));
|
|
162 memset(qmfs->v[0], 0, channels * 10 * sizeof(real_t));
|
|
163 qmfs->v[1] = (real_t*)malloc(channels * 10 * sizeof(real_t));
|
|
164 memset(qmfs->v[1], 0, channels * 10 * sizeof(real_t));
|
|
165
|
|
166 qmfs->v_index = 0;
|
10725
|
167
|
|
168 qmfs->channels = channels;
|
|
169
|
|
170 return qmfs;
|
|
171 }
|
|
172
|
|
173 void qmfs_end(qmfs_info *qmfs)
|
|
174 {
|
|
175 if (qmfs)
|
|
176 {
|
10989
|
177 if (qmfs->v[0]) free(qmfs->v[0]);
|
|
178 if (qmfs->v[1]) free(qmfs->v[1]);
|
10725
|
179 free(qmfs);
|
|
180 }
|
|
181 }
|
|
182
|
10989
|
183 #ifdef SBR_LOW_POWER
|
|
184 void sbr_qmf_synthesis_64(sbr_info *sbr, qmfs_info *qmfs, const qmf_t *X,
|
10725
|
185 real_t *output)
|
|
186 {
|
|
187 uint8_t l;
|
|
188 int16_t n, k;
|
|
189 real_t x[64];
|
|
190 real_t *outptr = output;
|
|
191
|
|
192
|
|
193 /* qmf subsample l */
|
10989
|
194 for (l = 0; l < sbr->numTimeSlotsRate; l++)
|
|
195 {
|
|
196 real_t *v0, *v1;
|
|
197
|
|
198 /* shift buffers */
|
|
199 memmove(qmfs->v[0] + 64, qmfs->v[0], (640-64)*sizeof(real_t));
|
|
200 memmove(qmfs->v[1] + 64, qmfs->v[1], (640-64)*sizeof(real_t));
|
|
201
|
|
202 v0 = qmfs->v[qmfs->v_index];
|
|
203 v1 = qmfs->v[(qmfs->v_index + 1) & 0x1];
|
|
204 qmfs->v_index = (qmfs->v_index + 1) & 0x1;
|
10725
|
205
|
|
206 /* calculate 128 samples */
|
|
207 for (k = 0; k < 64; k++)
|
|
208 {
|
|
209 #ifdef FIXED_POINT
|
|
210 x[k] = QMF_RE(X[(l<<6) + k]);
|
|
211 #else
|
|
212 x[k] = QMF_RE(X[(l<<6) + k]) / 32.;
|
|
213 #endif
|
|
214 }
|
|
215
|
|
216 DCT2_64_unscaled(x, x);
|
|
217
|
10989
|
218 for (n = 0; n < 32; n++)
|
10725
|
219 {
|
10989
|
220 v0[n+32] = x[n];
|
|
221 v1[n] = x[n+32];
|
10725
|
222 }
|
10989
|
223 v0[0] = v1[0];
|
|
224 for (n = 1; n < 32; n++)
|
|
225 {
|
|
226 v0[32 - n] = v0[n + 32];
|
|
227 v1[n + 32] = -v1[32 - n];
|
|
228 }
|
|
229 v1[32] = 0;
|
10725
|
230
|
|
231 /* calculate 64 output samples and window */
|
|
232 for (k = 0; k < 64; k++)
|
|
233 {
|
10989
|
234 *outptr++ = MUL_R_C(v0[k], qmf_c[k]) +
|
|
235 MUL_R_C(v0[64 + k], qmf_c[64 + k]) +
|
|
236 MUL_R_C(v0[128 + k], qmf_c[128 + k]) +
|
|
237 MUL_R_C(v0[192 + k], qmf_c[192 + k]) +
|
|
238 MUL_R_C(v0[256 + k], qmf_c[256 + k]) +
|
|
239 MUL_R_C(v0[320 + k], qmf_c[320 + k]) +
|
|
240 MUL_R_C(v0[384 + k], qmf_c[384 + k]) +
|
|
241 MUL_R_C(v0[448 + k], qmf_c[448 + k]) +
|
|
242 MUL_R_C(v0[512 + k], qmf_c[512 + k]) +
|
|
243 MUL_R_C(v0[576 + k], qmf_c[576 + k]);
|
10725
|
244 }
|
|
245 }
|
|
246 }
|
10989
|
247 #else
|
|
248 void sbr_qmf_synthesis_64(sbr_info *sbr, qmfs_info *qmfs, const qmf_t *X,
|
|
249 real_t *output)
|
|
250 {
|
|
251 uint8_t l;
|
|
252 int16_t n, k;
|
|
253 real_t x1[64], x2[64];
|
|
254 real_t *outptr = output;
|
|
255
|
|
256
|
|
257 /* qmf subsample l */
|
|
258 for (l = 0; l < sbr->numTimeSlotsRate; l++)
|
|
259 {
|
|
260 real_t *v0, *v1;
|
|
261
|
|
262 /* shift buffers */
|
|
263 memmove(qmfs->v[0] + 64, qmfs->v[0], (640-64)*sizeof(real_t));
|
|
264 memmove(qmfs->v[1] + 64, qmfs->v[1], (640-64)*sizeof(real_t));
|
|
265
|
|
266 v0 = qmfs->v[qmfs->v_index];
|
|
267 v1 = qmfs->v[(qmfs->v_index + 1) & 0x1];
|
|
268 qmfs->v_index = (qmfs->v_index + 1) & 0x1;
|
|
269
|
|
270 /* calculate 128 samples */
|
|
271 for (k = 0; k < 64; k++)
|
|
272 {
|
|
273 x1[k] = QMF_RE(X[(l<<6) + k])/64.;
|
|
274 x2[63 - k] = QMF_IM(X[(l<<6) + k])/64.;
|
|
275 }
|
|
276
|
|
277 DCT4_64(x1, x1);
|
|
278 DCT4_64(x2, x2);
|
|
279
|
|
280 for (n = 0; n < 64; n+=2)
|
|
281 {
|
|
282 v0[n] = x2[n] - x1[n];
|
|
283 v0[n+1] = -x2[n+1] - x1[n+1];
|
|
284 v1[63-n] = x2[n] + x1[n];
|
|
285 v1[63-n-1] = -x2[n+1] + x1[n+1];
|
|
286 }
|
|
287
|
|
288 /* calculate 64 output samples and window */
|
|
289 for (k = 0; k < 64; k++)
|
|
290 {
|
|
291 *outptr++ = MUL_R_C(v0[k], qmf_c[k]) +
|
|
292 MUL_R_C(v0[64 + k], qmf_c[64 + k]) +
|
|
293 MUL_R_C(v0[128 + k], qmf_c[128 + k]) +
|
|
294 MUL_R_C(v0[192 + k], qmf_c[192 + k]) +
|
|
295 MUL_R_C(v0[256 + k], qmf_c[256 + k]) +
|
|
296 MUL_R_C(v0[320 + k], qmf_c[320 + k]) +
|
|
297 MUL_R_C(v0[384 + k], qmf_c[384 + k]) +
|
|
298 MUL_R_C(v0[448 + k], qmf_c[448 + k]) +
|
|
299 MUL_R_C(v0[512 + k], qmf_c[512 + k]) +
|
|
300 MUL_R_C(v0[576 + k], qmf_c[576 + k]);
|
|
301 }
|
|
302 }
|
|
303 }
|
|
304 #endif
|
10725
|
305
|
|
306 #endif
|