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
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  *****************************************************************************/
20 //=============================================================================
21 // Iterative entropy minimization
22 //=============================================================================
31 namespace entropyminimizer
32 {
49 {
50 public:
51  EntropyMinimizer(const Piano &piano, const AlgorithmFactoryDescription &desciption);
54 protected:
55  virtual void handleMessage(MessagePtr m) override final;
56  void algorithmWorkerFunction() override final;
58 private:
62  void minimizeEntropy ();
65  using Keys = Keyboard::Keys;
69 private:
72  static double ftom (double f) { return Key::FrequencyToRealIndex(f); }
74  static double mtof (int m) { return Key::IndexToFrequency(m); }
76  void updateTuningcurve (int keynumber);
77  void updateTuningcurve ();
78  void clear();
79  double getElement(SpectrumType &spectrum, int m);
80  void addToAccumulator (SpectrumType &spectrum, int shift, double intensity);
81  void modifySpectralComponent (int key, int pitch);
83  void addReferenceSpectrum (double intensity);
84  int getTolerance (int keynumber);
86  double computeEntropy();
88 private:
90  std::vector<int> mPitch;
91  std::vector<double>mInitialPitch;
98  double getRecordedPitchET440(int keynumber);
99  int getRecordedPitchET440AsInt(int keynumber);
100  int getPitchET440(int keynumber, double f);
102 protected:
103  // only for development:
104  void writeAccumulator(std::string filename);
105  void writeSpectrum(int k, std::string filename, int pitch=0);
106 };
108 } // namespace entropyminimizer
int getTolerance(int keynumber)
Allowed tolerance of the tuning curve during the Monte Carlo process.
std::shared_ptr< Message > MessagePtr
Global type of a shared message pointer.
Definition: message.h:98
SpectrumType mAccumulator
Accumulator holding the sum of all spectra.
std::vector< int > mPitch
Vector of pitches (in cents)
std::vector< double > mInitialPitch
Vector of initial pitches.
Class describing the piano keyboard, holding a collection of keys.
Definition: keyboard.h:39
bool mRecalculateEntropy
Flag for entropy recalculation (after manual intervention by the user)
void ComputeInitialTuningCurve()
Compute initial condition of the tuning curve.
static double mtof(int m)
Convert array index in cent spacing to frequency in Hz.
void writeAccumulator(std::string filename)
int mRecalculateKey
Number of manually changed key.
bool performAuditoryPreprocessing()
Auditory preprocessing.
Class describing a single piano key.
Definition: key.h:45
void algorithmWorkerFunction() overridefinal
Main calculation, running in an independent thread.
Definition: piano.h:40
void addReferenceSpectrum(double intensity)
void addToAccumulator(SpectrumType &spectrum, int shift, double intensity)
Add or subtract a spectrum to the accumulator.
int mUpperCutoff
Upper cutoff for fluctuations.
static double IndexToFrequency(double m)
Convert continuous slot index to frequency in Hz.
Definition: key.cpp:102
virtual void handleMessage(MessagePtr m) overridefinal
Message listener and dispatcher for mouse clicks in the tuning curve.
int getRecordedPitchET440AsInt(int keynumber)
Get recorded pitch.
double mRecalculateFrequency
Frequency of manually changed key.
static double ftom(double f)
Convert frequency to array index in cent spacing.
static double FrequencyToRealIndex(double f)
Convert frequency to real-valued logbin index.
Definition: key.cpp:70
Namespace for all entropy minimizer components.
void updateTuningcurve()
Update the entire tuning curve.
int getPitchET440(int keynumber, double f)
Get pitch from frequ.
Iterative entropy minimization algorithm.
void modifySpectralComponent(int key, int pitch)
The Algorithm class is a basic abstract class for any algorithm.
Definition: algorithm.h:38
double getElement(SpectrumType &spectrum, int m)
Truncate logspectrum at the cutoffs and return an element.
EntropyMinimizer(const Piano &piano, const AlgorithmFactoryDescription &desciption)
double getRecordedPitchET440(int keynumber)
Get recorded pitch.
void minimizeEntropy()
Entropy minimizer.
double computeEntropy()
Compute the entropy of the current normalized accumulator content.
int mLowerCutoff
Lower cutoff for fluctuations.
void writeSpectrum(int k, std::string filename, int pitch=0)