Entropy Piano Tuner
1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
|
Thread-safe implementation of fftw3. More...
#include <fftimplementation.h>
Public Member Functions | |
FFT_Implementation () | |
Constructor, clears member variables and checks type consistency. More... | |
~FFT_Implementation () | |
Destructor, deletes plans and local vector copies if existing. More... | |
void | calculateFFT (const FFTRealVector &in, FFTComplexVector &out) |
Foward FFT, mapping a real vector with size N to a complex one with size N/2+1. More... | |
void | calculateFFT (const FFTComplexVector &in, FFTRealVector &out) |
Backward FFT, mapping a complex vector with size M to a complex one with size 2M-1. More... | |
void | optimize (FFTRealVector &in) |
Optimize plan for the forward transfomation. More... | |
void | optimize (FFTComplexVector &in) |
Optimize plan for the backward transformation. More... | |
Public Member Functions inherited from FFTAdapter | |
FFTAdapter () | |
virtual | ~FFTAdapter () |
Private Member Functions | |
void | updatePlan (const FFTRealVector &in, unsigned flags) |
Construct a new plan for the FFT transformation if necessary. More... | |
void | updatePlan (const FFTComplexVector &in, unsigned flags) |
Construct a new plan for the FFT transformation if necessary. More... | |
Private Attributes | |
double * | mRvec1 |
Local copy of incoming real data. More... | |
double * | mRvec2 |
Local copy of outgoing real data. More... | |
fftw_complex * | mCvec1 |
Local copy of incoming complex data. More... | |
fftw_complex * | mCvec2 |
Local copy of outgoing complex data. More... | |
size_t | mNRC |
Size of the FFT real -> complex. More... | |
size_t | mNCR |
Size of the FFT complex -> real. More... | |
fftw_plan | mPlanRC |
Plan for FFT real -> complex. More... | |
fftw_plan | mPlanCR |
Plan for FFT complex -> real. More... | |
Static Private Attributes | |
static std::mutex | mPlanMutex |
Static mutex protecting planmaking. More... | |
Thread-safe implementation of fftw3.
USAGE: FFT's can be carried out simply by calling the function calculateFFT with the corresponding arguments. If a given instance has to carry out a larger number of FFTs using the same vector sizes it is meaningful to optimize the calculation by initially calling the function optimize with the input vector as the argument.
DETAILS: A Fourier transformation using fftw3 requires two steps. First a so-called 'plan' has to be computed which optimizes the FFT algorithm. Then in a second step the actual Fourier transform is carried out. A plan may be kept for several calculations as long as the location of the vectors and their sizes are not changed. By keeping a plan the computation time is drastically reduced.
As of now, the second step (the FFT) is thread-safe while the first one is not. This means that only one thread is allowed to create a plan at a given time. To this end this implementation class protects all accesses to planmaking by a static mutex. In addition, it keeps local input and output vectors with a constant location.
The class provides two types of FFTs, namely, real to complex and comples to real. The second one is the inverse of the first one.
Since memory allocation should be carried out with the inbuilt allocation function of FFTW3, the implementation copies the vectors into local member vectors by memcpy.
Definition at line 66 of file fftimplementation.h.
FFT_Implementation::FFT_Implementation | ( | ) |
Constructor, clears member variables and checks type consistency.
Definition at line 48 of file fftimplementation.cpp.
FFT_Implementation::~FFT_Implementation | ( | ) |
Destructor, deletes plans and local vector copies if existing.
Definition at line 74 of file fftimplementation.cpp.
|
virtual |
Foward FFT, mapping a real vector with size N to a complex one with size N/2+1.
in | : vector of real numbers of size N |
out | : vector of complex numbers, will be resized to N/2+1 |
Implements FFTAdapter.
Definition at line 230 of file fftimplementation.cpp.
|
virtual |
Backward FFT, mapping a complex vector with size M to a complex one with size 2M-1.
in | : vector of complex numbers of size M |
out | : vector of real numbers, will be resized to size 2*M-1 |
Implements FFTAdapter.
Definition at line 257 of file fftimplementation.cpp.
|
virtual |
Optimize plan for the forward transfomation.
This function should be called at the beginning if the subsequent code performs many FFTs on vectors with varying content, but with the same location and the same size. Note that this function may be time-consuming, but it accelerates subsequent computations significantly.
in | : vector of real numbers to be transformed |
Implements FFTAdapter.
Definition at line 105 of file fftimplementation.cpp.
|
virtual |
Optimize plan for the backward transformation.
This function should be called at the beginning if the subsequent code performs many FFTs on vectors with varying content, but with the same location and the same size. Note that this function may be time-consuming, but it accelerates subsequent computations significantly.
in | : vector of complex numbers to be transformed |
Implements FFTAdapter.
Definition at line 126 of file fftimplementation.cpp.
|
private |
Construct a new plan for the FFT transformation if necessary.
This function checks whether the plan and the local vectors still exist and whether they have the correct size. If so, the function does nothing which means that the existing plan will be reused. Ohterwise, it deletes the plan and the vectors and constructs them again with the given size.
in | : vector of real numbers of size N |
flags | : fftw3 internal flags controlling planmaking |
Definition at line 149 of file fftimplementation.cpp.
|
private |
Construct a new plan for the FFT transformation if necessary.
This function checks whether the plan and the local vectors still exist and whether they have the correct size. If so, the function does nothing which means that the existing plan will be reused. Ohterwise, it deletes the plan and the vectors and constructs them again with the given size.
in | : vector of complex numbers |
flags | : fftw3 internal flags controlling planmaking |
Definition at line 192 of file fftimplementation.cpp.
|
private |
Local copy of incoming complex data.
Definition at line 88 of file fftimplementation.h.
|
private |
Local copy of outgoing complex data.
Definition at line 89 of file fftimplementation.h.
|
private |
Size of the FFT complex -> real.
Definition at line 91 of file fftimplementation.h.
|
private |
Size of the FFT real -> complex.
Definition at line 90 of file fftimplementation.h.
|
private |
Plan for FFT complex -> real.
Definition at line 94 of file fftimplementation.h.
|
staticprivate |
Static mutex protecting planmaking.
Definition at line 95 of file fftimplementation.h.
|
private |
Plan for FFT real -> complex.
Definition at line 93 of file fftimplementation.h.
|
private |
Local copy of incoming real data.
Definition at line 86 of file fftimplementation.h.
|
private |
Local copy of outgoing real data.
Definition at line 87 of file fftimplementation.h.