diff --git a/src/PitchName.cpp b/src/PitchName.cpp index dfc23e6b9..b647a1a52 100644 --- a/src/PitchName.cpp +++ b/src/PitchName.cpp @@ -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, diff --git a/src/effects/ChangePitch.cpp b/src/effects/ChangePitch.cpp index d86c685fb..16f12bf99 100644 --- a/src/effects/ChangePitch.cpp +++ b/src/effects/ChangePitch.cpp @@ -462,6 +462,7 @@ bool ChangePitchDialog::TransferDataFromWindow() // calculations +//vvvvv Probaly unnecessary with fix to FreqToMIDInoteNumber(), but leave it in until we decide how to handle very low freq values. void ChangePitchDialog::Calc_FromPitchIndex() { m_FromPitchIndex = (int)(m_ToPitchIndex - m_SemitonesChange) % 12; @@ -600,16 +601,17 @@ void ChangePitchDialog::OnText_FromFrequency(wxCommandEvent & WXUNUSED(event)) this->Calc_ToFrequency(); this->Calc_ToPitchIndex(); + //vvvvv Probaly unnecessary with fix to FreqToMIDInoteNumber(), but leave it in until we decide how to handle very low freq values. // This is Steve's incremental fix for cross-updating issues related to bug 309. // It's weird that in prior code (3 lines above this), we set m_FromPitchIndex, // then call 2 Calc methods for the other members, and then this call to // recalculate m_FromPitchIndex. Something's wrong there, but I want to figure // out the overall best scheme, and this is an incremental fix. - this->Calc_FromPitchIndex(); + // this->Calc_FromPitchIndex(); m_bLoopDetect = true; - this->Update_Choice_ToPitch(); this->Update_Choice_FromPitch(); + this->Update_Choice_ToPitch(); this->Update_Text_ToFrequency(); m_bLoopDetect = false;