Reputation:
Im trying to play 6 sound files (aiff), 5 mb each, simultaneously, or the closest they can be to the same miliseconds. But my code results in a mess : Some sounds are played indeed simultandeously, but some are not. You can hear 3 sounds being played at diferent times. So ... its like the 6 sounds were divided into 3 groups of 2 sounds, resulting into those 3 sounds at diferent time. This got be a clue...
The files are stored in the ram memory ( since i`m using a live lubuntu image loaded into ram), so its pretty fast, and i assume its no a lag problem. Even because when i loaded the sounds stored in a pendrive, the results sounded exactly the same. SO definetly not a problem here.
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'))
Upvotes: 3
Views: 520
Reputation: 13067
Testing by loading your 6 sound files from:
http://theremin.music.uiowa.edu/MISpiano.html
I suspect that calling each play() that then calls it's own load() is creating your staggered effect as play2 cannot even think about starting to load it's sound until after play1 is already playing.
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
I think this produces more or less what I hear when I open those 6 files in audacity and play them together. Just a heads up that they seem to be mostly silence.
Upvotes: 2