私信  •  关注

Mr. Snrub

Mr. Snrub 最近创建的主题
Mr. Snrub 最近回复了

看起来你在实施哈弗辛公式 here . (顺便说一句,我不得不这么做)你是对的 C .

您的代码(Python):

C = 2 * (atan2(sqrt(A),sqrt(1-A)) * (180/pi))

来自上面URL的代码(Javascript):

var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

问题是你正在转换 C类 到度 (180/pi) ),但接下来的计算 D = radEarth * C 只有当 C类 以弧度为单位。

5 年前
回复了 Mr. Snrub 创建的主题 » python吉他微动板音高/频率实现

不是有明显的模式吗?

是的,一般来说音乐是有的。两个相邻的音符被2^(1/12)的因数隔开。 Wikipedia - Twelfth root of two Wikipedia - Semitone . 它在链接文章中的数字上进行了尝试,并且该模式完全适合文章中显示的有效数字的数量。

编辑 OP要了一些密码。这里有一个快速但详细记录的镜头:

# A semitone (half-step) is the twelfth root of two
# https://en.wikipedia.org/wiki/Semitone
# https://en.wikipedia.org/wiki/Twelfth_root_of_two
SEMITONE_STEP = 2 ** (1/12)

# Standard tuning for a guitar - EADGBE
LOW_E_FREQ = 82.4    # Baseline - low 'E' is 82.4Hz
# In standard tuning, we use the fifth fret to tune the next string
# except for the next-to-highest string where we use the fourth fret.
STRING_STEPS = [5, 5, 5, 4, 5]

# Number of frets can vary but we will just presume it's 24 frets
N_FRETS = 24

# This will be a list of the frequencies of all six strings,
# a list of six lists, where each list is that string's frequencies at each fret
fret_freqs = []
# Start with the low string as our reference point
# We just short-hand the math of multipliying by SEMITONE_STEP over and over
fret_freqs.append([LOW_E_FREQ * (SEMITONE_STEP ** n) for n in range(N_FRETS)])
# Now go through the upper strings and base of each lower-string's fret, just like
# when we are tuning a guitar
for tuning_fret in STRING_STEPS:
    # Pick off the nth fret of the previous string and use it as our base frequency
    base_freq = fret_freqs[-1][tuning_fret]
    fret_freqs.append([base_freq * (SEMITONE_STEP ** n) for n in range(N_FRETS)])

for stringFreqs in fret_freqs:
    # We don't need 14 decimal places of precision, thank you very much.
    print(["{:.1f}".format(f) for f in stringFreqs])

输出:

['82.4', '87.3', '92.5', '98.0', '103.8', '110.0', '116.5', '123.5', '130.8', '138.6', '146.8', '155.6', '164.8', '174.6', '185.0', '196.0', '207.6', '220.0', '233.1', '246.9', '261.6', '277.2', '293.6', '311.1'] 
['110.0', '116.5', '123.5', '130.8', '138.6', '146.8', '155.6', '164.8', '174.6', '185.0', '196.0', '207.6', '220.0', '233.1', '246.9', '261.6', '277.2', '293.6', '311.1', '329.6', '349.2', '370.0', '392.0', '415.3'] 
['146.8', '155.6', '164.8', '174.6', '185.0', '196.0', '207.6', '220.0', '233.1', '246.9', '261.6', '277.2', '293.6', '311.1', '329.6', '349.2', '370.0', '392.0', '415.3', '440.0', '466.1', '493.8', '523.2', '554.3'] 
['196.0', '207.6', '220.0', '233.1', '246.9', '261.6', '277.2', '293.6', '311.1', '329.6', '349.2', '370.0', '392.0', '415.3', '440.0', '466.1', '493.8', '523.2', '554.3', '587.3', '622.2', '659.2', '698.4', '739.9'] 
['246.9', '261.6', '277.2', '293.6', '311.1', '329.6', '349.2', '370.0', '392.0', '415.3', '440.0', '466.1', '493.8', '523.2', '554.3', '587.3', '622.2', '659.2', '698.4', '739.9', '783.9', '830.5', '879.9', '932.2'] 
['329.6', '349.2', '370.0', '392.0', '415.3', '440.0', '466.1', '493.8', '523.2', '554.3', '587.3', '622.2', '659.2', '698.4', '739.9', '783.9', '830.5', '879.9', '932.2', '987.7', '1046.4', '1108.6', '1174.6', '1244.4']