1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_SOUND_HPP
\r
26 #define SFML_SOUND_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <SFML/System/Resource.hpp>
\r
32 #include <SFML/System/Vector3.hpp>
\r
33 #include <SFML/Audio/AudioResource.hpp>
\r
41 ////////////////////////////////////////////////////////////
\r
42 /// Sound defines the properties of a sound such as position,
\r
43 /// volume, pitch, etc.
\r
44 ////////////////////////////////////////////////////////////
\r
45 class SFML_API Sound : public AudioResource
\r
49 ////////////////////////////////////////////////////////////
\r
50 /// Enumeration of the sound states
\r
51 ////////////////////////////////////////////////////////////
\r
54 Stopped, ///< Sound is not playing
\r
55 Paused, ///< Sound is paused
\r
56 Playing ///< Sound is playing
\r
59 ////////////////////////////////////////////////////////////
\r
60 /// Default constructor
\r
62 ////////////////////////////////////////////////////////////
\r
65 ////////////////////////////////////////////////////////////
\r
66 /// Construct the sound from its parameters
\r
68 /// \param Buffer : Sound buffer to play (NULL by default)
\r
69 /// \param Loop : Loop flag (false by default)
\r
70 /// \param Pitch : Value of the pitch (1 by default)
\r
71 /// \param Volume : Volume (100 by default)
\r
72 /// \param Position : Position (0, 0, 0 by default)
\r
74 ////////////////////////////////////////////////////////////
\r
75 explicit Sound(const SoundBuffer& Buffer, bool Loop = false, float Pitch = 1.f, float Volume = 100.f, const Vector3f& Position = Vector3f(0, 0, 0));
\r
77 ////////////////////////////////////////////////////////////
\r
78 /// Copy constructor
\r
80 /// \param Copy : Instance to copy
\r
82 ////////////////////////////////////////////////////////////
\r
83 Sound(const Sound& Copy);
\r
85 ////////////////////////////////////////////////////////////
\r
88 ////////////////////////////////////////////////////////////
\r
91 ////////////////////////////////////////////////////////////
\r
94 ////////////////////////////////////////////////////////////
\r
97 ////////////////////////////////////////////////////////////
\r
100 ////////////////////////////////////////////////////////////
\r
103 ////////////////////////////////////////////////////////////
\r
106 ////////////////////////////////////////////////////////////
\r
109 ////////////////////////////////////////////////////////////
\r
110 /// Set the source buffer
\r
112 /// \param Buffer : New sound buffer to bind to the sound
\r
114 ////////////////////////////////////////////////////////////
\r
115 void SetBuffer(const SoundBuffer& Buffer);
\r
117 ////////////////////////////////////////////////////////////
\r
118 /// Set the sound loop state.
\r
119 /// This parameter is disabled by default
\r
121 /// \param Loop : True to play in loop, false to play once
\r
123 ////////////////////////////////////////////////////////////
\r
124 void SetLoop(bool Loop);
\r
126 ////////////////////////////////////////////////////////////
\r
127 /// Set the sound pitch.
\r
128 /// The default pitch is 1
\r
130 /// \param Pitch : New pitch
\r
132 ////////////////////////////////////////////////////////////
\r
133 void SetPitch(float Pitch);
\r
135 ////////////////////////////////////////////////////////////
\r
136 /// Set the sound volume.
\r
137 /// The default volume is 100
\r
139 /// \param Volume : Volume (in range [0, 100])
\r
141 ////////////////////////////////////////////////////////////
\r
142 void SetVolume(float Volume);
\r
144 ////////////////////////////////////////////////////////////
\r
145 /// Set the sound position (take 3 values).
\r
146 /// The default position is (0, 0, 0)
\r
148 /// \param X, Y, Z : Position of the sound in the world
\r
150 ////////////////////////////////////////////////////////////
\r
151 void SetPosition(float X, float Y, float Z);
\r
153 ////////////////////////////////////////////////////////////
\r
154 /// Set the sound position (take a 3D vector).
\r
155 /// The default position is (0, 0, 0)
\r
157 /// \param Position : Position of the sound in the world
\r
159 ////////////////////////////////////////////////////////////
\r
160 void SetPosition(const Vector3f& Position);
\r
162 ////////////////////////////////////////////////////////////
\r
163 /// Make the sound's position relative to the listener's
\r
164 /// position, or absolute.
\r
165 /// The default value is false (absolute)
\r
167 /// \param Relative : True to set the position relative, false to set it absolute
\r
169 ////////////////////////////////////////////////////////////
\r
170 void SetRelativeToListener(bool Relative);
\r
172 ////////////////////////////////////////////////////////////
\r
173 /// Set the minimum distance - closer than this distance,
\r
174 /// the listener will hear the sound at its maximum volume.
\r
175 /// The default minimum distance is 1.0
\r
177 /// \param MinDistance : New minimum distance for the sound
\r
179 ////////////////////////////////////////////////////////////
\r
180 void SetMinDistance(float MinDistance);
\r
182 ////////////////////////////////////////////////////////////
\r
183 /// Set the attenuation factor - the higher the attenuation, the
\r
184 /// more the sound will be attenuated with distance from listener.
\r
185 /// The default attenuation factor 1.0
\r
187 /// \param Attenuation : New attenuation factor for the sound
\r
189 ////////////////////////////////////////////////////////////
\r
190 void SetAttenuation(float Attenuation);
\r
192 ////////////////////////////////////////////////////////////
\r
193 /// Set the current playing position of the sound
\r
195 /// \param TimeOffset : New playing position, expressed in seconds
\r
197 ////////////////////////////////////////////////////////////
\r
198 void SetPlayingOffset(float TimeOffset);
\r
200 ////////////////////////////////////////////////////////////
\r
201 /// Get the source buffer
\r
203 /// \return Sound buffer bound to the sound (can be NULL)
\r
205 ////////////////////////////////////////////////////////////
\r
206 const SoundBuffer* GetBuffer() const;
\r
208 ////////////////////////////////////////////////////////////
\r
209 /// Tell whether or not the sound is looping
\r
211 /// \return True if the sound is looping, false otherwise
\r
213 ////////////////////////////////////////////////////////////
\r
214 bool GetLoop() const;
\r
216 ////////////////////////////////////////////////////////////
\r
219 /// \return Pitch value
\r
221 ////////////////////////////////////////////////////////////
\r
222 float GetPitch() const;
\r
224 ////////////////////////////////////////////////////////////
\r
227 /// \return Volume value (in range [1, 100])
\r
229 ////////////////////////////////////////////////////////////
\r
230 float GetVolume() const;
\r
232 ////////////////////////////////////////////////////////////
\r
233 /// Get the sound position
\r
235 /// \return Position of the sound in the world
\r
237 ////////////////////////////////////////////////////////////
\r
238 Vector3f GetPosition() const;
\r
240 ////////////////////////////////////////////////////////////
\r
241 /// Tell if the sound's position is relative to the listener's
\r
242 /// position, or if it's absolute
\r
244 /// \return True if the position is relative, false if it's absolute
\r
246 ////////////////////////////////////////////////////////////
\r
247 bool IsRelativeToListener() const;
\r
249 ////////////////////////////////////////////////////////////
\r
250 /// Get the minimum distance
\r
252 /// \return Minimum distance for the sound
\r
254 ////////////////////////////////////////////////////////////
\r
255 float GetMinDistance() const;
\r
257 ////////////////////////////////////////////////////////////
\r
258 /// Get the attenuation factor
\r
260 /// \return Attenuation factor of the sound
\r
262 ////////////////////////////////////////////////////////////
\r
263 float GetAttenuation() const;
\r
265 ////////////////////////////////////////////////////////////
\r
266 /// Get the status of the sound (stopped, paused, playing)
\r
268 /// \return Current status of the sound
\r
270 ////////////////////////////////////////////////////////////
\r
271 Status GetStatus() const;
\r
273 ////////////////////////////////////////////////////////////
\r
274 /// Get the current playing position of the sound
\r
276 /// \return Current playing position, expressed in seconds
\r
278 ////////////////////////////////////////////////////////////
\r
279 float GetPlayingOffset() const;
\r
281 ////////////////////////////////////////////////////////////
\r
282 /// Assignment operator
\r
284 /// \param Other : Instance to assign
\r
286 /// \return Reference to the sound
\r
288 ////////////////////////////////////////////////////////////
\r
289 Sound& operator =(const Sound& Other);
\r
291 ////////////////////////////////////////////////////////////
\r
292 /// Reset the internal buffer
\r
294 /// This function is for internal use only, you don't have
\r
297 ////////////////////////////////////////////////////////////
\r
298 void ResetBuffer();
\r
302 friend class SoundStream;
\r
304 ////////////////////////////////////////////////////////////
\r
306 ////////////////////////////////////////////////////////////
\r
307 unsigned int mySource; ///< OpenAL source identifier
\r
308 ResourcePtr<SoundBuffer> myBuffer; ///< Sound buffer bound to the source
\r
314 #endif // SFML_SOUND_HPP
\r