3 # a SDL module for manipulating the SDL_mixer lib.
5 # Copyright (C) 2000,2002 David J. Goehrig
6 # Copyright (C) 2009 Kartik Thakore
17 $SDL::Mixer::initialized = 0;
21 my $class = ref($proto) || $proto;
24 my $frequency = $options{-frequency} || $options{-rate} || SDL::MIX_DEFAULT_FREQUENCY();
25 my $format = $options{-format} || SDL::MIX_DEFAULT_FORMAT();
26 my $channels = $options{-channels} || SDL::MIX_DEFAULT_CHANNELS();
27 my $size = $options{-size} || 4096;
28 unless ( $SDL::Mixer::initialized ) {
29 SDL::MixOpenAudio($frequency,$format,$channels,$size ) &&
31 $SDL::Mixer::initialized = 1;
33 ++$SDL::Mixer::initialized;
41 --$SDL::Mixer::initialized;
42 unless ($SDL::Mixer::initialized) {
49 my ($status,$freq,$format,$channels) = SDL::MixQuerySpec();
50 my %hash = ( -status => $status, -frequency => $freq,
51 -format => $format, -channels => $channels );
55 sub reserve_channels ($$) {
56 my ($self,$channels) = @_;
57 return SDL::MixReserveChannels($channels);
60 sub allocate_channels ($$) {
61 my ($self,$channels) = @_;
62 return SDL::MixAllocateChannels($channels);
65 sub group_channel ($$$) {
66 my ($self,$channel,$group) = @_;
67 return SDL::MixGroupChannel($channel, $group);
70 sub group_channels ($$$$) {
71 my ($self,$from,$to,$group) = @_;
72 return SDL::MixGroupChannels($from,$to,$group);
75 sub group_available ($$) {
76 my ($self,$group) = @_;
77 return SDL::MixGroupAvailable($group);
80 sub group_count ($$) {
81 my ($self,$group) = @_;
82 return SDL::MixGroupCount($group);
85 sub group_oldest ($$) {
86 my ($self,$group) = @_;
87 return SDL::MixGroupOldest($group);
90 sub group_newer ($$) {
91 my ($self,$group) = @_;
92 return SDL::MixGroupNewer($group);
95 sub play_channel ($$$$;$) {
96 my ($self,$channel,$chunk,$loops,$ticks) = @_;
98 return SDL::MixPlayChannelTimed($channel,$$chunk,$loops,$ticks);
101 sub play_music ($$$) {
102 my ($self,$music,$loops) = @_;
103 return SDL::MixPlayMusic($$music,$loops);
106 sub fade_in_channel ($$$$$;$) {
107 my ($self,$channel,$chunk,$loops,$ms,$ticks) = @_;
109 return SDL::MixFadeInChannelTimed($channel,$$chunk,$loops,$ms,$ticks);
112 sub fade_in_music ($$$$) {
113 my ($self,$music,$loops,$ms) = @_;
114 return SDL::MixFadeInMusic($$music,$loops,$ms);
117 sub channel_volume ($$$) {
118 my ($self,$channel,$volume) = @_;
119 return SDL::MixVolume($channel,$volume);
122 sub music_volume ($$) {
123 my ($self,$volume) = @_;
124 return SDL::MixVolumeMusic($volume);
128 sub halt_channel ($$) {
129 my ($self,$channel) = @_;
130 return SDL::MixHaltChannel($channel);
133 sub halt_group ($$) {
134 my ($self,$group) = @_;
135 return SDL::MixHaltGroup($group);
139 return SDL::MixHaltMusic();
142 sub channel_expire ($$$) {
143 my ($self,$channel,$ticks) = @_;
144 return SDL::MixExpireChannel($channel,$ticks);
147 sub fade_out_channel ($$$) {
148 my ($self,$channel,$ms) = @_;
149 return SDL::MixFadeOutChannel($channel,$ms);
152 sub fade_out_group ($$$) {
153 my ($self,$group,$ms) = @_;
154 return SDL::MixFadeOutGroup($group,$ms);
157 sub fade_out_music ($$) {
159 return SDL::MixFadeOutMusic($ms);
162 sub fading_music () {
163 return SDL::MixFadingMusic();
166 sub fading_channel ($$) {
167 my ($self,$channel) = @_;
168 return SDL::MixFadingChannel($channel);
172 my ($self,$channel) = @_;
173 SDL::MixPause($channel);
177 my ($self,$channel) = @_;
178 SDL::MixResume($channel);
182 my ($self,$channel) = @_;
183 return SDL::MixPaused($channel);
187 SDL::MixPauseMusic();
190 sub resume_music () {
191 SDL::MixResumeMusic();
195 SDL::MixRewindMusic();
199 return SDL::MixPausedMusic();
203 my ($self,$channel) = @_;
204 return SDL::MixPlaying($channel);
207 sub mix_volume_chunk($$$) {
208 my ($self, $chunk, $volume) = @_;
209 return SDL::MixVolumeChunk($chunk, $volume);
212 sub playing_music () {
213 return SDL::MixPlayingMusic();
224 SDL::Mixer - a SDL perl extension
228 $mixer = new SDL::Mixer -frequency => MIX_DEFAULT_FREQUENCY,
229 -format => MIX_DEFAULT_FORMAT,
230 -channels => MIX_DEFAULT_CHANNELS,
235 SDL::Mixer allows you access to the SDL mixer library, enablig sound and
236 music volume setting, playing, pausing and resuming, as well as fading
237 the sound and music in and out.
243 $mixer = SDL::Mixer->new( -frequency => MIX_DEFAULT_FREQUENCY,
244 -format => MIX_DEFAULT_FORMAT,
245 -channels => MIX_DEFAULT_CHANNELS,
248 Creates a new SDL::Mixer object. C<$size> is the buffer size in bytes.
252 my $specs = SDL::Mixer::query_spec();
254 Returns a hash reference, containing the following keys and their respective
262 =head2 reserve_channels
264 $mixer->reserve_channels(4);
266 Reserve so many channels.
268 =head2 allocate_channels()
270 $mixer->reserve_channels(2);
272 Allocate so many channels.
274 =head2 group_channel(channel,group)
276 Group the channel number C<$channel> into group C<$group>.
278 =head2 group_channels(from,to,group)
280 Groups a range of channels
282 =head2 group_available(group)
284 Return true when the group is available.
286 =head2 group_count(group)
288 Returns the number of channels in the group
290 =head2 group_oldest()
296 =head2 play_channel()
301 Play C<$music> C<$loop> times.
303 =head2 fade_in_channel(channel,chunk,loops,ms,ticks)
307 =head2 fade_in_music(music,loops,ms)
309 Fades the music in over a number of ms, looping as it does
311 =head2 channel_volume(channel,volume)
313 Sets the volume for a single channel
315 =head2 mucis_volume(volume)
317 Set the volume for the music.
319 =head2 halt_channel(channel)
321 Stops a specific channel
323 =head2 halt_group(group)
325 Stops a group of channels
331 =head2 channel_expire(channel,ticks)
333 Ignores the channel after C<ticks> has expired
335 =head2 fade_out_channel(channel,ms)
337 Fade the channel number C<$channel> in C<$ms> ms out.
339 =head2 fade_out_group(group,ms)
341 Fade the channel group C<$group> in C<$ms> ms out.
343 =head2 fade_out_music(ms)
345 Fade the music in C<$ms> ms out.
347 =head2 fading_music()
349 Return true when the music is currently fading in or out.
351 =head2 fading_channel()
353 Return true when the channel number C<$channel> is currently fading in or out.
355 =head2 pause( channel )
357 Pause the channel C<$channel>.
359 =head2 resume(channel)
361 Resume the channel C<$channel>.
365 Return true when the channel is currently paused.
369 Pause the music play.
371 =head2 resume_music()
373 Resume the music play.
375 =head2 rewind_music()
377 Resets the music file to the beginning
379 =head2 music_paused()
381 Return true when the music is currently paused.
385 Return true when the channel is currently playing.
387 =head2 playing_music ()
389 Return true when the music is currently playing.
393 David J. Goehrig, basic doc added by Tels <http://bloodgate.com>.
397 L<perl>, L<SDL::Music> and L<SDL::Sound>.