I'm trying to write some code to play sounds using python. Specifically, I have recordings of some church bells and I'm trying to play them back in particular sequences to recreate the sound of church bell ringing. Currently I'm using pygame to handle timing and playback, like this:
import pygame.mixer as mx
import pygame.time as tm
mx.init()
sounds = [mx.Sound('./data/bell-{0}.wav'.format(i)) for i in range(1,9)]
def round():
for i in range(8):
sounds[i].play()
tm.delay(250)
for i in range(3):
round()
round()
tm.wait(250)
mx.quit()
This should play something like 'ringing rounds', a regularly played scale, with each bell sounding 250ms apart and an extra gap of 250ms after each scale.
But what I get is quite uneven, even if I run python as nice -n -19 python rounds.py. The variation in timing is a bit difficult to estimate, but I'd guess it's frequently well over 100ms, occasionally over 200ms.
If I import the sound files into Audacity and space them 250ms apart, I get a nice, even scale, so the problem is not just that the sound files are unevenly edited.
How can I improve this timing? It seems to me that accurate timing should be quite important in a game library, especially when the load is quite light (as in this case).
Aucun commentaire:
Enregistrer un commentaire