ape  0.5.0
Audio Programming Environment
fft.h
Go to the documentation of this file.
1 #ifndef CPPAPE_FFT_H
2 #define CPPAPE_FFT_H
3 
4 #include "baselib.h"
5 #include "misc.h"
6 #include <complex>
7 
8 namespace ape
9 {
15  template<typename T>
16  class FFT;
17 
23  template<typename T>
24  class FFTBase
25  {
26  public:
27 
31  void forward(uarray<std::complex<T>> inout)
32  {
33  assert(inout.size() == size);
34 
35  perform(APE_FFT_Forward, inout.data(), inout.data());
36  }
37 
41  void forward(uarray<const std::complex<T>> in, uarray<std::complex<T>> out)
42  {
43  assert(in.size() == size);
44  assert(out.size() == size);
45 
46  perform(APE_FFT_Forward, in.data(), out.data());
47  }
48 
55  void forwardReal(uarray<const T> in, uarray<std::complex<T>> out)
56  {
57  assert(in.size() == size);
58  assert(out.size() == size);
59 
60  perform(APE_FFT_Forward, in.data(), out.data());
61  }
62 
67  void inverse(uarray<std::complex<T>> inout)
68  {
69  assert(inout.size() == size);
70 
71  perform(APE_FFT_Inverse, inout.data(), inout.data());
72  }
73 
78  void inverse(uarray<const std::complex<T>> in, uarray<std::complex<T>> out)
79  {
80  assert(in.size() == size);
81  assert(out.size() == size);
82 
83  perform(APE_FFT_Inverse, in.data(), out.data());
84  }
85 
90  void inverseNonScaled(uarray<std::complex<T>> inout)
91  {
92  assert(inout.size() == size);
93 
94  perform(APE_FFT_Inverse | APE_FFT_NonScaled, inout.data(), inout.data());
95  }
96 
101  void inverseNonScaled(uarray<const std::complex<T>> in, uarray<std::complex<T>> out)
102  {
103  assert(in.size() == size);
104  assert(out.size() == size);
105 
106  perform(APE_FFT_Inverse | APE_FFT_NonScaled, in.data(), out.data());
107  }
108 
109  FFTBase(FFTBase&& other)
110  : size(other.size), fft(other.fft)
111  {
112  other.fft = 0;
113  }
114 
116  {
117  size = other.size;
118  fft = other.fft;
119  other.fft = 0;
120 
121  return *this;
122  }
123 
124  FFTBase& operator = (const FFTBase& other) = delete;
125  FFTBase(const FFTBase& other) = delete;
126 
128  {
129  if(fft != 0)
130  getInterface().releaseFFT(&getInterface(), fft);
131  }
132 
133  protected:
134 
135  FFTBase(std::size_t N, int fft)
136  : size(N), fft(fft)
137  {
138  }
139 
140  private:
141 
142  void perform(APE_FFT_Options options, const void* in, void* out)
143  {
144  assert(fft != 0);
145  assert(size != 0);
146 
147  getInterface().performFFT(&getInterface(), fft, options, in, out);
148  }
149 
150  std::size_t size;
151  int fft;
152  };
153 
157  template<>
158  class FFT<float> : public FFTBase<float>
159  {
160  public:
161 
168  FFT(std::size_t N)
169  : FFTBase(N, getInterface().createFFT(&getInterface(), APE_DataType_Single, N))
170  {
171  }
172 
176  FFT() : FFTBase(0, 0) {}
177  };
178 
182  template<>
183  class FFT<double> : public FFTBase<double>
184  {
185  public:
186 
193  FFT(std::size_t N)
194  : FFTBase(N, getInterface().createFFT(&getInterface(), APE_DataType_Double, N))
195  {
196  }
197 
201  FFT() : FFTBase(0, 0) {}
202 
203  };
204 
205 }
206 
207 #endif
ape::getInterface
APE_SharedInterface & getInterface()
Acquire the low-level C API.
ape::FFTBase::inverseNonScaled
void inverseNonScaled(uarray< std::complex< T >> inout)
Do in-place backwards / inverse complex fourier transform. The output will not be scaled.
Definition: fft.h:90
ape::FFTBase::forward
void forward(uarray< std::complex< T >> inout)
Do in-place forward complex fourier transform
Definition: fft.h:31
APE_DataType_Double
Definition: SharedInterface.h:52
ape::FFTBase
Shared operations on typed FFTs. FFT<float>, FFT<double>
Definition: fft.h:24
APE_FFT_NonScaled
Definition: SharedInterface.h:60
ape::FFTBase::inverseNonScaled
void inverseNonScaled(uarray< const std::complex< T >> in, uarray< std::complex< T >> out)
Do out of place backwards / inverse complex fourier transform. The output will not be scaled.
Definition: fft.h:101
APE_FFT_Forward
Definition: SharedInterface.h:58
ape::FFTBase::operator=
FFTBase & operator=(FFTBase &&other)
Definition: fft.h:115
misc.h
APE_FFT_Inverse
Definition: SharedInterface.h:57
ape::uarray
An unowned array wrapper - a mutable "view" of something else, that cannot be resized....
Definition: misc.h:24
ape::FFTBase::FFTBase
FFTBase(FFTBase &&other)
Definition: fft.h:109
ape::FFTBase::forwardReal
void forwardReal(uarray< const T > in, uarray< std::complex< T >> out)
Do out of place forward real only fourier transform
Definition: fft.h:55
ape
Definition: audiofile.h:7
ape::FFTBase::inverse
void inverse(uarray< std::complex< T >> inout)
Do in-place backwards / inverse complex fourier transform. The output will be scaled back such that i...
Definition: fft.h:67
ape::FFT< double >::FFT
FFT()
Default-initialized, invalid fft.
Definition: fft.h:201
ape::uarray::size
std::size_t size() const noexcept
Returns the size of the array pointed to by this uarray
Definition: misc.h:113
ape::FFTBase::~FFTBase
~FFTBase()
Definition: fft.h:127
ape::uarray::data
T * data() noexcept
Retrieve a raw pointer to the array pointed to
Definition: misc.h:104
ape::FFT< double >::FFT
FFT(std::size_t N)
Create a new instance of an fft.
Definition: fft.h:193
baselib.h
ape::FFT< float >::FFT
FFT()
Default-initialized, invalid fft.
Definition: fft.h:176
APE_DataType_Single
Definition: SharedInterface.h:51
ape::FFTBase::inverse
void inverse(uarray< const std::complex< T >> in, uarray< std::complex< T >> out)
Do out of place backwards / inverse complex fourier transform. The output will be scaled back such th...
Definition: fft.h:78
ape::FFT
A typed FFT. FFT<float>, FFT<double>
Definition: fft.h:16
ape::FFTBase::FFTBase
FFTBase(std::size_t N, int fft)
Definition: fft.h:135
ape::FFTBase::forward
void forward(uarray< const std::complex< T >> in, uarray< std::complex< T >> out)
Do out of place forward complex fourier transform
Definition: fft.h:41
APE_FFT_Options
APE_FFT_Options
Definition: SharedInterface.h:55
ape::FFT< float >::FFT
FFT(std::size_t N)
Create a new instance of an fft.
Definition: fft.h:168