f963132458669fbfe7582b5a91131d946652f312
[sdlgit/SDL-Site.git] / pages / SDL-Mixer.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="#init">init</a></li>
10 <li><a href="#quit">quit</a></li>
11 <li><a href="#linked_version">linked_version</a></li>
12 <li><a href="#open_audio">open_audio</a></li>
13 <li><a href="#close_audio">close_audio</a></li>
14 <li><a href="#query_spec">query_spec</a></li>
15 </ul>
16 </li>
17 <li><a href="#AUTHORS">AUTHORS </a></li>
18 <li><a href="#SEE_ALSO">SEE ALSO</a>
19 </li>
20 </ul><hr />
21 <!-- INDEX END -->
22
23 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
24 <div id="NAME_CONTENT">
25 <p>SDL::Mixer - Sound and music functions</p>
26
27 </div>
28 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
29 <div id="CATEGORY_CONTENT">
30 <p>Mixer</p>
31
32 </div>
33 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
34 <div id="DESCRIPTION_CONTENT">
35 <p>SDL::Mixer allows you to enable sound, alter music volume settings, and lets you play, pause and resume, as well as fading the sound and music 
36 in and out.</p>
37
38 </div>
39 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
40 <div id="METHODS_CONTENT">
41
42 </div>
43 <h2 id="init">init</h2>
44 <div id="init_CONTENT">
45 <pre> my $init_flags = SDL::Mixer::init( $flags );
46
47 </pre>
48 <p>Loads dynamic libraries and prepares them for use. Flags should be one or more flags from init flags OR'd together.
49 It returns the flags successfully initialized, or 0 on failure.</p>
50 <p>Example:</p>
51 <pre> use SDL::Mixer;
52
53  my $init_flags = SDL::Mixer::init( MIX_INIT_MP3 | MIX_INIT_MOD | MIX_INIT_FLAC | MIX_INIT_OGG );
54
55  print(&quot;We have MP3 support!\n&quot;)  if $init_flags &amp; MIX_INIT_MP3;
56  print(&quot;We have MOD support!\n&quot;)  if $init_flags &amp; MIX_INIT_MOD;
57  print(&quot;We have FLAC support!\n&quot;) if $init_flags &amp; MIX_INIT_FLAC;
58  print(&quot;We have OGG support!\n&quot;)  if $init_flags &amp; MIX_INIT_OGG;
59
60 </pre>
61 <p>Flags:</p>
62 <ul>
63                 <li>MIX_INIT_MP3        </li>
64                 <li>MIX_INIT_MOD        </li>
65                 <li>MIX_INIT_FLAC       </li>
66                 <li>MIX_INIT_OGG</li>
67 </ul>
68
69 <p><strong>Note</strong>: Only available for SDL_mixer &gt;= 1.2.10</p>
70
71 </div>
72 <h2 id="quit">quit</h2>
73 <div id="quit_CONTENT">
74 <pre> SDL::Mixer::quit();
75
76 </pre>
77 <p>This function unloads the liraries previously loaded with <a href="#init">init()</a>.</p>
78 <p><strong>Note</strong>: Only available for SDL_mixer &gt;= 1.2.10</p>
79
80 </div>
81 <h2 id="linked_version">linked_version</h2>
82 <div id="linked_version_CONTENT">
83 <pre> $version = SDL::Mixer::linked_version();
84
85 </pre>
86 <p><code>linked_version</code> gives you the major-, minor-, and patchlevel for SDL_mixer. This way you can check if e.g. <a href="#init">init()</a> and <a href="#quit">quit()</a> 
87 are available.</p>
88 <p>Example:</p>
89 <pre> use SDL::Mixer;
90  use SDL::Version;
91
92  my $version = SDL::Mixer::linked_version();
93
94  printf(&quot;%d.%d.%d\n&quot;, $version-&gt;major, $version-&gt;minor, $version-&gt;patch); # prints &quot;1.2.8&quot; for me
95
96 </pre>
97
98 </div>
99 <h2 id="open_audio">open_audio</h2>
100 <div id="open_audio_CONTENT">
101 <pre> my $audio_opened = SDL::Mixer::open_audio( $frequency, $format, $channels, $chunksize );
102
103 </pre>
104 <p><code>open_audio</code> will initialize SDL_mixer if it is not yet initialized, see note. SDL_mixer may not be able to provide the exact specifications 
105 your provided, however it will automatically translate between the expected format and the real one. You can retrieve the real format using 
106 <a href="http://search.cpan.org/perldoc?query_spec">query_spec</a>. </p>
107 <p>Returns 0 on success, -1 on error.</p>
108 <p><strong>Note</strong>: You must not use <code>AUDIO_S16</code>, <code>AUDIO_U16</code>, <code>AUDIO_S16LSB</code>, or <code>AUDIO_U16LSB.</code> They are not portable, and SDL will not return an 
109 error code when they fail. The result will be a horrible staticy noise. You can usually use <code>AUDIO_S16SYS</code>, though not always. Future versions 
110 of SDL should take this parameter only as a hint, then read back the value that the OS (for example, OSS or ALSA) has chosen to use in case the 
111 desired audio type is not supported. </p>
112 <p><strong>Note</strong>: When already initialized, this function will not re-initialize SDL_mixer, nor fail. It will merely increment the number of times 
113 <a href="/SDL-Mixer.html#close_audio">SDL::Mixer::close_audio</a> must be called to actually get it to uninitialize. This serves as a very simplistic method for multiple application 
114 components to use SDL_mixer without necessitating a great deal of inter-component awareness. Be warned however that in such a situation, the 
115 latest components to initialize SDL_mixer will probably not get the SDL_mixer settings they're expecting. </p>
116 <p>Example:</p>
117 <pre> use SDL;
118  use SDL::Mixer;
119
120  printf(&quot;Error initializing SDL_mixer: %s\n&quot;, SDL::get_error()) unless SDL::Mixer::open_audio(44100, AUDIO_S16, 2, 1024) == 0;
121
122 </pre>
123
124 </div>
125 <h2 id="close_audio">close_audio</h2>
126 <div id="close_audio_CONTENT">
127 <pre> SDL::Mixer::close_audio();
128
129 </pre>
130 <p>Close the mixer and halting all playing audio. This function does not return anything.</p>
131
132 </div>
133 <h2 id="query_spec">query_spec</h2>
134 <div id="query_spec_CONTENT">
135 <pre> my @query_spec = @{ SDL::Mixer::query_spec() };
136
137 </pre>
138 <p>Find out what the actual audio device parameters are.
139 This function returns 1 as first array element (status) if the audio has been opened, 0 otherwise.</p>
140 <p>Example:</p>
141 <pre> use SDL::Mixer;
142
143  my ($status, $freq, $format, $channels) = @{ SDL::Mixer::query_spec() };
144
145  printf(&quot;%s, %s, %s, %s\n&quot;, $status, $freq, $format, $channels);
146
147 </pre>
148
149 </div>
150 <h1 id="AUTHORS">AUTHORS </h1><p><a href="#TOP" class="toplink">Top</a></p>
151 <div id="AUTHORS_CONTENT">
152 <p>Tobias Leich [FROGGS]</p>
153
154 </div>
155 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
156 <div id="SEE_ALSO_CONTENT">
157 <p><a href="http://search.cpan.org/perldoc?perl">perl</a>, <a href="SDL-Mixer-Channels">SDL::Mixer::Channels</a>, <a href="SDL-Mixer-Effects">SDL::Mixer::Effects</a>, <a href="SDL-Mixer-Groups">SDL::Mixer::Groups</a>, <a href="SDL-Mixer-Music">SDL::Mixer::Music</a>.</p>
158
159 </div>
160 </div>