Loading...
Searching...
No Matches
Sound.hpp
Go to the documentation of this file.
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
34#include <cstdlib>
35
36
37namespace sf
38{
39class SoundBuffer;
40
46{
47public :
48
58
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
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
239
248
255 float GetMinDistance() const;
256
263 float GetAttenuation() const;
264
272
279 float GetPlayingOffset() const;
280
289 Sound& operator =(const Sound& Other);
290
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
#define SFML_API
Definition Config.hpp:114
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.
float GetPlayingOffset() const
Get the current playing position of the sound.
void SetMinDistance(float MinDistance)
Set the minimum distance - closer than this distance, the listener will hear the sound at its maximum...
void SetPosition(const Vector3f &Position)
Set the sound position (take a 3D vector).
void ResetBuffer()
Reset the internal buffer.
void SetVolume(float Volume)
Set the sound volume.
const SoundBuffer * GetBuffer() const
Get the source buffer.
bool GetLoop() const
Tell whether or not the sound is looping.
friend class SoundStream
Definition Sound.hpp:302
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
bool IsRelativeToListener() const
Tell if the sound's position is relative to the listener's position, or if it's absolute.
Sound()
Default constructor.
Sound(const SoundBuffer &Buffer, bool Loop=false, float Pitch=1.f, float Volume=100.f, const Vector3f &Position=Vector3f(0, 0, 0))
Construct the sound from its parameters.
void SetLoop(bool Loop)
Set the sound loop state.
float GetVolume() const
Get the volume.
void Pause()
Pause the sound.
float GetAttenuation() const
Get the attenuation factor.
void SetRelativeToListener(bool Relative)
Make the sound's position relative to the listener's position, or absolute.
Vector3f GetPosition() const
Get the sound position.
void SetBuffer(const SoundBuffer &Buffer)
Set the source buffer.
Sound(const Sound &Copy)
Copy constructor.
void Stop()
Stop the sound.
void SetPosition(float X, float Y, float Z)
Set the sound position (take 3 values).
float GetPitch() const
Get the pitch.
Status GetStatus() const
Get the status of the sound (stopped, paused, playing).
void SetAttenuation(float Attenuation)
Set the attenuation factor - the higher the attenuation, the more the sound will be attenuated with d...
~Sound()
Destructor.
float GetMinDistance() const
Get the minimum distance.
void SetPlayingOffset(float TimeOffset)
Set the current playing position of the sound.
void SetPitch(float Pitch)
Set the sound pitch.
void Play()
Play the sound.
Vector3< float > Vector3f
Definition Vector3.hpp:212