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
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{
52{
53public:
58 struct Chunk
59 {
60 const std::int16_t* samples{};
61 std::size_t sampleCount{};
62 };
63
68 ~SoundStream() override;
69
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:
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
#define SFML_AUDIO_API
Base class defining a sound's properties.
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.
Status
Enumeration of the sound source states.
Abstract base class for streamed audio sources.
SoundStream(SoundStream &&) noexcept
Move constructor.
~SoundStream() override
Destructor.
Represents a time value.
Definition Time.hpp:42
SoundChannel
Types of sound channels that can be read/written from sound buffers/files.
Structure defining a chunk of audio data to stream.