SFML 2.6.1

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

Loading...
Searching...
No Matches
SoundStream.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
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
183 enum
184 {
185 NoLoop = -1
186 };
187
194 SoundStream();
195
210 void initialize(unsigned int channelCount, unsigned int sampleRate);
211
229 virtual bool onGetData(Chunk& data) = 0;
230
240 virtual void onSeek(Time timeOffset) = 0;
241
252 virtual Int64 onLoop();
253
266 void setProcessingInterval(Time interval);
267
268 private:
269
277 void streamData();
278
293 bool fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop = false);
294
304 bool fillQueue();
305
312 void clearQueue();
313
314 enum
315 {
316 BufferCount = 3,
317 BufferRetries = 2
318 };
319
321 // Member data
323 Thread m_thread;
324 mutable Mutex m_threadMutex;
325 Status m_threadStartState;
326 bool m_isStreaming;
327 unsigned int m_buffers[BufferCount];
328 unsigned int m_channelCount;
329 unsigned int m_sampleRate;
330 Int32 m_format;
331 bool m_loop;
332 Uint64 m_samplesProcessed;
333 Int64 m_bufferSeeks[BufferCount];
334 Time m_processingInterval;
335};
336
337} // namespace sf
338
339
340#endif // SFML_SOUNDSTREAM_HPP
341
342
sf::Mutex
Blocks concurrent access to shared resources from multiple threads.
Definition Mutex.hpp:48
sf::SoundSource
Base class defining a sound's properties.
Definition SoundSource.hpp:43
sf::SoundSource::Status
Status
Enumeration of the sound source states.
Definition SoundSource.hpp:51
sf::SoundStream
Abstract base class for streamed audio sources.
Definition SoundStream.hpp:46
sf::SoundStream::stop
void stop()
Stop playing the audio stream.
sf::SoundStream::getChannelCount
unsigned int getChannelCount() const
Return the number of channels of the stream.
sf::SoundStream::~SoundStream
virtual ~SoundStream()
Destructor.
sf::SoundStream::setProcessingInterval
void setProcessingInterval(Time interval)
Set the processing interval.
sf::SoundStream::onLoop
virtual Int64 onLoop()
Change the current playing position in the stream source to the beginning of the loop.
sf::SoundStream::setLoop
void setLoop(bool loop)
Set whether or not the stream should loop after reaching the end.
sf::SoundStream::getLoop
bool getLoop() const
Tell whether or not the stream is in loop mode.
sf::SoundStream::getStatus
Status getStatus() const
Get the current status of the stream (stopped, paused, playing)
sf::SoundStream::SoundStream
SoundStream()
Default constructor.
sf::SoundStream::getSampleRate
unsigned int getSampleRate() const
Get the stream sample rate of the stream.
sf::SoundStream::onSeek
virtual void onSeek(Time timeOffset)=0
Change the current playing position in the stream source.
sf::SoundStream::pause
void pause()
Pause the audio stream.
sf::SoundStream::onGetData
virtual bool onGetData(Chunk &data)=0
Request a new chunk of audio samples from the stream source.
sf::SoundStream::initialize
void initialize(unsigned int channelCount, unsigned int sampleRate)
Define the audio stream parameters.
sf::SoundStream::getPlayingOffset
Time getPlayingOffset() const
Get the current playing position of the stream.
sf::SoundStream::setPlayingOffset
void setPlayingOffset(Time timeOffset)
Change the current playing position of the stream.
sf::SoundStream::play
void play()
Start or resume playing the audio stream.
sf::Thread
Utility class to manipulate threads.
Definition Thread.hpp:49
sf::Time
Represents a time value.
Definition Time.hpp:41
sf::SoundStream::Chunk
Structure defining a chunk of audio data to stream.
Definition SoundStream.hpp:54
sf::SoundStream::Chunk::samples
const Int16 * samples
Pointer to the audio samples.
Definition SoundStream.hpp:55
sf::SoundStream::Chunk::sampleCount
std::size_t sampleCount
Number of samples pointed by Samples.
Definition SoundStream.hpp:56