diff --git a/fft.hh b/fft.hh index 6c65499..25c5697 100644 --- a/fft.hh +++ b/fft.hh @@ -7,33 +7,28 @@ Copyright 2018 Ahmet Inan #ifndef FFT_HH #define FFT_HH +#include "unit_circle.hh" #include "const.hh" namespace DSP { namespace FFT { template -static inline TYPE rsqrt2(TYPE a) +static constexpr TYPE rsqrt2(TYPE a) { return Const::InvSqrtTwo() * a; } -template -static inline TYPE twopi(TYPE n, TYPE N) +template +static constexpr TYPE cx(TYPE a) { - return Const::TwoPi() * n / N; + return UnitCircle::cos(n, N) * a; } template -static inline TYPE cx(TYPE a) +static constexpr TYPE sx(TYPE a) { - return std::cos(twopi(n, N)) * a; -} - -template -static inline TYPE sx(TYPE a) -{ - return std::sin(twopi(n, N)) * a; + return UnitCircle::sin(n, N) * a; } template @@ -1122,10 +1117,8 @@ public: typedef typename TYPE::value_type value_type; FastFourierTransform() { - for (int n = 0; n < BINS; ++n) { - value_type a = SIGN * FFT::twopi(n, BINS); - factors[n] = TYPE(std::cos(a), std::sin(a)); - } + for (int n = 0; n < BINS; ++n) + factors[n] = TYPE(UnitCircle::cos(n, BINS), SIGN * UnitCircle::sin(n, BINS)); } inline void operator ()(TYPE *out, const TYPE *in) {