立体声与单声道、倍频程的变化?(Python)

2024-04-27 13:52:01 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有一个程序可以产生声音。我有单声道,但我想把它转换成立体声,让一些真正酷的东西。然而,当我试着这样做的时候,我做的任何东西的明显音调都要高出整整一个八度。你知道吗

import pygame.mixer, pygame.sndarray, time

def note(freq, len, amp=1, rate=44100):
    t = linspace(0,len,len*rate)
    data = sin(2*pi*freq*t)*amp
    return data.astype(int16) # two byte integers

pygame.mixer.init(44100,-16,2,4096)
pygame.mixer.init()
cleft=pygame.mixer.Channel(0)
cleft.set_volume(1,0)
cright=pygame.mixer.Channel(1)
cright.set_volume(0,1)

toneL = note(440,.1,amp=10000)
toneR = note(440,.1,amp=10000)
snd_outL=pygame.mixer.Sound(toneL)
snd_outR=pygame.mixer.Sound(toneR)
cleft.play(snd_outL)
cright.play(snd_outR)

当我从立体声转向单声道时,上面代码中唯一的变化是:

pygame.mixer.init(44100,-16,2,4096)

第三个参数(2)以前是1。这表示是否使用1或2个通道(因此,1表示单声道,2表示立体声)。你知道吗

有人知道为什么简单地将通道参数的1改为2会使音高增加一个八度吗?更重要的是,我该如何解决这个问题(如果不明显地选择较低的八度音符,我不想这样做)?你知道吗


Tags: datalenrateinitchannelpygamenoteamp
1条回答
网友
1楼 · 发布于 2024-04-27 13:52:01

PyGame的^{}方法有默认参数,当您第二次调用它时使用这些参数。重要的一点是,默认的采样率是22050,而不是您想要的44100。你知道吗

删除第二个电话&看看会发生什么。你知道吗

相关问题 更多 >