3 # a SDL module for manipulating the SDL_mixer lib.
5 # Copyright (C) 2000,2002 David J. Goehrig
16 $SDL::Mixer::initialized = 0;
20 my $class = ref($proto) || $proto;
23 my $frequency = $options{-frequency} || $options{-rate} || SDL::MIX_DEFAULT_FREQUENCY();
24 my $format = $options{-format} || SDL::MIX_DEFAULT_FORMAT();
25 my $channels = $options{-channels} || SDL::MIX_DEFAULT_CHANNELS();
26 my $size = $options{-size} || 4096;
27 unless ( $SDL::Mixer::initialized ) {
28 SDL::MixOpenAudio($frequency,$format,$channels,$size ) &&
30 $SDL::Mixer::initialized = 1;
32 ++$SDL::Mixer::initialized;
40 --$SDL::Mixer::initialized;
41 unless ($SDL::Mixer::initialized) {
48 my ($status,$freq,$format,$channels) = SDL::MixQuerySpec();
49 my %hash = ( -status => $status, -frequency => $freq,
50 -format => $format, -channels => $channels );
54 sub reserve_channels ($$) {
55 my ($self,$channels) = @_;
56 return SDL::MixReserveChannels($channels);
59 sub allocate_channels ($$) {
60 my ($self,$channels) = @_;
61 return SDL::MixAllocateChannels($channels);
64 sub group_channel ($$$) {
65 my ($self,$channel,$group) = @_;
66 return SDL::MixGroupChannel($channel, $group);
69 sub group_channels ($$$$) {
70 my ($self,$from,$to,$group) = @_;
71 return SDL::MixGroupChannels($from,$to,$group);
74 sub group_available ($$) {
75 my ($self,$group) = @_;
76 return SDL::MixGroupAvailable($group);
79 sub group_count ($$) {
80 my ($self,$group) = @_;
81 return SDL::MixGroupCount($group);
84 sub group_oldest ($$) {
85 my ($self,$group) = @_;
86 return SDL::MixGroupOldest($group);
89 sub group_newer ($$) {
90 my ($self,$group) = @_;
91 return SDL::MixGroupNewer($group);
94 sub play_channel ($$$$;$) {
95 my ($self,$channel,$chunk,$loops,$ticks) = @_;
97 return SDL::MixPlayChannelTimed($channel,$$chunk,$loops,$ticks);
100 sub play_music ($$$) {
101 my ($self,$music,$loops) = @_;
102 return SDL::MixPlayMusic($$music,$loops);
105 sub fade_in_channel ($$$$$;$) {
106 my ($self,$channel,$chunk,$loops,$ms,$ticks) = @_;
108 return SDL::MixFadeInChannelTimed($channel,$$chunk,$loops,$ms,$ticks);
111 sub fade_in_music ($$$$) {
112 my ($self,$music,$loops,$ms) = @_;
113 return SDL::MixFadeInMusic($$music,$loops,$ms);
116 sub channel_volume ($$$) {
117 my ($self,$channel,$volume) = @_;
118 return SDL::MixVolume($channel,$volume);
121 sub music_volume ($$) {
122 my ($self,$volume) = @_;
123 return SDL::MixVolumeMusic($volume);
126 sub halt_channel ($$) {
127 my ($self,$channel) = @_;
128 return SDL::MixHaltChannel($channel);
131 sub halt_group ($$) {
132 my ($self,$group) = @_;
133 return SDL::MixHaltGroup($group);
137 return SDL::MixHaltMusic();
140 sub channel_expire ($$$) {
141 my ($self,$channel,$ticks) = @_;
142 return SDL::MixExpireChannel($channel,$ticks);
145 sub fade_out_channel ($$$) {
146 my ($self,$channel,$ms) = @_;
147 return SDL::MixFadeOutChannel($channel,$ms);
150 sub fade_out_group ($$$) {
151 my ($self,$group,$ms) = @_;
152 return SDL::MixFadeOutGroup($group,$ms);
155 sub fade_out_music ($$) {
157 return SDL::MixFadeOutMusic($ms);
160 sub fading_music () {
161 return SDL::MixFadingMusic();
164 sub fading_channel ($$) {
165 my ($self,$channel) = @_;
166 return SDL::MixFadingChannel($channel);
170 my ($self,$channel) = @_;
171 SDL::MixPause($channel);
175 my ($self,$channel) = @_;
176 SDL::MixResume($channel);
180 my ($self,$channel) = @_;
181 return SDL::MixPaused($channel);
185 SDL::MixPauseMusic();
188 sub resume_music () {
189 SDL::MixResumeMusic();
193 SDL::MixRewindMusic();
197 return SDL::MixPausedMusic();
201 my ($self,$channel) = @_;
202 return SDL::MixPlaying($channel);
205 sub playing_music () {
206 return SDL::MixPlayingMusic();
217 SDL::Mixer - a SDL perl extension
221 $mixer = new SDL::Mixer -frequency => MIX_DEFAULT_FREQUENCY,
222 -format => MIX_DEFAULT_FORMAT,
223 -channels => MIX_DEFAULT_CHANNELS,
228 SDL::Mixer allows you access to the SDL mixer library, enablig sound and
229 music volume setting, playing, pausing and resuming, as well as fading
230 the sound and music in and out.
236 $mixer = SDL::Mixer->new( -frequency => MIX_DEFAULT_FREQUENCY,
237 -format => MIX_DEFAULT_FORMAT,
238 -channels => MIX_DEFAULT_CHANNELS,
241 Creates a new SDL::Mixer object. C<$size> is the buffer size in bytes.
245 my $specs = SDL::Mixer::query_spec();
247 Returns a hash reference, containing the following keys and their respective
255 =head2 reserve_channels
257 $mixer->reserve_channels(4);
259 Reserve so many channels.
261 =head2 allocate_channels()
263 $mixer->reserve_channels(2);
265 Allocate so many channels.
267 =head2 group_channel(channel,group)
269 Group the channel number C<$channel> into group C<$group>.
271 =head2 group_channels(from,to,group)
273 Groups a range of channels
275 =head2 group_available(group)
277 Return true when the group is available.
279 =head2 group_count(group)
281 Returns the number of channels in the group
283 =head2 group_oldest()
289 =head2 play_channel()
294 Play C<$music> C<$loop> times.
296 =head2 fade_in_channel(channel,chunk,loops,ms,ticks)
300 =head2 fade_in_music(music,loops,ms)
302 Fades the music in over a number of ms, looping as it does
304 =head2 channel_volume(channel,volume)
306 Sets the volume for a single channel
308 =head2 mucis_volume(volume)
310 Set the volume for the music.
312 =head2 halt_channel(channel)
314 Stops a specific channel
316 =head2 halt_group(group)
318 Stops a group of channels
324 =head2 channel_expire(channel,ticks)
326 Ignores the channel after C<ticks> has expired
328 =head2 fade_out_channel(channel,ms)
330 Fade the channel number C<$channel> in C<$ms> ms out.
332 =head2 fade_out_group(group,ms)
334 Fade the channel group C<$group> in C<$ms> ms out.
336 =head2 fade_out_music(ms)
338 Fade the music in C<$ms> ms out.
340 =head2 fading_music()
342 Return true when the music is currently fading in or out.
344 =head2 fading_channel()
346 Return true when the channel number C<$channel> is currently fading in or out.
348 =head2 pause( channel )
350 Pause the channel C<$channel>.
352 =head2 resume(channel)
354 Resume the channel C<$channel>.
358 Return true when the channel is currently paused.
362 Pause the music play.
364 =head2 resume_music()
366 Resume the music play.
368 =head2 rewind_music()
370 Resets the music file to the beginning
372 =head2 music_paused()
374 Return true when the music is currently paused.
378 Return true when the channel is currently playing.
380 =head2 playing_music ()
382 Return true when the music is currently playing.
386 David J. Goehrig, basic doc added by Tels <http://bloodgate.com>.
390 L<perl>, L<SDL::Music> and L<SDL::Sound>.