SFML 3.1.0
Loading...
Searching...
No Matches
SoundSource.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/AudioResource.hpp>
33
34#include <SFML/System/Angle.hpp>
35#include <SFML/System/Vector3.hpp>
36
37#include <functional>
38
39
40 namespace sf
41{
42// NOLINTBEGIN(readability-make-member-function-const)
47 class SFML_AUDIO_API SoundSource : protected AudioResource
48{
49 public:
54 enum class Status
55 {
56 Stopped,
57 Paused,
58 Playing
59 };
60
72 struct Cone
73 {
74 Angle innerAngle;
75 Angle outerAngle;
76 float outerGain{};
77 };
78
160 using EffectProcessor = std::function<
161 void(const float* inputFrames, unsigned int& inputFrameCount, float* outputFrames, unsigned int& outputFrameCount, unsigned int frameChannelCount)>;
162
167 SoundSource(const SoundSource&) = default;
168
173 SoundSource(SoundSource&&) noexcept = default;
174
179 SoundSource& operator=(SoundSource&&) noexcept = default;
180
185 virtual ~SoundSource() = default;
186
201 void setPitch(float pitch);
202
216 void setPan(float pan);
217
229 void setVolume(float volume);
230
244 void setSpatializationEnabled(bool enabled);
245
258 void setPosition(const Vector3f& position);
259
273 void setDirection(const Vector3f& direction);
274
286 void setCone(const Cone& cone);
287
301 void setVelocity(const Vector3f& velocity);
302
314 void setDopplerFactor(float factor);
315
331 void setDirectionalAttenuationFactor(float factor);
332
347 void setRelativeToListener(bool relative);
348
364 void setMinDistance(float distance);
365
381 void setMaxDistance(float distance);
382
395 void setMinGain(float gain);
396
409 void setMaxGain(float gain);
410
428 void setAttenuation(float attenuation);
429
439 virtual void setEffectProcessor(EffectProcessor effectProcessor);
440
449 [[nodiscard]] float getPitch() const;
450
459 [[nodiscard]] float getPan() const;
460
469 [[nodiscard]] float getVolume() const;
470
479 [[nodiscard]] bool isSpatializationEnabled() const;
480
489 [[nodiscard]] Vector3f getPosition() const;
490
499 [[nodiscard]] Vector3f getDirection() const;
500
509 [[nodiscard]] Cone getCone() const;
510
519 [[nodiscard]] Vector3f getVelocity() const;
520
529 [[nodiscard]] float getDopplerFactor() const;
530
539 [[nodiscard]] float getDirectionalAttenuationFactor() const;
540
550 [[nodiscard]] bool isRelativeToListener() const;
551
560 [[nodiscard]] float getMinDistance() const;
561
570 [[nodiscard]] float getMaxDistance() const;
571
580 [[nodiscard]] float getMinGain() const;
581
590 [[nodiscard]] float getMaxGain() const;
591
600 [[nodiscard]] float getAttenuation() const;
601
610 SoundSource& operator=(const SoundSource& right);
611
622 virtual void play() = 0;
623
633 virtual void pause() = 0;
634
645 virtual void stop() = 0;
646
653 [[nodiscard]] virtual Status getStatus() const = 0;
654
655protected:
662 SoundSource() = default;
663
664private:
671 [[nodiscard]] virtual void* getSound() const = 0;
672};
673
674// NOLINTEND(readability-make-member-function-const)
675} // namespace sf
676
677
Angle.hpp
AudioResource.hpp
Export.hpp
SFML_AUDIO_API
#define SFML_AUDIO_API
Definition Audio/Export.hpp:42
Vector3.hpp
sf::Angle
Represents an angle value.
Definition Angle.hpp:35
sf::AudioResource::AudioResource
AudioResource(const AudioResource &)=default
Copy constructor.
sf::SoundSource::getVolume
float getVolume() const
Get the volume of the sound.
sf::SoundSource::stop
virtual void stop()=0
Stop playing the sound source.
sf::SoundSource::getMinGain
float getMinGain() const
Get the minimum gain of the sound.
sf::SoundSource::getPan
float getPan() const
Get the pan of the sound.
sf::SoundSource::setPosition
void setPosition(const Vector3f &position)
Set the 3D position of the sound in the audio scene.
sf::SoundSource::pause
virtual void pause()=0
Pause the sound source.
sf::SoundSource::setDopplerFactor
void setDopplerFactor(float factor)
Set the doppler factor of the sound.
sf::SoundSource::getDirection
Vector3f getDirection() const
Get the 3D direction of the sound in the audio scene.
sf::SoundSource::setVolume
void setVolume(float volume)
Set the volume of the sound.
sf::SoundSource::setVelocity
void setVelocity(const Vector3f &velocity)
Set the 3D velocity of the sound in the audio scene.
sf::SoundSource::getMaxDistance
float getMaxDistance() const
Get the maximum distance of the sound.
sf::SoundSource::getPitch
float getPitch() const
Get the pitch of the sound.
sf::SoundSource::setMaxDistance
void setMaxDistance(float distance)
Set the maximum distance of the sound.
sf::SoundSource::SoundSource
SoundSource(SoundSource &&) noexcept=default
Move constructor.
sf::SoundSource::getMinDistance
float getMinDistance() const
Get the minimum distance of the sound.
sf::SoundSource::setSpatializationEnabled
void setSpatializationEnabled(bool enabled)
Set whether spatialization of the sound is enabled.
sf::SoundSource::SoundSource
SoundSource(const SoundSource &)=default
Copy constructor.
sf::SoundSource::play
virtual void play()=0
Start or resume playing the sound source.
sf::SoundSource::getMaxGain
float getMaxGain() const
Get the maximum gain of the sound.
sf::SoundSource::setPitch
void setPitch(float pitch)
Set the pitch of the sound.
sf::SoundSource::setMinDistance
void setMinDistance(float distance)
Set the minimum distance of the sound.
sf::SoundSource::isSpatializationEnabled
bool isSpatializationEnabled() const
Tell whether spatialization of the sound is enabled.
sf::SoundSource::getAttenuation
float getAttenuation() const
Get the attenuation factor of the sound.
sf::SoundSource::getPosition
Vector3f getPosition() const
Get the 3D position of the sound in the audio scene.
sf::SoundSource::setEffectProcessor
virtual void setEffectProcessor(EffectProcessor effectProcessor)
Set the effect processor to be applied to the sound.
sf::SoundSource::getVelocity
Vector3f getVelocity() const
Get the 3D velocity of the sound in the audio scene.
sf::SoundSource::getDirectionalAttenuationFactor
float getDirectionalAttenuationFactor() const
Get the directional attenuation factor of the sound.
sf::SoundSource::setAttenuation
void setAttenuation(float attenuation)
Set the attenuation factor of the sound.
sf::SoundSource::setMaxGain
void setMaxGain(float gain)
Set the maximum gain of the sound.
sf::SoundSource::getStatus
virtual Status getStatus() const =0
Get the current status of the sound (stopped, paused, playing).
sf::SoundSource::setCone
void setCone(const Cone &cone)
Set the cone properties of the sound in the audio scene.
sf::SoundSource::Status
Status
Enumeration of the sound source states.
Definition SoundSource.hpp:55
sf::SoundSource::setDirection
void setDirection(const Vector3f &direction)
Set the 3D direction of the sound in the audio scene.
sf::SoundSource::setRelativeToListener
void setRelativeToListener(bool relative)
Make the sound's position relative to the listener or absolute.
sf::SoundSource::setPan
void setPan(float pan)
Set the pan of the sound.
sf::SoundSource::isRelativeToListener
bool isRelativeToListener() const
Tell whether the sound's position is relative to the listener or is absolute.
sf::SoundSource::getCone
Cone getCone() const
Get the cone properties of the sound in the audio scene.
sf::SoundSource::setMinGain
void setMinGain(float gain)
Set the minimum gain of the sound.
sf::SoundSource::setDirectionalAttenuationFactor
void setDirectionalAttenuationFactor(float factor)
Set the directional attenuation factor of the sound.
sf::SoundSource::getDopplerFactor
float getDopplerFactor() const
Get the doppler factor of the sound.
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
Definition AudioResource.hpp:36
sf::Vector3f
Vector3< float > Vector3f
Definition Vector3.hpp:309
sf::SoundSource::Cone
Structure defining the properties of a directional cone.
Definition SoundSource.hpp:73
sf::SoundSource::Cone::outerGain
float outerGain
Outer gain.
Definition SoundSource.hpp:76
sf::SoundSource::Cone::innerAngle
Angle innerAngle
Inner angle.
Definition SoundSource.hpp:74
sf::SoundSource::Cone::outerAngle
Angle outerAngle
Outer angle.
Definition SoundSource.hpp:75