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:
41 $SDL::Mixer::initialized = 0;
45 my $class = ref($proto) || $proto;
48 my $frequency = $options{-frequency} || $options{-rate} || SDL::MIX_DEFAULT_FREQUENCY();
49 my $format = $options{-format} || SDL::MIX_DEFAULT_FORMAT();
50 my $channels = $options{-channels} || SDL::MIX_DEFAULT_CHANNELS();
51 my $size = $options{-size} || 4096;
52 unless ( $SDL::Mixer::initialized ) {
53 SDL::MixOpenAudio($frequency,$format,$channels,$size ) &&
55 $SDL::Mixer::initialized = 1;
57 ++$SDL::Mixer::initialized;
65 --$SDL::Mixer::initialized;
66 unless ($SDL::Mixer::initialized) {
73 my ($status,$freq,$format,$channels) = SDL::MixQuerySpec();
74 my %hash = ( -status => $status, -frequency => $freq,
75 -format => $format, -channels => $channels );
79 sub reserve_channels ($$) {
80 my ($self,$channels) = @_;
81 return SDL::MixReserveChannels($channels);
84 sub allocate_channels ($$) {
85 my ($self,$channels) = @_;
86 return SDL::MixAllocateChannels($channels);
89 sub group_channel ($$$) {
90 my ($self,$channel,$group) = @_;
91 return SDL::MixGroupChannel($channel, $group);
94 sub group_channels ($$$$) {
95 my ($self,$from,$to,$group) = @_;
96 return SDL::MixGroupChannels($from,$to,$group);
99 sub group_available ($$) {
100 my ($self,$group) = @_;
101 return SDL::MixGroupAvailable($group);
104 sub group_count ($$) {
105 my ($self,$group) = @_;
106 return SDL::MixGroupCount($group);
109 sub group_oldest ($$) {
110 my ($self,$group) = @_;
111 return SDL::MixGroupOldest($group);
114 sub group_newer ($$) {
115 my ($self,$group) = @_;
116 return SDL::MixGroupNewer($group);
119 sub play_channel ($$$$;$) {
120 my ($self,$channel,$chunk,$loops,$ticks) = @_;
122 return SDL::MixPlayChannelTimed($channel,$$chunk,$loops,$ticks);
125 sub play_music ($$$) {
126 my ($self,$music,$loops) = @_;
127 return SDL::MixPlayMusic($$music,$loops);
130 sub fade_in_channel ($$$$$;$) {
131 my ($self,$channel,$chunk,$loops,$ms,$ticks) = @_;
133 return SDL::MixFadeInChannelTimed($channel,$$chunk,$loops,$ms,$ticks);
136 sub fade_in_music ($$$$) {
137 my ($self,$music,$loops,$ms) = @_;
138 return SDL::MixFadeInMusic($$music,$loops,$ms);
141 sub channel_volume ($$$) {
142 my ($self,$channel,$volume) = @_;
143 return SDL::MixVolume($channel,$volume);
146 sub music_volume ($$) {
147 my ($self,$volume) = @_;
148 return SDL::MixVolumeMusic($volume);
151 sub halt_channel ($$) {
152 my ($self,$channel) = @_;
153 return SDL::MixHaltChannel($channel);
156 sub halt_group ($$) {
157 my ($self,$group) = @_;
158 return SDL::MixHaltGroup($group);
162 return SDL::MixHaltMusic();
165 sub channel_expire ($$$) {
166 my ($self,$channel,$ticks) = @_;
167 return SDL::MixExpireChannel($channel,$ticks);
170 sub fade_out_channel ($$$) {
171 my ($self,$channel,$ms) = @_;
172 return SDL::MixFadeOutChannel($channel,$ms);
175 sub fade_out_group ($$$) {
176 my ($self,$group,$ms) = @_;
177 return SDL::MixFadeOutGroup($group,$ms);
180 sub fade_out_music ($$) {
182 return SDL::MixFadeOutMusic($ms);
185 sub fading_music () {
186 return SDL::MixFadingMusic();
189 sub fading_channel ($$) {
190 my ($self,$channel) = @_;
191 return SDL::MixFadingChannel($channel);
195 my ($self,$channel) = @_;
196 SDL::MixPause($channel);
200 my ($self,$channel) = @_;
201 SDL::MixResume($channel);
205 my ($self,$channel) = @_;
206 return SDL::MixPaused($channel);
210 SDL::MixPauseMusic();
213 sub resume_music () {
214 SDL::MixResumeMusic();
218 SDL::MixRewindMusic();
222 return SDL::MixPausedMusic();
226 my ($self,$channel) = @_;
227 return SDL::MixPlaying($channel);
230 sub playing_music () {
231 return SDL::MixPlayingMusic();
242 SDL::Mixer - a SDL perl extension
246 $mixer = new SDL::Mixer -frequency => MIX_DEFAULT_FREQUENCY,
247 -format => MIX_DEFAULT_FORMAT,
248 -channels => MIX_DEFAULT_CHANNELS,
253 SDL::Mixer allows you access to the SDL mixer library, enablig sound and
254 music volume setting, playing, pausing and resuming, as well as fading
255 the sound and music in and out.
261 $mixer = SDL::Mixer->new( -frequency => MIX_DEFAULT_FREQUENCY,
262 -format => MIX_DEFAULT_FORMAT,
263 -channels => MIX_DEFAULT_CHANNELS,
266 Creates a new SDL::Mixer object. C<$size> is the buffer size in bytes.
270 my $specs = SDL::Mixer::query_spec();
272 Returns a hash reference, containing the following keys and their respective
280 =head2 reserve_channels
282 $mixer->reserve_channels(4);
284 Reserve so many channels.
286 =head2 allocate_channels()
288 $mixer->reserve_channels(2);
290 Allocate so many channels.
292 =head2 group_channel(channel,group)
294 Group the channel number C<$channel> into group C<$group>.
296 =head2 group_channels(from,to,group)
298 Groups a range of channels
300 =head2 group_available(group)
302 Return true when the group is available.
304 =head2 group_count(group)
306 Returns the number of channels in the group
308 =head2 group_oldest()
314 =head2 play_channel()
319 Play C<$music> C<$loop> times.
321 =head2 fade_in_channel(channel,chunk,loops,ms,ticks)
325 =head2 fade_in_music(music,loops,ms)
327 Fades the music in over a number of ms, looping as it does
329 =head2 channel_volume(channel,volume)
331 Sets the volume for a single channel
333 =head2 mucis_volume(volume)
335 Set the volume for the music.
337 =head2 halt_channel(channel)
339 Stops a specific channel
341 =head2 halt_group(group)
343 Stops a group of channels
349 =head2 channel_expire(channel,ticks)
351 Ignores the channel after C<ticks> has expired
353 =head2 fade_out_channel(channel,ms)
355 Fade the channel number C<$channel> in C<$ms> ms out.
357 =head2 fade_out_group(group,ms)
359 Fade the channel group C<$group> in C<$ms> ms out.
361 =head2 fade_out_music(ms)
363 Fade the music in C<$ms> ms out.
365 =head2 fading_music()
367 Return true when the music is currently fading in or out.
369 =head2 fading_channel()
371 Return true when the channel number C<$channel> is currently fading in or out.
373 =head2 pause( channel )
375 Pause the channel C<$channel>.
377 =head2 resume(channel)
379 Resume the channel C<$channel>.
383 Return true when the channel is currently paused.
387 Pause the music play.
389 =head2 resume_music()
391 Resume the music play.
393 =head2 rewind_music()
395 Resets the music file to the beginning
397 =head2 music_paused()
399 Return true when the music is currently paused.
403 Return true when the channel is currently playing.
405 =head2 playing_music ()
407 Return true when the music is currently playing.
411 David J. Goehrig, basic doc added by Tels <http://bloodgate.com>.
415 L<perl>, L<SDL::Music> and L<SDL::Sound>.