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
soundgenerator.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 // Sound generator driving the synthesizer
22 //=============================================================================
23 
24 #ifndef SOUNDGENERATOR_H
25 #define SOUNDGENERATOR_H
26 
27 
28 #include "synthesizer.h"
29 #include "soundgenerator.h"
30 #include "../midi/midiadapter.h"
31 #include "../../piano/piano.h"
32 #include "../../messages/messagelistener.h"
33 
40 
42 {
43 public:
44  SoundGenerator (AudioPlayerAdapter *audioAdapter);
46 
47  void init () { }
48  void exit () { mSynthesizer.exit(); }
49 
52  {
56  };
57 
58 private:
59  void handleMessage(MessagePtr m) override final;
61  void playResonatingSineWave (int keynumber, double frequency, double volume);
62  void playResonatingReferenceSound (int keynumber);
64  void changeVolumeOfResonatingReferenceSound (double level);
65  void preCalculateSoundOfKey (const int keynumber);
66  void preCalculateSoundOfKey (const int keynumber, Synthesizer::Spectrum &spectrum);
68 
69 private:
71  const Piano *mPiano;
78 };
79 
80 #endif // SOUNDGENERATOR_H
void preCalculateSoundOfAllKeys()
Calculate the sound of all keys in advance.
std::shared_ptr< Message > MessagePtr
Global type of a shared message pointer.
Definition: message.h:98
void handleMessage(MessagePtr m) overridefinal
Sound generator message listener and dispatcher.
Class for managing the sound generation in the EPT.
OperationMode
Operation mode of the tuner.
Definition: prerequisites.h:66
void stopResonatingReferenceSound()
Stop the resonating reference sound.
int mResonatingKey
Keynumber of the resonating sound.
double mResonatingVolume
Volume of the resonating sound.
void preCalculateSoundOfKey(const int keynumber)
Calculate the sound of a given key in advance, using the spectrum of the given key.
Synthesizer mSynthesizer
Instance of the synthesizer.
SoundGeneratorMode
Mode for sound generation.
const Piano * mPiano
Pointer to the piano.
SoundGenerator(AudioPlayerAdapter *audioAdapter)
Constructor, initializes the member variables.
Definition: piano.h:40
void exit()
Synthesizer shutdown.
OperationMode mOperationMode
Copy of the operation mode.
void playResonatingSineWave(int keynumber, double frequency, double volume)
Play a permanent sine wave as a resonating background sound for tuning.
virtual void exit() overridefinal
Exit, shut down writer interface.
Definition: synthesizer.h:118
int mSelectedKey
Copy of selected key.
Synthesizer class.
Definition: synthesizer.h:109
int mNumberOfKeys
Copy of the number of keys.
void playResonatingReferenceSound(int keynumber)
Play a resonating reference sound in the tuning mode.
Produce a sound which imitates the string.
void handleMidiKeypress(MidiAdapter::Data &data)
Handle MIDI keypress.
Produce a simple sine wave as reference.
void init()
Initialize (no functionality)
std::map< double, double > Spectrum
Definition: synthesizer.h:113
Abstract adapter class for PCM-based audio output drivers.
int mKeyNumberOfA4
Copy of A-key position.
void changeVolumeOfResonatingReferenceSound(double level)
Change the volume of the resonating reference sound.
Structure of the data associated with a MIDI event.
Definition: midiadapter.h:88