pygame / docs / ref / pygame_mixer.html

<html>
<title>pygame.mixer</title>
<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>
      pygame</b></i></font></a>&nbsp;&nbsp;</td>
<td valign=middle><tt><font color=#dddddd><br>
	pygame<br>documentation</font>
</td></tr></table></td><td width=100% align=center valign=middle>

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

|| <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>


</td></tr></table>
<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.
<br>&nbsp;<br>
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.Channel().
<br>&nbsp;<br>
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.
<br>&nbsp;<br>
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.
<br>&nbsp;<br>
The mixer also contains a special channel for music. You can
control the music channel through pygame.mixer.music./

<hr>

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


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


<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_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=#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>


</table>

<hr>

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

<a name=Sound><font size=+2><b>Sound
</b></font><br><font size=+1><tt>
pygame.mixer.Sound(file) -> Sound
</tt></font><ul>
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.
</ul><br>&nbsp;<br>

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

<a name=find_channel><font size=+2><b>find_channel
</b></font><br><font size=+1><tt>
pygame.mixer.find_channel([force]) -> Channel
</tt></font><ul>
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.
</ul><br>&nbsp;<br>

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

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

<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
</tt></font><ul>
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.
</ul><br>&nbsp;<br>

<a name=init><font size=+2><b>init
</b></font><br><font size=+1><tt>
pygame.mixer.init([freq, [size, [stereo]]]) -> None
</tt></font><ul>
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.
<br>&nbsp;<br>
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>.
</ul><br>&nbsp;<br>

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

<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
</tt></font><ul>
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.
</ul><br>&nbsp;<br>

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

<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
</tt></font><ul>
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.
</ul><br>&nbsp;<br>

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

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

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


<hr>

</body></html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.