Loading...
Searching...
No Matches
SoundStream.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_SOUNDSTREAM_HPP
26#define SFML_SOUNDSTREAM_HPP
27
29// Headers
31#include <SFML/Audio/Sound.hpp>
33#include <cstdlib>
34
35
36namespace sf
37{
44class SFML_API SoundStream : private Thread, private Sound
45{
46public :
47
48 using Sound::Status;
49 using Sound::Stopped;
50 using Sound::Paused;
51 using Sound::Playing;
52 using Sound::Pause;
53 using Sound::SetPitch;
54 using Sound::SetVolume;
59 using Sound::GetPitch;
60 using Sound::GetVolume;
65
69 struct Chunk
70 {
71 const Int16* Samples;
72 std::size_t NbSamples;
73 };
74
79 virtual ~SoundStream();
80
85 void Play();
86
91 void Stop();
92
99 unsigned int GetChannelsCount() const;
100
107 unsigned int GetSampleRate() const;
108
116
123 float GetPlayingOffset() const;
124
132 void SetLoop(bool Loop);
133
140 bool GetLoop() const;
141
142protected :
143
149
157 void Initialize(unsigned int ChannelsCount, unsigned int SampleRate);
158
159private :
160
165 virtual void Run();
166
173 virtual bool OnStart();
174
183 virtual bool OnGetData(Chunk& Data) = 0;
184
194 bool FillAndPushBuffer(unsigned int BufferNum);
195
202 bool FillQueue();
203
208 void ClearQueue();
209
210 enum {BuffersCount = 3};
211
213 // Member data
215 bool myIsStreaming;
216 unsigned int myBuffers[BuffersCount];
217 unsigned int myChannelsCount;
218 unsigned int mySampleRate;
219 unsigned long myFormat;
220 bool myLoop;
221 unsigned int mySamplesProcessed;
222 bool myEndBuffers[BuffersCount];
223};
224
225} // namespace sf
226
227
228#endif // SFML_SOUNDSTREAM_HPP
#define SFML_API
Definition Config.hpp:114
void SetLoop(bool Loop)
Set the stream loop state.
virtual ~SoundStream()
Virtual destructor.
Status
Enumeration of the sound states.
Definition Sound.hpp:53
Status GetStatus() const
Get the status of the stream (stopped, paused, playing).
void Play()
Start playing the audio stream.
void Stop()
Stop playing the audio stream.
float GetPlayingOffset() const
Get the current playing position of the stream.
SoundStream()
Default constructor.
unsigned int GetSampleRate() const
Get the stream sample rate.
bool GetLoop() const
Tell whether or not the stream is looping.
void Initialize(unsigned int ChannelsCount, unsigned int SampleRate)
Set the audio stream parameters, you must call it before Play().
unsigned int GetChannelsCount() const
Return the number of channels (1 = mono, 2 = stereo).
void SetMinDistance(float MinDistance)
Set the minimum distance - closer than this distance, the listener will hear the sound at its maximum...
void SetVolume(float Volume)
Set the sound volume.
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.
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 SetPosition(float X, float Y, float Z)
Set the sound position (take 3 values).
float GetPitch() const
Get the pitch.
void SetAttenuation(float Attenuation)
Set the attenuation factor - the higher the attenuation, the more the sound will be attenuated with d...
float GetMinDistance() const
Get the minimum distance.
void SetPitch(float Pitch)
Set the sound pitch.
Thread(FuncType Function, void *UserData=NULL)
Construct the thread from a function pointer.
Structure defining a chunk of audio data to stream.
std::size_t NbSamples
Number of samples pointed by Samples.
const Int16 * Samples
Pointer to the audio samples.