Sound.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef SFML_SOUND_HPP
26#define SFML_SOUND_HPP
27
29// Headers
31#include <SFML/System/Resource.hpp>
32#include <SFML/System/Vector3.hpp>
33#include <SFML/Audio/AudioResource.hpp>
34#include <cstdlib>
35
36
37namespace sf
38{
39class SoundBuffer;
40
45class SFML_API Sound : public AudioResource
46{
47public :
48
58
63 Sound();
64
75 explicit Sound(const SoundBuffer& Buffer, bool Loop = false, float Pitch = 1.f, float Volume = 100.f, const Vector3f& Position = Vector3f(0, 0, 0));
76
83 Sound(const Sound& Copy);
84
89 ~Sound();
90
95 void Play();
96
101 void Pause();
102
107 void Stop();
108
115 void SetBuffer(const SoundBuffer& Buffer);
116
124 void SetLoop(bool Loop);
125
133 void SetPitch(float Pitch);
134
142 void SetVolume(float Volume);
143
151 void SetPosition(float X, float Y, float Z);
152
160 void SetPosition(const Vector3f& Position);
161
170 void SetRelativeToListener(bool Relative);
171
180 void SetMinDistance(float MinDistance);
181
190 void SetAttenuation(float Attenuation);
191
198 void SetPlayingOffset(float TimeOffset);
199
206 const SoundBuffer* GetBuffer() const;
207
214 bool GetLoop() const;
215
222 float GetPitch() const;
223
230 float GetVolume() const;
231
238 Vector3f GetPosition() const;
239
247 bool IsRelativeToListener() const;
248
255 float GetMinDistance() const;
256
263 float GetAttenuation() const;
264
271 Status GetStatus() const;
272
279 float GetPlayingOffset() const;
280
289 Sound& operator =(const Sound& Other);
290
298 void ResetBuffer();
299
300private :
301
302 friend class SoundStream;
303
305 // Member data
307 unsigned int mySource;
308 ResourcePtr<SoundBuffer> myBuffer;
309};
310
311} // namespace sf
312
313
314#endif // SFML_SOUND_HPP
AudioResource()
Default constructor.
Safe pointer to a T resource (inheriting from sf::Resource<T>), its pointer is automatically reseted ...
Definition Resource.hpp:117
SoundBuffer is the low-level for loading and manipulating sound buffers.
SoundStream is a streamed sound, ie samples are acquired while the sound is playing.
Sound defines the properties of a sound such as position, volume, pitch, etc.
Definition Sound.hpp:46
Status
Enumeration of the sound states.
Definition Sound.hpp:53
@ Playing
Sound is playing.
Definition Sound.hpp:56
@ Stopped
Sound is not playing.
Definition Sound.hpp:54
@ Paused
Sound is paused.
Definition Sound.hpp:55
Sound()
Default constructor.
Definition Sound.cpp:38