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

RE: [pygame] Timing...



Thanks for the code. 
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!)

Maybe if SDL is using DirectSound, and if I'm_on_Windows: I can have 
code to access DS directly and add the buffers behind
SDL. (Does SDL use DS or MMSYSTEM on Windows??)

The way to do this may just be to on-the-fly concatenate a wave file,
and then load/play it as normal. A small initial delay is not as important
as the continuous play. (I could use use memmapped files I guess.)
I could keep a certain # of files cached as well.

m

-----Original Message-----
From: owner-pygame-users@seul.org [mailto:owner-pygame-users@seul.org]On
Behalf Of Pete Shinners
Sent: Friday, July 27, 2001 8:27 AM
To: pygame-users@seul.org
Subject: Re: [pygame] Timing...


> - music.fadeout does not seem to fadeout, but just stops the music
> after the requested interval. (loaded music is currently a wav file.) 
> Ideas?

i've had this problem to. the sound objects fade out fine, but you
can't seem to change the volume for the music. this is an sdl problem.
everynowandthen i see this come up on the SDL mailing list, but for
some reason i never quite see it resolved.

it's probably not too hard to fix, but i don't think it ever has.



> - Is there a way to queue up a sound on a channel, rather than having
> it play at the same time on a new channel? It seems like if Play
> accepted an optional channel as an argument rather than just giving
> one, this could be done.  I want to do real-time concatenation of
> stored phrases.

hmm, there's no built in way to do this, but it should be do-able with
a small helper class. here's some dirty code off the top of my head...



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:
                channel.play(self.sounds[0])
                self.sounds = self.sounds[1:]
            else:
                self.channel = None
        return self.get_busy()

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

 

this should do it as-is for you (aside from any typos or brain
failures included). just initialize it with any sequence of 
Sound objects and it will play through them. once per frame call
the update() function to keep it running, and you can use the
get_busy() to see if it is still running.

(hey, is it enough for a code repository entry?)


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org

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

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org