Entropy Piano Tuner
1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
|
Class for managing the sound generation in the EPT. More...
#include <soundgenerator.h>
Public Types | |
enum | SoundGeneratorMode { SGM_DEACTIVATED, SGM_SYNTHESIZE_KEY, SGM_REFERENCE_TONE } |
Mode for sound generation. More... | |
Public Member Functions | |
SoundGenerator (AudioPlayerAdapter *audioAdapter) | |
Constructor, initializes the member variables. More... | |
~SoundGenerator () | |
void | init () |
Initialize (no functionality) More... | |
void | exit () |
Synthesizer shutdown. More... | |
Private Member Functions | |
void | handleMessage (MessagePtr m) overridefinal |
Sound generator message listener and dispatcher. More... | |
void | handleMidiKeypress (MidiAdapter::Data &data) |
Handle MIDI keypress. More... | |
void | playResonatingSineWave (int keynumber, double frequency, double volume) |
Play a permanent sine wave as a resonating background sound for tuning. More... | |
void | playResonatingReferenceSound (int keynumber) |
Play a resonating reference sound in the tuning mode. More... | |
void | stopResonatingReferenceSound () |
Stop the resonating reference sound. More... | |
void | changeVolumeOfResonatingReferenceSound (double level) |
Change the volume of the resonating reference sound. More... | |
void | preCalculateSoundOfKey (const int keynumber) |
Calculate the sound of a given key in advance, using the spectrum of the given key. More... | |
void | preCalculateSoundOfKey (const int keynumber, Synthesizer::Spectrum &spectrum) |
Calculate the sound of a given key in advance, using an explicit spectrum passed as a parameter. More... | |
void | preCalculateSoundOfAllKeys () |
Calculate the sound of all keys in advance. More... | |
Private Attributes | |
Synthesizer | mSynthesizer |
Instance of the synthesizer. More... | |
const Piano * | mPiano |
Pointer to the piano. More... | |
OperationMode | mOperationMode |
Copy of the operation mode. More... | |
int | mNumberOfKeys |
Copy of the number of keys. More... | |
int | mKeyNumberOfA4 |
Copy of A-key position. More... | |
int | mSelectedKey |
Copy of selected key. More... | |
int | mResonatingKey |
Keynumber of the resonating sound. More... | |
double | mResonatingVolume |
Volume of the resonating sound. More... | |
Class for managing the sound generation in the EPT.
This class manages and composes the sound to be played by the synthesizer. It is completely driven by messages. It is some kind of SoundGenerationManager.
Definition at line 41 of file soundgenerator.h.
Mode for sound generation.
Enumerator | |
---|---|
SGM_DEACTIVATED |
No sound generation. |
SGM_SYNTHESIZE_KEY |
Produce a sound which imitates the string. |
SGM_REFERENCE_TONE |
Produce a simple sine wave as reference. |
Definition at line 51 of file soundgenerator.h.
SoundGenerator::SoundGenerator | ( | AudioPlayerAdapter * | audioAdapter | ) |
Constructor, initializes the member variables.
audioadapter | : Pointer to the audio output implementation |
Definition at line 54 of file soundgenerator.cpp.
|
inline |
Definition at line 45 of file soundgenerator.h.
|
private |
Change the volume of the resonating reference sound.
In order to produce an efficient interference, the volume of the resonating reference sound is adjusted automatically to the actual volume of the piano. To this end the 'level' sent to the VU meter is mapped back to a volume and the sustain level of the reference sound in the synthesizer is changed accordingly.
level | : Level between 0 and 1 |
Definition at line 395 of file soundgenerator.cpp.
|
inline |
Synthesizer shutdown.
Definition at line 48 of file soundgenerator.h.
|
finaloverrideprivatevirtual |
Sound generator message listener and dispatcher.
The sound generator is exclusively driven by messages. The present function listens to the messages and takes action accordingly.
m | : Pointer to the message. |
Implements MessageListener.
Definition at line 79 of file soundgenerator.cpp.
|
private |
Handle MIDI keypress.
This function takes action on MIDI keypress events depending on the actual operation mode. In the tuning mode the MIDI keybaord plays simple ET sine waves. In the recording mode it echos the recorded key as a confirmation of successful recording. In the calculating mode it can be used to test the computed tuning curve by playing the MIDI keyboard.
data | : Data structure delivered by the MIDI event. |
Definition at line 249 of file soundgenerator.cpp.
|
inline |
Initialize (no functionality)
Definition at line 47 of file soundgenerator.h.
|
private |
Play a resonating reference sound in the tuning mode.
To support accurate tuning, the EPT generates an imitation of the recorded piano sound in the computed tune in the background. This allows the user to tune the strings according to the sound in the earphone.
The following function starts such a "resonating reference sound". To avoid interference with the MIDI playback system, which is also active in the tuning mode, the synthesizer id's of the reference sound are internally shifted by mNumberOfKeys.
keynumber | : Number of the key. |
Definition at line 325 of file soundgenerator.cpp.
|
private |
Play a permanent sine wave as a resonating background sound for tuning.
keynumber | : Number of the key |
frequency | : Frequency of the sine wave to be played. |
volume | : Volume of the tone |
Definition at line 418 of file soundgenerator.cpp.
|
private |
Calculate the sound of all keys in advance.
Definition at line 476 of file soundgenerator.cpp.
|
private |
Calculate the sound of a given key in advance, using the spectrum of the given key.
keynumber | : Number of the key |
Definition at line 445 of file soundgenerator.cpp.
|
private |
Calculate the sound of a given key in advance, using an explicit spectrum passed as a parameter.
keynumber | : Number of the key |
spectrum | : The explicit spectrum |
Definition at line 462 of file soundgenerator.cpp.
|
private |
Stop the resonating reference sound.
Definition at line 369 of file soundgenerator.cpp.
|
private |
Copy of A-key position.
Definition at line 74 of file soundgenerator.h.
|
private |
Copy of the number of keys.
Definition at line 73 of file soundgenerator.h.
|
private |
Copy of the operation mode.
Definition at line 72 of file soundgenerator.h.
|
private |
Pointer to the piano.
Definition at line 71 of file soundgenerator.h.
|
private |
Keynumber of the resonating sound.
Definition at line 76 of file soundgenerator.h.
|
private |
Volume of the resonating sound.
Definition at line 77 of file soundgenerator.h.
|
private |
Copy of selected key.
Definition at line 75 of file soundgenerator.h.
|
private |
Instance of the synthesizer.
Definition at line 70 of file soundgenerator.h.