1SDL::Mixer::Channels(3pUms)er Contributed Perl DocumentatSiDoLn::Mixer::Channels(3pm)
2
3
4
6 SDL::Mixer::Channels -- SDL::Mixer channel functions and bindings
7
9 Mixer
10
13 allocate_channels
14 my $ret = SDL::Mixer::Channels::allocate_channels( $number_of_channels );
15
16 Dynamically change the number of channels managed by the mixer. If
17 decreasing the number of channels, the upper channels are stopped.
18 This function returns the new number of allocated channels.
19
20 Example
21
22 use SDL::Mixer::Channels;
23
24 printf("We got %d channels!\n", SDL::Mixer::Channels::allocate_channels( 8 ) );
25
26 volume
27 my $prev_volume = SDL::Mixer::Channels::volume( $channel_number, $volume );
28
29 "volume" changes the volume of the channel specified in channel by the
30 amount set in volume. The range of volume is from 0 to "MIX_MAX_VOLUME"
31 which is 128. Passing -1 to channel will change the volume of all
32 channels. If the specified volume is -1, it will just return the
33 current volume.
34
35 Returns the previously set volume of the channel.
36
37 play_channel
38 my $channel_number = SDL::Mixer::Channels::play_channel( $channel, $chunk, $loops );
39
40 "play_channel" will play the specified "chunk" over the specified
41 "channel". SDL_mixer will choose a channel for you if you pass -1 for
42 "channel".
43
44 The chunk will be looped "loops" times, the total number of times
45 played will be "loops+1". Passing -1 will loop the chunk infinitely.
46
47 Returns the channel the chunk will be played on, or -1 on error.
48
49 Example:
50
51 use SDL::Mixer;
52 use SDL::Mixer::Channels;
53 use SDL::Mixer::Samples;
54
55 SDL::init(SDL_INIT_AUDIO);
56 SDL::Mixer::open_audio( 44100, SDL::Constants::AUDIO_S16, 2, 4096 );
57
58 my $chunk = SDL::Mixer::Samples::load_WAV('sample.wav');
59
60 SDL::Mixer::Channels::play_channel( -1, $chunk, -1 );
61
62 SDL::delay(1000);
63 SDL::Mixer::close_audio();
64
65 play_channel_timed
66 my $channel = SDL::Mixer::Channels::play_channel_timed( $channel, $chunk, $loops, $ticks );
67
68 Same as play_channel but you can specify the time it will play by
69 $ticks.
70
71 fade_in_channel
72 my $channel = SDL::Mixer::Channels::fade_in_channel( $channel, $chunk, $loops, $ms );
73
74 Same as play_channel but you can specify the fade-in time by $ms.
75
76 fade_in_channel_timed
77 my $channel = SDL::Mixer::Channels::fade_in_channel_timed( $channel, $chunk, $loops, $ms, $ticks );
78
79 Same as fade_in_channel but you can specify the time how long the chunk
80 will be played by $ticks.
81
82 pause
83 SDL::Mixer::Channels::pause( $channel );
84
85 Pauses the given channel or all by passing -1.
86
87 resume
88 SDL::Mixer::Channels::resume( $channel );
89
90 Resumes the given channel or all by passing -1.
91
92 halt_channel
93 SDL::Mixer::Channels::halt_channel( $channel );
94
95 Stops the given channel or all by passing -1.
96
97 expire_channel
98 my $channels = SDL::Mixer::Channels::expire_channel( $channel, $ticks );
99
100 Stops the given channel (or -1 for all) after the time specified by
101 $ticks (in milliseconds).
102
103 Returns the number of affected channels.
104
105 fade_out_channel
106 my $fading_channels = SDL::Mixer::Channels::fade_out_channel( $which, $ms );
107
108 "fade_out_channel" fades out a channel specified in "which" with a
109 duration specified in "ms" in milliseconds.
110
111 Returns the the number of channels that will be faded out.
112
113 channel_finished
114 SDL::Mixer::Channels::channel_finished( $callback );
115
116 Add your own callback when a channel has finished playing. "NULL" to
117 disable callback. The callback may be called from the mixer's audio
118 callback or it could be called as a result of halt_channel, etc. do not
119 call "lock_audio" from this callback; you will either be inside the
120 audio callback, or SDL_mixer will explicitly lock the audio before
121 calling your callback.
122
123 Example 1:
124
125 my $callback = sub{ printf("[channel_finished] callback called for channel %d\n", shift); };
126
127 SDL::Mixer::Channels::channel_finished( $callback );
128
129 Example 2:
130
131 sub callback
132 {
133 ...
134 }
135
136 SDL::Mixer::Channels::channel_finished( \&callback );
137
138 playing
139 my $playing = SDL::Mixer::Channels::playing( $channel );
140
141 Returns 1 if the given channel is playing sound, otherwise 0. It
142 doesn't check if the channel is paused.
143
144 Note: If you pass -1 you will get the number of playing channels.
145
146 paused
147 my $paused = SDL::Mixer::Channels::paused( $channel );
148
149 Returns 1 if the given channel is paused, otherwise 0.
150
151 Note: If you pass -1 you will get the number of paused channels.
152
153 fading_channel
154 my $fading_channel = SDL::Mixer::Channels::fading_channel( $channel );
155
156 Returns one of the following for the given channel:
157
158 • MIX_NO_FADING
159
160 • MIX_FADING_OUT
161
162 • MIX_FADING_IN
163
164 Note: Never pass -1 to this function!
165
166 get_chunk
167 my $chunk = SDL::Mixer::Channels::get_chunk( $channel );
168
169 "get_chunk" gets the most recent sample chunk played on channel. This
170 chunk may be currently playing, or just the last used.
171
172 Note: Never pass -1 to this function!
173
175 See "AUTHORS" in SDL.
176
177
178
179perl v5.38.0 2023-07-21 SDL::Mixer::Channels(3pm)