我正在尝试播放6个声音文件(aiff),每个5MB,同时,或他们可以最接近相同的毫秒。但是我的代码导致了混乱:有些声音确实是同时播放的,但有些却不是。你可以听到3个声音在不同的时间播放。所以..。就像这6个音被分成3组,每组2个音,在不同的时间就形成了这3个音。这应该是一条线索。
这些文件存储在内存中(因为我使用的是加载到内存中的实时lubuntu镜像),所以速度非常快,我假设这不是一个延迟问题。即使当我加载存储在挂盘中的声音时,结果听起来也是一样的。所以这里绝对不是问题。
import pygame as pg
pg.init()
pg.mixer.set_num_channels(50)
pg.mixer.Channel(1).play(pg.mixer.Sound('/home/lubuntu/Piano.pp.B2.aiff'))
pg.mixer.Channel(2).play(pg.mixer.Sound('/home/lubuntu/Piano.pp.A3.aiff'))
pg.mixer.Channel(3).play(pg.mixer.Sound('/home/lubuntu/Piano.pp.A4.aiff'))
pg.mixer.Channel(4).play(pg.mixer.Sound('/home/lubuntu/Piano.pp.A5.aiff'))
pg.mixer.Channel(5).play(pg.mixer.Sound('/home/lubuntu/Piano.pp.A6.aiff'))
pg.mixer.Channel(6).play(pg.mixer.Sound('/home/lubuntu/Piano.pp.A1.aiff'))发布于 2021-05-14 03:01:53
从以下位置加载您的6个声音文件进行测试:
http://theremin.music.uiowa.edu/MISpiano.html
我怀疑调用每个play()然后再调用它自己的load()会产生交错的效果,因为在play1已经开始播放之前,play2甚至不能考虑开始加载它的声音。
import pygame as pg
import time
pg.init()
pg.mixer.set_num_channels(50)
foo = [
pg.mixer.Sound("Piano.pp.A1.aiff"),
##pg.mixer.Sound("Piano.pp.A2.aiff"),
pg.mixer.Sound("Piano.pp.A3.aiff"),
pg.mixer.Sound("Piano.pp.A4.aiff"),
pg.mixer.Sound("Piano.pp.A5.aiff"),
pg.mixer.Sound("Piano.pp.A5.aiff"),
pg.mixer.Sound("Piano.pp.B2.aiff"),
]
for i,x in enumerate(foo):
pg.mixer.Channel(i+1).play(x)
time.sleep(10) ## so you can hear something rather than having the app just quit我认为这或多或少地产生了我在audacity中打开这6个文件并一起播放时听到的内容。只是提醒一下,他们似乎大部分时候都是沉默的。
https://stackoverflow.com/questions/67524067
复制相似问题