24 #ifndef KEYRECOGNIZER_H
25 #define KEYRECOGNIZER_H
27 #include "../system/simplethreadhandler.h"
28 #include "../messages/messagelistener.h"
29 #include "../piano/piano.h"
30 #include "../math/fftimplementation.h"
43 virtual void keyRecognized(
int keyIndex,
double frequency) = 0;
68 void init(
bool optimize);
72 int selectedKey,
bool keyForced);
107 void Write(std::
string filename, std::vector<
double> &v,
bool log=true);
110 #endif // KEYRECOGNIZER_H
FFTDataPointer mFFTPtr
Pointer to Fourier transform.
double detectForcedFrequency()
Detect forced key.
FFT_Implementation mFFT
Instance of FFT implementation.
std::vector< double > mFlatSpectrum
DoubleLogarithmic spectrum (LogLogSpec)
std::vector< FFTComplexType > FFTComplexVector
void signalPreprocessing()
Preprocessing of the signal.
Callback class for KeyRecognizer.
void init(bool optimize)
Initialization of the KeyRecognizer.
void constructLogSpec()
Construct logarithmic spectrum.
int mKeyNumberOfA
Index of the A-key.
static const int M
Number of bins (powers of 2,3,5)
KeyRecognizer(KeyRecognizerCallback *callback)
Constructor of the KeyRecognizer.
int ftom(double f)
Map frequency to bin index.
void Write(std::string filename, std::vector< double > &v, bool log=true)
FFTComplexVector mFlatFFT
Fourier transform of LogLogSpec.
double mConcertPitch
Actual frequency of the A-key.
bool mKeyForced
Flag indicating that the key is forced.
void defineKernel()
Define the kernel vector for key recognition.
double estimateFrequency()
Estimate frequency for a given log-log spectrum.
void workerFunction() overridefinal
Main worker function for executing the key recognition thread.
std::vector< double > mLogSpec
Logarithmic spectrum (LogSpec)
static const double logfmax
Log of maximal frequency.
double detectFrequencyInTreble()
Detect keys in the treble.
const Piano * mPiano
Pointer to the piano data.
void recognizeKey(bool forceRestart, const Piano *piano, FFTDataPointer fftPointer, int selectedKey, bool keyForced)
Start key recognition.
virtual void keyRecognized(int keyIndex, double frequency)=0
int mNumberOfKeys
Number of piano keys.
std::vector< FFTRealType > FFTRealVector
static const double fmax
Frequency of bin M-1.
int mSelectedKey
Number of the actually selected key.
Module for fast recognition of the pressed key.
FFTComplexVector mKernelFFT
Fourier transform of the kernel.
KeyRecognizerCallback * mCallback
Pointer to the caller.
std::shared_ptr< FFTData > FFTDataPointer
Shared pointer of FFTData.
FFTRealVector mConvolution
Convolution vector.
static const double fmin
Frequency of bin 0.
static const double logfmin
Log of minimal frequency.
double mtof(int m)
Map bin index to frequency.
int findNearestKey(double f)
Find the nearest key for a given frequency.
Thread-safe implementation of fftw3.