4 * Copyright (C) 2007 Krzysztof Foltman
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02111-1307, USA.
29 /// FFT routine copied from my old OneSignal library, modified to
30 /// match Calf's style. It's not fast at all, just a straightforward
32 template<class T
, int O
>
35 typedef typename
std::complex<T
> complex;
43 for (int i
=0; i
<N
; i
++)
46 for (int j
=0; j
<O
; j
++)
52 T divN
= 2 * M_PI
/ N
;
54 for (int i
=0; i
<N90
; i
++)
57 T c
= cos(angle
), s
= sin(angle
);
58 sines
[i
+ 3 * N90
] = -(sines
[i
+ N90
] = complex(-s
, c
));
59 sines
[i
+ 2 * N90
] = -(sines
[i
] = complex(c
, s
));
62 void calculate(complex *input
, complex *output
, bool inverse
)
67 // Scramble the input data
73 complex &c
=input
[scramble
[i
]];
74 output
[i
]=mf
*complex(c
.imag(),c
.real());
79 output
[i
]=input
[scramble
[i
]];
84 int PO
=1<<i
, PNO
=1<<(O
-i
-1);
93 complex r1
=output
[B1
];
94 complex r2
=output
[B2
];
95 output
[B1
]=r1
+r2
*sines
[(B1
<<(O
-i
-1))&N1
];
96 output
[B2
]=r1
+r2
*sines
[(B2
<<(O
-i
-1))&N1
];
104 const complex &c
=output
[i
];
105 output
[i
]=complex(c
.imag(),c
.real());