2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
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.
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.
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.
19 ** Any non-GPL usage of this software or parts of this software is strictly
22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
25 ** $Id: cfft.c,v 1.30 2004/09/08 09:43:11 gcp Exp $
29 * Algorithmically based on Fortran-77 FFTPACK
30 * by Paul N. Swarztrauber(Version 4, 1985).
32 * Does even sized fft only
35 /* isign is +1 for backward and -1 for forward transforms */
46 /* static function declarations */
47 static void passf2pos(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
,
48 complex_t
*ch
, const complex_t
*wa
);
49 static void passf2neg(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
,
50 complex_t
*ch
, const complex_t
*wa
);
51 static void passf3(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
,
52 complex_t
*ch
, const complex_t
*wa1
, const complex_t
*wa2
, const int8_t isign
);
53 static void passf4pos(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
, complex_t
*ch
,
54 const complex_t
*wa1
, const complex_t
*wa2
, const complex_t
*wa3
);
55 static void passf4neg(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
, complex_t
*ch
,
56 const complex_t
*wa1
, const complex_t
*wa2
, const complex_t
*wa3
);
57 static void passf5(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
, complex_t
*ch
,
58 const complex_t
*wa1
, const complex_t
*wa2
, const complex_t
*wa3
,
59 const complex_t
*wa4
, const int8_t isign
);
60 INLINE
void cfftf1(uint16_t n
, complex_t
*c
, complex_t
*ch
,
61 const uint16_t *ifac
, const complex_t
*wa
, const int8_t isign
);
62 static void cffti1(uint16_t n
, complex_t
*wa
, uint16_t *ifac
);
65 /*----------------------------------------------------------------------
66 passf2, passf3, passf4, passf5. Complex FFT passes fwd and bwd.
67 ----------------------------------------------------------------------*/
69 static void passf2pos(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
,
70 complex_t
*ch
, const complex_t
*wa
)
72 uint16_t i
, k
, ah
, ac
;
76 for (k
= 0; k
< l1
; k
++)
81 RE(ch
[ah
]) = RE(cc
[ac
]) + RE(cc
[ac
+1]);
82 RE(ch
[ah
+l1
]) = RE(cc
[ac
]) - RE(cc
[ac
+1]);
83 IM(ch
[ah
]) = IM(cc
[ac
]) + IM(cc
[ac
+1]);
84 IM(ch
[ah
+l1
]) = IM(cc
[ac
]) - IM(cc
[ac
+1]);
87 for (k
= 0; k
< l1
; k
++)
92 for (i
= 0; i
< ido
; i
++)
96 RE(ch
[ah
+i
]) = RE(cc
[ac
+i
]) + RE(cc
[ac
+i
+ido
]);
97 RE(t2
) = RE(cc
[ac
+i
]) - RE(cc
[ac
+i
+ido
]);
99 IM(ch
[ah
+i
]) = IM(cc
[ac
+i
]) + IM(cc
[ac
+i
+ido
]);
100 IM(t2
) = IM(cc
[ac
+i
]) - IM(cc
[ac
+i
+ido
]);
103 ComplexMult(&IM(ch
[ah
+i
+l1
*ido
]), &RE(ch
[ah
+i
+l1
*ido
]),
104 IM(t2
), RE(t2
), RE(wa
[i
]), IM(wa
[i
]));
106 ComplexMult(&RE(ch
[ah
+i
+l1
*ido
]), &IM(ch
[ah
+i
+l1
*ido
]),
107 RE(t2
), IM(t2
), RE(wa
[i
]), IM(wa
[i
]));
114 static void passf2neg(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
,
115 complex_t
*ch
, const complex_t
*wa
)
117 uint16_t i
, k
, ah
, ac
;
121 for (k
= 0; k
< l1
; k
++)
126 RE(ch
[ah
]) = RE(cc
[ac
]) + RE(cc
[ac
+1]);
127 RE(ch
[ah
+l1
]) = RE(cc
[ac
]) - RE(cc
[ac
+1]);
128 IM(ch
[ah
]) = IM(cc
[ac
]) + IM(cc
[ac
+1]);
129 IM(ch
[ah
+l1
]) = IM(cc
[ac
]) - IM(cc
[ac
+1]);
132 for (k
= 0; k
< l1
; k
++)
137 for (i
= 0; i
< ido
; i
++)
141 RE(ch
[ah
+i
]) = RE(cc
[ac
+i
]) + RE(cc
[ac
+i
+ido
]);
142 RE(t2
) = RE(cc
[ac
+i
]) - RE(cc
[ac
+i
+ido
]);
144 IM(ch
[ah
+i
]) = IM(cc
[ac
+i
]) + IM(cc
[ac
+i
+ido
]);
145 IM(t2
) = IM(cc
[ac
+i
]) - IM(cc
[ac
+i
+ido
]);
148 ComplexMult(&RE(ch
[ah
+i
+l1
*ido
]), &IM(ch
[ah
+i
+l1
*ido
]),
149 RE(t2
), IM(t2
), RE(wa
[i
]), IM(wa
[i
]));
151 ComplexMult(&IM(ch
[ah
+i
+l1
*ido
]), &RE(ch
[ah
+i
+l1
*ido
]),
152 IM(t2
), RE(t2
), RE(wa
[i
]), IM(wa
[i
]));
160 static void passf3(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
,
161 complex_t
*ch
, const complex_t
*wa1
, const complex_t
*wa2
,
164 static real_t taur
= FRAC_CONST(-0.5);
165 static real_t taui
= FRAC_CONST(0.866025403784439);
166 uint16_t i
, k
, ac
, ah
;
167 complex_t c2
, c3
, d2
, d3
, t2
;
173 for (k
= 0; k
< l1
; k
++)
178 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+1]);
179 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+1]);
180 RE(c2
) = RE(cc
[ac
-1]) + MUL_F(RE(t2
),taur
);
181 IM(c2
) = IM(cc
[ac
-1]) + MUL_F(IM(t2
),taur
);
183 RE(ch
[ah
]) = RE(cc
[ac
-1]) + RE(t2
);
184 IM(ch
[ah
]) = IM(cc
[ac
-1]) + IM(t2
);
186 RE(c3
) = MUL_F((RE(cc
[ac
]) - RE(cc
[ac
+1])), taui
);
187 IM(c3
) = MUL_F((IM(cc
[ac
]) - IM(cc
[ac
+1])), taui
);
189 RE(ch
[ah
+l1
]) = RE(c2
) - IM(c3
);
190 IM(ch
[ah
+l1
]) = IM(c2
) + RE(c3
);
191 RE(ch
[ah
+2*l1
]) = RE(c2
) + IM(c3
);
192 IM(ch
[ah
+2*l1
]) = IM(c2
) - RE(c3
);
195 for (k
= 0; k
< l1
; k
++)
200 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+1]);
201 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+1]);
202 RE(c2
) = RE(cc
[ac
-1]) + MUL_F(RE(t2
),taur
);
203 IM(c2
) = IM(cc
[ac
-1]) + MUL_F(IM(t2
),taur
);
205 RE(ch
[ah
]) = RE(cc
[ac
-1]) + RE(t2
);
206 IM(ch
[ah
]) = IM(cc
[ac
-1]) + IM(t2
);
208 RE(c3
) = MUL_F((RE(cc
[ac
]) - RE(cc
[ac
+1])), taui
);
209 IM(c3
) = MUL_F((IM(cc
[ac
]) - IM(cc
[ac
+1])), taui
);
211 RE(ch
[ah
+l1
]) = RE(c2
) + IM(c3
);
212 IM(ch
[ah
+l1
]) = IM(c2
) - RE(c3
);
213 RE(ch
[ah
+2*l1
]) = RE(c2
) - IM(c3
);
214 IM(ch
[ah
+2*l1
]) = IM(c2
) + RE(c3
);
220 for (k
= 0; k
< l1
; k
++)
222 for (i
= 0; i
< ido
; i
++)
224 ac
= i
+ (3*k
+1)*ido
;
227 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+ido
]);
228 RE(c2
) = RE(cc
[ac
-ido
]) + MUL_F(RE(t2
),taur
);
229 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+ido
]);
230 IM(c2
) = IM(cc
[ac
-ido
]) + MUL_F(IM(t2
),taur
);
232 RE(ch
[ah
]) = RE(cc
[ac
-ido
]) + RE(t2
);
233 IM(ch
[ah
]) = IM(cc
[ac
-ido
]) + IM(t2
);
235 RE(c3
) = MUL_F((RE(cc
[ac
]) - RE(cc
[ac
+ido
])), taui
);
236 IM(c3
) = MUL_F((IM(cc
[ac
]) - IM(cc
[ac
+ido
])), taui
);
238 RE(d2
) = RE(c2
) - IM(c3
);
239 IM(d3
) = IM(c2
) - RE(c3
);
240 RE(d3
) = RE(c2
) + IM(c3
);
241 IM(d2
) = IM(c2
) + RE(c3
);
244 ComplexMult(&IM(ch
[ah
+l1
*ido
]), &RE(ch
[ah
+l1
*ido
]),
245 IM(d2
), RE(d2
), RE(wa1
[i
]), IM(wa1
[i
]));
246 ComplexMult(&IM(ch
[ah
+2*l1
*ido
]), &RE(ch
[ah
+2*l1
*ido
]),
247 IM(d3
), RE(d3
), RE(wa2
[i
]), IM(wa2
[i
]));
249 ComplexMult(&RE(ch
[ah
+l1
*ido
]), &IM(ch
[ah
+l1
*ido
]),
250 RE(d2
), IM(d2
), RE(wa1
[i
]), IM(wa1
[i
]));
251 ComplexMult(&RE(ch
[ah
+2*l1
*ido
]), &IM(ch
[ah
+2*l1
*ido
]),
252 RE(d3
), IM(d3
), RE(wa2
[i
]), IM(wa2
[i
]));
257 for (k
= 0; k
< l1
; k
++)
259 for (i
= 0; i
< ido
; i
++)
261 ac
= i
+ (3*k
+1)*ido
;
264 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+ido
]);
265 RE(c2
) = RE(cc
[ac
-ido
]) + MUL_F(RE(t2
),taur
);
266 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+ido
]);
267 IM(c2
) = IM(cc
[ac
-ido
]) + MUL_F(IM(t2
),taur
);
269 RE(ch
[ah
]) = RE(cc
[ac
-ido
]) + RE(t2
);
270 IM(ch
[ah
]) = IM(cc
[ac
-ido
]) + IM(t2
);
272 RE(c3
) = MUL_F((RE(cc
[ac
]) - RE(cc
[ac
+ido
])), taui
);
273 IM(c3
) = MUL_F((IM(cc
[ac
]) - IM(cc
[ac
+ido
])), taui
);
275 RE(d2
) = RE(c2
) + IM(c3
);
276 IM(d3
) = IM(c2
) + RE(c3
);
277 RE(d3
) = RE(c2
) - IM(c3
);
278 IM(d2
) = IM(c2
) - RE(c3
);
281 ComplexMult(&RE(ch
[ah
+l1
*ido
]), &IM(ch
[ah
+l1
*ido
]),
282 RE(d2
), IM(d2
), RE(wa1
[i
]), IM(wa1
[i
]));
283 ComplexMult(&RE(ch
[ah
+2*l1
*ido
]), &IM(ch
[ah
+2*l1
*ido
]),
284 RE(d3
), IM(d3
), RE(wa2
[i
]), IM(wa2
[i
]));
286 ComplexMult(&IM(ch
[ah
+l1
*ido
]), &RE(ch
[ah
+l1
*ido
]),
287 IM(d2
), RE(d2
), RE(wa1
[i
]), IM(wa1
[i
]));
288 ComplexMult(&IM(ch
[ah
+2*l1
*ido
]), &RE(ch
[ah
+2*l1
*ido
]),
289 IM(d3
), RE(d3
), RE(wa2
[i
]), IM(wa2
[i
]));
298 static void passf4pos(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
,
299 complex_t
*ch
, const complex_t
*wa1
, const complex_t
*wa2
,
300 const complex_t
*wa3
)
302 uint16_t i
, k
, ac
, ah
;
306 for (k
= 0; k
< l1
; k
++)
308 complex_t t1
, t2
, t3
, t4
;
313 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+2]);
314 RE(t1
) = RE(cc
[ac
]) - RE(cc
[ac
+2]);
315 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+2]);
316 IM(t1
) = IM(cc
[ac
]) - IM(cc
[ac
+2]);
317 RE(t3
) = RE(cc
[ac
+1]) + RE(cc
[ac
+3]);
318 IM(t4
) = RE(cc
[ac
+1]) - RE(cc
[ac
+3]);
319 IM(t3
) = IM(cc
[ac
+3]) + IM(cc
[ac
+1]);
320 RE(t4
) = IM(cc
[ac
+3]) - IM(cc
[ac
+1]);
322 RE(ch
[ah
]) = RE(t2
) + RE(t3
);
323 RE(ch
[ah
+2*l1
]) = RE(t2
) - RE(t3
);
325 IM(ch
[ah
]) = IM(t2
) + IM(t3
);
326 IM(ch
[ah
+2*l1
]) = IM(t2
) - IM(t3
);
328 RE(ch
[ah
+l1
]) = RE(t1
) + RE(t4
);
329 RE(ch
[ah
+3*l1
]) = RE(t1
) - RE(t4
);
331 IM(ch
[ah
+l1
]) = IM(t1
) + IM(t4
);
332 IM(ch
[ah
+3*l1
]) = IM(t1
) - IM(t4
);
335 for (k
= 0; k
< l1
; k
++)
340 for (i
= 0; i
< ido
; i
++)
342 complex_t c2
, c3
, c4
, t1
, t2
, t3
, t4
;
344 RE(t2
) = RE(cc
[ac
+i
]) + RE(cc
[ac
+i
+2*ido
]);
345 RE(t1
) = RE(cc
[ac
+i
]) - RE(cc
[ac
+i
+2*ido
]);
346 IM(t2
) = IM(cc
[ac
+i
]) + IM(cc
[ac
+i
+2*ido
]);
347 IM(t1
) = IM(cc
[ac
+i
]) - IM(cc
[ac
+i
+2*ido
]);
348 RE(t3
) = RE(cc
[ac
+i
+ido
]) + RE(cc
[ac
+i
+3*ido
]);
349 IM(t4
) = RE(cc
[ac
+i
+ido
]) - RE(cc
[ac
+i
+3*ido
]);
350 IM(t3
) = IM(cc
[ac
+i
+3*ido
]) + IM(cc
[ac
+i
+ido
]);
351 RE(t4
) = IM(cc
[ac
+i
+3*ido
]) - IM(cc
[ac
+i
+ido
]);
353 RE(c2
) = RE(t1
) + RE(t4
);
354 RE(c4
) = RE(t1
) - RE(t4
);
356 IM(c2
) = IM(t1
) + IM(t4
);
357 IM(c4
) = IM(t1
) - IM(t4
);
359 RE(ch
[ah
+i
]) = RE(t2
) + RE(t3
);
360 RE(c3
) = RE(t2
) - RE(t3
);
362 IM(ch
[ah
+i
]) = IM(t2
) + IM(t3
);
363 IM(c3
) = IM(t2
) - IM(t3
);
366 ComplexMult(&IM(ch
[ah
+i
+l1
*ido
]), &RE(ch
[ah
+i
+l1
*ido
]),
367 IM(c2
), RE(c2
), RE(wa1
[i
]), IM(wa1
[i
]));
368 ComplexMult(&IM(ch
[ah
+i
+2*l1
*ido
]), &RE(ch
[ah
+i
+2*l1
*ido
]),
369 IM(c3
), RE(c3
), RE(wa2
[i
]), IM(wa2
[i
]));
370 ComplexMult(&IM(ch
[ah
+i
+3*l1
*ido
]), &RE(ch
[ah
+i
+3*l1
*ido
]),
371 IM(c4
), RE(c4
), RE(wa3
[i
]), IM(wa3
[i
]));
373 ComplexMult(&RE(ch
[ah
+i
+l1
*ido
]), &IM(ch
[ah
+i
+l1
*ido
]),
374 RE(c2
), IM(c2
), RE(wa1
[i
]), IM(wa1
[i
]));
375 ComplexMult(&RE(ch
[ah
+i
+2*l1
*ido
]), &IM(ch
[ah
+i
+2*l1
*ido
]),
376 RE(c3
), IM(c3
), RE(wa2
[i
]), IM(wa2
[i
]));
377 ComplexMult(&RE(ch
[ah
+i
+3*l1
*ido
]), &IM(ch
[ah
+i
+3*l1
*ido
]),
378 RE(c4
), IM(c4
), RE(wa3
[i
]), IM(wa3
[i
]));
385 static void passf4neg(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
,
386 complex_t
*ch
, const complex_t
*wa1
, const complex_t
*wa2
,
387 const complex_t
*wa3
)
389 uint16_t i
, k
, ac
, ah
;
393 for (k
= 0; k
< l1
; k
++)
395 complex_t t1
, t2
, t3
, t4
;
400 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+2]);
401 RE(t1
) = RE(cc
[ac
]) - RE(cc
[ac
+2]);
402 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+2]);
403 IM(t1
) = IM(cc
[ac
]) - IM(cc
[ac
+2]);
404 RE(t3
) = RE(cc
[ac
+1]) + RE(cc
[ac
+3]);
405 IM(t4
) = RE(cc
[ac
+1]) - RE(cc
[ac
+3]);
406 IM(t3
) = IM(cc
[ac
+3]) + IM(cc
[ac
+1]);
407 RE(t4
) = IM(cc
[ac
+3]) - IM(cc
[ac
+1]);
409 RE(ch
[ah
]) = RE(t2
) + RE(t3
);
410 RE(ch
[ah
+2*l1
]) = RE(t2
) - RE(t3
);
412 IM(ch
[ah
]) = IM(t2
) + IM(t3
);
413 IM(ch
[ah
+2*l1
]) = IM(t2
) - IM(t3
);
415 RE(ch
[ah
+l1
]) = RE(t1
) - RE(t4
);
416 RE(ch
[ah
+3*l1
]) = RE(t1
) + RE(t4
);
418 IM(ch
[ah
+l1
]) = IM(t1
) - IM(t4
);
419 IM(ch
[ah
+3*l1
]) = IM(t1
) + IM(t4
);
422 for (k
= 0; k
< l1
; k
++)
427 for (i
= 0; i
< ido
; i
++)
429 complex_t c2
, c3
, c4
, t1
, t2
, t3
, t4
;
431 RE(t2
) = RE(cc
[ac
+i
]) + RE(cc
[ac
+i
+2*ido
]);
432 RE(t1
) = RE(cc
[ac
+i
]) - RE(cc
[ac
+i
+2*ido
]);
433 IM(t2
) = IM(cc
[ac
+i
]) + IM(cc
[ac
+i
+2*ido
]);
434 IM(t1
) = IM(cc
[ac
+i
]) - IM(cc
[ac
+i
+2*ido
]);
435 RE(t3
) = RE(cc
[ac
+i
+ido
]) + RE(cc
[ac
+i
+3*ido
]);
436 IM(t4
) = RE(cc
[ac
+i
+ido
]) - RE(cc
[ac
+i
+3*ido
]);
437 IM(t3
) = IM(cc
[ac
+i
+3*ido
]) + IM(cc
[ac
+i
+ido
]);
438 RE(t4
) = IM(cc
[ac
+i
+3*ido
]) - IM(cc
[ac
+i
+ido
]);
440 RE(c2
) = RE(t1
) - RE(t4
);
441 RE(c4
) = RE(t1
) + RE(t4
);
443 IM(c2
) = IM(t1
) - IM(t4
);
444 IM(c4
) = IM(t1
) + IM(t4
);
446 RE(ch
[ah
+i
]) = RE(t2
) + RE(t3
);
447 RE(c3
) = RE(t2
) - RE(t3
);
449 IM(ch
[ah
+i
]) = IM(t2
) + IM(t3
);
450 IM(c3
) = IM(t2
) - IM(t3
);
453 ComplexMult(&RE(ch
[ah
+i
+l1
*ido
]), &IM(ch
[ah
+i
+l1
*ido
]),
454 RE(c2
), IM(c2
), RE(wa1
[i
]), IM(wa1
[i
]));
455 ComplexMult(&RE(ch
[ah
+i
+2*l1
*ido
]), &IM(ch
[ah
+i
+2*l1
*ido
]),
456 RE(c3
), IM(c3
), RE(wa2
[i
]), IM(wa2
[i
]));
457 ComplexMult(&RE(ch
[ah
+i
+3*l1
*ido
]), &IM(ch
[ah
+i
+3*l1
*ido
]),
458 RE(c4
), IM(c4
), RE(wa3
[i
]), IM(wa3
[i
]));
460 ComplexMult(&IM(ch
[ah
+i
+l1
*ido
]), &RE(ch
[ah
+i
+l1
*ido
]),
461 IM(c2
), RE(c2
), RE(wa1
[i
]), IM(wa1
[i
]));
462 ComplexMult(&IM(ch
[ah
+i
+2*l1
*ido
]), &RE(ch
[ah
+i
+2*l1
*ido
]),
463 IM(c3
), RE(c3
), RE(wa2
[i
]), IM(wa2
[i
]));
464 ComplexMult(&IM(ch
[ah
+i
+3*l1
*ido
]), &RE(ch
[ah
+i
+3*l1
*ido
]),
465 IM(c4
), RE(c4
), RE(wa3
[i
]), IM(wa3
[i
]));
472 static void passf5(const uint16_t ido
, const uint16_t l1
, const complex_t
*cc
,
473 complex_t
*ch
, const complex_t
*wa1
, const complex_t
*wa2
, const complex_t
*wa3
,
474 const complex_t
*wa4
, const int8_t isign
)
476 static real_t tr11
= FRAC_CONST(0.309016994374947);
477 static real_t ti11
= FRAC_CONST(0.951056516295154);
478 static real_t tr12
= FRAC_CONST(-0.809016994374947);
479 static real_t ti12
= FRAC_CONST(0.587785252292473);
480 uint16_t i
, k
, ac
, ah
;
481 complex_t c2
, c3
, c4
, c5
, d3
, d4
, d5
, d2
, t2
, t3
, t4
, t5
;
487 for (k
= 0; k
< l1
; k
++)
492 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+3]);
493 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+3]);
494 RE(t3
) = RE(cc
[ac
+1]) + RE(cc
[ac
+2]);
495 IM(t3
) = IM(cc
[ac
+1]) + IM(cc
[ac
+2]);
496 RE(t4
) = RE(cc
[ac
+1]) - RE(cc
[ac
+2]);
497 IM(t4
) = IM(cc
[ac
+1]) - IM(cc
[ac
+2]);
498 RE(t5
) = RE(cc
[ac
]) - RE(cc
[ac
+3]);
499 IM(t5
) = IM(cc
[ac
]) - IM(cc
[ac
+3]);
501 RE(ch
[ah
]) = RE(cc
[ac
-1]) + RE(t2
) + RE(t3
);
502 IM(ch
[ah
]) = IM(cc
[ac
-1]) + IM(t2
) + IM(t3
);
504 RE(c2
) = RE(cc
[ac
-1]) + MUL_F(RE(t2
),tr11
) + MUL_F(RE(t3
),tr12
);
505 IM(c2
) = IM(cc
[ac
-1]) + MUL_F(IM(t2
),tr11
) + MUL_F(IM(t3
),tr12
);
506 RE(c3
) = RE(cc
[ac
-1]) + MUL_F(RE(t2
),tr12
) + MUL_F(RE(t3
),tr11
);
507 IM(c3
) = IM(cc
[ac
-1]) + MUL_F(IM(t2
),tr12
) + MUL_F(IM(t3
),tr11
);
509 ComplexMult(&RE(c5
), &RE(c4
),
510 ti11
, ti12
, RE(t5
), RE(t4
));
511 ComplexMult(&IM(c5
), &IM(c4
),
512 ti11
, ti12
, IM(t5
), IM(t4
));
514 RE(ch
[ah
+l1
]) = RE(c2
) - IM(c5
);
515 IM(ch
[ah
+l1
]) = IM(c2
) + RE(c5
);
516 RE(ch
[ah
+2*l1
]) = RE(c3
) - IM(c4
);
517 IM(ch
[ah
+2*l1
]) = IM(c3
) + RE(c4
);
518 RE(ch
[ah
+3*l1
]) = RE(c3
) + IM(c4
);
519 IM(ch
[ah
+3*l1
]) = IM(c3
) - RE(c4
);
520 RE(ch
[ah
+4*l1
]) = RE(c2
) + IM(c5
);
521 IM(ch
[ah
+4*l1
]) = IM(c2
) - RE(c5
);
524 for (k
= 0; k
< l1
; k
++)
529 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+3]);
530 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+3]);
531 RE(t3
) = RE(cc
[ac
+1]) + RE(cc
[ac
+2]);
532 IM(t3
) = IM(cc
[ac
+1]) + IM(cc
[ac
+2]);
533 RE(t4
) = RE(cc
[ac
+1]) - RE(cc
[ac
+2]);
534 IM(t4
) = IM(cc
[ac
+1]) - IM(cc
[ac
+2]);
535 RE(t5
) = RE(cc
[ac
]) - RE(cc
[ac
+3]);
536 IM(t5
) = IM(cc
[ac
]) - IM(cc
[ac
+3]);
538 RE(ch
[ah
]) = RE(cc
[ac
-1]) + RE(t2
) + RE(t3
);
539 IM(ch
[ah
]) = IM(cc
[ac
-1]) + IM(t2
) + IM(t3
);
541 RE(c2
) = RE(cc
[ac
-1]) + MUL_F(RE(t2
),tr11
) + MUL_F(RE(t3
),tr12
);
542 IM(c2
) = IM(cc
[ac
-1]) + MUL_F(IM(t2
),tr11
) + MUL_F(IM(t3
),tr12
);
543 RE(c3
) = RE(cc
[ac
-1]) + MUL_F(RE(t2
),tr12
) + MUL_F(RE(t3
),tr11
);
544 IM(c3
) = IM(cc
[ac
-1]) + MUL_F(IM(t2
),tr12
) + MUL_F(IM(t3
),tr11
);
546 ComplexMult(&RE(c4
), &RE(c5
),
547 ti12
, ti11
, RE(t5
), RE(t4
));
548 ComplexMult(&IM(c4
), &IM(c5
),
549 ti12
, ti12
, IM(t5
), IM(t4
));
551 RE(ch
[ah
+l1
]) = RE(c2
) + IM(c5
);
552 IM(ch
[ah
+l1
]) = IM(c2
) - RE(c5
);
553 RE(ch
[ah
+2*l1
]) = RE(c3
) + IM(c4
);
554 IM(ch
[ah
+2*l1
]) = IM(c3
) - RE(c4
);
555 RE(ch
[ah
+3*l1
]) = RE(c3
) - IM(c4
);
556 IM(ch
[ah
+3*l1
]) = IM(c3
) + RE(c4
);
557 RE(ch
[ah
+4*l1
]) = RE(c2
) - IM(c5
);
558 IM(ch
[ah
+4*l1
]) = IM(c2
) + RE(c5
);
564 for (k
= 0; k
< l1
; k
++)
566 for (i
= 0; i
< ido
; i
++)
568 ac
= i
+ (k
*5 + 1) * ido
;
571 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+3*ido
]);
572 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+3*ido
]);
573 RE(t3
) = RE(cc
[ac
+ido
]) + RE(cc
[ac
+2*ido
]);
574 IM(t3
) = IM(cc
[ac
+ido
]) + IM(cc
[ac
+2*ido
]);
575 RE(t4
) = RE(cc
[ac
+ido
]) - RE(cc
[ac
+2*ido
]);
576 IM(t4
) = IM(cc
[ac
+ido
]) - IM(cc
[ac
+2*ido
]);
577 RE(t5
) = RE(cc
[ac
]) - RE(cc
[ac
+3*ido
]);
578 IM(t5
) = IM(cc
[ac
]) - IM(cc
[ac
+3*ido
]);
580 RE(ch
[ah
]) = RE(cc
[ac
-ido
]) + RE(t2
) + RE(t3
);
581 IM(ch
[ah
]) = IM(cc
[ac
-ido
]) + IM(t2
) + IM(t3
);
583 RE(c2
) = RE(cc
[ac
-ido
]) + MUL_F(RE(t2
),tr11
) + MUL_F(RE(t3
),tr12
);
584 IM(c2
) = IM(cc
[ac
-ido
]) + MUL_F(IM(t2
),tr11
) + MUL_F(IM(t3
),tr12
);
585 RE(c3
) = RE(cc
[ac
-ido
]) + MUL_F(RE(t2
),tr12
) + MUL_F(RE(t3
),tr11
);
586 IM(c3
) = IM(cc
[ac
-ido
]) + MUL_F(IM(t2
),tr12
) + MUL_F(IM(t3
),tr11
);
588 ComplexMult(&RE(c5
), &RE(c4
),
589 ti11
, ti12
, RE(t5
), RE(t4
));
590 ComplexMult(&IM(c5
), &IM(c4
),
591 ti11
, ti12
, IM(t5
), IM(t4
));
593 IM(d2
) = IM(c2
) + RE(c5
);
594 IM(d3
) = IM(c3
) + RE(c4
);
595 RE(d4
) = RE(c3
) + IM(c4
);
596 RE(d5
) = RE(c2
) + IM(c5
);
597 RE(d2
) = RE(c2
) - IM(c5
);
598 IM(d5
) = IM(c2
) - RE(c5
);
599 RE(d3
) = RE(c3
) - IM(c4
);
600 IM(d4
) = IM(c3
) - RE(c4
);
603 ComplexMult(&IM(ch
[ah
+l1
*ido
]), &RE(ch
[ah
+l1
*ido
]),
604 IM(d2
), RE(d2
), RE(wa1
[i
]), IM(wa1
[i
]));
605 ComplexMult(&IM(ch
[ah
+2*l1
*ido
]), &RE(ch
[ah
+2*l1
*ido
]),
606 IM(d3
), RE(d3
), RE(wa2
[i
]), IM(wa2
[i
]));
607 ComplexMult(&IM(ch
[ah
+3*l1
*ido
]), &RE(ch
[ah
+3*l1
*ido
]),
608 IM(d4
), RE(d4
), RE(wa3
[i
]), IM(wa3
[i
]));
609 ComplexMult(&IM(ch
[ah
+4*l1
*ido
]), &RE(ch
[ah
+4*l1
*ido
]),
610 IM(d5
), RE(d5
), RE(wa4
[i
]), IM(wa4
[i
]));
612 ComplexMult(&RE(ch
[ah
+l1
*ido
]), &IM(ch
[ah
+l1
*ido
]),
613 RE(d2
), IM(d2
), RE(wa1
[i
]), IM(wa1
[i
]));
614 ComplexMult(&RE(ch
[ah
+2*l1
*ido
]), &IM(ch
[ah
+2*l1
*ido
]),
615 RE(d3
), IM(d3
), RE(wa2
[i
]), IM(wa2
[i
]));
616 ComplexMult(&RE(ch
[ah
+3*l1
*ido
]), &IM(ch
[ah
+3*l1
*ido
]),
617 RE(d4
), IM(d4
), RE(wa3
[i
]), IM(wa3
[i
]));
618 ComplexMult(&RE(ch
[ah
+4*l1
*ido
]), &IM(ch
[ah
+4*l1
*ido
]),
619 RE(d5
), IM(d5
), RE(wa4
[i
]), IM(wa4
[i
]));
624 for (k
= 0; k
< l1
; k
++)
626 for (i
= 0; i
< ido
; i
++)
628 ac
= i
+ (k
*5 + 1) * ido
;
631 RE(t2
) = RE(cc
[ac
]) + RE(cc
[ac
+3*ido
]);
632 IM(t2
) = IM(cc
[ac
]) + IM(cc
[ac
+3*ido
]);
633 RE(t3
) = RE(cc
[ac
+ido
]) + RE(cc
[ac
+2*ido
]);
634 IM(t3
) = IM(cc
[ac
+ido
]) + IM(cc
[ac
+2*ido
]);
635 RE(t4
) = RE(cc
[ac
+ido
]) - RE(cc
[ac
+2*ido
]);
636 IM(t4
) = IM(cc
[ac
+ido
]) - IM(cc
[ac
+2*ido
]);
637 RE(t5
) = RE(cc
[ac
]) - RE(cc
[ac
+3*ido
]);
638 IM(t5
) = IM(cc
[ac
]) - IM(cc
[ac
+3*ido
]);
640 RE(ch
[ah
]) = RE(cc
[ac
-ido
]) + RE(t2
) + RE(t3
);
641 IM(ch
[ah
]) = IM(cc
[ac
-ido
]) + IM(t2
) + IM(t3
);
643 RE(c2
) = RE(cc
[ac
-ido
]) + MUL_F(RE(t2
),tr11
) + MUL_F(RE(t3
),tr12
);
644 IM(c2
) = IM(cc
[ac
-ido
]) + MUL_F(IM(t2
),tr11
) + MUL_F(IM(t3
),tr12
);
645 RE(c3
) = RE(cc
[ac
-ido
]) + MUL_F(RE(t2
),tr12
) + MUL_F(RE(t3
),tr11
);
646 IM(c3
) = IM(cc
[ac
-ido
]) + MUL_F(IM(t2
),tr12
) + MUL_F(IM(t3
),tr11
);
648 ComplexMult(&RE(c4
), &RE(c5
),
649 ti12
, ti11
, RE(t5
), RE(t4
));
650 ComplexMult(&IM(c4
), &IM(c5
),
651 ti12
, ti12
, IM(t5
), IM(t4
));
653 IM(d2
) = IM(c2
) - RE(c5
);
654 IM(d3
) = IM(c3
) - RE(c4
);
655 RE(d4
) = RE(c3
) - IM(c4
);
656 RE(d5
) = RE(c2
) - IM(c5
);
657 RE(d2
) = RE(c2
) + IM(c5
);
658 IM(d5
) = IM(c2
) + RE(c5
);
659 RE(d3
) = RE(c3
) + IM(c4
);
660 IM(d4
) = IM(c3
) + RE(c4
);
663 ComplexMult(&RE(ch
[ah
+l1
*ido
]), &IM(ch
[ah
+l1
*ido
]),
664 RE(d2
), IM(d2
), RE(wa1
[i
]), IM(wa1
[i
]));
665 ComplexMult(&RE(ch
[ah
+2*l1
*ido
]), &IM(ch
[ah
+2*l1
*ido
]),
666 RE(d3
), IM(d3
), RE(wa2
[i
]), IM(wa2
[i
]));
667 ComplexMult(&RE(ch
[ah
+3*l1
*ido
]), &IM(ch
[ah
+3*l1
*ido
]),
668 RE(d4
), IM(d4
), RE(wa3
[i
]), IM(wa3
[i
]));
669 ComplexMult(&RE(ch
[ah
+4*l1
*ido
]), &IM(ch
[ah
+4*l1
*ido
]),
670 RE(d5
), IM(d5
), RE(wa4
[i
]), IM(wa4
[i
]));
672 ComplexMult(&IM(ch
[ah
+l1
*ido
]), &RE(ch
[ah
+l1
*ido
]),
673 IM(d2
), RE(d2
), RE(wa1
[i
]), IM(wa1
[i
]));
674 ComplexMult(&IM(ch
[ah
+2*l1
*ido
]), &RE(ch
[ah
+2*l1
*ido
]),
675 IM(d3
), RE(d3
), RE(wa2
[i
]), IM(wa2
[i
]));
676 ComplexMult(&IM(ch
[ah
+3*l1
*ido
]), &RE(ch
[ah
+3*l1
*ido
]),
677 IM(d4
), RE(d4
), RE(wa3
[i
]), IM(wa3
[i
]));
678 ComplexMult(&IM(ch
[ah
+4*l1
*ido
]), &RE(ch
[ah
+4*l1
*ido
]),
679 IM(d5
), RE(d5
), RE(wa4
[i
]), IM(wa4
[i
]));
688 /*----------------------------------------------------------------------
689 cfftf1, cfftf, cfftb, cffti1, cffti. Complex FFTs.
690 ----------------------------------------------------------------------*/
692 static INLINE
void cfftf1pos(uint16_t n
, complex_t
*c
, complex_t
*ch
,
693 const uint16_t *ifac
, const complex_t
*wa
,
698 uint16_t na
, nf
, ip
, iw
, ix2
, ix3
, ix4
, ido
, idl1
;
705 for (k1
= 2; k1
<= nf
+1; k1
++)
719 passf4pos((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)c
, ch
, &wa
[iw
], &wa
[ix2
], &wa
[ix3
]);
721 passf4pos((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)ch
, c
, &wa
[iw
], &wa
[ix2
], &wa
[ix3
]);
727 passf2pos((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)c
, ch
, &wa
[iw
]);
729 passf2pos((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)ch
, c
, &wa
[iw
]);
737 passf3((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)c
, ch
, &wa
[iw
], &wa
[ix2
], isign
);
739 passf3((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)ch
, c
, &wa
[iw
], &wa
[ix2
], isign
);
749 passf5((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)c
, ch
, &wa
[iw
], &wa
[ix2
], &wa
[ix3
], &wa
[ix4
], isign
);
751 passf5((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)ch
, c
, &wa
[iw
], &wa
[ix2
], &wa
[ix3
], &wa
[ix4
], isign
);
764 for (i
= 0; i
< n
; i
++)
766 RE(c
[i
]) = RE(ch
[i
]);
767 IM(c
[i
]) = IM(ch
[i
]);
771 static INLINE
void cfftf1neg(uint16_t n
, complex_t
*c
, complex_t
*ch
,
772 const uint16_t *ifac
, const complex_t
*wa
,
777 uint16_t na
, nf
, ip
, iw
, ix2
, ix3
, ix4
, ido
, idl1
;
784 for (k1
= 2; k1
<= nf
+1; k1
++)
798 passf4neg((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)c
, ch
, &wa
[iw
], &wa
[ix2
], &wa
[ix3
]);
800 passf4neg((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)ch
, c
, &wa
[iw
], &wa
[ix2
], &wa
[ix3
]);
806 passf2neg((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)c
, ch
, &wa
[iw
]);
808 passf2neg((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)ch
, c
, &wa
[iw
]);
816 passf3((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)c
, ch
, &wa
[iw
], &wa
[ix2
], isign
);
818 passf3((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)ch
, c
, &wa
[iw
], &wa
[ix2
], isign
);
828 passf5((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)c
, ch
, &wa
[iw
], &wa
[ix2
], &wa
[ix3
], &wa
[ix4
], isign
);
830 passf5((const uint16_t)ido
, (const uint16_t)l1
, (const complex_t
*)ch
, c
, &wa
[iw
], &wa
[ix2
], &wa
[ix3
], &wa
[ix4
], isign
);
843 for (i
= 0; i
< n
; i
++)
845 RE(c
[i
]) = RE(ch
[i
]);
846 IM(c
[i
]) = IM(ch
[i
]);
850 void cfftf(cfft_info
*cfft
, complex_t
*c
)
852 cfftf1neg(cfft
->n
, c
, cfft
->work
, (const uint16_t*)cfft
->ifac
, (const complex_t
*)cfft
->tab
, -1);
855 void cfftb(cfft_info
*cfft
, complex_t
*c
)
857 cfftf1pos(cfft
->n
, c
, cfft
->work
, (const uint16_t*)cfft
->ifac
, (const complex_t
*)cfft
->tab
, +1);
860 static void cffti1(uint16_t n
, complex_t
*wa
, uint16_t *ifac
)
862 static uint16_t ntryh
[4] = {3, 4, 2, 5};
864 real_t arg
, argh
, argld
, fi
;
866 uint16_t i1
, k1
, l1
, l2
;
869 uint16_t ntry
= 0, i
, j
;
871 uint16_t nf
, nl
, nq
, nr
;
897 if (ntry
== 2 && nf
!= 1)
899 for (i
= 2; i
<= nf
; i
++)
902 ifac
[ib
+1] = ifac
[ib
];
912 argh
= (real_t
)2.0*(real_t
)M_PI
/ (real_t
)n
;
916 for (k1
= 1; k1
<= nf
; k1
++)
924 for (j
= 0; j
< ipm
; j
++)
933 for (ii
= 0; ii
< ido
; ii
++)
938 RE(wa
[i
]) = (real_t
)cos(arg
);
940 IM(wa
[i
]) = (real_t
)sin(arg
);
942 IM(wa
[i
]) = (real_t
)-sin(arg
);
948 RE(wa
[i1
]) = RE(wa
[i
]);
949 IM(wa
[i1
]) = IM(wa
[i
]);
957 cfft_info
*cffti(uint16_t n
)
959 cfft_info
*cfft
= (cfft_info
*)faad_malloc(sizeof(cfft_info
));
962 cfft
->work
= (complex_t
*)faad_malloc(n
*sizeof(complex_t
));
965 cfft
->tab
= (complex_t
*)faad_malloc(n
*sizeof(complex_t
));
967 cffti1(n
, cfft
->tab
, cfft
->ifac
);
969 cffti1(n
, NULL
, cfft
->ifac
);
973 case 64: cfft
->tab
= (complex_t
*)cfft_tab_64
; break;
974 case 512: cfft
->tab
= (complex_t
*)cfft_tab_512
; break;
976 case 256: cfft
->tab
= (complex_t
*)cfft_tab_256
; break;
979 #ifdef ALLOW_SMALL_FRAMELENGTH
980 case 60: cfft
->tab
= (complex_t
*)cfft_tab_60
; break;
981 case 480: cfft
->tab
= (complex_t
*)cfft_tab_480
; break;
983 case 240: cfft
->tab
= (complex_t
*)cfft_tab_240
; break;
986 case 128: cfft
->tab
= (complex_t
*)cfft_tab_128
; break;
993 void cfftu(cfft_info
*cfft
)
995 if (cfft
->work
) faad_free(cfft
->work
);
997 if (cfft
->tab
) faad_free(cfft
->tab
);
1000 if (cfft
) faad_free(cfft
);