Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
fftadapter.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // Adapter for fast Fourier transformations
22 //=============================================================================
23 
24 #ifndef FFTADAPTER
25 #define FFTADAPTER
26 
27 #include <complex>
28 #include <vector>
29 #include <map>
30 #include <memory>
31 
32 // Data types to be processed by the FFT software
33 using FFTRealType = double;
34 using FFTComplexType = std::complex<double>;
35 using FFTRealVector = std::vector<FFTRealType>;
36 using FFTComplexVector = std::vector<FFTComplexType>;
37 
38 // external used datatypes
39 
43 using FFTWVector = std::vector<FFTWType>;
45 typedef std::map<double,double> FFTPolygon;
46 
55 struct FFTData {
57  int samplingRate = -1;
58 
66  bool isValid() {
67  return fft.size() > 0 && samplingRate > 0;
68  }
69 
75  double getTime() {
76  return fft.size() * 2.0 / samplingRate;
77  }
78 };
79 
86 using FFTDataPointer = std::shared_ptr<FFTData>;
87 
99 
101 {
102 public:
103 
105  virtual ~FFTAdapter() {}
106 
107  virtual void calculateFFT (const FFTRealVector &in, FFTComplexVector &out) = 0;
108  virtual void calculateFFT (const FFTComplexVector &in, FFTRealVector &out) = 0;
109 
110  // Call these functions to speed up FFT with the same size
111  virtual void optimize (FFTRealVector &in) = 0;
112  virtual void optimize (FFTComplexVector &in) = 0;
113 
114 };
115 
116 #endif // FFTADAPTER
117 
bool isValid()
Function to validate the fft data.
Definition: fftadapter.h:66
virtual void calculateFFT(const FFTRealVector &in, FFTComplexVector &out)=0
std::vector< FFTComplexType > FFTComplexVector
Definition: fftadapter.h:36
std::map< double, double > FFTPolygon
Type for a frequency-to-intensity map for graphics.
Definition: fftadapter.h:45
int samplingRate
The sampling rate of the fft.
Definition: fftadapter.h:57
virtual ~FFTAdapter()
Definition: fftadapter.h:105
virtual void optimize(FFTRealVector &in)=0
Abstract base class for handling fast Fourier transforms.
Definition: fftadapter.h:100
std::complex< double > FFTComplexType
Definition: fftadapter.h:34
double getTime()
Function to get the time of the signal in seconds.
Definition: fftadapter.h:75
double FFTRealType
Definition: fftadapter.h:33
FFTRealType FFTWType
data type
Definition: fftadapter.h:41
std::vector< FFTRealType > FFTRealVector
Definition: fftadapter.h:35
FFTWVector fft
The actual fft.
Definition: fftadapter.h:56
std::shared_ptr< FFTData > FFTDataPointer
Shared pointer of FFTData.
Definition: fftadapter.h:86
std::vector< FFTWType > FFTWVector
fftw array
Definition: fftadapter.h:43
Data struct for a FFT.
Definition: fftadapter.h:55