pygame   documentation
||  Home  ||  Help Contents  ||
 
|| pygame || cdrom || constants || cursor || display || draw ||
|| event || font || image || joystick || key || mixer ||
|| mixer_music || mouse || movie || sndarray || surfarray || time ||
|| transform ||
 
|| CD || Channel || Clock || Font || Joystick || Movie ||
|| Overlay || Rect || Sound || Surface ||
 
|| color || cursors || sprite ||

pygame.mixer

Contains sound mixer routines and objects. The mixer module is an optional pygame module, dependent on the SDL_mixer library. This module contains the usual routines needed to initialize the module. One difference is the pygame.mixer.init() function takes several optional arguments. These arguments control the playback rates and datatypes for the sound playback. If you do need specific control over the playback rate, but don't want to bother with hand-initializing the modules, there is a function named pygame.mixer.pre_init() which takes the same arguments as init(), but only sets the new default values. You can call this before pygame.init() and not have to worry about the pygame module initialization order.
 
Sound objects are created from the pygame.mixer.Sound() function. Simple sound playback can simply use the Sound.play() method to play the sound. Each Sound object can be played multiple times simultaneously. If you desire more specific control over the Sound objects, you can access the Channel objects with functions like pygame.mixer.Channel().
 
The mixer defaults to supporting 8 simultaneous soundfiles. You can change the number of available sound channels at any time with the set_num_channels() function.
 
All loaded Sound objects are resampled to match the same format that pygame.mixer is initialized to. The current SDL resampling functions are not that good, so it is best if you initialize pygame.mixer to the same format as your sound resources. Also setting the mixer frequency to even multiples of your sound resources will result in a cleaner conversion.
 
The mixer also contains a special channel for music. You can control the music channel through pygame.mixer.music.
Channel - get channel object
Sound - load a new soundfile
fadeout - fadeout all channels
find_channel - find an available sound channel
get_busy - query busy channels
get_init - query initialization for the mixer
get_num_channels - query the number of channels
init - initialize mixer module
pause - pause all channels
pre_init - presets the init default values
quit - unitializes the mixer
set_num_channels - sets the number of available channels
set_reserved - reserves first given channels
stop - stop all channels
unpause - restart any pause channels

Channel
pygame.mixer.Channel(int) -> Channel
 
Sound
pygame.mixer.Sound(file) -> Sound
 
fadeout
pygame.mixer.fadeout(millisec) -> None
 
find_channel
pygame.mixer.find_channel([force]) -> Channel
 
get_busy
pygame.mixer.get_busy() -> int
 
get_init
pygame.mixer.get_init() -> (frequency,format,stereo)
 
get_num_channels
pygame.mixer.get_num_channels() -> int

 
init
pygame.mixer.init([freq, [size, [stereo, [buffersize]]]]) -> None

 
pause
pygame.mixer.pause() -> None
 
pre_init
pygame.mixer.pre_init([freq, [size, [stereo, [buffersize]]]]) -> None

 
quit
pygame.mixer.quit() -> None
 
set_num_channels
pygame.mixer.set_num_channels(int) -> None
 
set_reserved
pygame.mixer.set_reserved(numchans) -> None

 
stop
pygame.mixer.stop() -> None
 
unpause
pygame.mixer.unpause() -> None