为什么 music21 以意想不到的方式使用音高属性?

Why is music21 using pitch attributes in an unexpected way?

考虑以下测试代码。

from music21 import pitch

C0 = 16.35

for f in [261, 130, 653, 64, 865]:
    p = pitch.Pitch()
    p.frequency = f

    # Compare manual frequency with music21 frequency
    f1 = p.frequency
    f2 = C0 * pow(2, p.octave) * pow(2, p.pitchClass / 12) * pow(2, p.microtone.cents / 1200)
    print(f, f1, f2)

    # Compare manual pitchspace with music21 pitchspace
    ps1 = p.ps
    ps2 = 12 * (p.octave + 1) + p.pitchClass + p.microtone.cents / 100
    print(ps1, ps2)
    print()

这个的输出是

261 260.99999402174154 521.9489797003519
59.958555 71.95855499999999

130 129.99999854289362 259.974590631057
47.892097 59.892097

653 653.0000144741496 652.9362051837928
75.834954 75.834954

64 63.999998381902046 65.86890433005668
35.623683 36.123683

865 864.9999846113213 890.2594167561009
80.702359 81.202359

我手动计算的频率和频率之间经常存在差异。音高 space 和 music21 值。 请注意,有时这种差异可能是一个八度音程(如前两个 C 音符频率),但大多数情况下是一个音调。另一个奇怪的事情是,对于第三个测试频率,音调space 值相同而频率不同。

我的手动公式有什么问题?

所以看起来虽然八度音程的偏差是一个错误,但其他偏差是预期的行为。详见https://github.com/cuthbertLab/music21/issues/96