Python吉他指板音高/频率实现

时间:2019-02-26 06:31:19

标签: python audio

我正在开发一个应用程序,为了使我的生活更轻松,需要一个数字转换器将音符转换为频率,该频率每秒可以执行一定数量的音符,包括和弦。。

我发现this article突出显示了每个音符的频率,并使用文章中每个音符的映射顺序手动混合(与pyaudio结合使用)来呈现我自己的《水上烟雾》。

这是可行的,尽管我无法将音符或制表符转换为特定的音高,但我可以通过创建并行处理来创建和弦。我的大部分数据的格式为:

0 3 5 0 3 6 5 0 3 5 3 0

从本质上讲,我需要一个方程式或函数,该方程式或函数可以返回输入的频率,其中0是打开的E-低弦,并且每个值增加1都会使指板高一跳(1 = F)。 / p>

没有公然的模式吗?

我希望如此,但我怀疑是正弦波。以E与F之差为 5.1 ,F与F#之差为 5.2 ,最后,F#与G之差为 5.5

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

  

没有公然的模式吗?

是的,一般来说,音乐都有。两个相邻音符之间的距离为2 ^(1/12)。 Wikipedia - Twelfth root of two Wikipedia - Semitone。它在您链接的文章中的数字上进行了尝试,该模式与文章中显示的有效位数完全吻合。

编辑 OP要求提供一些代码。这是一个快速的-但详细记录了一下-

"status": true,
"message": "success",
"data": "projects/{project_name}/messages/5670594709975500395"

此输出:

# 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])