1SDL::Mixer(3) User Contributed Perl Documentation SDL::Mixer(3)
2
3
4
6 SDL::Mixer - Sound and music functions
7
9 Mixer
10
12 The constants are exported by default. You can avoid this by doing:
13
14 use SDL::Mixer ();
15
16 and access them directly:
17
18 SDL::Mixer::MIX_DEFAULT_FREQUENCY;
19
20 or by choosing the export tags below:
21
22 Export tag: ':init'
23
24 MIX_INIT_FLAC
25 MIX_INIT_MOD
26 MIX_INIT_MP3
27 MIX_INIT_OGG
28
29 Export tag: ':defaults'
30
31 MIX_CHANNELS
32 MIX_DEFAULT_FORMAT
33 MIX_DEFAULT_FREQUENCY
34 MIX_DEFAULT_CHANNELS
35 MIX_MAX_VOLUME
36 MIX_CHANNEL_POST
37
38 Export tag: ':fading'
39
40 MIX_NO_FADING
41 MIX_FADING_OUT
42 MIX_FADING_IN
43
44 Export tag: ':type'
45
46 MUS_NONE
47 MUS_CMD
48 MUS_WAV
49 MUS_MOD
50 MUS_MID
51 MUS_OGG
52 MUS_MP3
53 MUS_MP3_MAD
54 MUS_MP3_FLAC
55
56 Export tag: ':format'
57
58 AUDIO_U8
59 AUDIO_S8
60 AUDIO_U16LSB
61 AUDIO_S16LSB
62 AUDIO_U16MSB
63 AUDIO_S16MSB
64 AUDIO_U16
65 AUDIO_S16
66 AUDIO_U16SYS
67 AUDIO_S16SYS
68
69 Export tag: ':status'
70
71 SDL_AUDIO_STOPPED
72 SDL_AUDIO_PLAYING
73 SDL_AUDIO_PAUSED
74
76 SDL::Mixer allows you to enable sound, alter music volume settings, and
77 lets you play, pause and resume, as well as fading the sound and music
78 in and out.
79
80 Supported Formats
81 The SDL Mixer library is a multi-channel audio mixer. It supports 8
82 channels of 16 bit stereo audio, and a single channel for music.
83
84 You can use the channels to load samples (i.e. sound effects) in the
85 following formats:
86
87 • Microsoft WAVE files (WAV)
88
89 • Creative Labs VOC files (VOC)
90
91 • MIDI files (if compiled with Timidity)
92
93 If you use MIDI, you should note that the process of mixing MIDI files
94 to wave output is very CPU-intensive, so if playing regular WAVE files
95 sound great, but playing MIDI files sound choppy, try using 8-bit
96 audio, mono audio, or lower frequencies.
97
98 The music channel can play the following formats:
99
100 • AIFF
101
102 • MOD (.mod .xm .s3m .669 .it .med and more - if compiled with
103 libmikmod)
104
105 • OggVorbis (.ogg - if compiled with ogg/vorbis libraries)
106
107 • MP3 (if compiled with SMPEG or MAD libraries)
108
109 • FLAC (if compiled with FLAC library)
110
112 init
113 my $init_flags = SDL::Mixer::init( $flags );
114
115 Loads dynamic libraries and prepares them for use. Flags should be one
116 or more flags from init flags OR'd together. It returns the flags
117 successfully initialized, or 0 on failure.
118
119 Example:
120
121 use SDL::Mixer;
122
123 my $init_flags = SDL::Mixer::init( MIX_INIT_MP3 | MIX_INIT_MOD | MIX_INIT_FLAC | MIX_INIT_OGG );
124
125 print("We have MP3 support!\n") if $init_flags & MIX_INIT_MP3;
126 print("We have MOD support!\n") if $init_flags & MIX_INIT_MOD;
127 print("We have FLAC support!\n") if $init_flags & MIX_INIT_FLAC;
128 print("We have OGG support!\n") if $init_flags & MIX_INIT_OGG;
129
130 Flags:
131
132 • MIX_INIT_MP3
133
134 • MIX_INIT_MOD
135
136 • MIX_INIT_FLAC
137
138 • MIX_INIT_OGG
139
140 Note: Only available for SDL_mixer >= 1.2.10
141
142 quit
143 SDL::Mixer::quit();
144
145 This function unloads the libraries previously loaded with init().
146
147 Note: Only available for SDL_mixer >= 1.2.10
148
149 linked_version
150 $version = SDL::Mixer::linked_version();
151
152 "linked_version" gives you the major-, minor-, and patchlevel for
153 SDL_mixer. This way you can check if e.g. init() and quit() are
154 available.
155
156 Example:
157
158 use SDL::Mixer;
159 use SDL::Version;
160
161 my $version = SDL::Mixer::linked_version();
162
163 printf("%d.%d.%d\n", $version->major, $version->minor, $version->patch); # prints "1.2.8" for me
164
165 open_audio
166 my $audio_opened = SDL::Mixer::open_audio( $frequency, $format, $channels, $chunksize );
167
168 "open_audio" will initialize SDL_mixer if it is not yet initialized,
169 see note. SDL_mixer may not be able to provide the exact specifications
170 your provided, however it will automatically translate between the
171 expected format and the real one. You can retrieve the real format
172 using query_spec.
173
174 Returns 0 on success, -1 on error.
175
176 Note: You must not use "AUDIO_S16", "AUDIO_U16", "AUDIO_S16LSB", or
177 "AUDIO_U16LSB." They are not portable, and SDL will not return an error
178 code when they fail. The result will be a horrible staticy noise. You
179 can usually use "AUDIO_S16SYS", though not always. Future versions of
180 SDL should take this parameter only as a hint, then read back the value
181 that the OS (for example, OSS or ALSA) has chosen to use in case the
182 desired audio type is not supported.
183
184 Note: When already initialized, this function will not re-initialize
185 SDL_mixer, nor fail. It will merely increment the number of times
186 SDL::Mixer::close_audio must be called to actually get it to
187 uninitialize. This serves as a very simplistic method for multiple
188 application components to use SDL_mixer without necessitating a great
189 deal of inter-component awareness. Be warned however that in such a
190 situation, the latest components to initialize SDL_mixer will probably
191 not get the SDL_mixer settings they're expecting.
192
193 Example:
194
195 use SDL;
196 use SDL::Mixer;
197
198 printf("Error initializing SDL_mixer: %s\n", SDL::get_error()) unless SDL::Mixer::open_audio(44100, AUDIO_S16, 2, 1024) == 0;
199
200 close_audio
201 SDL::Mixer::close_audio();
202
203 Close the mixer and halting all playing audio. This function does not
204 return anything.
205
206 query_spec
207 my @query_spec = @{ SDL::Mixer::query_spec() };
208
209 Find out what the actual audio device parameters are. This function
210 returns 1 as first array element (status) if the audio has been opened,
211 0 otherwise.
212
213 Example:
214
215 use SDL::Mixer;
216
217 my ($status, $freq, $format, $channels) = @{ SDL::Mixer::query_spec() };
218
219 printf("%s, %s, %s, %s\n", $status, $freq, $format, $channels);
220
222 perl, SDL::Mixer::Channels, SDL::Mixer::Effects, SDL::Mixer::Groups,
223 SDL::Mixer::Music.
224
226 See "AUTHORS" in SDL.
227
228
229
230perl v5.32.1 2021-01-27 SDL::Mixer(3)