1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-13 16:16:33 +01:00

further constraints regarding bug 309, from off-list discussion with Steve

This commit is contained in:
v.audacity
2013-05-30 23:30:09 +00:00
parent 39f03edd8d
commit c39f9a4b53
2 changed files with 14 additions and 3 deletions

View File

@@ -31,7 +31,16 @@
double FreqToMIDInoteNumber(double freq)
{
// Make the calculation relative to A440 (A4), note number 69.
return double (69.0 + (12.0 * (log(freq / 440.0) / log(2.0))));
double dCalc = 69.0 + (12.0 * (log(freq / 440.0) / log(2.0)));
//vvv For freq values in the range (0.0, ~8.2], that calculation
// produces negative dCalc, and as close in frequency as they are,
// their modulo 12 results are different.
// Also, not clear that any of those frequencies is a "pitch",
// so pending further discussion, just enforce a floor.
// MIDI numbers are non-negative.
if (dCalc < 0.0)
dCalc = 0.0;
return dCalc;
}
// PitchIndex returns the [0,11] index for a double pitchNum,