SoundStream.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_SOUNDSTREAM_HPP
26#define SFML_SOUNDSTREAM_HPP
27
29// Headers
31#include <SFML/Audio/Sound.hpp>
32#include <SFML/System/Thread.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;
55 using Sound::SetPosition;
56 using Sound::SetRelativeToListener;
57 using Sound::SetMinDistance;
58 using Sound::SetAttenuation;
59 using Sound::GetPitch;
60 using Sound::GetVolume;
61 using Sound::GetPosition;
62 using Sound::IsRelativeToListener;
63 using Sound::GetMinDistance;
64 using Sound::GetAttenuation;
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
115 Status GetStatus() const;
116
123 float GetPlayingOffset() const;
124
132 void SetLoop(bool Loop);
133
140 bool GetLoop() const;
141
142protected :
143
148 SoundStream();
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
SoundStream is a streamed sound, ie samples are acquired while the sound is playing.
Status
Enumeration of the sound states.
Definition Sound.hpp:53
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
Thread defines an easy way to manipulate a thread.
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.