[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] reserving an audio channel?



On Mon, 2005-10-03 at 11:35 +0200, Jack Nutting wrote:
> Most of the sounds I've used in my games so far are short,
> fire'n'forget thingies.  I manually grab a channel (so I can do stereo
> effects) with pygame.mixer.find_channel(True) so that if there are no
> available channels, it will grab the longest-running busy one.

This is exactly what reserving channels is for. Now that you mention it,
I'm not sure if the find_channel() call respects the reserved channels.
It all happens inside SDL_mixer. I'm pretty sure it does work with
reserved channels, but I would recommend testing.

First call pygame.mixer.set_reserved(1) to give you one reserved
channel. These are always the first 'n' channels in the system. Play
your longer lasting effects like this,
pygame.mixer.Channel(0).play(long_sound)

If you are noticing your short effects getting cut, it's also easy to
bump up the number of mixing channels in play.
pygame.mixer.set_num_channels(20). The default is 8.

One last note, you can use stereo effects using the Sound.play() method.
This returns the channel object that is playing the sound. So a
mysound.play().set_volume(0, 1) will do the trick.