[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [pygame] Timing...

Unless I'm missing something, I don't know why threading would help.
In this case, things will be even worse than calling per frame, because
you're spinning
100% of whatever the CPU can muster for this thread, virtually grinding the
game to a halt.
Adding a time.sleep(ms_wait) would be an option to give the game some
ticks - but in any case you
still need to wait for get_busy to return false, at which time it's too late
for a sample to appear again in time. (Even a done event would suffer the
same problem,
but at least take no CPU during the play.)
All the buffers need to be added before the
channel ever stops playing - then there's no reason for a spin-wait

I suppose I'm too picky comming from a speech background - if you're
just doing sound f/x or you're willing to have the thing sound like most
telephony IVR
systems, these schemes should be okay if you have enough CPU to spare.


-----Original Message-----
From: owner-pygame-users@seul.org [mailto:owner-pygame-users@seul.org]On
Behalf Of Frank Raiser
Sent: Friday, July 27, 2001 1:16 PM
To: pygame-users@seul.org
Subject: Re: [pygame] Timing...

> The only problems are that I want to avoid calling *anything* every frame,
> and there can't be any delay between sounds even at 60fps - unfortunately
> the ear is really good at picking that stuff up, especially is speech.
> (I'll give it a try anyway!)
Why don't you simply use threading for this?
Some more risky brain code (building on pete's code):

import thread

class SoundSequence:
    "plays a sequence of sounds in order"
     def __init__(self, *sounds):
         "pass a sequence of Sound objects"
         self.channel = pygame.mixer.play(sounds[0])
         self.sounds = sounds[1:]

     def update(self):
         "call once per frame"
         if self.channel and self.channel.get_busy():
             if self.sounds:
                 self.sounds = self.sounds[1:]
                 self.channel = None
         return self.get_busy()

     def get_busy(self):
         "query if sounds are still playing"
         return self.channel is not None

Then you would only make one instance of this class and that's it.. no
more framebased calling.. just my $.02

> (hey, is it enough for a code repository entry?)
heh.. now it is :P

Raiser, Frank aka CrashChaos
IRC: #United-Programmers

MS Office XP - the more money I give to Microsoft,
the more vulnerable my Windows computers are
    -- Georgi Guninski
pygame mailing list

Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

pygame mailing list