5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
7 # ------------------------------------------------------------------------------
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 # ------------------------------------------------------------------------------
25 # Please feel free to send questions, suggestions or improvements to:
44 $SDL::Mixer::initialized = 0;
48 my $class = ref($proto) || $proto;
51 my $frequency = $options{-frequency} || $options{-rate} || SDL::MIX_DEFAULT_FREQUENCY();
52 my $format = $options{-format} || SDL::MIX_DEFAULT_FORMAT();
53 my $channels = $options{-channels} || SDL::MIX_DEFAULT_CHANNELS();
54 my $size = $options{-size} || 4096;
55 unless ( $SDL::Mixer::initialized ) {
56 SDL::MixOpenAudio($frequency,$format,$channels,$size ) &&
57 croak SDL::GetError();
58 $SDL::Mixer::initialized = 1;
60 ++$SDL::Mixer::initialized;
68 --$SDL::Mixer::initialized;
69 unless ($SDL::Mixer::initialized) {
76 my ($status,$freq,$format,$channels) = SDL::MixQuerySpec();
77 my %hash = ( -status => $status, -frequency => $freq,
78 -format => $format, -channels => $channels );
82 sub reserve_channels ($$) {
83 my ($self,$channels) = @_;
84 return SDL::MixReserveChannels($channels);
87 sub allocate_channels ($$) {
88 my ($self,$channels) = @_;
89 return SDL::MixAllocateChannels($channels);
92 sub group_channel ($$$) {
93 my ($self,$channel,$group) = @_;
94 return SDL::MixGroupChannel($channel, $group);
97 sub group_channels ($$$$) {
98 my ($self,$from,$to,$group) = @_;
99 return SDL::MixGroupChannels($from,$to,$group);
102 sub group_available ($$) {
103 my ($self,$group) = @_;
104 return SDL::MixGroupAvailable($group);
107 sub group_count ($$) {
108 my ($self,$group) = @_;
109 return SDL::MixGroupCount($group);
112 sub group_oldest ($$) {
113 my ($self,$group) = @_;
114 return SDL::MixGroupOldest($group);
117 sub group_newer ($$) {
118 my ($self,$group) = @_;
119 return SDL::MixGroupNewer($group);
122 sub play_channel ($$$$;$) {
123 my ($self,$channel,$chunk,$loops,$ticks) = @_;
125 return SDL::MixPlayChannelTimed($channel,$$chunk,$loops,$ticks);
128 sub play_music ($$$) {
129 my ($self,$music,$loops) = @_;
130 return SDL::MixPlayMusic($$music,$loops);
133 sub fade_in_channel ($$$$$;$) {
134 my ($self,$channel,$chunk,$loops,$ms,$ticks) = @_;
136 return SDL::MixFadeInChannelTimed($channel,$$chunk,$loops,$ms,$ticks);
139 sub fade_in_music ($$$$) {
140 my ($self,$music,$loops,$ms) = @_;
141 return SDL::MixFadeInMusic($$music,$loops,$ms);
144 sub channel_volume ($$$) {
145 my ($self,$channel,$volume) = @_;
146 return SDL::MixVolume($channel,$volume);
149 sub music_volume ($$) {
150 my ($self,$volume) = @_;
151 return SDL::MixVolumeMusic($volume);
154 sub halt_channel ($$) {
155 my ($self,$channel) = @_;
156 return SDL::MixHaltChannel($channel);
159 sub halt_group ($$) {
160 my ($self,$group) = @_;
161 return SDL::MixHaltGroup($group);
165 return SDL::MixHaltMusic();
168 sub channel_expire ($$$) {
169 my ($self,$channel,$ticks) = @_;
170 return SDL::MixExpireChannel($channel,$ticks);
173 sub fade_out_channel ($$$) {
174 my ($self,$channel,$ms) = @_;
175 return SDL::MixFadeOutChannel($channel,$ms);
178 sub fade_out_group ($$$) {
179 my ($self,$group,$ms) = @_;
180 return SDL::MixFadeOutGroup($group,$ms);
183 sub fade_out_music ($$) {
185 return SDL::MixFadeOutMusic($ms);
188 sub fading_music () {
189 return SDL::MixFadingMusic();
192 sub fading_channel ($$) {
193 my ($self,$channel) = @_;
194 return SDL::MixFadingChannel($channel);
198 my ($self,$channel) = @_;
199 SDL::MixPause($channel);
203 my ($self,$channel) = @_;
204 SDL::MixResume($channel);
208 my ($self,$channel) = @_;
209 return SDL::MixPaused($channel);
213 SDL::MixPauseMusic();
216 sub resume_music () {
217 SDL::MixResumeMusic();
221 SDL::MixRewindMusic();
225 return SDL::MixPausedMusic();
229 my ($self,$channel) = @_;
230 return SDL::MixPlaying($channel);
233 sub playing_music () {
234 return SDL::MixPlayingMusic();
238 my($self, $channel, $left, $right) = @_;
239 return SDL::MixSetPanning($channel, $left, $right);
250 SDL::Mixer - a SDL perl extension
254 $mixer = new SDL::Mixer -frequency => MIX_DEFAULT_FREQUENCY,
255 -format => MIX_DEFAULT_FORMAT,
256 -channels => MIX_DEFAULT_CHANNELS,
261 SDL::Mixer allows you access to the SDL mixer library, enablig sound and
262 music volume setting, playing, pausing and resuming, as well as fading
263 the sound and music in and out.
269 $mixer = SDL::Mixer->new( -frequency => MIX_DEFAULT_FREQUENCY,
270 -format => MIX_DEFAULT_FORMAT,
271 -channels => MIX_DEFAULT_CHANNELS,
274 Creates a new SDL::Mixer object. C<$size> is the buffer size in bytes.
278 my $specs = SDL::Mixer::query_spec();
280 Returns a hash reference, containing the following keys and their respective
288 =head2 reserve_channels
290 $mixer->reserve_channels(4);
292 Reserve so many channels.
294 =head2 allocate_channels()
296 $mixer->reserve_channels(2);
298 Allocate so many channels.
300 =head2 group_channel(channel,group)
302 Group the channel number C<$channel> into group C<$group>.
304 =head2 group_channels(from,to,group)
306 Groups a range of channels
308 =head2 group_available(group)
310 Return true when the group is available.
312 =head2 group_count(group)
314 Returns the number of channels in the group
316 =head2 group_oldest()
322 =head2 play_channel()
327 Play C<$music> C<$loop> times.
329 =head2 fade_in_channel(channel,chunk,loops,ms,ticks)
333 =head2 fade_in_music(music,loops,ms)
335 Fades the music in over a number of ms, looping as it does
337 =head2 channel_volume(channel,volume)
339 Sets the volume for a single channel
341 =head2 mucis_volume(volume)
343 Set the volume for the music.
345 =head2 halt_channel(channel)
347 Stops a specific channel
349 =head2 halt_group(group)
351 Stops a group of channels
357 =head2 channel_expire(channel,ticks)
359 Ignores the channel after C<ticks> has expired
361 =head2 fade_out_channel(channel,ms)
363 Fade the channel number C<$channel> in C<$ms> ms out.
365 =head2 fade_out_group(group,ms)
367 Fade the channel group C<$group> in C<$ms> ms out.
369 =head2 fade_out_music(ms)
371 Fade the music in C<$ms> ms out.
373 =head2 fading_music()
375 Return true when the music is currently fading in or out.
377 =head2 fading_channel()
379 Return true when the channel number C<$channel> is currently fading in or out.
381 =head2 pause( channel )
383 Pause the channel C<$channel>.
385 =head2 resume(channel)
387 Resume the channel C<$channel>.
391 Return true when the channel is currently paused.
395 Pause the music play.
397 =head2 resume_music()
399 Resume the music play.
401 =head2 rewind_music()
403 Resets the music file to the beginning
405 =head2 music_paused()
407 Return true when the music is currently paused.
411 Return true when the channel is currently playing.
413 =head2 playing_music ()
415 Return true when the music is currently playing.
417 =head1 set_panning($channel, $left, $right)
419 Sets the volume for the left or right channels. To do true panning:
421 $mixer->set_panning($channel, $left, 254 - $left);
425 David J. Goehrig, basic doc added by Tels <http://bloodgate.com>.
429 L<perl>, L<SDL::Music> and L<SDL::Sound>.