1. pygame
  2. pygame
  3. pygame


pygame / docs / ref / pygame_mixer.html

<body bgcolor=#dddddd text=#333377 link=#7777bb vlink=#7777bb>

<table border=0 width=100% cellpadding=0 cellspacing=0 bgcolor=#f5f5f5><tr valign=top>
<td rowspan=2><table border=0 cellpadding=5 cellspacing=0 bgcolor=#333377>
<tr height=86 align=left><td valign=middle><font color=#ffffff size=+5>
	<a href=../index.html><font size=+5 color=#ffffff><i><b>
<td valign=middle><tt><font color=#dddddd><br>
</td></tr></table></td><td width=100% align=center valign=middle>

	<a href=http://pygame.seul.org>Home</a> &nbsp;||&nbsp;
	<a href=../index.html>Help Contents</a> &nbsp;||

|| <a href=CD.html>CD</a> || 
<a href=Channel.html>Channel</a> || 
<a href=Font.html>Font</a> || 
<a href=Joystick.html>Joystick</a> || 
<a href=Rect.html>Rect</a> || 
<a href=Sound.html>Sound</a> || 
<a href=Surface.html>Surface</a> ||<br>
|| <a href=pygame.html>pygame</a> || 
<a href=pygame_cdrom.html>cdrom</a> || 
<a href=pygame_constants.html>constants</a> || 
<a href=pygame_display.html>display</a> || 
<a href=pygame_event.html>event</a> || 
<a href=pygame_font.html>font</a> || 
<a href=pygame_image.html>image</a> ||<br>
|| <a href=pygame_joystick.html>joystick</a> || 
<a href=pygame_key.html>key</a> || 
<a href=pygame_mixer.html>mixer</a> || 
<a href=pygame_mixer_music.html>mixer_music</a> || 
<a href=pygame_mouse.html>mouse</a> || 
<a href=pygame_surfarray.html>surfarray</a> || 
<a href=pygame_time.html>time</a> ||<br>

<h2 align=center>pygame.mixer</h2>
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.load() 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.get_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 clean conversion.
The mixer also contains a special channel for music. You can
control the music channel through pygame.mixer.music./


<tr><td><a href=#fadeout>fadeout</a></td><td> -
fadeout all channels</td></tr>

<tr><td><a href=#find_channel>find_channel</a></td><td> -
find an available sound channel</td></tr>

<tr><td><a href=#get_busy>get_busy</a></td><td> -
query busy channels</td></tr>

<tr><td><a href=#get_channel>get_channel</a></td><td> -
get channel object</td></tr>

<tr><td><a href=#get_init>get_init</a></td><td> -
query initialization for the mixer</td></tr>

<tr><td><a href=#get_num_channels>get_num_channels</a></td><td> -
query the number of channels</td></tr>

<tr><td><a href=#init>init</a></td><td> -
initialize mixer module</td></tr>

<tr><td><a href=#load>load</a></td><td> -
load a new soundfile</td></tr>

<tr><td><a href=#pause>pause</a></td><td> -
pause all channels</td></tr>

<tr><td><a href=#pre_init>pre_init</a></td><td> -
presets the init default values</td></tr>

<tr><td><a href=#quit>quit</a></td><td> -
unitializes the mixer</td></tr>

<tr><td><a href=#set_num_channels>set_num_channels</a></td><td> -
sets the number of available channels</td></tr>

<tr><td><a href=#set_reserved>set_reserved</a></td><td> -
reserves first given channels</td></tr>

<tr><td><a href=#stop>stop</a></td><td> -
stop all channels</td></tr>

<tr><td><a href=#unpause>unpause</a></td><td> -
restart any pause channels</td></tr>



<a name=fadeout><font size=+2><b>fadeout
</b></font><br><font size=+1><tt>
pygame.mixer.fadeout(millisec) -> None
Fade out all the playing channels over the given number of

<a name=find_channel><font size=+2><b>find_channel
</b></font><br><font size=+1><tt>
pygame.mixer.find_channel([force]) -> Channel
Find a sound channel that is not busy. If the force argument is
passed as a nonzero number, this will return the channel of the
longest running sound. If not forced, and there are no available
channels, returns None.

<a name=get_busy><font size=+2><b>get_busy
</b></font><br><font size=+1><tt>
pygame.mixer.get_busy() -> int
Returns the number of current active channels. This is not the
total channels, but the number of channels that are currently
playing sound.

<a name=get_channel><font size=+2><b>get_channel
</b></font><br><font size=+1><tt>
pygame.mixer.get_channel(int) -> Channel
Get a channel object for the given channel. This number must be
less that the current number of channels.

<a name=get_init><font size=+2><b>get_init
</b></font><br><font size=+1><tt>
pygame.mixer.get_init() -> bool
Returns true if the mixer module is initialized.

<a name=get_num_channels><font size=+2><b>get_num_channels
</b></font><br><font size=+1><tt>
pygame.mixer.get_num_channels() -> int
Gets the current number of channels available for the mixer. This
value can be changed with <a href=#set_num_channels>set_num_channels()</a>. This value defaults
to 8 when the mixer is first initialized.

<a name=init><font size=+2><b>init
</b></font><br><font size=+1><tt>
pygame.mixer.init([freq, [size, [stereo]]]) -> None
Initializes the mixer module. Usually no arguments will be
needed, the defaults are 22050 frequency data in stereo with
signed 16bit data. The size argument can be 8 or 16 for unsigned
data, or -8 or -16 for signed data.
On many platforms it is important that the display module is
initialized before the audio. (that is, if the display will be
initialized at all). You can easily use the <a href=pygame.html#init>pygame.init()</a>
function to cleanly initialize everything, but first use the
pygame.mixer.pre_init() function to change the default values for
this <a href=pygame.html#init>init()</a>.

<a name=load><font size=+2><b>load
</b></font><br><font size=+1><tt>
pygame.mixer.load(file) -> Sound
Loads a new sound object from a WAV file. File can be a filename
or a file-like object. The sound will be converted to match the
current mode of the mixer.

<a name=pause><font size=+2><b>pause
</b></font><br><font size=+1><tt>
pygame.mixer.pause() -> None
Temporarily stops playback on all the mixer channels.

<a name=pre_init><font size=+2><b>pre_init
</b></font><br><font size=+1><tt>
pygame.mixer.pre_init([freq, [size, [stereo]]]) -> None
This routine is usefull when you want to customize the sound
mixer playback modes. The values you pass will change the default
values used by <a href=#init>pygame.mixer.init()</a>. This way you can still use
the pygame automatic initialization to ensure everything happens
in the right order, but set the desired mixer mode.

<a name=quit><font size=+2><b>quit
</b></font><br><font size=+1><tt>
pygame.mixer.quit() -> None
This will stop all playing sounds and uninitialize
the mixer module

<a name=set_num_channels><font size=+2><b>set_num_channels
</b></font><br><font size=+1><tt>
pygame.mixer.set_num_channels(int) -> None
Sets the current number of channels available for the mixer. This
value defaults to 8 when the mixer is first initialized. If the
value is decreased, sounds playing in channels above the new
value will stop.

<a name=set_reserved><font size=+2><b>set_reserved
</b></font><br><font size=+1><tt>
pygame.mixer.set_reserved(int) -> None
Reserves the first channels. Reserved channels won't be used when
a sound is played without using a specific channel object.

<a name=stop><font size=+2><b>stop
</b></font><br><font size=+1><tt>
pygame.mixer.stop() -> None
Stop the playback on all mixer channels.

<a name=unpause><font size=+2><b>unpause
</b></font><br><font size=+1><tt>
pygame.mixer.unpause() -> None
Restarts playback of any paused channels.