mirror of
https://github.com/mborgerding/kissfft.git
synced 2025-06-04 01:28:23 -04:00
Removed the needless use of a traits class.
This commit is contained in:
parent
b10fb43644
commit
0395af753e
64
kissfft.hh
64
kissfft.hh
@ -3,35 +3,30 @@
|
|||||||
#include <complex>
|
#include <complex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace kissfft_utils {
|
|
||||||
|
|
||||||
template <typename T_scalar>
|
template <typename T_Scalar,
|
||||||
struct traits
|
typename T_Complex=std::complex<T_Scalar>
|
||||||
|
>
|
||||||
|
class kissfft
|
||||||
{
|
{
|
||||||
typedef T_scalar scalar_type;
|
public:
|
||||||
typedef std::complex<scalar_type> cpx_type;
|
typedef T_Scalar scalar_type;
|
||||||
static void fill_twiddles( cpx_type * dst,
|
typedef T_Complex cpx_type;
|
||||||
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<nfft;++i)
|
|
||||||
dst[i] = std::exp( cpx_type(0,i*phinc) );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void prepare(
|
kissfft( std::size_t nfft,
|
||||||
std::vector< cpx_type > & _twiddles,
|
bool inverse )
|
||||||
std::size_t nfft,
|
:_nfft(nfft)
|
||||||
bool inverse,
|
,_inverse(inverse)
|
||||||
std::vector<std::size_t> & stageRadix,
|
|
||||||
std::vector<std::size_t> & stageRemainder )
|
|
||||||
{
|
{
|
||||||
_twiddles.resize(nfft);
|
// fill twiddle factors
|
||||||
fill_twiddles( &_twiddles[0],nfft,inverse);
|
_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
|
//factorize
|
||||||
//start factoring out 4's, then 2's, then 3,5,7,9,...
|
//start factoring out 4's, then 2's, then 3,5,7,9,...
|
||||||
std::size_t n= nfft;
|
std::size_t n= _nfft;
|
||||||
std::size_t p=4;
|
std::size_t p=4;
|
||||||
do {
|
do {
|
||||||
while (n % p) {
|
while (n % p) {
|
||||||
@ -44,31 +39,10 @@ struct traits
|
|||||||
p = n;// no more factors
|
p = n;// no more factors
|
||||||
}
|
}
|
||||||
n /= p;
|
n /= p;
|
||||||
stageRadix.push_back(p);
|
_stageRadix.push_back(p);
|
||||||
stageRemainder.push_back(n);
|
_stageRemainder.push_back(n);
|
||||||
}while(n>1);
|
}while(n>1);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T_Scalar,
|
|
||||||
typename T_traits=kissfft_utils::traits<T_Scalar>
|
|
||||||
>
|
|
||||||
class kissfft
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef T_traits traits_type;
|
|
||||||
typedef typename traits_type::scalar_type scalar_type;
|
|
||||||
typedef typename traits_type::cpx_type cpx_type;
|
|
||||||
|
|
||||||
kissfft( std::size_t nfft,
|
|
||||||
bool inverse )
|
|
||||||
:_nfft(nfft)
|
|
||||||
,_inverse(inverse)
|
|
||||||
{
|
|
||||||
T_traits::prepare(_twiddles, _nfft,_inverse ,_stageRadix, _stageRemainder);
|
|
||||||
}
|
|
||||||
|
|
||||||
void transform( const cpx_type * src,
|
void transform( const cpx_type * src,
|
||||||
cpx_type * dst ) const
|
cpx_type * dst ) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user