Entropy Piano Tuner
1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
|
The WaveformGenerator class. More...
#include <waveformgenerator.h>
Public Types | |
using | Waveform = std::vector< float > |
using | Spectrum = std::map< double, double > |
Public Member Functions | |
WaveformGenerator () | |
Constructor, resetting the member variables. More... | |
void | init (int numberOfKeys, int samplerate) |
Initialization procedure of the waveform generator. More... | |
void | exit () |
void | preCalculate (int keynumber, const Spectrum &spectrum) |
pre-calculate a waveform More... | |
Waveform | getWaveForm (const int keynumber) |
Mutexed getter function to obtain the calculated waveform. More... | |
float | getInterpolation (const Waveform &W, const double t) |
Get an a linearly interpolated value of the waveform. More... | |
bool | isComputing (const int keynumber) |
Find out whether the WaveformGenerator is still computing. More... | |
Public Member Functions inherited from SimpleThreadHandler | |
SimpleThreadHandler () | |
Constructor. More... | |
virtual | ~SimpleThreadHandler () |
virtual destructor calls stop More... | |
virtual void | start () |
Start the thread. More... | |
virtual void | stop () |
Stop the thread. More... | |
Private Member Functions | |
void | workerFunction () |
Main thread function for wavefrom generation. More... | |
Private Attributes | |
const double | mWaveformTime = 15 |
int | mSampleRate |
int | mWaveformSize = 0 |
int | mNumberOfKeys |
std::vector< Waveform > | mLibrary |
std::vector< std::mutex > | mLibraryMutex |
std::vector< bool > | mComputing |
FFTComplexVector | mIn |
FFTRealVector | mOut |
FFT_Implementation | mFFT |
std::map< int, Spectrum > | mQueue |
std::mutex | mQueueMutex |
Additional Inherited Members | |
Static Public Member Functions inherited from SimpleThreadHandler | |
static void | setThreadName (std::string s) |
Specify the name of the thread. More... | |
Protected Member Functions inherited from SimpleThreadHandler | |
virtual void | exceptionCaught (const EptException &e) |
EPT exception handling. More... | |
void | setCancelThread (bool b) |
Cancel-flag setter method, thread-safe. More... | |
bool | cancelThread () const |
Cancel-flag getter method, thread-safe. More... | |
void | msleep (double milliseconds) |
Sleep function for staying idle. More... | |
bool | isThreadRunning () const |
Flag to check if the thread is running. More... | |
The WaveformGenerator class.
The purpose of this class is mainly to save time. In early versions of the EPT we generated the waveforms in real time. This led on small mobile devices to problems if more the one key was pressed. The present wave form generator creates the PCM waveforms in advance and stores them in a vector. This costs some memory but it save a lot of time. The waveform is generated in the recording pitch. The synthesizer changes the pitch if required by resampling.
The WaveformGenerator runs in an independent thread with normal priority.
Definition at line 44 of file waveformgenerator.h.
using WaveformGenerator::Spectrum = std::map<double,double> |
Definition at line 55 of file waveformgenerator.h.
using WaveformGenerator::Waveform = std::vector<float> |
Definition at line 54 of file waveformgenerator.h.
WaveformGenerator::WaveformGenerator | ( | ) |
Constructor, resetting the member variables.
Definition at line 38 of file waveformgenerator.cpp.
|
inline |
float WaveformGenerator::getInterpolation | ( | const Waveform & | W, |
const double | t | ||
) |
Get an a linearly interpolated value of the waveform.
In this class the generated waveforms are stored in the pitch of the original recording. After tuning different pitches are needed. This is achieved in the Synthesizer by resampling the pre-calculated PCM signal around the mean sampling rate. To this end one needs a function which interpolates the waveform between neighboring indices.
W | : The waveform as a vector of floats |
t | : Continuous time |
Definition at line 151 of file waveformgenerator.cpp.
WaveformGenerator::Waveform WaveformGenerator::getWaveForm | ( | const int | keynumber | ) |
Mutexed getter function to obtain the calculated waveform.
keynumber | : Number of the key (registration id) |
Definition at line 125 of file waveformgenerator.cpp.
void WaveformGenerator::init | ( | int | numberOfKeys, |
int | samplerate | ||
) |
Initialization procedure of the waveform generator.
This function initializes the waveform generator. It depends on the number of keys and the actual output sampling rate. If these parameters are changed during runtime, the waveform generator needs to be reinitialized. The function basically allocates the memory needed for waveform generation.
numberOfKeys | : Total number of keys |
samplerate | : Actual sampling rate of the ouput device |
Definition at line 66 of file waveformgenerator.cpp.
bool WaveformGenerator::isComputing | ( | const int | keynumber | ) |
Find out whether the WaveformGenerator is still computing.
In some cases, for example when playing the echo sound after recording, it is necessary to re-calculate the waveform and to make sure that the new waveform (and not the previous one) is played. This means that one has to wait for the computation to finish – a task accomplished by ths function.
keynumber | : Number of the key |
Definition at line 176 of file waveformgenerator.cpp.
void WaveformGenerator::preCalculate | ( | int | keynumber, |
const Spectrum & | spectrum | ||
) |
pre-calculate a waveform
Whenever a new spectrum has been recorded or a file has been loaded, the EPT asks the WaveformGenerator to pre-calculate the waveform. This pre-calculation is first stored in a local queue in order to free the calling thread as soon as possible.
keynumber | : The number of the key to which the spectrum belongs |
spectrum | : Spectrum as a map from frequency to intensity |
Definition at line 105 of file waveformgenerator.cpp.
|
privatevirtual |
Main thread function for wavefrom generation.
This thread checks the queue of pre-calculation requests. If there is such a request it is removed from the queue and a new wave form is computed. The generation is done by using FFTW3. Each peak gets a complex random phase in order to avoid a synchronous "click" at the beginning.
Implements SimpleThreadHandler.
Definition at line 195 of file waveformgenerator.cpp.
|
private |
Definition at line 71 of file waveformgenerator.h.
|
private |
Definition at line 74 of file waveformgenerator.h.
|
private |
Definition at line 72 of file waveformgenerator.h.
|
private |
Definition at line 69 of file waveformgenerator.h.
|
private |
Definition at line 70 of file waveformgenerator.h.
|
private |
Definition at line 68 of file waveformgenerator.h.
|
private |
Definition at line 73 of file waveformgenerator.h.
|
private |
Definition at line 75 of file waveformgenerator.h.
|
private |
Definition at line 76 of file waveformgenerator.h.
|
private |
Definition at line 66 of file waveformgenerator.h.
|
private |
Definition at line 67 of file waveformgenerator.h.
|
private |
Definition at line 50 of file waveformgenerator.h.