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-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
33
34#include <memory>
35
36#include <cstdlib>
37
38namespace sf
39{
40class Time;
41class SoundBuffer;
42
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
#define SFML_AUDIO_API
Storage for audio samples defining a sound.
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.
Regular sound that can be played in the audio environment.
Definition Sound.hpp:48
Status getStatus() const override
Get the current status of the sound (stopped, paused, playing)
void pause() override
Pause the sound.
~Sound() override
Destructor.
void setLooping(bool loop)
Set whether or not the sound should loop after reaching the end.
Sound(const SoundBuffer &buffer)
Construct the sound with a buffer.
Sound(const SoundBuffer &&buffer)=delete
Disallow construction from a temporary sound buffer.
bool isLooping() const
Tell whether or not the sound is in loop mode.
Time getPlayingOffset() const
Get the current playing position of the sound.
void setBuffer(const SoundBuffer &buffer)
Set the source buffer containing the audio data to play.
Sound & operator=(const Sound &right)
Overload of assignment operator.
void stop() override
stop playing the sound
void play() override
Start or resume playing the sound.
void setBuffer(const SoundBuffer &&buffer)=delete
Disallow setting from a temporary sound buffer.
const SoundBuffer & getBuffer() const
Get the audio buffer attached to the sound.
void setPlayingOffset(Time timeOffset)
Change the current playing position of the sound.
void setEffectProcessor(EffectProcessor effectProcessor) override
Set the effect processor to be applied to the sound.
Sound(const Sound &copy)
Copy constructor.
Represents a time value.
Definition Time.hpp:42