# SFML - Simple and Fast Multimedia Library

SFML 3.0.0

- Main Page
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

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-2024 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
45namespace sf
46{
51 class SFML_AUDIO_API SoundStream : public SoundSource
52{
53public:
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]] 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
Base class defining a sound's properties.
Definition SoundSource.hpp:48
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:154
sf::SoundSource::Status
Status
Enumeration of the sound source states.
Definition SoundSource.hpp:55
sf::SoundStream
Abstract base class for streamed audio sources.
Definition SoundStream.hpp:52
sf::SoundStream::SoundStream
SoundStream(SoundStream &&) noexcept
Move constructor.
sf::SoundStream::~SoundStream
~SoundStream() override
Destructor.
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