Added SDL::Mixer::mix_set_panning support
[sdlgit/SDL_perl.git] / lib / SDL / Mixer.pm
CommitLineData
8fde61e3 1# Mixer.pm
2#
3# a SDL module for manipulating the SDL_mixer lib.
4d2f5fe1 4#
8fde61e3 5# Copyright (C) 2000,2002 David J. Goehrig
4d2f5fe1 6# Copyright (C) 2009 Kartik Thakore
8fde61e3 7
8package SDL::Mixer;
9use strict;
10use SDL;
11use SDL::Sound;
12use SDL::Music;
13
14BEGIN {
15}
16
17$SDL::Mixer::initialized = 0;
18
19sub new {
20 my $proto = shift;
21 my $class = ref($proto) || $proto;
22 my $self = {};
23 my %options = @_;
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 ) &&
30 die SDL::GetError();
31 $SDL::Mixer::initialized = 1;
32 } else {
33 ++$SDL::Mixer::initialized;
34 }
35 bless $self,$class;
36 return $self;
37}
38
39sub DESTROY {
40 my $self = shift;
41 --$SDL::Mixer::initialized;
42 unless ($SDL::Mixer::initialized) {
43 SDL::MixCloseAudio();
44 }
45}
46
47
48sub query_spec () {
49 my ($status,$freq,$format,$channels) = SDL::MixQuerySpec();
50 my %hash = ( -status => $status, -frequency => $freq,
51 -format => $format, -channels => $channels );
52 return \%hash;
53}
54
55sub reserve_channels ($$) {
56 my ($self,$channels) = @_;
57 return SDL::MixReserveChannels($channels);
58}
59
60sub allocate_channels ($$) {
61 my ($self,$channels) = @_;
62 return SDL::MixAllocateChannels($channels);
63}
64
65sub group_channel ($$$) {
66 my ($self,$channel,$group) = @_;
67 return SDL::MixGroupChannel($channel, $group);
68}
69
70sub group_channels ($$$$) {
71 my ($self,$from,$to,$group) = @_;
72 return SDL::MixGroupChannels($from,$to,$group);
73}
74
75sub group_available ($$) {
76 my ($self,$group) = @_;
77 return SDL::MixGroupAvailable($group);
78}
79
80sub group_count ($$) {
81 my ($self,$group) = @_;
82 return SDL::MixGroupCount($group);
83}
84
85sub group_oldest ($$) {
86 my ($self,$group) = @_;
87 return SDL::MixGroupOldest($group);
88}
89
90sub group_newer ($$) {
91 my ($self,$group) = @_;
92 return SDL::MixGroupNewer($group);
93}
94
95sub play_channel ($$$$;$) {
96 my ($self,$channel,$chunk,$loops,$ticks) = @_;
97 $ticks ||= -1;
98 return SDL::MixPlayChannelTimed($channel,$$chunk,$loops,$ticks);
99}
100
101sub play_music ($$$) {
102 my ($self,$music,$loops) = @_;
103 return SDL::MixPlayMusic($$music,$loops);
104}
105
106sub fade_in_channel ($$$$$;$) {
107 my ($self,$channel,$chunk,$loops,$ms,$ticks) = @_;
108 $ticks ||= -1;
109 return SDL::MixFadeInChannelTimed($channel,$$chunk,$loops,$ms,$ticks);
110}
111
112sub fade_in_music ($$$$) {
113 my ($self,$music,$loops,$ms) = @_;
114 return SDL::MixFadeInMusic($$music,$loops,$ms);
115}
116
117sub channel_volume ($$$) {
118 my ($self,$channel,$volume) = @_;
119 return SDL::MixVolume($channel,$volume);
120}
121
122sub music_volume ($$) {
123 my ($self,$volume) = @_;
124 return SDL::MixVolumeMusic($volume);
125}
126
ae1cb2f6 127sub mix_set_panning($$$$) {
128 my ($self,$channel,$left,$right) = @_;
129 return SDL::MixSetPanning($channel,$left,$right);
130 }
131
4d2f5fe1 132
8fde61e3 133sub halt_channel ($$) {
134 my ($self,$channel) = @_;
135 return SDL::MixHaltChannel($channel);
136}
137
138sub halt_group ($$) {
139 my ($self,$group) = @_;
140 return SDL::MixHaltGroup($group);
141}
142
143sub halt_music (){
144 return SDL::MixHaltMusic();
145}
146
147sub channel_expire ($$$) {
148 my ($self,$channel,$ticks) = @_;
149 return SDL::MixExpireChannel($channel,$ticks);
150}
151
152sub fade_out_channel ($$$) {
153 my ($self,$channel,$ms) = @_;
154 return SDL::MixFadeOutChannel($channel,$ms);
155}
156
157sub fade_out_group ($$$) {
158 my ($self,$group,$ms) = @_;
159 return SDL::MixFadeOutGroup($group,$ms);
160}
161
162sub fade_out_music ($$) {
163 my ($self,$ms) = @_;
164 return SDL::MixFadeOutMusic($ms);
165}
166
167sub fading_music () {
168 return SDL::MixFadingMusic();
169}
170
171sub fading_channel ($$) {
172 my ($self,$channel) = @_;
173 return SDL::MixFadingChannel($channel);
174}
175
176sub pause ($$) {
177 my ($self,$channel) = @_;
178 SDL::MixPause($channel);
179}
180
181sub resume ($$) {
182 my ($self,$channel) = @_;
183 SDL::MixResume($channel);
184}
185
186sub paused ($$) {
187 my ($self,$channel) = @_;
188 return SDL::MixPaused($channel);
189}
190
191sub pause_music () {
192 SDL::MixPauseMusic();
193}
194
195sub resume_music () {
196 SDL::MixResumeMusic();
197}
198
199sub rewind_music (){
200 SDL::MixRewindMusic();
201}
202
203sub music_paused (){
204 return SDL::MixPausedMusic();
205}
206
207sub playing ($$) {
208 my ($self,$channel) = @_;
209 return SDL::MixPlaying($channel);
210}
211
4d2f5fe1 212sub mix_volume_chunk($$$) {
213 my ($self, $chunk, $volume) = @_;
214 return SDL::MixVolumeChunk($chunk, $volume);
215}
216
8fde61e3 217sub playing_music () {
218 return SDL::MixPlayingMusic();
219}
220
2211;
222
223__END__;
224
225=pod
226
227=head1 NAME
228
229SDL::Mixer - a SDL perl extension
230
231=head1 SYNOPSIS
232
233 $mixer = new SDL::Mixer -frequency => MIX_DEFAULT_FREQUENCY,
234 -format => MIX_DEFAULT_FORMAT,
235 -channels => MIX_DEFAULT_CHANNELS,
236 -size => 4096;
237
238=head1 DESCRIPTION
239
240SDL::Mixer allows you access to the SDL mixer library, enablig sound and
241music volume setting, playing, pausing and resuming, as well as fading
242the sound and music in and out.
243
244=head1 METHODS
245
246=head2 new()
247
248 $mixer = SDL::Mixer->new( -frequency => MIX_DEFAULT_FREQUENCY,
249 -format => MIX_DEFAULT_FORMAT,
250 -channels => MIX_DEFAULT_CHANNELS,
251 -size => 4096);
252
253Creates a new SDL::Mixer object. C<$size> is the buffer size in bytes.
254
255=head2 query_spec()
256
257 my $specs = SDL::Mixer::query_spec();
258
259Returns a hash reference, containing the following keys and their respective
260values:
261
262 -status
263 -frequency
264 -channels
265 -format
266
267=head2 reserve_channels
268
269 $mixer->reserve_channels(4);
270
271Reserve so many channels.
272
273=head2 allocate_channels()
274
275 $mixer->reserve_channels(2);
276
277Allocate so many channels.
278
279=head2 group_channel(channel,group)
280
281Group the channel number C<$channel> into group C<$group>.
282
283=head2 group_channels(from,to,group)
284
285Groups a range of channels
286
287=head2 group_available(group)
288
289Return true when the group is available.
290
291=head2 group_count(group)
292
293Returns the number of channels in the group
294
295=head2 group_oldest()
296
297
298=head2 group_newer()
299
300
301=head2 play_channel()
302
303
304=head2 play_music()
305
306Play C<$music> C<$loop> times.
307
308=head2 fade_in_channel(channel,chunk,loops,ms,ticks)
309
310Fades a channel in
311
312=head2 fade_in_music(music,loops,ms)
313
314Fades the music in over a number of ms, looping as it does
315
316=head2 channel_volume(channel,volume)
317
318Sets the volume for a single channel
319
320=head2 mucis_volume(volume)
321
322Set the volume for the music.
323
324=head2 halt_channel(channel)
325
326Stops a specific channel
327
328=head2 halt_group(group)
329
330Stops a group of channels
331
332=head2 halt_music()
333
334Stops the music
335
336=head2 channel_expire(channel,ticks)
337
338Ignores the channel after C<ticks> has expired
339
340=head2 fade_out_channel(channel,ms)
341
342Fade the channel number C<$channel> in C<$ms> ms out.
343
344=head2 fade_out_group(group,ms)
345
346Fade the channel group C<$group> in C<$ms> ms out.
347
348=head2 fade_out_music(ms)
349
350Fade the music in C<$ms> ms out.
351
352=head2 fading_music()
353
354Return true when the music is currently fading in or out.
355
356=head2 fading_channel()
357
358Return true when the channel number C<$channel> is currently fading in or out.
359
360=head2 pause( channel )
361
362Pause the channel C<$channel>.
363
364=head2 resume(channel)
365
366Resume the channel C<$channel>.
367
368=head2 paused()
369
370Return true when the channel is currently paused.
371
372=head2 pause_music()
373
374Pause the music play.
375
376=head2 resume_music()
377
378Resume the music play.
379
380=head2 rewind_music()
381
382Resets the music file to the beginning
383
384=head2 music_paused()
385
386Return true when the music is currently paused.
387
388=head2 playing()
389
390Return true when the channel is currently playing.
391
392=head2 playing_music ()
393
394Return true when the music is currently playing.
395
ae1cb2f6 396=head2 sub mix_set_panning(channel,left,right)
397
398Set panning for mixer, Use MIX_CHANNEL_POST to process the postmix stream
399
400Volume for the left channel, range is 0(silence) to 255(loud)
401
402Volume for the right channel, range is 0(silence) to 255(loud)
403
8fde61e3 404=head1 AUTHORS
405
ae1cb2f6 406Kartik Thakore
8fde61e3 407David J. Goehrig, basic doc added by Tels <http://bloodgate.com>.
408
409=head1 SEE ALSO
410
411L<perl>, L<SDL::Music> and L<SDL::Sound>.
412
413=cut