55 mPitch(piano.getKeyboard().getNumberOfKeys(),0)
91 for (
int keynumber = 0; keynumber <
mNumberOfKeys; ++keynumber)
118 LogI(
"Pitch Raise algorithm started");
120 std::vector<double> X(2,0),Y(2,0),XX(2,0),XY(2,0),A(2,0),B(2,0);
121 std::vector<int> N(2,0);
136 if (s==0)
LogI(
"Found recorded key number %d in the left section with B=%lf.",i,B)
137 else LogI(
"Found recorded key number %d in the right section with B=%lf.",i,B);
138 double x = i, y = -log(B);
149 MessageHandler::send<MessageCaluclationProgress>
157 MessageHandler::send<MessageCaluclationProgress>
164 for (
int s=0; s<2; ++s)
166 A[s] = (XX[s]*Y[s] -X[s]*XY[s]) / (N[s]*XX[s] - X[s]*X[s]);
167 B[s] = (N[s]*XY[s] - X[s]*Y[s]) / (N[s]*XX[s] - X[s]*X[s]);
171 auto estimatedInharmonicity = [
this,A,B] (
int k)
174 double minusLogB = A[s] + k*B[s];
175 return exp(-minusLogB);
182 auto cents = [estimatedInharmonicity] (
int keynumber,
int n)
184 log((1+n*n*estimatedInharmonicity(keynumber)) /
185 (1+estimatedInharmonicity(keynumber))); };
191 double pitchA5 = 0.5*cents(numberA4,3)+0.5*cents(numberA4,2);
192 double pitchA3 = cents(numberA4,2)-cents(numberA3,4);
196 mPitch[k] = pitchA3*(mKeyNumberOfA4-k)/12.0;
202 for (
int k=mKeyNumberOfA4+1; k<=numberA5; ++k)
215 double pitch42 =
mPitch[k-12] + cents(k-12,4) -cents(k,2);
216 double pitch21 =
mPitch[k-12] + cents(k-12,2);
217 mPitch[k] = 0.3*pitch42 + 0.7*pitch21;
224 for (
int k=numberA3-1; k>=0; k--)
227 double pitch42 =
mPitch[k+12] + cents(k+12,2) -cents(k,4);
228 double pitch105 =
mPitch[k+12] + cents(k+12,5) -cents(k,10);
229 double fraction = 1.0*k/numberA3;
230 mPitch[k] = pitch42*fraction+pitch105*(1-fraction);
The AlgorithmFactory class is a template class to be created with the actual Algorithm.
PitchRaise(const Piano &piano, const AlgorithmFactoryDescription &description)
Constructor of the pitch-raise algorithm.
void updateTuningcurve()
Update the entire tuning curve.
#define CHECK_CANCEL_THREAD
void msleep(double milliseconds)
Sleep function for staying idle.
double getDefiningTempFrequency(int keynumber, double cents=0, double A4=0) const
Compute the defining temperatent.
virtual void algorithmWorkerFunction() overridefinal
PitchRaise::algorithmWorkerFunction.
Class describing a single piano key.
std::vector< double > mPitch
int getNumberOfBassKeys() const
const Keyboard & getKeyboard() const
const int mKeyNumberOfA4
Number of A4.
double getMeasuredInharmonicity() const
Get estimated inharmonicity.
static const AlgorithmFactory mSingleton
void showCalculationProgress(double fraction)
Transmit the current percentage of progress to the messaging system.
void updateTuningCurve(int keynumber, double frequency)
The Algorithm class is a basic abstract class for any algorithm.
Piano mPiano
Copy of the piano.
const Key & getKey(int i) const
const int mNumberOfKeys
The number of keys.