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