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

标签 python audio

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

我找到了this article它突出显示了每个音符的频率,并使用文章中每个音符的映射序列手动混合(使用 pyaudio)以制作我自己的《Smoke On The Water》演绎版。

这可行,我可以通过创建并行进程来创建和弦,尽管我无法将音符或标签号转换为特定的音高。我的大部分数据都是以下形式:

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

本质上,我需要一个可以返回输入频率的方程或函数,其中 0 是一个开放的 E-低弦,每个值增加 1 就是指板上的一品 (1 = F)。

这不是明显的模式吗?

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

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

最佳答案

Isn't there a blatant pattern?

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

关于Python吉他指板音高/频率实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54879626/

相关文章:

python - Python 中的 GUI 与 TUI

python - 我可以使用 urllib 提交 SOAP 请求吗?

python - 如何自动实例化 OWL 本体类?

Android concat 2 音频(wav 或 mp3)文件

python - python 中可以找到 x 的值吗?即当 x 不是预定义变量时,要求 python 求解 2x + 23 - 7x 等方程

python - 如何使用逆 CDF 在 Python 中随机抽样对数正态数据并指定目标百分位数?

c++ - 如何使用OpenAL录制声音

html - 按批处理文件打开页面时,HTML音频不会播放

javascript - 使用网络录音机需要将音频保存到服务器

audio - 如何计算 ffmpeg astats 波峰因数