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
waveformgenerator.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 // PCM Waveform generator using FFTW3
22 //=============================================================================
23 
24 #ifndef WAVEFORMGENERATOR_H
25 #define WAVEFORMGENERATOR_H
26 
27 #include "../../system/simplethreadhandler.h"
28 #include "../../math/fftimplementation.h"
29 
43 
45 {
46 private:
47 #ifdef __ANDROID__
48  const double mWaveformTime = 5;
49 #else
50  const double mWaveformTime = 15;
51 #endif
52 
53 public:
54  using Waveform = std::vector<float>;
55  using Spectrum = std::map<double,double>; // type of spectrum
56 
58  void init (int numberOfKeys, int samplerate);
59  void exit () { stop(); }
60  void preCalculate (int keynumber, const Spectrum &spectrum);
61  Waveform getWaveForm (const int keynumber);
62  float getInterpolation(const Waveform &W, const double t);
63  bool isComputing (const int keynumber);
64 
65 private:
67  int mWaveformSize = 0;
69  std::vector<Waveform> mLibrary;
70  std::vector<std::mutex> mLibraryMutex;
71  std::vector<bool> mComputing;
75  std::map<int,Spectrum> mQueue;
76  std::mutex mQueueMutex;
77 
78 private:
79  void workerFunction();
80 };
81 
82 #endif // WAVEFORMGENERATOR_H
std::map< int, Spectrum > mQueue
The WaveformGenerator class.
virtual void stop()
Stop the thread.
std::vector< FFTComplexType > FFTComplexVector
Definition: fftadapter.h:36
FFT_Implementation mFFT
FFTRealVector mOut
std::map< double, double > Spectrum
std::vector< Waveform > mLibrary
void init(int numberOfKeys, int samplerate)
Initialization procedure of the waveform generator.
const double mWaveformTime
FFTComplexVector mIn
std::vector< bool > mComputing
std::vector< float > Waveform
Waveform getWaveForm(const int keynumber)
Mutexed getter function to obtain the calculated waveform.
bool isComputing(const int keynumber)
Find out whether the WaveformGenerator is still computing.
float getInterpolation(const Waveform &W, const double t)
Get an a linearly interpolated value of the waveform.
std::vector< FFTRealType > FFTRealVector
Definition: fftadapter.h:35
void preCalculate(int keynumber, const Spectrum &spectrum)
pre-calculate a waveform
std::vector< std::mutex > mLibraryMutex
void workerFunction()
Main thread function for wavefrom generation.
WaveformGenerator()
Constructor, resetting the member variables.
Simple thread handler.
Thread-safe implementation of fftw3.