diff --git a/kissfft.hh b/kissfft.hh index 213e4e2..9a7fb7c 100644 --- a/kissfft.hh +++ b/kissfft.hh @@ -1,6 +1,7 @@ #ifndef KISSFFT_CLASS_HH #define KISSFFT_CLASS_HH #include +#include #include @@ -44,6 +45,30 @@ class kissfft }while(n>1); } + + /// Changes the FFT-length and/or the transform direction. + /// + /// @post The @c kissfft object will be in the same state as if it + /// had been newly constructed with the passed arguments. + /// However, the implementation may be faster than constructing a + /// new fft object. + void assign( std::size_t nfft, + bool inverse ) + { + if ( nfft != _nfft ) + { + kissfft tmp( nfft, inverse ); // O(n) time. + std::swap( tmp, *this ); // this is O(1) in C++11, O(n) otherwise. + } + else if ( inverse != _inverse ) + { + // conjugate the twiddle factors. + for ( typename std::vector::iterator it = _twiddles.begin(); + it != _twiddles.end(); ++it ) + it->imag( -it->imag() ); + } + } + /// Calculates the complex Discrete Fourier Transform. /// /// The size of the passed arrays must be passed in the constructor.