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);
127 sub mix_set_panning($$$$) {
128 my ($self,$channel,$left,$right) = @_;
129 return SDL::MixSetPanning($channel,$left,$right);
133 sub halt_channel ($$) {
134 my ($self,$channel) = @_;
135 return SDL::MixHaltChannel($channel);
138 sub halt_group ($$) {
139 my ($self,$group) = @_;
140 return SDL::MixHaltGroup($group);
144 return SDL::MixHaltMusic();
147 sub channel_expire ($$$) {
148 my ($self,$channel,$ticks) = @_;
149 return SDL::MixExpireChannel($channel,$ticks);
152 sub fade_out_channel ($$$) {
153 my ($self,$channel,$ms) = @_;
154 return SDL::MixFadeOutChannel($channel,$ms);
157 sub fade_out_group ($$$) {
158 my ($self,$group,$ms) = @_;
159 return SDL::MixFadeOutGroup($group,$ms);
162 sub fade_out_music ($$) {
164 return SDL::MixFadeOutMusic($ms);
167 sub fading_music () {
168 return SDL::MixFadingMusic();
171 sub fading_channel ($$) {
172 my ($self,$channel) = @_;
173 return SDL::MixFadingChannel($channel);
177 my ($self,$channel) = @_;
178 SDL::MixPause($channel);
182 my ($self,$channel) = @_;
183 SDL::MixResume($channel);
187 my ($self,$channel) = @_;
188 return SDL::MixPaused($channel);
192 SDL::MixPauseMusic();
195 sub resume_music () {
196 SDL::MixResumeMusic();
200 SDL::MixRewindMusic();
204 return SDL::MixPausedMusic();
208 my ($self,$channel) = @_;
209 return SDL::MixPlaying($channel);
212 sub mix_volume_chunk($$$) {
213 my ($self, $chunk, $volume) = @_;
214 return SDL::MixVolumeChunk($chunk, $volume);
217 sub playing_music () {
218 return SDL::MixPlayingMusic();
229 SDL::Mixer - a SDL perl extension
233 $mixer = new SDL::Mixer -frequency => MIX_DEFAULT_FREQUENCY,
234 -format => MIX_DEFAULT_FORMAT,
235 -channels => MIX_DEFAULT_CHANNELS,
240 SDL::Mixer allows you access to the SDL mixer library, enablig sound and
241 music volume setting, playing, pausing and resuming, as well as fading
242 the sound and music in and out.
248 $mixer = SDL::Mixer->new( -frequency => MIX_DEFAULT_FREQUENCY,
249 -format => MIX_DEFAULT_FORMAT,
250 -channels => MIX_DEFAULT_CHANNELS,
253 Creates a new SDL::Mixer object. C<$size> is the buffer size in bytes.
257 my $specs = SDL::Mixer::query_spec();
259 Returns a hash reference, containing the following keys and their respective
267 =head2 reserve_channels
269 $mixer->reserve_channels(4);
271 Reserve so many channels.
273 =head2 allocate_channels()
275 $mixer->reserve_channels(2);
277 Allocate so many channels.
279 =head2 group_channel(channel,group)
281 Group the channel number C<$channel> into group C<$group>.
283 =head2 group_channels(from,to,group)
285 Groups a range of channels
287 =head2 group_available(group)
289 Return true when the group is available.
291 =head2 group_count(group)
293 Returns the number of channels in the group
295 =head2 group_oldest()
301 =head2 play_channel()
306 Play C<$music> C<$loop> times.
308 =head2 fade_in_channel(channel,chunk,loops,ms,ticks)
312 =head2 fade_in_music(music,loops,ms)
314 Fades the music in over a number of ms, looping as it does
316 =head2 channel_volume(channel,volume)
318 Sets the volume for a single channel
320 =head2 mucis_volume(volume)
322 Set the volume for the music.
324 =head2 halt_channel(channel)
326 Stops a specific channel
328 =head2 halt_group(group)
330 Stops a group of channels
336 =head2 channel_expire(channel,ticks)
338 Ignores the channel after C<ticks> has expired
340 =head2 fade_out_channel(channel,ms)
342 Fade the channel number C<$channel> in C<$ms> ms out.
344 =head2 fade_out_group(group,ms)
346 Fade the channel group C<$group> in C<$ms> ms out.
348 =head2 fade_out_music(ms)
350 Fade the music in C<$ms> ms out.
352 =head2 fading_music()
354 Return true when the music is currently fading in or out.
356 =head2 fading_channel()
358 Return true when the channel number C<$channel> is currently fading in or out.
360 =head2 pause( channel )
362 Pause the channel C<$channel>.
364 =head2 resume(channel)
366 Resume the channel C<$channel>.
370 Return true when the channel is currently paused.
374 Pause the music play.
376 =head2 resume_music()
378 Resume the music play.
380 =head2 rewind_music()
382 Resets the music file to the beginning
384 =head2 music_paused()
386 Return true when the music is currently paused.
390 Return true when the channel is currently playing.
392 =head2 playing_music ()
394 Return true when the music is currently playing.
396 =head2 sub mix_set_panning(channel,left,right)
398 Set panning for mixer, Use MIX_CHANNEL_POST to process the postmix stream
400 Volume for the left channel, range is 0(silence) to 255(loud)
402 Volume for the right channel, range is 0(silence) to 255(loud)
407 David J. Goehrig, basic doc added by Tels <http://bloodgate.com>.
411 L<perl>, L<SDL::Music> and L<SDL::Sound>.