Py学习  »  Python

python吉他微动板音高/频率实现

Jack Hales • 4 年前 • 800 次点击  

我正在开发一个应用程序,为了让我的生活更简单,它需要一个数字转换器,把音符转换成频率,每秒做一定数量的音符, 包括和弦

我发现 this article 它突出显示了每个音符的频率,手动混合(与pyaudio)以使用文章中每个音符的映射序列在水中生成我自己的烟雾呈现。

这是可行的,我可以通过创建并行进程来创建和弦,尽管我无法转换音符或 制表号码 进入一个特定的音高。我的大多数数据都是以下形式的:

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

本质上,我需要一个方程或函数,它可以返回输入的频率,0是一个开放的E-低字符串,每个值增加1是一个烦扰的Frut板(1=F)。

不是有明显的模式吗?

我希望如此,但我怀疑是正弦波引起的。取e到f的差是 五点一 ,f到f是 五点二 最后,f to g being 五点五

谢谢你的帮助,非常感谢。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43594
 
800 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Mr. Snrub
Reply   •   1 楼
Mr. Snrub    5 年前

不是有明显的模式吗?

是的,一般来说音乐是有的。两个相邻的音符被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']