|
Hi
all,
Not sure if this is related to the timing issues that Alex is already looking into. I'm having trouble with sounds on pyglet, particularly with trying to run a thread that automatically dispatches events for ManagedSoundPlayers. I need to do this rather than simply dispatching events in my frame draw loop, because the users of my software sometimes need sounds to play without page flipping and sometimes use very brief sounds or want very precise onset times (which would seem to need a more frequent event dispatch than once per 12ms frame). The following works fine under OS X and python 2.5 (given a different media location, obviously) but, under XP python 2.5 (pyglet 1.1.1 or 1.1.2 or svn) the sounds are unpredictably broken - sometimes they miss the beginning, sometimes the end and sometimes result in an error message (pasted below the code). At the polling rate below (every 1ms) the error occurs rarely (once every 10 runs or so). If I reduce the polling time further to 0.0001, the error message becomes consistent. Can anyone see a problem with my threading code? And/or can anyone explain the callproc error message? Could it be related to the timing issues on win XP? cheers, Jon #----------------------------------- import pyglet.media import time, threading evtDispatchLock = threading.Lock() class _EventDispatchThread(threading.Thread): """a thread that will periodically call dispatch_events """ def __init__(self, pollingPeriod): threading.Thread.__init__ ( self ) self.setDaemon(True)#if only daemons are left then python will exit self.pollingPeriod=pollingPeriod def run(self): while True: #try to get lock (but don't block - just sleep if it's already held) if evtDispatchLock.acquire():#only dispatch if we aren't already in that loop try: pyglet.media.dispatch_events() finally: evtDispatchLock.release() time.sleep(self.pollingPeriod)#yeilds to other processes while sleeping _eventThread = _EventDispatchThread(pollingPeriod=0.001) _eventThread.start() player1 = pyglet.media.ManagedSoundPlayer() snd1 = pyglet.media.load('C:\\Windows\\Media\\ding.wav', streaming=False) player1.queue(snd1) player1.play() time.sleep(1) player2 = pyglet.media.ManagedSoundPlayer() snd2 = pyglet.media.load('C:\\Windows\\Media\\tada.wav', streaming=False) player2.queue(snd2) player2.play() time.sleep(2) player1.queue(snd1) player1.play() time.sleep(2) Running C:\users\jwp\Code\PsychoPy\svn\trunk\tests\pygletSoundTest.py --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~--- This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation. |
- sounds (and threading?) on win XP Jon Peirce
