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: filtbank.c,v 1.1 2003/08/30 22:30:21 arpi Exp $
|
10725
|
26 **/
|
|
27
|
|
28 #include "common.h"
|
|
29 #include "structs.h"
|
|
30
|
|
31 #include <stdlib.h>
|
|
32 #include <string.h>
|
|
33 #ifdef _WIN32_WCE
|
|
34 #define assert(x)
|
|
35 #else
|
|
36 #include <assert.h>
|
|
37 #endif
|
|
38
|
|
39 #include "filtbank.h"
|
|
40 #include "decoder.h"
|
|
41 #include "syntax.h"
|
|
42 #include "kbd_win.h"
|
|
43 #include "sine_win.h"
|
|
44 #include "mdct.h"
|
|
45
|
|
46
|
|
47 fb_info *filter_bank_init(uint16_t frame_len)
|
|
48 {
|
|
49 uint16_t nshort = frame_len/8;
|
|
50 #ifdef LD_DEC
|
|
51 uint16_t frame_len_ld = frame_len/2;
|
|
52 #endif
|
|
53
|
|
54 fb_info *fb = (fb_info*)malloc(sizeof(fb_info));
|
|
55 memset(fb, 0, sizeof(fb_info));
|
|
56
|
|
57 /* normal */
|
|
58 fb->mdct256 = faad_mdct_init(2*nshort);
|
|
59 fb->mdct2048 = faad_mdct_init(2*frame_len);
|
|
60 #ifdef LD_DEC
|
|
61 /* LD */
|
|
62 fb->mdct1024 = faad_mdct_init(2*frame_len_ld);
|
|
63 #endif
|
|
64
|
|
65 if (frame_len == 1024)
|
|
66 {
|
|
67 fb->long_window[0] = sine_long_1024;
|
|
68 fb->short_window[0] = sine_short_128;
|
|
69 fb->long_window[1] = kbd_long_1024;
|
|
70 fb->short_window[1] = kbd_short_128;
|
|
71 #ifdef LD_DEC
|
|
72 fb->ld_window[0] = sine_mid_512;
|
|
73 fb->ld_window[1] = ld_mid_512;
|
|
74 #endif
|
|
75 } else /* (frame_len == 960) */ {
|
|
76 fb->long_window[0] = sine_long_960;
|
|
77 fb->short_window[0] = sine_short_120;
|
|
78 fb->long_window[1] = kbd_long_960;
|
|
79 fb->short_window[1] = kbd_short_120;
|
|
80 #ifdef LD_DEC
|
|
81 fb->ld_window[0] = sine_mid_480;
|
|
82 fb->ld_window[1] = ld_mid_480;
|
|
83 #endif
|
|
84 }
|
|
85
|
|
86 return fb;
|
|
87 }
|
|
88
|
|
89 void filter_bank_end(fb_info *fb)
|
|
90 {
|
|
91 if (fb != NULL)
|
|
92 {
|
|
93 faad_mdct_end(fb->mdct256);
|
|
94 faad_mdct_end(fb->mdct2048);
|
|
95 #ifdef LD_DEC
|
|
96 faad_mdct_end(fb->mdct1024);
|
|
97 #endif
|
|
98
|
|
99 free(fb);
|
|
100 }
|
|
101 }
|
|
102
|
|
103 static INLINE void imdct(fb_info *fb, real_t *in_data, real_t *out_data, uint16_t len)
|
|
104 {
|
|
105 mdct_info *mdct;
|
|
106
|
|
107 switch (len)
|
|
108 {
|
|
109 case 2048:
|
|
110 case 1920:
|
|
111 mdct = fb->mdct2048;
|
|
112 break;
|
|
113 case 256:
|
|
114 case 240:
|
|
115 mdct = fb->mdct256;
|
|
116 break;
|
|
117 #ifdef LD_DEC
|
|
118 case 1024:
|
|
119 case 960:
|
|
120 mdct = fb->mdct1024;
|
|
121 break;
|
|
122 #endif
|
|
123 }
|
|
124
|
|
125 faad_imdct(mdct, in_data, out_data);
|
|
126 }
|
|
127
|
|
128 #ifdef LTP_DEC
|
|
129 static INLINE void mdct(fb_info *fb, real_t *in_data, real_t *out_data, uint16_t len)
|
|
130 {
|
|
131 mdct_info *mdct;
|
|
132
|
|
133 switch (len)
|
|
134 {
|
|
135 case 2048:
|
|
136 case 1920:
|
|
137 mdct = fb->mdct2048;
|
|
138 break;
|
|
139 case 256:
|
|
140 case 240:
|
|
141 mdct = fb->mdct256;
|
|
142 break;
|
|
143 #ifdef LD_DEC
|
|
144 case 1024:
|
|
145 case 960:
|
|
146 mdct = fb->mdct1024;
|
|
147 break;
|
|
148 #endif
|
|
149 }
|
|
150
|
|
151 faad_mdct(mdct, in_data, out_data);
|
|
152 }
|
|
153 #endif
|
|
154
|
|
155 void ifilter_bank(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
|
|
156 uint8_t window_shape_prev, real_t *freq_in,
|
|
157 real_t *time_out, uint8_t object_type, uint16_t frame_len)
|
|
158 {
|
|
159 int16_t i;
|
|
160 real_t *transf_buf;
|
|
161
|
|
162 real_t *window_long;
|
|
163 real_t *window_long_prev;
|
|
164 real_t *window_short;
|
|
165 real_t *window_short_prev;
|
|
166
|
|
167 uint16_t nlong = frame_len;
|
|
168 uint16_t nshort = frame_len/8;
|
|
169 uint16_t trans = nshort/2;
|
|
170
|
|
171 uint16_t nflat_ls = (nlong-nshort)/2;
|
|
172
|
|
173 transf_buf = (real_t*)malloc(2*nlong*sizeof(real_t));
|
|
174
|
|
175 #ifdef LD_DEC
|
|
176 if (object_type == LD)
|
|
177 {
|
|
178 window_long = fb->ld_window[window_shape];
|
|
179 window_long_prev = fb->ld_window[window_shape_prev];
|
|
180 } else {
|
|
181 #endif
|
|
182 window_long = fb->long_window[window_shape];
|
|
183 window_long_prev = fb->long_window[window_shape_prev];
|
|
184 window_short = fb->short_window[window_shape];
|
|
185 window_short_prev = fb->short_window[window_shape_prev];
|
|
186 #ifdef LD_DEC
|
|
187 }
|
|
188 #endif
|
|
189
|
|
190 switch (window_sequence)
|
|
191 {
|
|
192 case ONLY_LONG_SEQUENCE:
|
|
193 imdct(fb, freq_in, transf_buf, 2*nlong);
|
10989
|
194 for (i = 0; i < nlong; i+=4)
|
10725
|
195 {
|
|
196 time_out[i] = time_out[nlong+i] + MUL_R_C(transf_buf[i],window_long_prev[i]);
|
10989
|
197 time_out[i+1] = time_out[nlong+i+1] + MUL_R_C(transf_buf[i+1],window_long_prev[i+1]);
|
|
198 time_out[i+2] = time_out[nlong+i+2] + MUL_R_C(transf_buf[i+2],window_long_prev[i+2]);
|
|
199 time_out[i+3] = time_out[nlong+i+3] + MUL_R_C(transf_buf[i+3],window_long_prev[i+3]);
|
|
200 }
|
|
201 for (i = 0; i < nlong; i+=4)
|
|
202 {
|
10725
|
203 time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]);
|
10989
|
204 time_out[nlong+i+1] = MUL_R_C(transf_buf[nlong+i+1],window_long[nlong-2-i]);
|
|
205 time_out[nlong+i+2] = MUL_R_C(transf_buf[nlong+i+2],window_long[nlong-3-i]);
|
|
206 time_out[nlong+i+3] = MUL_R_C(transf_buf[nlong+i+3],window_long[nlong-4-i]);
|
10725
|
207 }
|
|
208 break;
|
|
209
|
|
210 case LONG_START_SEQUENCE:
|
|
211 imdct(fb, freq_in, transf_buf, 2*nlong);
|
10989
|
212 for (i = 0; i < nlong; i+=4)
|
|
213 {
|
10725
|
214 time_out[i] = time_out[nlong+i] + MUL_R_C(transf_buf[i],window_long_prev[i]);
|
10989
|
215 time_out[i+1] = time_out[nlong+i+1] + MUL_R_C(transf_buf[i+1],window_long_prev[i+1]);
|
|
216 time_out[i+2] = time_out[nlong+i+2] + MUL_R_C(transf_buf[i+2],window_long_prev[i+2]);
|
|
217 time_out[i+3] = time_out[nlong+i+3] + MUL_R_C(transf_buf[i+3],window_long_prev[i+3]);
|
|
218 }
|
10725
|
219 for (i = 0; i < nflat_ls; i++)
|
|
220 time_out[nlong+i] = transf_buf[nlong+i];
|
|
221 for (i = 0; i < nshort; i++)
|
|
222 time_out[nlong+nflat_ls+i] = MUL_R_C(transf_buf[nlong+nflat_ls+i],window_short[nshort-i-1]);
|
|
223 for (i = 0; i < nflat_ls; i++)
|
|
224 time_out[nlong+nflat_ls+nshort+i] = 0;
|
|
225 break;
|
|
226
|
|
227 case EIGHT_SHORT_SEQUENCE:
|
|
228 imdct(fb, freq_in+0*nshort, transf_buf+2*nshort*0, 2*nshort);
|
|
229 imdct(fb, freq_in+1*nshort, transf_buf+2*nshort*1, 2*nshort);
|
|
230 imdct(fb, freq_in+2*nshort, transf_buf+2*nshort*2, 2*nshort);
|
|
231 imdct(fb, freq_in+3*nshort, transf_buf+2*nshort*3, 2*nshort);
|
|
232 imdct(fb, freq_in+4*nshort, transf_buf+2*nshort*4, 2*nshort);
|
|
233 imdct(fb, freq_in+5*nshort, transf_buf+2*nshort*5, 2*nshort);
|
|
234 imdct(fb, freq_in+6*nshort, transf_buf+2*nshort*6, 2*nshort);
|
|
235 imdct(fb, freq_in+7*nshort, transf_buf+2*nshort*7, 2*nshort);
|
|
236 for (i = 0; i < nflat_ls; i++)
|
|
237 time_out[i] = time_out[nlong+i];
|
|
238 for(i = nshort-1; i >= 0; i--)
|
|
239 {
|
|
240 time_out[nflat_ls+ i] = time_out[nlong+nflat_ls+ i] + MUL_R_C(transf_buf[nshort*0+i],window_short_prev[i]);
|
|
241 time_out[nflat_ls+1*nshort+i] = time_out[nlong+nflat_ls+nshort*1+i] + MUL_R_C(transf_buf[nshort*1+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*2+i],window_short[i]);
|
|
242 time_out[nflat_ls+2*nshort+i] = time_out[nlong+nflat_ls+nshort*2+i] + MUL_R_C(transf_buf[nshort*3+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*4+i],window_short[i]);
|
|
243 time_out[nflat_ls+3*nshort+i] = time_out[nlong+nflat_ls+nshort*3+i] + MUL_R_C(transf_buf[nshort*5+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*6+i],window_short[i]);
|
|
244 if (i < trans)
|
|
245 time_out[nflat_ls+4*nshort+i] = time_out[nlong+nflat_ls+nshort*4+i] + MUL_R_C(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*8+i],window_short[i]);
|
|
246 else
|
|
247 time_out[nflat_ls+4*nshort+i] = MUL_R_C(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*8+i],window_short[i]);
|
|
248 time_out[nflat_ls+5*nshort+i] = MUL_R_C(transf_buf[nshort*9+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*10+i],window_short[i]);
|
|
249 time_out[nflat_ls+6*nshort+i] = MUL_R_C(transf_buf[nshort*11+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*12+i],window_short[i]);
|
|
250 time_out[nflat_ls+7*nshort+i] = MUL_R_C(transf_buf[nshort*13+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*14+i],window_short[i]);
|
|
251 time_out[nflat_ls+8*nshort+i] = MUL_R_C(transf_buf[nshort*15+i],window_short[nshort-1-i]);
|
|
252 }
|
|
253 for (i = 0; i < nflat_ls; i++)
|
|
254 time_out[nlong+nflat_ls+nshort+i] = 0;
|
|
255 break;
|
|
256
|
|
257 case LONG_STOP_SEQUENCE:
|
|
258 imdct(fb, freq_in, transf_buf, 2*nlong);
|
|
259 for (i = 0; i < nflat_ls; i++)
|
|
260 time_out[i] = time_out[nlong+i];
|
|
261 for (i = 0; i < nshort; i++)
|
|
262 time_out[nflat_ls+i] = time_out[nlong+nflat_ls+i] + MUL_R_C(transf_buf[nflat_ls+i],window_short_prev[i]);
|
|
263 for (i = 0; i < nflat_ls; i++)
|
|
264 time_out[nflat_ls+nshort+i] = time_out[nlong+nflat_ls+nshort+i] + transf_buf[nflat_ls+nshort+i];
|
|
265 for (i = 0; i < nlong; i++)
|
|
266 time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]);
|
|
267 break;
|
|
268 }
|
|
269
|
|
270 free(transf_buf);
|
|
271 }
|
|
272
|
|
273 #ifdef LTP_DEC
|
|
274 /* only works for LTP -> no overlapping, no short blocks */
|
|
275 void filter_bank_ltp(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
|
|
276 uint8_t window_shape_prev, real_t *in_data, real_t *out_mdct,
|
|
277 uint8_t object_type, uint16_t frame_len)
|
|
278 {
|
|
279 int16_t i;
|
|
280 real_t *windowed_buf;
|
|
281
|
|
282 real_t *window_long;
|
|
283 real_t *window_long_prev;
|
|
284 real_t *window_short;
|
|
285 real_t *window_short_prev;
|
|
286
|
|
287 uint16_t nlong = frame_len;
|
|
288 uint16_t nshort = frame_len/8;
|
|
289 uint16_t nflat_ls = (nlong-nshort)/2;
|
|
290
|
|
291 assert(window_sequence != EIGHT_SHORT_SEQUENCE);
|
|
292
|
|
293 windowed_buf = (real_t*)malloc(nlong*2*sizeof(real_t));
|
|
294
|
|
295 #ifdef LD_DEC
|
|
296 if (object_type == LD)
|
|
297 {
|
|
298 window_long = fb->ld_window[window_shape];
|
|
299 window_long_prev = fb->ld_window[window_shape_prev];
|
|
300 } else {
|
|
301 #endif
|
|
302 window_long = fb->long_window[window_shape];
|
|
303 window_long_prev = fb->long_window[window_shape_prev];
|
|
304 window_short = fb->short_window[window_shape];
|
|
305 window_short_prev = fb->short_window[window_shape_prev];
|
|
306 #ifdef LD_DEC
|
|
307 }
|
|
308 #endif
|
|
309
|
|
310 switch(window_sequence)
|
|
311 {
|
|
312 case ONLY_LONG_SEQUENCE:
|
|
313 for (i = nlong-1; i >= 0; i--)
|
|
314 {
|
|
315 windowed_buf[i] = MUL_R_C(in_data[i], window_long_prev[i]);
|
|
316 windowed_buf[i+nlong] = MUL_R_C(in_data[i+nlong], window_long[nlong-1-i]);
|
|
317 }
|
|
318 mdct(fb, windowed_buf, out_mdct, 2*nlong);
|
|
319 break;
|
|
320
|
|
321 case LONG_START_SEQUENCE:
|
|
322 for (i = 0; i < nlong; i++)
|
|
323 windowed_buf[i] = MUL_R_C(in_data[i], window_long_prev[i]);
|
|
324 for (i = 0; i < nflat_ls; i++)
|
|
325 windowed_buf[i+nlong] = in_data[i+nlong];
|
|
326 for (i = 0; i < nshort; i++)
|
|
327 windowed_buf[i+nlong+nflat_ls] = MUL_R_C(in_data[i+nlong+nflat_ls], window_short[nshort-1-i]);
|
|
328 for (i = 0; i < nflat_ls; i++)
|
|
329 windowed_buf[i+nlong+nflat_ls+nshort] = 0;
|
|
330 mdct(fb, windowed_buf, out_mdct, 2*nlong);
|
|
331 break;
|
|
332
|
|
333 case LONG_STOP_SEQUENCE:
|
|
334 for (i = 0; i < nflat_ls; i++)
|
|
335 windowed_buf[i] = 0;
|
|
336 for (i = 0; i < nshort; i++)
|
|
337 windowed_buf[i+nflat_ls] = MUL_R_C(in_data[i+nflat_ls], window_short_prev[i]);
|
|
338 for (i = 0; i < nflat_ls; i++)
|
|
339 windowed_buf[i+nflat_ls+nshort] = in_data[i+nflat_ls+nshort];
|
|
340 for (i = 0; i < nlong; i++)
|
|
341 windowed_buf[i+nlong] = MUL_R_C(in_data[i+nlong], window_long[nlong-1-i]);
|
|
342 mdct(fb, windowed_buf, out_mdct, 2*nlong);
|
|
343 break;
|
|
344 }
|
|
345
|
|
346 free(windowed_buf);
|
|
347 }
|
|
348 #endif
|