SFML - Simple and Fast Multimedia Library

SFML 3.0.2
Loading...
Searching...
No Matches
Sound.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2025 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/SoundSource.hpp>
33
34#include <memory>
35
36#include <cstdlib>
37
38namespace sf
39{
40class Time;
41class SoundBuffer;
42
47 class SFML_AUDIO_API Sound : public SoundSource
48{
49public:
56 explicit Sound(const SoundBuffer& buffer);
57
62 Sound(const SoundBuffer&& buffer) = delete;
63
70 Sound(const Sound& copy);
71
76 ~Sound() override;
77
90 void play() override;
91
101 void pause() override;
102
113 void stop() override;
114
127 void setBuffer(const SoundBuffer& buffer);
128
133 void setBuffer(const SoundBuffer&& buffer) = delete;
134
148 void setLooping(bool loop);
149
163 void setPlayingOffset(Time timeOffset);
164
174 void setEffectProcessor(EffectProcessor effectProcessor) override;
175
182 [[nodiscard]] const SoundBuffer& getBuffer() const;
183
192 [[nodiscard]] bool isLooping() const;
193
202 [[nodiscard]] Time getPlayingOffset() const;
203
210 [[nodiscard]] Status getStatus() const override;
211
220 Sound& operator=(const Sound& right);
221
222private:
223 friend class SoundBuffer;
224
232 void detachBuffer();
233
240 [[nodiscard]] void* getSound() const override;
241
243 // Member data
245 struct Impl;
246 const std::unique_ptr<Impl> m_impl;
247};
248
249} // namespace sf
250
251
Export.hpp
SFML_AUDIO_API
#define SFML_AUDIO_API
Definition Audio/Export.hpp:42
SoundSource.hpp
sf::SoundBuffer
Storage for audio samples defining a sound.
Definition SoundBuffer.hpp:55
sf::SoundSource::SoundSource
SoundSource(const SoundSource &)=default
Copy constructor.
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::Sound::getStatus
Status getStatus() const override
Get the current status of the sound (stopped, paused, playing)
sf::Sound::pause
void pause() override
Pause the sound.
sf::Sound::~Sound
~Sound() override
Destructor.
sf::Sound::setLooping
void setLooping(bool loop)
Set whether or not the sound should loop after reaching the end.
sf::Sound::Sound
Sound(const SoundBuffer &buffer)
Construct the sound with a buffer.
sf::Sound::Sound
Sound(const SoundBuffer &&buffer)=delete
Disallow construction from a temporary sound buffer.
sf::Sound::isLooping
bool isLooping() const
Tell whether or not the sound is in loop mode.
sf::Sound::SoundBuffer
friend class SoundBuffer
Definition Sound.hpp:223
sf::Sound::getPlayingOffset
Time getPlayingOffset() const
Get the current playing position of the sound.
sf::Sound::setBuffer
void setBuffer(const SoundBuffer &buffer)
Set the source buffer containing the audio data to play.
sf::Sound::operator=
Sound & operator=(const Sound &right)
Overload of assignment operator.
sf::Sound::stop
void stop() override
stop playing the sound
sf::Sound::play
void play() override
Start or resume playing the sound.
sf::Sound::setBuffer
void setBuffer(const SoundBuffer &&buffer)=delete
Disallow setting from a temporary sound buffer.
sf::Sound::getBuffer
const SoundBuffer & getBuffer() const
Get the audio buffer attached to the sound.
sf::Sound::setPlayingOffset
void setPlayingOffset(Time timeOffset)
Change the current playing position of the sound.
sf::Sound::setEffectProcessor
void setEffectProcessor(EffectProcessor effectProcessor) override
Set the effect processor to be applied to the sound.
sf::Sound::Sound
Sound(const Sound &copy)
Copy constructor.
sf::Time
Represents a time value.
Definition Time.hpp:42
sf
Definition AudioResource.hpp:36