Documentation of SFML 2.2

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
SoundStream.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 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/Export.hpp>
32 #include <SFML/Audio/SoundSource.hpp>
33 #include <SFML/System/Thread.hpp>
34 #include <SFML/System/Time.hpp>
35 #include <SFML/System/Mutex.hpp>
36 #include <cstdlib>
37 
38 
39 namespace sf
40 {
45 class SFML_AUDIO_API SoundStream : public SoundSource
46 {
47 public:
48 
53  struct Chunk
54  {
55  const Int16* samples;
56  std::size_t sampleCount;
57  };
58 
63  virtual ~SoundStream();
64 
77  void play();
78 
88  void pause();
89 
100  void stop();
101 
110  unsigned int getChannelCount() const;
111 
121  unsigned int getSampleRate() const;
122 
129  Status getStatus() const;
130 
144  void setPlayingOffset(Time timeOffset);
145 
154  Time getPlayingOffset() const;
155 
169  void setLoop(bool loop);
170 
179  bool getLoop() const;
180 
181 protected:
182 
189  SoundStream();
190 
205  void initialize(unsigned int channelCount, unsigned int sampleRate);
206 
224  virtual bool onGetData(Chunk& data) = 0;
225 
235  virtual void onSeek(Time timeOffset) = 0;
236 
237 private:
238 
246  void streamData();
247 
261  bool fillAndPushBuffer(unsigned int bufferNum);
262 
272  bool fillQueue();
273 
280  void clearQueue();
281 
282  enum
283  {
284  BufferCount = 3
285  };
286 
288  // Member data
290  Thread m_thread;
291  mutable Mutex m_threadMutex;
292  Status m_threadStartState;
293  bool m_isStreaming;
294  unsigned int m_buffers[BufferCount];
295  unsigned int m_channelCount;
296  unsigned int m_sampleRate;
297  Uint32 m_format;
298  bool m_loop;
299  Uint64 m_samplesProcessed;
300  bool m_endBuffers[BufferCount];
301 };
302 
303 } // namespace sf
304 
305 
306 #endif // SFML_SOUNDSTREAM_HPP
307 
308 
Structure defining a chunk of audio data to stream.
Definition: SoundStream.hpp:53
Definition: Listener.hpp:35
Represents a time value.
Definition: Time.hpp:40
const Int16 * samples
Pointer to the audio samples.
Definition: SoundStream.hpp:55
Blocks concurrent access to shared resources from multiple threads.
Definition: Mutex.hpp:47
Abstract base class for streamed audio sources.
Definition: SoundStream.hpp:45
Status
Enumeration of the sound source states.
Definition: SoundSource.hpp:49
Base class defining a sound's properties.
Definition: SoundSource.hpp:41
std::size_t sampleCount
Number of samples pointed by Samples.
Definition: SoundStream.hpp:56
Utility class to manipulate threads.
Definition: Thread.hpp:48