1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>SFML - Simple and Fast Multimedia Library</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="tabs.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="logo">
<img src="./logo.jpg" width="770" height="200" title="SFML home" alt="SFML logo" />
</div>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.htm"><span>Main Page</span></a></li>
<li><a href="namespaces.htm"><span>Namespaces</span></a></li>
<li><a href="annotated.htm"><span>Classes</span></a></li>
<li class="current"><a href="files.htm"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.htm"><span>File List</span></a></li>
</ul>
</div>
<h1>Sound.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// SFML - Simple and Fast Multimedia Library</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)</span>
<a name="l00005"></a>00005 <span class="comment">//</span>
<a name="l00006"></a>00006 <span class="comment">// This software is provided 'as-is', without any express or implied warranty.</span>
<a name="l00007"></a>00007 <span class="comment">// In no event will the authors be held liable for any damages arising from the use of this software.</span>
<a name="l00008"></a>00008 <span class="comment">//</span>
<a name="l00009"></a>00009 <span class="comment">// Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00010"></a>00010 <span class="comment">// including commercial applications, and to alter it and redistribute it freely,</span>
<a name="l00011"></a>00011 <span class="comment">// subject to the following restrictions:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// 1. The origin of this software must not be misrepresented;</span>
<a name="l00014"></a>00014 <span class="comment">// you must not claim that you wrote the original software.</span>
<a name="l00015"></a>00015 <span class="comment">// If you use this software in a product, an acknowledgment</span>
<a name="l00016"></a>00016 <span class="comment">// in the product documentation would be appreciated but is not required.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018 <span class="comment">// 2. Altered source versions must be plainly marked as such,</span>
<a name="l00019"></a>00019 <span class="comment">// and must not be misrepresented as being the original software.</span>
<a name="l00020"></a>00020 <span class="comment">//</span>
<a name="l00021"></a>00021 <span class="comment">// 3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00022"></a>00022 <span class="comment">//</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00026"></a>00026 <span class="comment">// Headers</span>
<a name="l00028"></a>00028 <span class="comment"></span><span class="preprocessor">#include <SFML/Audio/Sound.hpp></span>
<a name="l00029"></a>00029 <span class="preprocessor">#include <SFML/Audio/SoundBuffer.hpp></span>
<a name="l00030"></a>00030 <span class="preprocessor">#include <SFML/Audio/OpenAL.hpp></span>
<a name="l00031"></a>00031
<a name="l00032"></a>00032
<a name="l00033"></a>00033 <span class="keyword">namespace </span>sf
<a name="l00034"></a>00034 {
<a name="l00038"></a><a class="code" href="classsf_1_1Sound.htm#36ab74beaaa953d9879c933ddd246282">00038</a> <a class="code" href="classsf_1_1Sound.htm#36ab74beaaa953d9879c933ddd246282" title="Default constructor.">Sound::Sound</a>()
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040 ALCheck(alGenSources(1, &mySource));
<a name="l00041"></a>00041 ALCheck(alSourcei(mySource, AL_BUFFER, 0));
<a name="l00042"></a>00042 }
<a name="l00043"></a>00043
<a name="l00044"></a>00044
<a name="l00048"></a><a class="code" href="classsf_1_1Sound.htm#45aff03dc5bf87647eba6bed7c1ced29">00048</a> <a class="code" href="classsf_1_1Sound.htm#36ab74beaaa953d9879c933ddd246282" title="Default constructor.">Sound::Sound</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1SoundBuffer.htm" title="SoundBuffer is the low-level for loading and manipulating sound buffers.">SoundBuffer</a>& Buffer, <span class="keywordtype">bool</span> Loop, <span class="keywordtype">float</span> Pitch, <span class="keywordtype">float</span> Volume, <span class="keyword">const</span> <a class="code" href="classsf_1_1Vector3.htm" title="Vector3 is an utility class for manipulating 3 dimensional vectors.">Vector3f</a>& Position) :
<a name="l00049"></a>00049 myBuffer(NULL)
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051 ALCheck(alGenSources(1, &mySource));
<a name="l00052"></a>00052
<a name="l00053"></a>00053 <a class="code" href="classsf_1_1Sound.htm#9dbc27c54f0ee633c831a0b6e24ecc55" title="Set the source buffer.">SetBuffer</a>(Buffer);
<a name="l00054"></a>00054 <a class="code" href="classsf_1_1Sound.htm#4eb9966b7289c69623a39cc0125012f4" title="Set the sound loop state.">SetLoop</a>(Loop);
<a name="l00055"></a>00055 <a class="code" href="classsf_1_1Sound.htm#f93301feb88770789ba7cd993c9dd3a0" title="Set the sound pitch.">SetPitch</a>(Pitch);
<a name="l00056"></a>00056 <a class="code" href="classsf_1_1Sound.htm#1536095045923a2332dd9eed6bf8e96a" title="Set the sound volume.">SetVolume</a>(Volume);
<a name="l00057"></a>00057 <a class="code" href="classsf_1_1Sound.htm#b445e8738218525d8dd067628bc70c78" title="Set the sound position (take 3 values).">SetPosition</a>(Position);
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059
<a name="l00060"></a>00060
<a name="l00064"></a><a class="code" href="classsf_1_1Sound.htm#a930dcf53775f501ce43d44bf54c0ce4">00064</a> <a class="code" href="classsf_1_1Sound.htm#36ab74beaaa953d9879c933ddd246282" title="Default constructor.">Sound::Sound</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1Sound.htm" title="Sound defines the properties of a sound such as position, volume, pitch, etc.">Sound</a>& Copy) :
<a name="l00065"></a>00065 <a class="code" href="classsf_1_1AudioResource.htm" title="Abstract base class for every class that owns a device-dependant resource -- allow...">AudioResource</a>(Copy),
<a name="l00066"></a>00066 myBuffer(NULL)
<a name="l00067"></a>00067 {
<a name="l00068"></a>00068 ALCheck(alGenSources(1, &mySource));
<a name="l00069"></a>00069
<a name="l00070"></a>00070 <span class="keywordflow">if</span> (Copy.<a class="code" href="classsf_1_1Sound.htm#853812e73ff1cfdd04fe562431bd5a16" title="Sound buffer bound to the source.">myBuffer</a>)
<a name="l00071"></a>00071 <a class="code" href="classsf_1_1Sound.htm#9dbc27c54f0ee633c831a0b6e24ecc55" title="Set the source buffer.">SetBuffer</a>(*Copy.<a class="code" href="classsf_1_1Sound.htm#853812e73ff1cfdd04fe562431bd5a16" title="Sound buffer bound to the source.">myBuffer</a>);
<a name="l00072"></a>00072 <a class="code" href="classsf_1_1Sound.htm#4eb9966b7289c69623a39cc0125012f4" title="Set the sound loop state.">SetLoop</a>(Copy.<a class="code" href="classsf_1_1Sound.htm#5cdc44ade7bda8db2d0431701d72495e" title="Tell whether or not the sound is looping.">GetLoop</a>());
<a name="l00073"></a>00073 <a class="code" href="classsf_1_1Sound.htm#f93301feb88770789ba7cd993c9dd3a0" title="Set the sound pitch.">SetPitch</a>(Copy.<a class="code" href="classsf_1_1Sound.htm#42333202ed0586f434d852cc35b9d4ef" title="Get the pitch.">GetPitch</a>());
<a name="l00074"></a>00074 <a class="code" href="classsf_1_1Sound.htm#1536095045923a2332dd9eed6bf8e96a" title="Set the sound volume.">SetVolume</a>(Copy.<a class="code" href="classsf_1_1Sound.htm#018e78cd6c50d653fffff1005a350782" title="Get the volume.">GetVolume</a>());
<a name="l00075"></a>00075 <a class="code" href="classsf_1_1Sound.htm#b445e8738218525d8dd067628bc70c78" title="Set the sound position (take 3 values).">SetPosition</a>(Copy.<a class="code" href="classsf_1_1Sound.htm#b1adb173ee12a86f261fb765be050643" title="Get the sound position.">GetPosition</a>());
<a name="l00076"></a>00076 <a class="code" href="classsf_1_1Sound.htm#7604f576d184ba8031789beee96d04d3" title="Make the sound&#39;s position relative to the listener&#39;s position, or absolute...">SetRelativeToListener</a>(Copy.<a class="code" href="classsf_1_1Sound.htm#f0278152abf6e3f195353ce3c270f34e" title="Tell if the sound&#39;s position is relative to the listener&#39;s position, or if...">IsRelativeToListener</a>());
<a name="l00077"></a>00077 <a class="code" href="classsf_1_1Sound.htm#0a545d8dca68d85a03390f6da7c446a9" title="Set the minimum distance - closer than this distance, the listener will hear the...">SetMinDistance</a>(Copy.<a class="code" href="classsf_1_1Sound.htm#07f37119f7b3b00f274ac0263a4bc58b" title="Get the minimum distance.">GetMinDistance</a>());
<a name="l00078"></a>00078 <a class="code" href="classsf_1_1Sound.htm#c3743f1fb53bf9818fbab6e9220bd7b9" title="Set the attenuation factor - the higher the attenuation, the more the sound will...">SetAttenuation</a>(Copy.<a class="code" href="classsf_1_1Sound.htm#f594211c35d6ac7a9df083c226749c42" title="Get the attenuation factor.">GetAttenuation</a>());
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080
<a name="l00081"></a>00081
<a name="l00085"></a><a class="code" href="classsf_1_1Sound.htm#d0792c35310eba2dffd8489c80fad076">00085</a> <a class="code" href="classsf_1_1Sound.htm#d0792c35310eba2dffd8489c80fad076" title="Destructor.">Sound::~Sound</a>()
<a name="l00086"></a>00086 {
<a name="l00087"></a>00087 <span class="keywordflow">if</span> (mySource)
<a name="l00088"></a>00088 {
<a name="l00089"></a>00089 <span class="keywordflow">if</span> (myBuffer)
<a name="l00090"></a>00090 {
<a name="l00091"></a>00091 <a class="code" href="classsf_1_1Sound.htm#b1f5f103f737c52ceb0b1a067b4d0630" title="Stop the sound.">Stop</a>();
<a name="l00092"></a>00092 ALCheck(alSourcei(mySource, AL_BUFFER, 0));
<a name="l00093"></a>00093 myBuffer->DetachSound(<span class="keyword">this</span>);
<a name="l00094"></a>00094 }
<a name="l00095"></a>00095 ALCheck(alDeleteSources(1, &mySource));
<a name="l00096"></a>00096 }
<a name="l00097"></a>00097 }
<a name="l00098"></a>00098
<a name="l00099"></a>00099
<a name="l00103"></a><a class="code" href="classsf_1_1Sound.htm#fdafa7970587f04d3833b4095c2de1db">00103</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#fdafa7970587f04d3833b4095c2de1db" title="Play the sound.">Sound::Play</a>()
<a name="l00104"></a>00104 {
<a name="l00105"></a>00105 ALCheck(alSourcePlay(mySource));
<a name="l00106"></a>00106 }
<a name="l00107"></a>00107
<a name="l00108"></a>00108
<a name="l00112"></a><a class="code" href="classsf_1_1Sound.htm#6a712910ac1340f32e3ec3a04295ebd3">00112</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#6a712910ac1340f32e3ec3a04295ebd3" title="Pause the sound.">Sound::Pause</a>()
<a name="l00113"></a>00113 {
<a name="l00114"></a>00114 ALCheck(alSourcePause(mySource));
<a name="l00115"></a>00115 }
<a name="l00116"></a>00116
<a name="l00117"></a>00117
<a name="l00121"></a><a class="code" href="classsf_1_1Sound.htm#b1f5f103f737c52ceb0b1a067b4d0630">00121</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#b1f5f103f737c52ceb0b1a067b4d0630" title="Stop the sound.">Sound::Stop</a>()
<a name="l00122"></a>00122 {
<a name="l00123"></a>00123 ALCheck(alSourceStop(mySource));
<a name="l00124"></a>00124 }
<a name="l00125"></a>00125
<a name="l00126"></a>00126
<a name="l00130"></a><a class="code" href="classsf_1_1Sound.htm#9dbc27c54f0ee633c831a0b6e24ecc55">00130</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#9dbc27c54f0ee633c831a0b6e24ecc55" title="Set the source buffer.">Sound::SetBuffer</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1SoundBuffer.htm" title="SoundBuffer is the low-level for loading and manipulating sound buffers.">SoundBuffer</a>& Buffer)
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132 <span class="comment">// First detach from the previous buffer</span>
<a name="l00133"></a>00133 <span class="keywordflow">if</span> (myBuffer)
<a name="l00134"></a>00134 {
<a name="l00135"></a>00135 <a class="code" href="classsf_1_1Sound.htm#b1f5f103f737c52ceb0b1a067b4d0630" title="Stop the sound.">Stop</a>();
<a name="l00136"></a>00136 myBuffer->DetachSound(<span class="keyword">this</span>);
<a name="l00137"></a>00137 }
<a name="l00138"></a>00138
<a name="l00139"></a>00139 <span class="comment">// Assign and use the new buffer</span>
<a name="l00140"></a>00140 myBuffer = &Buffer;
<a name="l00141"></a>00141 myBuffer->AttachSound(<span class="keyword">this</span>);
<a name="l00142"></a>00142 ALCheck(alSourcei(mySource, AL_BUFFER, myBuffer->myBuffer));
<a name="l00143"></a>00143 }
<a name="l00144"></a>00144
<a name="l00145"></a>00145
<a name="l00149"></a><a class="code" href="classsf_1_1Sound.htm#4eb9966b7289c69623a39cc0125012f4">00149</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#4eb9966b7289c69623a39cc0125012f4" title="Set the sound loop state.">Sound::SetLoop</a>(<span class="keywordtype">bool</span> Loop)
<a name="l00150"></a>00150 {
<a name="l00151"></a>00151 ALCheck(alSourcei(mySource, AL_LOOPING, Loop));
<a name="l00152"></a>00152 }
<a name="l00153"></a>00153
<a name="l00154"></a>00154
<a name="l00158"></a><a class="code" href="classsf_1_1Sound.htm#f93301feb88770789ba7cd993c9dd3a0">00158</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#f93301feb88770789ba7cd993c9dd3a0" title="Set the sound pitch.">Sound::SetPitch</a>(<span class="keywordtype">float</span> Pitch)
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160 ALCheck(alSourcef(mySource, AL_PITCH, Pitch));
<a name="l00161"></a>00161 }
<a name="l00162"></a>00162
<a name="l00163"></a>00163
<a name="l00167"></a><a class="code" href="classsf_1_1Sound.htm#1536095045923a2332dd9eed6bf8e96a">00167</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#1536095045923a2332dd9eed6bf8e96a" title="Set the sound volume.">Sound::SetVolume</a>(<span class="keywordtype">float</span> Volume)
<a name="l00168"></a>00168 {
<a name="l00169"></a>00169 ALCheck(alSourcef(mySource, AL_GAIN, Volume * 0.01f));
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171
<a name="l00176"></a><a class="code" href="classsf_1_1Sound.htm#b445e8738218525d8dd067628bc70c78">00176</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#b445e8738218525d8dd067628bc70c78" title="Set the sound position (take 3 values).">Sound::SetPosition</a>(<span class="keywordtype">float</span> X, <span class="keywordtype">float</span> Y, <span class="keywordtype">float</span> Z)
<a name="l00177"></a>00177 {
<a name="l00178"></a>00178 ALCheck(alSource3f(mySource, AL_POSITION, X, Y, Z));
<a name="l00179"></a>00179 }
<a name="l00180"></a>00180
<a name="l00181"></a>00181
<a name="l00186"></a><a class="code" href="classsf_1_1Sound.htm#0d8c6f11281a574b781c53d62a4af776">00186</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#b445e8738218525d8dd067628bc70c78" title="Set the sound position (take 3 values).">Sound::SetPosition</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1Vector3.htm" title="Vector3 is an utility class for manipulating 3 dimensional vectors.">Vector3f</a>& Position)
<a name="l00187"></a>00187 {
<a name="l00188"></a>00188 <a class="code" href="classsf_1_1Sound.htm#b445e8738218525d8dd067628bc70c78" title="Set the sound position (take 3 values).">SetPosition</a>(Position.<a class="code" href="classsf_1_1Vector3.htm#3cb0c769390bc37c346bb1a69e510d16" title="X coordinate of the vector.">x</a>, Position.<a class="code" href="classsf_1_1Vector3.htm#6590d50ccb862c5efc5512e974e9b794" title="Y coordinate of the vector.">y</a>, Position.<a class="code" href="classsf_1_1Vector3.htm#2f36ab4b552c028e3a9734c1ad4df7d1" title="Z coordinate of the vector.">z</a>);
<a name="l00189"></a>00189 }
<a name="l00190"></a>00190
<a name="l00191"></a>00191
<a name="l00197"></a><a class="code" href="classsf_1_1Sound.htm#7604f576d184ba8031789beee96d04d3">00197</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#7604f576d184ba8031789beee96d04d3" title="Make the sound&#39;s position relative to the listener&#39;s position, or absolute...">Sound::SetRelativeToListener</a>(<span class="keywordtype">bool</span> Relative)
<a name="l00198"></a>00198 {
<a name="l00199"></a>00199 ALCheck(alSourcei(mySource, AL_SOURCE_RELATIVE, Relative));
<a name="l00200"></a>00200 }
<a name="l00201"></a>00201
<a name="l00202"></a>00202
<a name="l00208"></a><a class="code" href="classsf_1_1Sound.htm#0a545d8dca68d85a03390f6da7c446a9">00208</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#0a545d8dca68d85a03390f6da7c446a9" title="Set the minimum distance - closer than this distance, the listener will hear the...">Sound::SetMinDistance</a>(<span class="keywordtype">float</span> MinDistance)
<a name="l00209"></a>00209 {
<a name="l00210"></a>00210 ALCheck(alSourcef(mySource, AL_REFERENCE_DISTANCE, MinDistance));
<a name="l00211"></a>00211 }
<a name="l00212"></a>00212
<a name="l00213"></a>00213
<a name="l00219"></a><a class="code" href="classsf_1_1Sound.htm#c3743f1fb53bf9818fbab6e9220bd7b9">00219</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#c3743f1fb53bf9818fbab6e9220bd7b9" title="Set the attenuation factor - the higher the attenuation, the more the sound will...">Sound::SetAttenuation</a>(<span class="keywordtype">float</span> Attenuation)
<a name="l00220"></a>00220 {
<a name="l00221"></a>00221 ALCheck(alSourcef(mySource, AL_ROLLOFF_FACTOR, Attenuation));
<a name="l00222"></a>00222 }
<a name="l00223"></a>00223
<a name="l00224"></a>00224
<a name="l00228"></a><a class="code" href="classsf_1_1Sound.htm#e779b4fa3d8d98a1490334dbd32e8d62">00228</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#e779b4fa3d8d98a1490334dbd32e8d62" title="Set the current playing position of the sound.">Sound::SetPlayingOffset</a>(<span class="keywordtype">float</span> TimeOffset)
<a name="l00229"></a>00229 {
<a name="l00230"></a>00230 ALCheck(alSourcef(mySource, AL_SEC_OFFSET, TimeOffset));
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232
<a name="l00233"></a>00233
<a name="l00237"></a><a class="code" href="classsf_1_1Sound.htm#bb46557ecfb32c4538fedad28cc59d9e">00237</a> <span class="keyword">const</span> <a class="code" href="classsf_1_1SoundBuffer.htm" title="SoundBuffer is the low-level for loading and manipulating sound buffers.">SoundBuffer</a>* <a class="code" href="classsf_1_1Sound.htm#bb46557ecfb32c4538fedad28cc59d9e" title="Get the source buffer.">Sound::GetBuffer</a>()<span class="keyword"> const</span>
<a name="l00238"></a>00238 <span class="keyword"></span>{
<a name="l00239"></a>00239 <span class="keywordflow">return</span> myBuffer;
<a name="l00240"></a>00240 }
<a name="l00241"></a>00241
<a name="l00242"></a>00242
<a name="l00246"></a><a class="code" href="classsf_1_1Sound.htm#5cdc44ade7bda8db2d0431701d72495e">00246</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Sound.htm#5cdc44ade7bda8db2d0431701d72495e" title="Tell whether or not the sound is looping.">Sound::GetLoop</a>()<span class="keyword"> const</span>
<a name="l00247"></a>00247 <span class="keyword"></span>{
<a name="l00248"></a>00248 ALint Loop;
<a name="l00249"></a>00249 ALCheck(alGetSourcei(mySource, AL_LOOPING, &Loop));
<a name="l00250"></a>00250
<a name="l00251"></a>00251 <span class="keywordflow">return</span> Loop != 0;
<a name="l00252"></a>00252 }
<a name="l00253"></a>00253
<a name="l00254"></a>00254
<a name="l00258"></a><a class="code" href="classsf_1_1Sound.htm#42333202ed0586f434d852cc35b9d4ef">00258</a> <span class="keywordtype">float</span> <a class="code" href="classsf_1_1Sound.htm#42333202ed0586f434d852cc35b9d4ef" title="Get the pitch.">Sound::GetPitch</a>()<span class="keyword"> const</span>
<a name="l00259"></a>00259 <span class="keyword"></span>{
<a name="l00260"></a>00260 ALfloat Pitch;
<a name="l00261"></a>00261 ALCheck(alGetSourcef(mySource, AL_PITCH, &Pitch));
<a name="l00262"></a>00262
<a name="l00263"></a>00263 <span class="keywordflow">return</span> Pitch;
<a name="l00264"></a>00264 }
<a name="l00265"></a>00265
<a name="l00266"></a>00266
<a name="l00270"></a><a class="code" href="classsf_1_1Sound.htm#018e78cd6c50d653fffff1005a350782">00270</a> <span class="keywordtype">float</span> <a class="code" href="classsf_1_1Sound.htm#018e78cd6c50d653fffff1005a350782" title="Get the volume.">Sound::GetVolume</a>()<span class="keyword"> const</span>
<a name="l00271"></a>00271 <span class="keyword"></span>{
<a name="l00272"></a>00272 ALfloat Gain;
<a name="l00273"></a>00273 ALCheck(alGetSourcef(mySource, AL_GAIN, &Gain));
<a name="l00274"></a>00274
<a name="l00275"></a>00275 <span class="keywordflow">return</span> Gain * 100.f;
<a name="l00276"></a>00276 }
<a name="l00277"></a>00277
<a name="l00278"></a>00278
<a name="l00282"></a><a class="code" href="classsf_1_1Sound.htm#b1adb173ee12a86f261fb765be050643">00282</a> <a class="code" href="classsf_1_1Vector3.htm" title="Vector3 is an utility class for manipulating 3 dimensional vectors.">Vector3f</a> <a class="code" href="classsf_1_1Sound.htm#b1adb173ee12a86f261fb765be050643" title="Get the sound position.">Sound::GetPosition</a>()<span class="keyword"> const</span>
<a name="l00283"></a>00283 <span class="keyword"></span>{
<a name="l00284"></a>00284 <a class="code" href="classsf_1_1Vector3.htm" title="Vector3 is an utility class for manipulating 3 dimensional vectors.">Vector3f</a> Position;
<a name="l00285"></a>00285 ALCheck(alGetSource3f(mySource, AL_POSITION, &Position.<a class="code" href="classsf_1_1Vector3.htm#3cb0c769390bc37c346bb1a69e510d16" title="X coordinate of the vector.">x</a>, &Position.<a class="code" href="classsf_1_1Vector3.htm#6590d50ccb862c5efc5512e974e9b794" title="Y coordinate of the vector.">y</a>, &Position.<a class="code" href="classsf_1_1Vector3.htm#2f36ab4b552c028e3a9734c1ad4df7d1" title="Z coordinate of the vector.">z</a>));
<a name="l00286"></a>00286
<a name="l00287"></a>00287 <span class="keywordflow">return</span> Position;
<a name="l00288"></a>00288 }
<a name="l00289"></a>00289
<a name="l00290"></a>00290
<a name="l00295"></a><a class="code" href="classsf_1_1Sound.htm#f0278152abf6e3f195353ce3c270f34e">00295</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Sound.htm#f0278152abf6e3f195353ce3c270f34e" title="Tell if the sound&#39;s position is relative to the listener&#39;s position, or if...">Sound::IsRelativeToListener</a>()<span class="keyword"> const</span>
<a name="l00296"></a>00296 <span class="keyword"></span>{
<a name="l00297"></a>00297 ALint Relative;
<a name="l00298"></a>00298 ALCheck(alGetSourcei(mySource, AL_SOURCE_RELATIVE, &Relative));
<a name="l00299"></a>00299
<a name="l00300"></a>00300 <span class="keywordflow">return</span> Relative != 0;
<a name="l00301"></a>00301 }
<a name="l00302"></a>00302
<a name="l00303"></a>00303
<a name="l00307"></a><a class="code" href="classsf_1_1Sound.htm#07f37119f7b3b00f274ac0263a4bc58b">00307</a> <span class="keywordtype">float</span> <a class="code" href="classsf_1_1Sound.htm#07f37119f7b3b00f274ac0263a4bc58b" title="Get the minimum distance.">Sound::GetMinDistance</a>()<span class="keyword"> const</span>
<a name="l00308"></a>00308 <span class="keyword"></span>{
<a name="l00309"></a>00309 ALfloat MinDistance;
<a name="l00310"></a>00310 ALCheck(alGetSourcef(mySource, AL_REFERENCE_DISTANCE, &MinDistance));
<a name="l00311"></a>00311
<a name="l00312"></a>00312 <span class="keywordflow">return</span> MinDistance;
<a name="l00313"></a>00313 }
<a name="l00314"></a>00314
<a name="l00315"></a>00315
<a name="l00319"></a><a class="code" href="classsf_1_1Sound.htm#f594211c35d6ac7a9df083c226749c42">00319</a> <span class="keywordtype">float</span> <a class="code" href="classsf_1_1Sound.htm#f594211c35d6ac7a9df083c226749c42" title="Get the attenuation factor.">Sound::GetAttenuation</a>()<span class="keyword"> const</span>
<a name="l00320"></a>00320 <span class="keyword"></span>{
<a name="l00321"></a>00321 ALfloat Attenuation;
<a name="l00322"></a>00322 ALCheck(alGetSourcef(mySource, AL_ROLLOFF_FACTOR, &Attenuation));
<a name="l00323"></a>00323
<a name="l00324"></a>00324 <span class="keywordflow">return</span> Attenuation;
<a name="l00325"></a>00325 }
<a name="l00326"></a>00326
<a name="l00327"></a>00327
<a name="l00331"></a><a class="code" href="classsf_1_1Sound.htm#0e80c736a6865123be0c19e99f36467f">00331</a> <span class="keywordtype">float</span> <a class="code" href="classsf_1_1Sound.htm#0e80c736a6865123be0c19e99f36467f" title="Get the current playing position of the sound.">Sound::GetPlayingOffset</a>()<span class="keyword"> const</span>
<a name="l00332"></a>00332 <span class="keyword"></span>{
<a name="l00333"></a>00333 ALfloat Seconds = 0.f;
<a name="l00334"></a>00334 ALCheck(alGetSourcef(mySource, AL_SEC_OFFSET, &Seconds));
<a name="l00335"></a>00335
<a name="l00336"></a>00336 <span class="keywordflow">return</span> Seconds;
<a name="l00337"></a>00337 }
<a name="l00338"></a>00338
<a name="l00339"></a>00339
<a name="l00343"></a><a class="code" href="classsf_1_1Sound.htm#76c97fca3a5092db606eb66461f063af">00343</a> <a class="code" href="classsf_1_1Sound.htm#28ad2186cde78fed2c79c867b9622195" title="Enumeration of the sound states.">Sound::Status</a> <a class="code" href="classsf_1_1Sound.htm#76c97fca3a5092db606eb66461f063af" title="Get the status of the sound (stopped, paused, playing).">Sound::GetStatus</a>()<span class="keyword"> const</span>
<a name="l00344"></a>00344 <span class="keyword"></span>{
<a name="l00345"></a>00345 ALint State;
<a name="l00346"></a>00346 ALCheck(alGetSourcei(mySource, AL_SOURCE_STATE, &State));
<a name="l00347"></a>00347
<a name="l00348"></a>00348 <span class="keywordflow">switch</span> (State)
<a name="l00349"></a>00349 {
<a name="l00350"></a>00350 <span class="keywordflow">case</span> AL_INITIAL :
<a name="l00351"></a>00351 <span class="keywordflow">case</span> AL_STOPPED : <span class="keywordflow">return</span> <a class="code" href="classsf_1_1Sound.htm#28ad2186cde78fed2c79c867b962219539fd53aa83db9189ca2fff82e0553cf9" title="Sound is not playing.">Stopped</a>;
<a name="l00352"></a>00352 <span class="keywordflow">case</span> AL_PAUSED : <span class="keywordflow">return</span> <a class="code" href="classsf_1_1Sound.htm#28ad2186cde78fed2c79c867b9622195c9fedbd48103548431e7851d16be5f4f" title="Sound is paused.">Paused</a>;
<a name="l00353"></a>00353 <span class="keywordflow">case</span> AL_PLAYING : <span class="keywordflow">return</span> <a class="code" href="classsf_1_1Sound.htm#28ad2186cde78fed2c79c867b962219516657b221888cf11e2a076f5b2783288" title="Sound is playing.">Playing</a>;
<a name="l00354"></a>00354 }
<a name="l00355"></a>00355
<a name="l00356"></a>00356 <span class="keywordflow">return</span> <a class="code" href="classsf_1_1Sound.htm#28ad2186cde78fed2c79c867b962219539fd53aa83db9189ca2fff82e0553cf9" title="Sound is not playing.">Stopped</a>;
<a name="l00357"></a>00357 }
<a name="l00358"></a>00358
<a name="l00359"></a>00359
<a name="l00363"></a><a class="code" href="classsf_1_1Sound.htm#b794404f8facdad9578c31eff25110a7">00363</a> <a class="code" href="classsf_1_1Sound.htm" title="Sound defines the properties of a sound such as position, volume, pitch, etc.">Sound</a>& <a class="code" href="classsf_1_1Sound.htm#b794404f8facdad9578c31eff25110a7" title="Assignment operator.">Sound::operator =</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1Sound.htm" title="Sound defines the properties of a sound such as position, volume, pitch, etc.">Sound</a>& Other)
<a name="l00364"></a>00364 {
<a name="l00365"></a>00365 <span class="comment">// Here we don't use the copy-and-swap idiom, because it would mess up</span>
<a name="l00366"></a>00366 <span class="comment">// the list of sound instances contained in the buffers</span>
<a name="l00367"></a>00367
<a name="l00368"></a>00368 <span class="comment">// Detach the sound instance from the previous buffer (if any)</span>
<a name="l00369"></a>00369 <span class="keywordflow">if</span> (myBuffer)
<a name="l00370"></a>00370 {
<a name="l00371"></a>00371 <a class="code" href="classsf_1_1Sound.htm#b1f5f103f737c52ceb0b1a067b4d0630" title="Stop the sound.">Stop</a>();
<a name="l00372"></a>00372 myBuffer->DetachSound(<span class="keyword">this</span>);
<a name="l00373"></a>00373 myBuffer = NULL;
<a name="l00374"></a>00374 }
<a name="l00375"></a>00375
<a name="l00376"></a>00376 <span class="comment">// Copy the sound attributes</span>
<a name="l00377"></a>00377 <span class="keywordflow">if</span> (Other.<a class="code" href="classsf_1_1Sound.htm#853812e73ff1cfdd04fe562431bd5a16" title="Sound buffer bound to the source.">myBuffer</a>)
<a name="l00378"></a>00378 <a class="code" href="classsf_1_1Sound.htm#9dbc27c54f0ee633c831a0b6e24ecc55" title="Set the source buffer.">SetBuffer</a>(*Other.<a class="code" href="classsf_1_1Sound.htm#853812e73ff1cfdd04fe562431bd5a16" title="Sound buffer bound to the source.">myBuffer</a>);
<a name="l00379"></a>00379 <a class="code" href="classsf_1_1Sound.htm#4eb9966b7289c69623a39cc0125012f4" title="Set the sound loop state.">SetLoop</a>(Other.<a class="code" href="classsf_1_1Sound.htm#5cdc44ade7bda8db2d0431701d72495e" title="Tell whether or not the sound is looping.">GetLoop</a>());
<a name="l00380"></a>00380 <a class="code" href="classsf_1_1Sound.htm#f93301feb88770789ba7cd993c9dd3a0" title="Set the sound pitch.">SetPitch</a>(Other.<a class="code" href="classsf_1_1Sound.htm#42333202ed0586f434d852cc35b9d4ef" title="Get the pitch.">GetPitch</a>());
<a name="l00381"></a>00381 <a class="code" href="classsf_1_1Sound.htm#1536095045923a2332dd9eed6bf8e96a" title="Set the sound volume.">SetVolume</a>(Other.<a class="code" href="classsf_1_1Sound.htm#018e78cd6c50d653fffff1005a350782" title="Get the volume.">GetVolume</a>());
<a name="l00382"></a>00382 <a class="code" href="classsf_1_1Sound.htm#b445e8738218525d8dd067628bc70c78" title="Set the sound position (take 3 values).">SetPosition</a>(Other.<a class="code" href="classsf_1_1Sound.htm#b1adb173ee12a86f261fb765be050643" title="Get the sound position.">GetPosition</a>());
<a name="l00383"></a>00383 <a class="code" href="classsf_1_1Sound.htm#7604f576d184ba8031789beee96d04d3" title="Make the sound&#39;s position relative to the listener&#39;s position, or absolute...">SetRelativeToListener</a>(Other.<a class="code" href="classsf_1_1Sound.htm#f0278152abf6e3f195353ce3c270f34e" title="Tell if the sound&#39;s position is relative to the listener&#39;s position, or if...">IsRelativeToListener</a>());
<a name="l00384"></a>00384 <a class="code" href="classsf_1_1Sound.htm#0a545d8dca68d85a03390f6da7c446a9" title="Set the minimum distance - closer than this distance, the listener will hear the...">SetMinDistance</a>(Other.<a class="code" href="classsf_1_1Sound.htm#07f37119f7b3b00f274ac0263a4bc58b" title="Get the minimum distance.">GetMinDistance</a>());
<a name="l00385"></a>00385 <a class="code" href="classsf_1_1Sound.htm#c3743f1fb53bf9818fbab6e9220bd7b9" title="Set the attenuation factor - the higher the attenuation, the more the sound will...">SetAttenuation</a>(Other.<a class="code" href="classsf_1_1Sound.htm#f594211c35d6ac7a9df083c226749c42" title="Get the attenuation factor.">GetAttenuation</a>());
<a name="l00386"></a>00386
<a name="l00387"></a>00387 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00388"></a>00388 }
<a name="l00389"></a>00389
<a name="l00390"></a>00390
<a name="l00394"></a><a class="code" href="classsf_1_1Sound.htm#0fe562f8a52994658398c61796cde331">00394</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Sound.htm#0fe562f8a52994658398c61796cde331" title="Reset the internal buffer.">Sound::ResetBuffer</a>()
<a name="l00395"></a>00395 {
<a name="l00396"></a>00396 <span class="comment">// First stop the sound in case it is playing</span>
<a name="l00397"></a>00397 <a class="code" href="classsf_1_1Sound.htm#b1f5f103f737c52ceb0b1a067b4d0630" title="Stop the sound.">Stop</a>();
<a name="l00398"></a>00398
<a name="l00399"></a>00399 <span class="comment">// Detach the buffer</span>
<a name="l00400"></a>00400 ALCheck(alSourcei(mySource, AL_BUFFER, 0));
<a name="l00401"></a>00401 myBuffer = NULL;
<a name="l00402"></a>00402 }
<a name="l00403"></a>00403
<a name="l00404"></a>00404 } <span class="comment">// namespace sf</span>
</pre></div></div>
<p id="footer">
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved ::
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen 1.5.2</a> ::
</p>
</body>
</html>
|