mirror of
https://github.com/cookiengineer/audacity
synced 2026-03-06 14:35:32 +01:00
Steve Daulton's fix for PitchIndex() to round in the correct direction for negative MIDI numbers.
This commit is contained in:
@@ -36,11 +36,14 @@ double MIDInoteToFreq(const double dMIDInote)
|
|||||||
|
|
||||||
unsigned int PitchIndex(const double dMIDInote)
|
unsigned int PitchIndex(const double dMIDInote)
|
||||||
{
|
{
|
||||||
int nPitchIndex = ((int)(dMIDInote + 0.5) % 12);
|
// MIDI numbers can be negative. Round in the right direction.
|
||||||
// MIDI numbers can be negative.
|
double dRound = (dMIDInote < 0.0) ? -0.5 : 0.5;
|
||||||
// Because of the modulo, we know we're within 12 of positive.
|
int nPitchIndex = ((int)(dMIDInote + dRound) % 12);
|
||||||
|
|
||||||
|
// Because of the modulo, we know we're within 12 of positive, if dMIDInote is negative.
|
||||||
if (nPitchIndex < 0)
|
if (nPitchIndex < 0)
|
||||||
nPitchIndex += 12;
|
nPitchIndex += 12;
|
||||||
|
|
||||||
return nPitchIndex;
|
return nPitchIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user