Mercurial > mplayer.hg
comparison libfaad2/filtbank.c @ 10725:e989150f8216
libfaad2 v2.0rc1 imported
author | arpi |
---|---|
date | Sat, 30 Aug 2003 22:30:28 +0000 |
parents | |
children | 3185f64f6350 |
comparison
equal
deleted
inserted
replaced
10724:adf5697b9d83 | 10725:e989150f8216 |
---|---|
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 ** | |
25 ** $Id: filtbank.c,v 1.25 2003/07/29 08:20:12 menno Exp $ | |
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); | |
194 for (i = nlong-1; i >= 0; i--) | |
195 { | |
196 time_out[i] = time_out[nlong+i] + MUL_R_C(transf_buf[i],window_long_prev[i]); | |
197 time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]); | |
198 } | |
199 break; | |
200 | |
201 case LONG_START_SEQUENCE: | |
202 imdct(fb, freq_in, transf_buf, 2*nlong); | |
203 for (i = 0; i < nlong; i++) | |
204 time_out[i] = time_out[nlong+i] + MUL_R_C(transf_buf[i],window_long_prev[i]); | |
205 for (i = 0; i < nflat_ls; i++) | |
206 time_out[nlong+i] = transf_buf[nlong+i]; | |
207 for (i = 0; i < nshort; i++) | |
208 time_out[nlong+nflat_ls+i] = MUL_R_C(transf_buf[nlong+nflat_ls+i],window_short[nshort-i-1]); | |
209 for (i = 0; i < nflat_ls; i++) | |
210 time_out[nlong+nflat_ls+nshort+i] = 0; | |
211 break; | |
212 | |
213 case EIGHT_SHORT_SEQUENCE: | |
214 imdct(fb, freq_in+0*nshort, transf_buf+2*nshort*0, 2*nshort); | |
215 imdct(fb, freq_in+1*nshort, transf_buf+2*nshort*1, 2*nshort); | |
216 imdct(fb, freq_in+2*nshort, transf_buf+2*nshort*2, 2*nshort); | |
217 imdct(fb, freq_in+3*nshort, transf_buf+2*nshort*3, 2*nshort); | |
218 imdct(fb, freq_in+4*nshort, transf_buf+2*nshort*4, 2*nshort); | |
219 imdct(fb, freq_in+5*nshort, transf_buf+2*nshort*5, 2*nshort); | |
220 imdct(fb, freq_in+6*nshort, transf_buf+2*nshort*6, 2*nshort); | |
221 imdct(fb, freq_in+7*nshort, transf_buf+2*nshort*7, 2*nshort); | |
222 for (i = 0; i < nflat_ls; i++) | |
223 time_out[i] = time_out[nlong+i]; | |
224 for(i = nshort-1; i >= 0; i--) | |
225 { | |
226 time_out[nflat_ls+ i] = time_out[nlong+nflat_ls+ i] + MUL_R_C(transf_buf[nshort*0+i],window_short_prev[i]); | |
227 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]); | |
228 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]); | |
229 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]); | |
230 if (i < trans) | |
231 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]); | |
232 else | |
233 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]); | |
234 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]); | |
235 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]); | |
236 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]); | |
237 time_out[nflat_ls+8*nshort+i] = MUL_R_C(transf_buf[nshort*15+i],window_short[nshort-1-i]); | |
238 } | |
239 for (i = 0; i < nflat_ls; i++) | |
240 time_out[nlong+nflat_ls+nshort+i] = 0; | |
241 break; | |
242 | |
243 case LONG_STOP_SEQUENCE: | |
244 imdct(fb, freq_in, transf_buf, 2*nlong); | |
245 for (i = 0; i < nflat_ls; i++) | |
246 time_out[i] = time_out[nlong+i]; | |
247 for (i = 0; i < nshort; i++) | |
248 time_out[nflat_ls+i] = time_out[nlong+nflat_ls+i] + MUL_R_C(transf_buf[nflat_ls+i],window_short_prev[i]); | |
249 for (i = 0; i < nflat_ls; i++) | |
250 time_out[nflat_ls+nshort+i] = time_out[nlong+nflat_ls+nshort+i] + transf_buf[nflat_ls+nshort+i]; | |
251 for (i = 0; i < nlong; i++) | |
252 time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]); | |
253 break; | |
254 } | |
255 | |
256 free(transf_buf); | |
257 } | |
258 | |
259 #ifdef LTP_DEC | |
260 /* only works for LTP -> no overlapping, no short blocks */ | |
261 void filter_bank_ltp(fb_info *fb, uint8_t window_sequence, uint8_t window_shape, | |
262 uint8_t window_shape_prev, real_t *in_data, real_t *out_mdct, | |
263 uint8_t object_type, uint16_t frame_len) | |
264 { | |
265 int16_t i; | |
266 real_t *windowed_buf; | |
267 | |
268 real_t *window_long; | |
269 real_t *window_long_prev; | |
270 real_t *window_short; | |
271 real_t *window_short_prev; | |
272 | |
273 uint16_t nlong = frame_len; | |
274 uint16_t nshort = frame_len/8; | |
275 uint16_t nflat_ls = (nlong-nshort)/2; | |
276 | |
277 assert(window_sequence != EIGHT_SHORT_SEQUENCE); | |
278 | |
279 windowed_buf = (real_t*)malloc(nlong*2*sizeof(real_t)); | |
280 | |
281 #ifdef LD_DEC | |
282 if (object_type == LD) | |
283 { | |
284 window_long = fb->ld_window[window_shape]; | |
285 window_long_prev = fb->ld_window[window_shape_prev]; | |
286 } else { | |
287 #endif | |
288 window_long = fb->long_window[window_shape]; | |
289 window_long_prev = fb->long_window[window_shape_prev]; | |
290 window_short = fb->short_window[window_shape]; | |
291 window_short_prev = fb->short_window[window_shape_prev]; | |
292 #ifdef LD_DEC | |
293 } | |
294 #endif | |
295 | |
296 switch(window_sequence) | |
297 { | |
298 case ONLY_LONG_SEQUENCE: | |
299 for (i = nlong-1; i >= 0; i--) | |
300 { | |
301 windowed_buf[i] = MUL_R_C(in_data[i], window_long_prev[i]); | |
302 windowed_buf[i+nlong] = MUL_R_C(in_data[i+nlong], window_long[nlong-1-i]); | |
303 } | |
304 mdct(fb, windowed_buf, out_mdct, 2*nlong); | |
305 break; | |
306 | |
307 case LONG_START_SEQUENCE: | |
308 for (i = 0; i < nlong; i++) | |
309 windowed_buf[i] = MUL_R_C(in_data[i], window_long_prev[i]); | |
310 for (i = 0; i < nflat_ls; i++) | |
311 windowed_buf[i+nlong] = in_data[i+nlong]; | |
312 for (i = 0; i < nshort; i++) | |
313 windowed_buf[i+nlong+nflat_ls] = MUL_R_C(in_data[i+nlong+nflat_ls], window_short[nshort-1-i]); | |
314 for (i = 0; i < nflat_ls; i++) | |
315 windowed_buf[i+nlong+nflat_ls+nshort] = 0; | |
316 mdct(fb, windowed_buf, out_mdct, 2*nlong); | |
317 break; | |
318 | |
319 case LONG_STOP_SEQUENCE: | |
320 for (i = 0; i < nflat_ls; i++) | |
321 windowed_buf[i] = 0; | |
322 for (i = 0; i < nshort; i++) | |
323 windowed_buf[i+nflat_ls] = MUL_R_C(in_data[i+nflat_ls], window_short_prev[i]); | |
324 for (i = 0; i < nflat_ls; i++) | |
325 windowed_buf[i+nflat_ls+nshort] = in_data[i+nflat_ls+nshort]; | |
326 for (i = 0; i < nlong; i++) | |
327 windowed_buf[i+nlong] = MUL_R_C(in_data[i+nlong], window_long[nlong-1-i]); | |
328 mdct(fb, windowed_buf, out_mdct, 2*nlong); | |
329 break; | |
330 } | |
331 | |
332 free(windowed_buf); | |
333 } | |
334 #endif |