mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-28 14:18:41 +02:00
Steve Daulton's fix for PitchIndex() to round in the correct direction for negative MIDI numbers.
This commit is contained in:
parent
08dd4d9813
commit
7d7b0a3e00
@ -36,11 +36,14 @@ double MIDInoteToFreq(const double dMIDInote)
|
||||
|
||||
unsigned int PitchIndex(const double dMIDInote)
|
||||
{
|
||||
int nPitchIndex = ((int)(dMIDInote + 0.5) % 12);
|
||||
// MIDI numbers can be negative.
|
||||
// Because of the modulo, we know we're within 12 of positive.
|
||||
// MIDI numbers can be negative. Round in the right direction.
|
||||
double dRound = (dMIDInote < 0.0) ? -0.5 : 0.5;
|
||||
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)
|
||||
nPitchIndex += 12;
|
||||
|
||||
return nPitchIndex;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user