Commit | Line | Data |
7b6a53a1 |
1 | #!/usr/bin/env perl |
2 | # |
3 | # Mixer.pm |
4 | # |
5 | # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org> |
6 | # |
7 | # ------------------------------------------------------------------------------ |
8 | # |
9 | # This library is free software; you can redistribute it and/or |
10 | # modify it under the terms of the GNU Lesser General Public |
11 | # License as published by the Free Software Foundation; either |
12 | # version 2.1 of the License, or (at your option) any later version. |
13 | # |
14 | # This library is distributed in the hope that it will be useful, |
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | # Lesser General Public License for more details. |
18 | # |
19 | # You should have received a copy of the GNU Lesser General Public |
20 | # License along with this library; if not, write to the Free Software |
21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | # |
23 | # ------------------------------------------------------------------------------ |
24 | # |
25 | # Please feel free to send questions, suggestions or improvements to: |
26 | # |
27 | # David J. Goehrig |
28 | # dgoehrig@cpan.org |
8fde61e3 |
29 | # |
8fde61e3 |
30 | |
31 | package SDL::Mixer; |
7b6a53a1 |
32 | |
8fde61e3 |
33 | use strict; |
084b921f |
34 | use warnings; |
35 | use Carp; |
36 | |
8fde61e3 |
37 | use SDL; |
38 | use SDL::Sound; |
39 | use SDL::Music; |
40 | |
41 | BEGIN { |
42 | } |
43 | |
44 | $SDL::Mixer::initialized = 0; |
45 | |
46 | sub new { |
47 | my $proto = shift; |
48 | my $class = ref($proto) || $proto; |
49 | my $self = {}; |
50 | my %options = @_; |
51 | my $frequency = $options{-frequency} || $options{-rate} || SDL::MIX_DEFAULT_FREQUENCY(); |
52 | my $format = $options{-format} || SDL::MIX_DEFAULT_FORMAT(); |
53 | my $channels = $options{-channels} || SDL::MIX_DEFAULT_CHANNELS(); |
54 | my $size = $options{-size} || 4096; |
55 | unless ( $SDL::Mixer::initialized ) { |
56 | SDL::MixOpenAudio($frequency,$format,$channels,$size ) && |
084b921f |
57 | croak SDL::GetError(); |
8fde61e3 |
58 | $SDL::Mixer::initialized = 1; |
59 | } else { |
60 | ++$SDL::Mixer::initialized; |
61 | } |
62 | bless $self,$class; |
63 | return $self; |
64 | } |
65 | |
66 | sub DESTROY { |
67 | my $self = shift; |
68 | --$SDL::Mixer::initialized; |
69 | unless ($SDL::Mixer::initialized) { |
70 | SDL::MixCloseAudio(); |
71 | } |
72 | } |
73 | |
74 | |
75 | sub query_spec () { |
76 | my ($status,$freq,$format,$channels) = SDL::MixQuerySpec(); |
77 | my %hash = ( -status => $status, -frequency => $freq, |
78 | -format => $format, -channels => $channels ); |
79 | return \%hash; |
80 | } |
81 | |
82 | sub reserve_channels ($$) { |
83 | my ($self,$channels) = @_; |
84 | return SDL::MixReserveChannels($channels); |
85 | } |
86 | |
87 | sub allocate_channels ($$) { |
88 | my ($self,$channels) = @_; |
89 | return SDL::MixAllocateChannels($channels); |
90 | } |
91 | |
92 | sub group_channel ($$$) { |
93 | my ($self,$channel,$group) = @_; |
94 | return SDL::MixGroupChannel($channel, $group); |
95 | } |
96 | |
97 | sub group_channels ($$$$) { |
98 | my ($self,$from,$to,$group) = @_; |
99 | return SDL::MixGroupChannels($from,$to,$group); |
100 | } |
101 | |
102 | sub group_available ($$) { |
103 | my ($self,$group) = @_; |
104 | return SDL::MixGroupAvailable($group); |
105 | } |
106 | |
107 | sub group_count ($$) { |
108 | my ($self,$group) = @_; |
109 | return SDL::MixGroupCount($group); |
110 | } |
111 | |
112 | sub group_oldest ($$) { |
113 | my ($self,$group) = @_; |
114 | return SDL::MixGroupOldest($group); |
115 | } |
116 | |
117 | sub group_newer ($$) { |
118 | my ($self,$group) = @_; |
119 | return SDL::MixGroupNewer($group); |
120 | } |
121 | |
122 | sub play_channel ($$$$;$) { |
123 | my ($self,$channel,$chunk,$loops,$ticks) = @_; |
124 | $ticks ||= -1; |
125 | return SDL::MixPlayChannelTimed($channel,$$chunk,$loops,$ticks); |
126 | } |
127 | |
128 | sub play_music ($$$) { |
129 | my ($self,$music,$loops) = @_; |
130 | return SDL::MixPlayMusic($$music,$loops); |
131 | } |
132 | |
133 | sub fade_in_channel ($$$$$;$) { |
134 | my ($self,$channel,$chunk,$loops,$ms,$ticks) = @_; |
135 | $ticks ||= -1; |
136 | return SDL::MixFadeInChannelTimed($channel,$$chunk,$loops,$ms,$ticks); |
137 | } |
138 | |
139 | sub fade_in_music ($$$$) { |
140 | my ($self,$music,$loops,$ms) = @_; |
141 | return SDL::MixFadeInMusic($$music,$loops,$ms); |
142 | } |
143 | |
144 | sub channel_volume ($$$) { |
145 | my ($self,$channel,$volume) = @_; |
146 | return SDL::MixVolume($channel,$volume); |
147 | } |
148 | |
149 | sub music_volume ($$) { |
150 | my ($self,$volume) = @_; |
151 | return SDL::MixVolumeMusic($volume); |
152 | } |
153 | |
154 | sub halt_channel ($$) { |
155 | my ($self,$channel) = @_; |
156 | return SDL::MixHaltChannel($channel); |
157 | } |
158 | |
159 | sub halt_group ($$) { |
160 | my ($self,$group) = @_; |
161 | return SDL::MixHaltGroup($group); |
162 | } |
163 | |
164 | sub halt_music (){ |
165 | return SDL::MixHaltMusic(); |
166 | } |
167 | |
168 | sub channel_expire ($$$) { |
169 | my ($self,$channel,$ticks) = @_; |
170 | return SDL::MixExpireChannel($channel,$ticks); |
171 | } |
172 | |
173 | sub fade_out_channel ($$$) { |
174 | my ($self,$channel,$ms) = @_; |
175 | return SDL::MixFadeOutChannel($channel,$ms); |
176 | } |
177 | |
178 | sub fade_out_group ($$$) { |
179 | my ($self,$group,$ms) = @_; |
180 | return SDL::MixFadeOutGroup($group,$ms); |
181 | } |
182 | |
183 | sub fade_out_music ($$) { |
184 | my ($self,$ms) = @_; |
185 | return SDL::MixFadeOutMusic($ms); |
186 | } |
187 | |
188 | sub fading_music () { |
189 | return SDL::MixFadingMusic(); |
190 | } |
191 | |
192 | sub fading_channel ($$) { |
193 | my ($self,$channel) = @_; |
194 | return SDL::MixFadingChannel($channel); |
195 | } |
196 | |
197 | sub pause ($$) { |
198 | my ($self,$channel) = @_; |
199 | SDL::MixPause($channel); |
200 | } |
201 | |
202 | sub resume ($$) { |
203 | my ($self,$channel) = @_; |
204 | SDL::MixResume($channel); |
205 | } |
206 | |
207 | sub paused ($$) { |
208 | my ($self,$channel) = @_; |
209 | return SDL::MixPaused($channel); |
210 | } |
211 | |
212 | sub pause_music () { |
213 | SDL::MixPauseMusic(); |
214 | } |
215 | |
216 | sub resume_music () { |
217 | SDL::MixResumeMusic(); |
218 | } |
219 | |
220 | sub rewind_music (){ |
221 | SDL::MixRewindMusic(); |
222 | } |
223 | |
224 | sub music_paused (){ |
225 | return SDL::MixPausedMusic(); |
226 | } |
227 | |
228 | sub playing ($$) { |
229 | my ($self,$channel) = @_; |
230 | return SDL::MixPlaying($channel); |
231 | } |
232 | |
233 | sub playing_music () { |
234 | return SDL::MixPlayingMusic(); |
235 | } |
236 | |
ee72c5c6 |
237 | sub set_panning { |
238 | my($self, $channel, $left, $right) = @_; |
239 | return SDL::MixSetPanning($channel, $left, $right); |
240 | } |
241 | |
8fde61e3 |
242 | 1; |