updated docs
[sdlgit/SDL-Site.git] / pages / SDL-Mixer-Channels.html-inc
1 <div class="pod">
2 <!-- INDEX START -->
3 <h3 id="TOP">Index</h3>
4
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#CATEGORY">CATEGORY</a></li>
7 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
8 <li><a href="#METHODS">METHODS</a>
9 <ul><li><a href="#allocate_channels">allocate_channels</a></li>
10 <li><a href="#volume">volume</a></li>
11 <li><a href="#play_channel">play_channel</a></li>
12 <li><a href="#play_channel_timed">play_channel_timed</a></li>
13 <li><a href="#fade_in_channel">fade_in_channel</a></li>
14 <li><a href="#fade_in_channel_timed">fade_in_channel_timed</a></li>
15 <li><a href="#pause">pause</a></li>
16 <li><a href="#resume">resume</a></li>
17 <li><a href="#halt_channel">halt_channel</a></li>
18 <li><a href="#expire_channel">expire_channel</a></li>
19 <li><a href="#fade_out_channel">fade_out_channel</a></li>
20 <li><a href="#channel_finished">channel_finished</a></li>
21 <li><a href="#playing">playing</a></li>
22 <li><a href="#paused">paused</a></li>
23 <li><a href="#fading_channel">fading_channel</a></li>
24 <li><a href="#get_chunk">get_chunk</a></li>
25 </ul>
26 </li>
27 <li><a href="#AUTHORS">AUTHORS</a>
28 </li>
29 </ul><hr />
30 <!-- INDEX END -->
31
32 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
33 <div id="NAME_CONTENT">
34 <p>SDL::Mixer::Channels -- SDL::Mixer channel functions and bindings</p>
35
36 </div>
37 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
38 <div id="CATEGORY_CONTENT">
39 <p>Mixer</p>
40
41 </div>
42 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
43 <div id="DESCRIPTION_CONTENT">
44
45 </div>
46 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
47 <div id="METHODS_CONTENT">
48
49 </div>
50 <h2 id="allocate_channels">allocate_channels</h2>
51 <div id="allocate_channels_CONTENT">
52 <pre> my $ret = SDL::Mixer::Channels::allocate_channels( $number_of_channels );
53
54 </pre>
55 <p>Dynamically change the number of channels managed by the mixer. If decreasing the number of channels, the upper channels arestopped.
56 This function returns the new number of allocated channels.</p>
57 <p>Example</p>
58 <pre> use SDL::Mixer::Channels;
59
60  printf(&quot;We got %d channels!\n&quot;, SDL::Mixer::Channels::allocate_channels( 8 ) );
61
62 </pre>
63
64 </div>
65 <h2 id="volume">volume</h2>
66 <div id="volume_CONTENT">
67 <pre> my $prev_volume = SDL::Mixer::Channels::volume( $channel_number, $volume );
68
69 </pre>
70 <p><code>volume</code> changes the volume of the channel specified in channel by the amount set in volume. The range of volume is from 0 to <code>MIX_MAX_VOLUME</code>
71 which is <code>128</code>. Passing <code>-1</code> to channel will change the volume of all channels. If the specified volume is <code>-1</code>, it will just return the 
72 current volume. </p>
73 <p>Returns the previously set volume of the channel.</p>
74
75 </div>
76 <h2 id="play_channel">play_channel</h2>
77 <div id="play_channel_CONTENT">
78 <pre> my $channel_number = SDL::Mixer::Channels::play_channel( $channel, $chunk, $loops );
79
80 </pre>
81 <p><code>play_channel</code> will play the specified <code>chunk</code> over the specified <code>channel</code>. SDL_mixer will choose a channel for you if you pass <code>-1</code> for 
82 <code>channel</code>.</p>
83 <p>The chunk will be looped <code>loops</code> times, the total number of times played will be <code>loops+1</code>. Passing <code>-1</code> will loop the chunk infinitely. </p>
84 <p>Returns the channel the chunk will be played on, or <code>-1</code> on error.</p>
85 <p>Example:</p>
86 <pre> use SDL::Mixer;
87  use SDL::Mixer::Channels;
88  use SDL::Mixer::Samples;
89
90  SDL::init(SDL_INIT_AUDIO);
91  SDL::Mixer::open_audio( 44100, SDL::Constants::AUDIO_S16, 2, 4096 );
92
93  my $chunk = SDL::Mixer::Samples::load_WAV('sample.wav');
94
95  SDL::Mixer::Channels::play_channel( -1, $chunk, -1 );
96
97  SDL::delay(1000);
98  SDL::Mixer::close_audio();
99
100 </pre>
101
102 </div>
103 <h2 id="play_channel_timed">play_channel_timed</h2>
104 <div id="play_channel_timed_CONTENT">
105 <pre> my $channel = SDL::Mixer::Channels::play_channel_timed( $channel, $chunk, $loops, $ticks );
106
107 </pre>
108 <p>Same as <a href="http://search.cpan.org/perldoc?play_channel">play_channel</a> but you can specify the time it will play by <code>$ticks</code>.</p>
109
110 </div>
111 <h2 id="fade_in_channel">fade_in_channel</h2>
112 <div id="fade_in_channel_CONTENT">
113 <pre> my $channel = SDL::Mixer::Channels::fade_in_channel( $channel, $chunk, $loops, $ms );
114
115 </pre>
116 <p>Same as <a href="http://search.cpan.org/perldoc?play_channel">play_channel</a> but you can specify the fade-in time by <code>$ms</code>.</p>
117
118 </div>
119 <h2 id="fade_in_channel_timed">fade_in_channel_timed</h2>
120 <div id="fade_in_channel_timed_CONTENT">
121 <pre> my $channel = SDL::Mixer::Channels::fade_in_channel_timed( $channel, $chunk, $loops, $ms, $ticks );
122
123 </pre>
124 <p>Same as <a href="http://search.cpan.org/perldoc?fade_in_channel">fade_in_channel</a> but you can specify the time how long the chunk will be played by <code>$ticks</code>.</p>
125
126 </div>
127 <h2 id="pause">pause</h2>
128 <div id="pause_CONTENT">
129 <pre> SDL::Mixer::Channels::pause( $channel );
130
131 </pre>
132 <p>Pauses the given channel or all by passing <code>-1</code>.</p>
133
134 </div>
135 <h2 id="resume">resume</h2>
136 <div id="resume_CONTENT">
137 <pre> SDL::Mixer::Channels::resume( $channel );
138
139 </pre>
140 <p>Resumes the given channel or all by passing <code>-1</code>.</p>
141
142 </div>
143 <h2 id="halt_channel">halt_channel</h2>
144 <div id="halt_channel_CONTENT">
145 <pre> SDL::Mixer::Channels::halt_channel( $channel );
146
147 </pre>
148 <p>Stops the given channel or all by passing <code>-1</code>.</p>
149
150 </div>
151 <h2 id="expire_channel">expire_channel</h2>
152 <div id="expire_channel_CONTENT">
153 <pre> my $channels = SDL::Mixer::Channels::expire_channel( $channel, $ticks );
154
155 </pre>
156 <p>Stops the given channel (or <code>-1</code> for all) after the time specified by <code>$ticks</code> (in milliseconds).</p>
157 <p>Returns the number of affected channels.</p>
158
159 </div>
160 <h2 id="fade_out_channel">fade_out_channel</h2>
161 <div id="fade_out_channel_CONTENT">
162 <pre> my $fading_channels = SDL::Mixer::Channels::fade_out_channel( $which, $ms );
163
164 </pre>
165 <p><code>fade_out_channel</code> fades out a channel specified in <code>which</code> with a duration specified in <code>ms</code> in milliseconds.</p>
166 <p>Returns the the number of channels that will be faded out.</p>
167
168 </div>
169 <h2 id="channel_finished">channel_finished</h2>
170 <div id="channel_finished_CONTENT">
171 <pre> SDL::Mixer::Channels::channel_finished( $callback );
172
173 </pre>
174 <p>Add your own callback when a channel has finished playing. <code>NULL</code> to disable callback. The callback may be called from the mixer's audio 
175 callback or it could be called as a result of <a href="http://search.cpan.org/perldoc?halt_channel">halt_channel</a>, etc. do not call <code>lock_audio</code> from this callback; you will either be inside 
176 the audio callback, or SDL_mixer will explicitly lock the audio before calling your callback.</p>
177 <p>Example 1:</p>
178 <pre> my $callback = sub{ printf(&quot;[channel_finished] callback called for channel %d\n&quot;, shift); };
179
180  SDL::Mixer::Channels::channel_finished( $callback );
181
182 </pre>
183 <p>Example 2:</p>
184 <pre> sub callback
185  {
186      ...
187  }
188
189  SDL::Mixer::Channels::channel_finished( \&amp;callback );
190
191 </pre>
192
193 </div>
194 <h2 id="playing">playing</h2>
195 <div id="playing_CONTENT">
196 <pre> my $playing = SDL::Mixer::Channels::playing( $channel );
197
198 </pre>
199 <p>Returns <code>1</code> if the given channel is playing sound, otherwise <code>0</code>. It does'nt check if the channel is paused.</p>
200 <p><strong>Note</strong>: If you pass <code>-1</code> you will get the number of playing channels.</p>
201
202 </div>
203 <h2 id="paused">paused</h2>
204 <div id="paused_CONTENT">
205 <pre> my $paused = SDL::Mixer::Channels::paused( $channel );
206
207 </pre>
208 <p>Returns <code>1</code> if the given channel is paused, otherwise <code>0</code>.</p>
209 <p><strong>Note</strong>: If you pass <code>-1</code> you will get the number of paused channels.</p>
210
211 </div>
212 <h2 id="fading_channel">fading_channel</h2>
213 <div id="fading_channel_CONTENT">
214 <pre> my $fading_channel = SDL::Mixer::Channels::fading_channel( $channel );
215
216 </pre>
217 <p>Returns one of the following for the given channel:</p>
218 <ul>
219                 <li>MIX_NO_FADING       </li>
220                 <li>MIX_FADING_OUT      </li>
221                 <li>MIX_FADING_IN</li>
222 </ul>
223
224 <p><strong>Note</strong>: Never pass <code>-1</code> to this function!</p>
225
226 </div>
227 <h2 id="get_chunk">get_chunk</h2>
228 <div id="get_chunk_CONTENT">
229 <pre> my $chunk = SDL::Mixer::Channels::get_chunk( $channel );
230
231 </pre>
232 <p><code>get_chunk</code> gets the most recent sample chunk played on channel. This chunk may be currently playing, or just the last used. </p>
233 <p><strong>Note</strong>: Never pass <code>-1</code> to this function!</p>
234
235 </div>
236 <h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
237 <div id="AUTHORS_CONTENT">
238 <p>See <b>AUTHORS</b> in <cite>SDL</cite>.</p>
239
240 </div>
241 </div>