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 Class Reference

The WaveformGenerator class. More...

#include <waveformgenerator.h>

+ Inheritance diagram for WaveformGenerator:
+ Collaboration diagram for WaveformGenerator:

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< WaveformmLibrary
std::vector< std::mutex > mLibraryMutex
std::vector< bool > mComputing
FFTComplexVector mIn
FFTRealVector mOut
FFT_Implementation mFFT
std::map< int, SpectrummQueue
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...

Detailed Description

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.

Member Typedef Documentation

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.

Constructor & Destructor Documentation

WaveformGenerator::WaveformGenerator ( )

Constructor, resetting the member variables.

Definition at line 38 of file waveformgenerator.cpp.

Member Function Documentation

void WaveformGenerator::exit ( )

Definition at line 59 of file waveformgenerator.h.

+ Here is the call graph for this function:

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
Interpolated PCM value

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)
Waveform as a vector of floats

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
: True if the WaveformGenerator is still computing this 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.

void WaveformGenerator::workerFunction ( )

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.

+ Here is the call graph for this function:

Member Data Documentation

std::vector<bool> WaveformGenerator::mComputing

Definition at line 71 of file waveformgenerator.h.

FFT_Implementation WaveformGenerator::mFFT

Definition at line 74 of file waveformgenerator.h.

FFTComplexVector WaveformGenerator::mIn

Definition at line 72 of file waveformgenerator.h.

std::vector<Waveform> WaveformGenerator::mLibrary

Definition at line 69 of file waveformgenerator.h.

std::vector<std::mutex> WaveformGenerator::mLibraryMutex

Definition at line 70 of file waveformgenerator.h.

int WaveformGenerator::mNumberOfKeys

Definition at line 68 of file waveformgenerator.h.

FFTRealVector WaveformGenerator::mOut

Definition at line 73 of file waveformgenerator.h.

std::map<int,Spectrum> WaveformGenerator::mQueue

Definition at line 75 of file waveformgenerator.h.

std::mutex WaveformGenerator::mQueueMutex

Definition at line 76 of file waveformgenerator.h.

int WaveformGenerator::mSampleRate

Definition at line 66 of file waveformgenerator.h.

int WaveformGenerator::mWaveformSize = 0

Definition at line 67 of file waveformgenerator.h.

const double WaveformGenerator::mWaveformTime = 15

Definition at line 50 of file waveformgenerator.h.

The documentation for this class was generated from the following files: