SFML 3.1.0
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-2026 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#pragma once
26
28// Headers
30#include <SFML/Audio/Export.hpp>
31
32#include <SFML/Audio/SoundChannel.hpp>
33#include <SFML/Audio/SoundSource.hpp>
34
35#include <SFML/System/Time.hpp>
36
37#include <memory>
38#include <optional>
39#include <vector>
40
41#include <cstddef>
42#include <cstdint>
43
44
45 namespace sf
46{
51 class SFML_AUDIO_API SoundStream : public SoundSource
52{
53 public:
58 struct Chunk
59 {
60 const std::int16_t* samples{};
61 std::size_t sampleCount{};
62 };
63
68 ~SoundStream() override;
69
74 SoundStream(SoundStream&&) noexcept;
75
80 SoundStream& operator=(SoundStream&&) noexcept;
81
94 void play() override;
95
105 void pause() override;
106
117 void stop() override;
118
127 [[nodiscard]] unsigned int getChannelCount() const;
128
138 [[nodiscard]] unsigned int getSampleRate() const;
139
149 [[nodiscard]] const std::vector<SoundChannel>& getChannelMap() const;
150
157 [[nodiscard]] Status getStatus() const override;
158
172 void setPlayingOffset(Time timeOffset);
173
182 [[nodiscard]] Time getPlayingOffset() const;
183
197 void setLooping(bool loop);
198
207 [[nodiscard]] bool isLooping() const;
208
218 void setEffectProcessor(EffectProcessor effectProcessor) override;
219
220protected:
227 SoundStream();
228
244 void initialize(unsigned int channelCount, unsigned int sampleRate, const std::vector<SoundChannel>& channelMap);
245
263 [[nodiscard]] virtual bool onGetData(Chunk& data) = 0;
264
274 virtual void onSeek(Time timeOffset) = 0;
275
286 virtual std::optional<std::uint64_t> onLoop();
287
288private:
295 [[nodiscard]] void* getSound() const override;
296
298 // Member data
300 struct Impl;
301 std::unique_ptr<Impl> m_impl;
302};
303
304} // namespace sf
305
306
Export.hpp
SFML_AUDIO_API
#define SFML_AUDIO_API
Definition Audio/Export.hpp:42
SoundChannel.hpp
SoundSource.hpp
Time.hpp
sf::SoundSource::SoundSource
SoundSource(const SoundSource &)=default
Copy constructor.
sf::SoundSource::Status
Status
Enumeration of the sound source states.
Definition SoundSource.hpp:55
sf::SoundSource::EffectProcessor
std::function< void(const float *inputFrames, unsigned int &inputFrameCount, float *outputFrames, unsigned int &outputFrameCount, unsigned int frameChannelCount)> EffectProcessor
Callable that is provided with sound data for processing.
Definition SoundSource.hpp:160
sf::SoundStream::setLooping
void setLooping(bool loop)
Set whether or not the stream should loop after reaching the end.
sf::SoundStream::SoundStream
SoundStream(SoundStream &&) noexcept
Move constructor.
sf::SoundStream::getChannelCount
unsigned int getChannelCount() const
Return the number of channels of the stream.
sf::SoundStream::pause
void pause() override
Pause the audio stream.
sf::SoundStream::getChannelMap
const std::vector< SoundChannel > & getChannelMap() const
Get the map of position in sample frame to sound channel.
sf::SoundStream::initialize
void initialize(unsigned int channelCount, unsigned int sampleRate, const std::vector< SoundChannel > &channelMap)
Define the audio stream parameters.
sf::SoundStream::isLooping
bool isLooping() const
Tell whether or not the stream is in loop mode.
sf::SoundStream::getStatus
Status getStatus() const override
Get the current status of the stream (stopped, paused, playing).
sf::SoundStream::setEffectProcessor
void setEffectProcessor(EffectProcessor effectProcessor) override
Set the effect processor to be applied to the sound.
sf::SoundStream::stop
void stop() override
Stop playing the audio stream.
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::onGetData
virtual bool onGetData(Chunk &data)=0
Request a new chunk of audio samples from the stream source.
sf::SoundStream::onLoop
virtual std::optional< std::uint64_t > onLoop()
Change the current playing position in the stream source to the beginning of the loop.
sf::SoundStream::~SoundStream
~SoundStream() override
Destructor.
sf::SoundStream::getPlayingOffset
Time getPlayingOffset() const
Get the current playing position of the stream.
sf::SoundStream::play
void play() override
Start or resume playing the audio stream.
sf::SoundStream::setPlayingOffset
void setPlayingOffset(Time timeOffset)
Change the current playing position of the stream.
sf::Time
Represents a time value.
Definition Time.hpp:42
sf::SoundChannel
SoundChannel
Types of sound channels that can be read/written from sound buffers/files.
Definition SoundChannel.hpp:42
sf
Definition AudioResource.hpp:36
sf::SoundStream::Chunk
Structure defining a chunk of audio data to stream.
Definition SoundStream.hpp:59
sf::SoundStream::Chunk::samples
const std::int16_t * samples
Pointer to the audio samples.
Definition SoundStream.hpp:60
sf::SoundStream::Chunk::sampleCount
std::size_t sampleCount
Number of samples pointed by Samples.
Definition SoundStream.hpp:61