3 # a SDL module for manipulating the SDL_mixer lib.
5 # Copyright (C) 2000,2002 David J. Goehrig
6 # Copyright (C) 2009 Kartik Thakore
20 $SDL::Mixer::initialized = 0;
24 my $class = ref($proto) || $proto;
27 my $frequency = $options{-frequency} || $options{-rate} || SDL::MIX_DEFAULT_FREQUENCY();
28 my $format = $options{-format} || SDL::MIX_DEFAULT_FORMAT();
29 my $channels = $options{-channels} || SDL::MIX_DEFAULT_CHANNELS();
30 my $size = $options{-size} || 4096;
31 unless ( $SDL::Mixer::initialized ) {
32 SDL::MixOpenAudio($frequency,$format,$channels,$size ) &&
33 croak SDL::GetError();
34 $SDL::Mixer::initialized = 1;
36 ++$SDL::Mixer::initialized;
44 --$SDL::Mixer::initialized;
45 unless ($SDL::Mixer::initialized) {
52 my ($status,$freq,$format,$channels) = SDL::MixQuerySpec();
53 my %hash = ( -status => $status, -frequency => $freq,
54 -format => $format, -channels => $channels );
58 sub reserve_channels ($$) {
59 my ($self,$channels) = @_;
60 return SDL::MixReserveChannels($channels);
63 sub allocate_channels ($$) {
64 my ($self,$channels) = @_;
65 return SDL::MixAllocateChannels($channels);
68 sub group_channel ($$$) {
69 my ($self,$channel,$group) = @_;
70 return SDL::MixGroupChannel($channel, $group);
73 sub group_channels ($$$$) {
74 my ($self,$from,$to,$group) = @_;
75 return SDL::MixGroupChannels($from,$to,$group);
78 sub group_available ($$) {
79 my ($self,$group) = @_;
80 return SDL::MixGroupAvailable($group);
83 sub group_count ($$) {
84 my ($self,$group) = @_;
85 return SDL::MixGroupCount($group);
88 sub group_oldest ($$) {
89 my ($self,$group) = @_;
90 return SDL::MixGroupOldest($group);
93 sub group_newer ($$) {
94 my ($self,$group) = @_;
95 return SDL::MixGroupNewer($group);
98 sub play_channel ($$$$;$) {
99 my ($self,$channel,$chunk,$loops,$ticks) = @_;
101 return SDL::MixPlayChannelTimed($channel,$$chunk,$loops,$ticks);
104 sub play_music ($$$) {
105 my ($self,$music,$loops) = @_;
106 return SDL::MixPlayMusic($$music,$loops);
109 sub fade_in_channel ($$$$$;$) {
110 my ($self,$channel,$chunk,$loops,$ms,$ticks) = @_;
112 return SDL::MixFadeInChannelTimed($channel,$$chunk,$loops,$ms,$ticks);
115 sub fade_in_music ($$$$) {
116 my ($self,$music,$loops,$ms) = @_;
117 return SDL::MixFadeInMusic($$music,$loops,$ms);
120 sub channel_volume ($$$) {
121 my ($self,$channel,$volume) = @_;
122 return SDL::MixVolume($channel,$volume);
125 sub music_volume ($$) {
126 my ($self,$volume) = @_;
127 return SDL::MixVolumeMusic($volume);
130 sub mix_set_panning($$$$) {
131 my ($self,$channel,$left,$right) = @_;
132 return SDL::MixSetPanning($channel,$left,$right);
136 sub halt_channel ($$) {
137 my ($self,$channel) = @_;
138 return SDL::MixHaltChannel($channel);
141 sub halt_group ($$) {
142 my ($self,$group) = @_;
143 return SDL::MixHaltGroup($group);
147 return SDL::MixHaltMusic();
150 sub channel_expire ($$$) {
151 my ($self,$channel,$ticks) = @_;
152 return SDL::MixExpireChannel($channel,$ticks);
155 sub fade_out_channel ($$$) {
156 my ($self,$channel,$ms) = @_;
157 return SDL::MixFadeOutChannel($channel,$ms);
160 sub fade_out_group ($$$) {
161 my ($self,$group,$ms) = @_;
162 return SDL::MixFadeOutGroup($group,$ms);
165 sub fade_out_music ($$) {
167 return SDL::MixFadeOutMusic($ms);
170 sub fading_music () {
171 return SDL::MixFadingMusic();
174 sub fading_channel ($$) {
175 my ($self,$channel) = @_;
176 return SDL::MixFadingChannel($channel);
180 my ($self,$channel) = @_;
181 SDL::MixPause($channel);
185 my ($self,$channel) = @_;
186 SDL::MixResume($channel);
190 my ($self,$channel) = @_;
191 return SDL::MixPaused($channel);
195 SDL::MixPauseMusic();
198 sub resume_music () {
199 SDL::MixResumeMusic();
203 SDL::MixRewindMusic();
207 return SDL::MixPausedMusic();
211 my ($self,$channel) = @_;
212 return SDL::MixPlaying($channel);
215 sub mix_volume_chunk($$$) {
216 my ($self, $chunk, $volume) = @_;
217 return SDL::MixVolumeChunk($chunk, $volume);
220 sub playing_music () {
221 return SDL::MixPlayingMusic();
232 SDL::Mixer - a SDL perl extension
236 $mixer = new SDL::Mixer -frequency => MIX_DEFAULT_FREQUENCY,
237 -format => MIX_DEFAULT_FORMAT,
238 -channels => MIX_DEFAULT_CHANNELS,
243 SDL::Mixer allows you access to the SDL mixer library, enablig sound and
244 music volume setting, playing, pausing and resuming, as well as fading
245 the sound and music in and out.
251 $mixer = SDL::Mixer->new( -frequency => MIX_DEFAULT_FREQUENCY,
252 -format => MIX_DEFAULT_FORMAT,
253 -channels => MIX_DEFAULT_CHANNELS,
256 Creates a new SDL::Mixer object. C<$size> is the buffer size in bytes.
260 my $specs = SDL::Mixer::query_spec();
262 Returns a hash reference, containing the following keys and their respective
270 =head2 reserve_channels
272 $mixer->reserve_channels(4);
274 Reserve so many channels.
276 =head2 allocate_channels()
278 $mixer->reserve_channels(2);
280 Allocate so many channels.
282 =head2 group_channel(channel,group)
284 Group the channel number C<$channel> into group C<$group>.
286 =head2 group_channels(from,to,group)
288 Groups a range of channels
290 =head2 group_available(group)
292 Return true when the group is available.
294 =head2 group_count(group)
296 Returns the number of channels in the group
298 =head2 group_oldest()
304 =head2 play_channel()
309 Play C<$music> C<$loop> times.
311 =head2 fade_in_channel(channel,chunk,loops,ms,ticks)
315 =head2 fade_in_music(music,loops,ms)
317 Fades the music in over a number of ms, looping as it does
319 =head2 channel_volume(channel,volume)
321 Sets the volume for a single channel
323 =head2 mucis_volume(volume)
325 Set the volume for the music.
327 =head2 halt_channel(channel)
329 Stops a specific channel
331 =head2 halt_group(group)
333 Stops a group of channels
339 =head2 channel_expire(channel,ticks)
341 Ignores the channel after C<ticks> has expired
343 =head2 fade_out_channel(channel,ms)
345 Fade the channel number C<$channel> in C<$ms> ms out.
347 =head2 fade_out_group(group,ms)
349 Fade the channel group C<$group> in C<$ms> ms out.
351 =head2 fade_out_music(ms)
353 Fade the music in C<$ms> ms out.
355 =head2 fading_music()
357 Return true when the music is currently fading in or out.
359 =head2 fading_channel()
361 Return true when the channel number C<$channel> is currently fading in or out.
363 =head2 pause( channel )
365 Pause the channel C<$channel>.
367 =head2 resume(channel)
369 Resume the channel C<$channel>.
373 Return true when the channel is currently paused.
377 Pause the music play.
379 =head2 resume_music()
381 Resume the music play.
383 =head2 rewind_music()
385 Resets the music file to the beginning
387 =head2 music_paused()
389 Return true when the music is currently paused.
393 Return true when the channel is currently playing.
395 =head2 playing_music ()
397 Return true when the music is currently playing.
399 =head2 sub mix_set_panning(channel,left,right)
401 Set panning for mixer, Use MIX_CHANNEL_POST to process the postmix stream
403 Volume for the left channel, range is 0(silence) to 255(loud)
405 Volume for the right channel, range is 0(silence) to 255(loud)
410 David J. Goehrig, basic doc added by Tels <http://bloodgate.com>.
414 L<perl>, L<SDL::Music> and L<SDL::Sound>.