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

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