From 0395af753ecb6962bf21d87855061a6b485b677a Mon Sep 17 00:00:00 2001 From: Ralph Tandetzky Date: Thu, 21 Apr 2016 13:20:29 +0200 Subject: [PATCH] Removed the needless use of a traits class. --- kissfft.hh | 80 ++++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 53 deletions(-) diff --git a/kissfft.hh b/kissfft.hh index 9fdded3..b098d16 100644 --- a/kissfft.hh +++ b/kissfft.hh @@ -3,71 +3,45 @@ #include #include -namespace kissfft_utils { - -template -struct traits -{ - typedef T_scalar scalar_type; - typedef std::complex cpx_type; - static void fill_twiddles( cpx_type * dst, - std::size_t nfft, - bool inverse ) - { - const T_scalar phinc = (inverse?2:-2)* acos( (T_scalar) -1) / nfft; - for (std::size_t i=0;i & _twiddles, - std::size_t nfft, - bool inverse, - std::vector & stageRadix, - std::vector & stageRemainder ) - { - _twiddles.resize(nfft); - fill_twiddles( &_twiddles[0],nfft,inverse); - - //factorize - //start factoring out 4's, then 2's, then 3,5,7,9,... - std::size_t n= nfft; - std::size_t p=4; - do { - while (n % p) { - switch (p) { - case 4: p = 2; break; - case 2: p = 3; break; - default: p += 2; break; - } - if (p*p>n) - p = n;// no more factors - } - n /= p; - stageRadix.push_back(p); - stageRemainder.push_back(n); - }while(n>1); - } -}; - -} template + typename T_Complex=std::complex > class kissfft { public: - typedef T_traits traits_type; - typedef typename traits_type::scalar_type scalar_type; - typedef typename traits_type::cpx_type cpx_type; + typedef T_Scalar scalar_type; + typedef T_Complex cpx_type; kissfft( std::size_t nfft, bool inverse ) :_nfft(nfft) ,_inverse(inverse) { - T_traits::prepare(_twiddles, _nfft,_inverse ,_stageRadix, _stageRemainder); + // fill twiddle factors + _twiddles.resize(_nfft); + const scalar_type phinc = (_inverse?2:-2)* acos( (scalar_type) -1) / _nfft; + for (std::size_t i=0;i<_nfft;++i) + _twiddles[i] = std::exp( cpx_type(0,i*phinc) ); + + //factorize + //start factoring out 4's, then 2's, then 3,5,7,9,... + std::size_t n= _nfft; + std::size_t p=4; + do { + while (n % p) { + switch (p) { + case 4: p = 2; break; + case 2: p = 3; break; + default: p += 2; break; + } + if (p*p>n) + p = n;// no more factors + } + n /= p; + _stageRadix.push_back(p); + _stageRemainder.push_back(n); + }while(n>1); } void transform( const cpx_type * src,