]> git.sesse.net Git - casparcg/blob - dependencies/SFML-1.6/include/SFML/Audio/Sound.hpp
Subtree merge of old SVN "dependencies" folder into the "master" git branch. You...
[casparcg] / dependencies / SFML-1.6 / include / SFML / Audio / Sound.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\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
8 //\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
12 //\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
17 //\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
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef SFML_SOUND_HPP\r
26 #define SFML_SOUND_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <SFML/System/Resource.hpp>\r
32 #include <SFML/System/Vector3.hpp>\r
33 #include <SFML/Audio/AudioResource.hpp>\r
34 #include <cstdlib>\r
35 \r
36 \r
37 namespace sf\r
38 {\r
39 class SoundBuffer;\r
40 \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
46 {\r
47 public :\r
48 \r
49     ////////////////////////////////////////////////////////////\r
50     /// Enumeration of the sound states\r
51     ////////////////////////////////////////////////////////////\r
52     enum Status\r
53     {\r
54         Stopped, ///< Sound is not playing\r
55         Paused,  ///< Sound is paused\r
56         Playing  ///< Sound is playing\r
57     };\r
58 \r
59     ////////////////////////////////////////////////////////////\r
60     /// Default constructor\r
61     ///\r
62     ////////////////////////////////////////////////////////////\r
63     Sound();\r
64 \r
65     ////////////////////////////////////////////////////////////\r
66     /// Construct the sound from its parameters\r
67     ///\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
73     ///\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
76 \r
77     ////////////////////////////////////////////////////////////\r
78     /// Copy constructor\r
79     ///\r
80     /// \param Copy : Instance to copy\r
81     ///\r
82     ////////////////////////////////////////////////////////////\r
83     Sound(const Sound& Copy);\r
84 \r
85     ////////////////////////////////////////////////////////////\r
86     /// Destructor\r
87     ///\r
88     ////////////////////////////////////////////////////////////\r
89     ~Sound();\r
90 \r
91     ////////////////////////////////////////////////////////////\r
92     /// Play the sound\r
93     ///\r
94     ////////////////////////////////////////////////////////////\r
95     void Play();\r
96 \r
97     ////////////////////////////////////////////////////////////\r
98     /// Pause the sound\r
99     ///\r
100     ////////////////////////////////////////////////////////////\r
101     void Pause();\r
102 \r
103     ////////////////////////////////////////////////////////////\r
104     /// Stop the sound\r
105     ///\r
106     ////////////////////////////////////////////////////////////\r
107     void Stop();\r
108 \r
109     ////////////////////////////////////////////////////////////\r
110     /// Set the source buffer\r
111     ///\r
112     /// \param Buffer : New sound buffer to bind to the sound\r
113     ///\r
114     ////////////////////////////////////////////////////////////\r
115     void SetBuffer(const SoundBuffer& Buffer);\r
116 \r
117     ////////////////////////////////////////////////////////////\r
118     /// Set the sound loop state.\r
119     /// This parameter is disabled by default\r
120     ///\r
121     /// \param Loop : True to play in loop, false to play once\r
122     ///\r
123     ////////////////////////////////////////////////////////////\r
124     void SetLoop(bool Loop);\r
125 \r
126     ////////////////////////////////////////////////////////////\r
127     /// Set the sound pitch.\r
128     /// The default pitch is 1\r
129     ///\r
130     /// \param Pitch : New pitch\r
131     ///\r
132     ////////////////////////////////////////////////////////////\r
133     void SetPitch(float Pitch);\r
134 \r
135     ////////////////////////////////////////////////////////////\r
136     /// Set the sound volume.\r
137     /// The default volume is 100\r
138     ///\r
139     /// \param Volume : Volume (in range [0, 100])\r
140     ///\r
141     ////////////////////////////////////////////////////////////\r
142     void SetVolume(float Volume);\r
143 \r
144     ////////////////////////////////////////////////////////////\r
145     /// Set the sound position (take 3 values).\r
146     /// The default position is (0, 0, 0)\r
147     ///\r
148     /// \param X, Y, Z : Position of the sound in the world\r
149     ///\r
150     ////////////////////////////////////////////////////////////\r
151     void SetPosition(float X, float Y, float Z);\r
152 \r
153     ////////////////////////////////////////////////////////////\r
154     /// Set the sound position (take a 3D vector).\r
155     /// The default position is (0, 0, 0)\r
156     ///\r
157     /// \param Position : Position of the sound in the world\r
158     ///\r
159     ////////////////////////////////////////////////////////////\r
160     void SetPosition(const Vector3f& Position);\r
161 \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
166     ///\r
167     /// \param Relative : True to set the position relative, false to set it absolute\r
168     ///\r
169     ////////////////////////////////////////////////////////////\r
170     void SetRelativeToListener(bool Relative);\r
171 \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
176     ///\r
177     /// \param MinDistance : New minimum distance for the sound\r
178     ///\r
179     ////////////////////////////////////////////////////////////\r
180     void SetMinDistance(float MinDistance);\r
181 \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
186     ///\r
187     /// \param Attenuation : New attenuation factor for the sound\r
188     ///\r
189     ////////////////////////////////////////////////////////////\r
190     void SetAttenuation(float Attenuation);\r
191 \r
192     ////////////////////////////////////////////////////////////\r
193     /// Set the current playing position of the sound\r
194     ///\r
195     /// \param TimeOffset : New playing position, expressed in seconds\r
196     ///\r
197     ////////////////////////////////////////////////////////////\r
198     void SetPlayingOffset(float TimeOffset);\r
199 \r
200     ////////////////////////////////////////////////////////////\r
201     /// Get the source buffer\r
202     ///\r
203     /// \return Sound buffer bound to the sound (can be NULL)\r
204     ///\r
205     ////////////////////////////////////////////////////////////\r
206     const SoundBuffer* GetBuffer() const;\r
207 \r
208     ////////////////////////////////////////////////////////////\r
209     /// Tell whether or not the sound is looping\r
210     ///\r
211     /// \return True if the sound is looping, false otherwise\r
212     ///\r
213     ////////////////////////////////////////////////////////////\r
214     bool GetLoop() const;\r
215 \r
216     ////////////////////////////////////////////////////////////\r
217     /// Get the pitch\r
218     ///\r
219     /// \return Pitch value\r
220     ///\r
221     ////////////////////////////////////////////////////////////\r
222     float GetPitch() const;\r
223 \r
224     ////////////////////////////////////////////////////////////\r
225     /// Get the volume\r
226     ///\r
227     /// \return Volume value (in range [1, 100])\r
228     ///\r
229     ////////////////////////////////////////////////////////////\r
230     float GetVolume() const;\r
231 \r
232     ////////////////////////////////////////////////////////////\r
233     /// Get the sound position\r
234     ///\r
235     /// \return Position of the sound in the world\r
236     ///\r
237     ////////////////////////////////////////////////////////////\r
238     Vector3f GetPosition() const;\r
239 \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
243     ///\r
244     /// \return True if the position is relative, false if it's absolute\r
245     ///\r
246     ////////////////////////////////////////////////////////////\r
247     bool IsRelativeToListener() const;\r
248 \r
249     ////////////////////////////////////////////////////////////\r
250     /// Get the minimum distance\r
251     ///\r
252     /// \return Minimum distance for the sound\r
253     ///\r
254     ////////////////////////////////////////////////////////////\r
255     float GetMinDistance() const;\r
256 \r
257     ////////////////////////////////////////////////////////////\r
258     /// Get the attenuation factor\r
259     ///\r
260     /// \return Attenuation factor of the sound\r
261     ///\r
262     ////////////////////////////////////////////////////////////\r
263     float GetAttenuation() const;\r
264 \r
265     ////////////////////////////////////////////////////////////\r
266     /// Get the status of the sound (stopped, paused, playing)\r
267     ///\r
268     /// \return Current status of the sound\r
269     ///\r
270     ////////////////////////////////////////////////////////////\r
271     Status GetStatus() const;\r
272 \r
273     ////////////////////////////////////////////////////////////\r
274     /// Get the current playing position of the sound\r
275     ///\r
276     /// \return Current playing position, expressed in seconds\r
277     ///\r
278     ////////////////////////////////////////////////////////////\r
279     float GetPlayingOffset() const;\r
280 \r
281     ////////////////////////////////////////////////////////////\r
282     /// Assignment operator\r
283     ///\r
284     /// \param Other : Instance to assign\r
285     ///\r
286     /// \return Reference to the sound\r
287     ///\r
288     ////////////////////////////////////////////////////////////\r
289     Sound& operator =(const Sound& Other);\r
290 \r
291     ////////////////////////////////////////////////////////////\r
292     /// Reset the internal buffer\r
293     ///\r
294     /// This function is for internal use only, you don't have\r
295     /// to use it.\r
296     ///\r
297     ////////////////////////////////////////////////////////////\r
298     void ResetBuffer();\r
299 \r
300 private :\r
301 \r
302     friend class SoundStream;\r
303 \r
304     ////////////////////////////////////////////////////////////\r
305     // Member data\r
306     ////////////////////////////////////////////////////////////\r
307     unsigned int             mySource; ///< OpenAL source identifier\r
308     ResourcePtr<SoundBuffer> myBuffer; ///< Sound buffer bound to the source\r
309 };\r
310 \r
311 } // namespace sf\r
312 \r
313 \r
314 #endif // SFML_SOUND_HPP\r