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
fftanalyzer.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 // FFT Analyzer
22 //=============================================================================
23 
24 #ifndef FFTANALYZER_H
25 #define FFTANALYZER_H
26 
27 #include <map>
28 
29 #include "fftanalyzererrorcodes.h"
30 #include "../piano/piano.h"
31 #include "../system/prerequisites.h"
32 #include "../math/fftadapter.h"
33 #include "../math/fftimplementation.h"
34 
42 
44 {
45 public:
46 
49 
50  FFTAnalyzer();
52 
53  std::pair<FFTAnalyzerErrorTypes, std::shared_ptr<Key> > analyse(
54  const Piano *piano,
55  FFTDataPointer finalFFT,
56  int finalKey);
57 
59  FFTDataPointer finalFFT,
60  const Piano *piano,
61  const Key &key,
62  int keyIndex);
63 
64 private:
65 
67 
72 
73 
74 private:
76  SpectrumType constructKernel(const SpectrumType &originalSpectrum);
77  TuningDeviationCurveType computeTuningDeviation(const SpectrumType &kernel, const SpectrumType &signal, int searchSize);
78  int locatePeak (const SpectrumType &spectrum, int m, int width);
79  double interpolatePeakPosition (const SpectrumType &spectrum, int m, int width);
80  int findNearestKey (double f, double conertPitch, int numberOfKeys, int keyNumberOfA);
81  double estimateFrequency (int keynumber, double concertPitch, int keyNumberOfA);
82  double findAccuratePeakFrequency (FFTDataPointer fftData, double f, int cents=5);
83 
84  double getExpectedInharmonicity (double f);
85  double estimateInharmonicity (FFTDataPointer fftData, SpectrumType &spectrum, double f);
86  double estimateQuality ();
87  double estimateFrequencyShift();
88  PeakListType identifyPeaks (FFTDataPointer fftData, const SpectrumType &spectrum, const double f, const double B);
89 
90  void Write(std::string filename, SpectrumType &v); // only for development
91  void Write(std::string filename, FFTComplexVector &v);
92  void WritePeaks(std::string filename, SpectrumType &v, PeakListType &peaks); // only for development
93 };
94 
95 #endif // FFTANALYZER_H
~FFTAnalyzer()
Empty destructor.
Definition: fftanalyzer.h:51
double findAccuratePeakFrequency(FFTDataPointer fftData, double f, int cents=5)
Find the accurate frequency of a spectral peak in the original FFT.
FFTAnalyzer()
Constructor.
Definition: fftanalyzer.cpp:41
Key::PeakListType PeakListType
Type for a peak map.
Definition: fftanalyzer.h:48
std::vector< FFTComplexType > FFTComplexVector
Definition: fftadapter.h:36
SpectrumType mCurrentKernel
The current kernel for the key detection.
Definition: fftanalyzer.h:70
Class describing a single piano key.
Definition: key.h:45
TuningDeviationCurveType computeTuningDeviation(const SpectrumType &kernel, const SpectrumType &signal, int searchSize)
static const int NumberOfBins
Total number of slots: 9 octaves.
Definition: key.h:50
std::vector< double > TuningDeviationCurveType
The FrequencyDetectionResultStruct struct.
double getExpectedInharmonicity(double f)
Definition: piano.h:40
Key::SpectrumType SpectrumType
Type of a log spectrum.
Definition: fftanalyzer.h:47
double estimateFrequencyShift()
PeakListType identifyPeaks(FFTDataPointer fftData, const SpectrumType &spectrum, const double f, const double B)
void Write(std::string filename, SpectrumType &v)
std::pair< FFTAnalyzerErrorTypes, std::shared_ptr< Key > > analyse(const Piano *piano, FFTDataPointer finalFFT, int finalKey)
Main analyzing function.
Definition: fftanalyzer.cpp:62
const int NumberOfBins
Definition: fftanalyzer.h:66
FFT_Implementation mFFT
Instance of FFT implementation.
Definition: fftanalyzer.h:69
std::vector< double > SpectrumType
Type of a log-binned spectrum.
Definition: key.h:54
int findNearestKey(double f, double conertPitch, int numberOfKeys, int keyNumberOfA)
Compute the number of the nearest key.
SpectrumType constructKernel(const SpectrumType &originalSpectrum)
FrequencyDetectionResult detectFrequencyOfKnownKey(FFTDataPointer finalFFT, const Piano *piano, const Key &key, int keyIndex)
FFTAnalyzer::detectFrequencyOfKnownKey.
Module performing the final analysis of the Fourier transform.
Definition: fftanalyzer.h:43
const Key * mCurrentKernelKey
The key of which mCurrentKernel belongs to.
Definition: fftanalyzer.h:71
int locatePeak(const SpectrumType &spectrum, int m, int width)
std::shared_ptr< FFTData > FFTDataPointer
Shared pointer of FFTData.
Definition: fftadapter.h:86
double interpolatePeakPosition(const SpectrumType &spectrum, int m, int width)
double estimateInharmonicity(FFTDataPointer fftData, SpectrumType &spectrum, double f)
Estimate the inharmonicity B.
double estimateQuality()
std::map< double, double > PeakListType
Type for a peak map.
Definition: key.h:55
std::shared_ptr< FrequencyDetectionResultStruct > FrequencyDetectionResult
void constructLogBinnedSpectrum(FFTDataPointer fftData, SpectrumType &spectrum)
Construct logarithmically binned spectrum from the mFinalFFT.
double estimateFrequency(int keynumber, double concertPitch, int keyNumberOfA)
Estimate the frequency for a given keynumber.
void WritePeaks(std::string filename, SpectrumType &v, PeakListType &peaks)
Thread-safe implementation of fftw3.
SpectrumType mOptimalSuperposition
Superposition of the partials.
Definition: fftanalyzer.h:68