Entropy Piano Tuner
1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
|
Module performing the final analysis of the Fourier transform. More...
#include <fftanalyzer.h>
Public Types | |
using | SpectrumType = Key::SpectrumType |
Type of a log spectrum. More... | |
using | PeakListType = Key::PeakListType |
Type for a peak map. More... | |
Public Member Functions | |
FFTAnalyzer () | |
Constructor. More... | |
~FFTAnalyzer () | |
Empty destructor. More... | |
std::pair < FFTAnalyzerErrorTypes, std::shared_ptr< Key > > | analyse (const Piano *piano, FFTDataPointer finalFFT, int finalKey) |
Main analyzing function. More... | |
FrequencyDetectionResult | detectFrequencyOfKnownKey (FFTDataPointer finalFFT, const Piano *piano, const Key &key, int keyIndex) |
FFTAnalyzer::detectFrequencyOfKnownKey. More... | |
Private Member Functions | |
void | constructLogBinnedSpectrum (FFTDataPointer fftData, SpectrumType &spectrum) |
Construct logarithmically binned spectrum from the mFinalFFT. More... | |
SpectrumType | constructKernel (const SpectrumType &originalSpectrum) |
TuningDeviationCurveType | computeTuningDeviation (const SpectrumType &kernel, const SpectrumType &signal, int searchSize) |
int | locatePeak (const SpectrumType &spectrum, int m, int width) |
double | interpolatePeakPosition (const SpectrumType &spectrum, int m, int width) |
int | findNearestKey (double f, double conertPitch, int numberOfKeys, int keyNumberOfA) |
Compute the number of the nearest key. More... | |
double | estimateFrequency (int keynumber, double concertPitch, int keyNumberOfA) |
Estimate the frequency for a given keynumber. More... | |
double | findAccuratePeakFrequency (FFTDataPointer fftData, double f, int cents=5) |
Find the accurate frequency of a spectral peak in the original FFT. More... | |
double | getExpectedInharmonicity (double f) |
double | estimateInharmonicity (FFTDataPointer fftData, SpectrumType &spectrum, double f) |
Estimate the inharmonicity B. More... | |
double | estimateQuality () |
double | estimateFrequencyShift () |
PeakListType | identifyPeaks (FFTDataPointer fftData, const SpectrumType &spectrum, const double f, const double B) |
void | Write (std::string filename, SpectrumType &v) |
void | Write (std::string filename, FFTComplexVector &v) |
void | WritePeaks (std::string filename, SpectrumType &v, PeakListType &peaks) |
Private Attributes | |
const int | NumberOfBins =Key::NumberOfBins |
SpectrumType | mOptimalSuperposition |
Superposition of the partials. More... | |
FFT_Implementation | mFFT |
Instance of FFT implementation. More... | |
SpectrumType | mCurrentKernel |
The current kernel for the key detection. More... | |
const Key * | mCurrentKernelKey |
The key of which mCurrentKernel belongs to. More... | |
Module performing the final analysis of the Fourier transform.
After completion of the recording process, the SignalAnalyzer sends the final Fourier transform via MessageNewFFTCalculated with a 'ture' flag to the FFT analyzer.
Definition at line 43 of file fftanalyzer.h.
Type for a peak map.
Definition at line 48 of file fftanalyzer.h.
Type of a log spectrum.
Definition at line 47 of file fftanalyzer.h.
FFTAnalyzer::FFTAnalyzer | ( | ) |
Constructor.
Definition at line 41 of file fftanalyzer.cpp.
|
inline |
Empty destructor.
Definition at line 51 of file fftanalyzer.h.
std::pair< FFTAnalyzerErrorTypes, std::shared_ptr< Key > > FFTAnalyzer::analyse | ( | const Piano * | piano, |
FFTDataPointer | finalFFT, | ||
int | finalKey | ||
) |
Main analyzing function.
piano | Pointer to the piano |
finalFFT | Data of the final fourier transformation |
sampling | rate the sampling rate |
finalKey | the identified key |
This function controls the main tasks of the FFTAnalyzer and is used by the SignalAnalyzer to analyze the final fft.
Definition at line 62 of file fftanalyzer.cpp.
|
private |
Definition at line 312 of file fftanalyzer.cpp.
|
private |
|
private |
Construct logarithmically binned spectrum from the mFinalFFT.
The FFT analysis yields a Fourier transform with an index which is linear in the frequency. For the tuning process, however, we need a spectrum which is logarithmic in the frequency. Only then it is possible to tune the key by simply shifting the index of the spectrum. This function transforms the incoming FFT into a logarithmically binned spectrum. The dimension NumberOfBins is copied from the constant in class Key. The actual map between the indices can be found in Key::IndexToFrequency.
fftData | Data of the fourier transform |
spectrum | Vector holding the logarithmically binned spectrum. |
Definition at line 291 of file fftanalyzer.cpp.
FrequencyDetectionResult FFTAnalyzer::detectFrequencyOfKnownKey | ( | FFTDataPointer | finalFFT, |
const Piano * | piano, | ||
const Key & | key, | ||
int | keyIndex | ||
) |
FFTAnalyzer::detectFrequencyOfKnownKey.
finalFFT | |
piano | |
key | |
keyIndex |
Definition at line 167 of file fftanalyzer.cpp.
|
private |
Estimate the frequency for a given keynumber.
This function uses a heuristic average tuning curve to roughly estimate the frequency of a given key. This function can be seen as an inverse of findNearestKey.
keynumber | : Number of the key |
Definition at line 420 of file fftanalyzer.cpp.
|
private |
|
private |
Estimate the inharmonicity B.
This function estimates the inharmonicity coefficient B on the basis of the recorded data. This estimate serves as a quality and consistency check.
The function uses the frequency estimate that has been obtained before by determineFrequency. The frequency and inhamronicity is then optimized iteratively. This is achieved by minimizing the Renyi entropy of the collapsed peak according to the known inharmonicity formula.
spectrum | : Logarithmically binned spectrum |
f | : Previous frequency estimate |
Definition at line 510 of file fftanalyzer.cpp.
|
private |
|
private |
Find the accurate frequency of a spectral peak in the original FFT.
The logarithmically binned spectrum has a resolution of one cent. However, the spectral peaks are not always mapped faithfully but their location may be slightly different (due to the integration involved in the mapping). To eliminate this uncertainty, the present function looks for the maximum of the spectral line in the original FFT and returns its frequency.
f | : Estimate of the frequency where the peak is supposed to be. |
cents | : Width of the search window around f in cents. |
Definition at line 449 of file fftanalyzer.cpp.
|
private |
Compute the number of the nearest key.
This function uses a heuristic average tuning curve to estimate the most likely number of the key for a given frequency.
f | : Frequency in Hz. |
Definition at line 394 of file fftanalyzer.cpp.
|
private |
This function provides a very rough estimate of the expected inharmonicity coefficient of an average upright. It is used improve the expectation where the spectral lines should be located in the spectrum during key recognition.
f | : frequency in Hz |
Definition at line 484 of file fftanalyzer.cpp.
|
private |
|
private |
Search for a local peak in the logarithmically binned spectrum. Optimize the index as a floating-point value
spectrum | : Logarithmically binned spectrum |
m | : Spectral index |
width | : Searching width in +/- cents |
Definition at line 363 of file fftanalyzer.cpp.
|
private |
Search for a local peak in the logarithmically binned spectrum
spectrum | : Logarithmically binned spectrum |
m | : Spectral index |
width | : Searching width in +/- cents |
Definition at line 341 of file fftanalyzer.cpp.
|
private |
|
private |
Definition at line 676 of file fftanalyzer.cpp.
|
private |
|
private |
The current kernel for the key detection.
Definition at line 70 of file fftanalyzer.h.
|
private |
The key of which mCurrentKernel belongs to.
Definition at line 71 of file fftanalyzer.h.
|
private |
Instance of FFT implementation.
Definition at line 69 of file fftanalyzer.h.
|
private |
Superposition of the partials.
Definition at line 68 of file fftanalyzer.h.
|
private |
Definition at line 66 of file fftanalyzer.h.