SFML 3.0.2
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-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/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
154 using EffectProcessor = std::function<
155 void(const float* inputFrames, unsigned int& inputFrameCount, float* outputFrames, unsigned int& outputFrameCount, unsigned int frameChannelCount)>;
156
161 SoundSource(const SoundSource&) = default;
162
167 SoundSource(SoundSource&&) noexcept = default;
168
173 SoundSource& operator=(SoundSource&&) noexcept = default;
174
179 virtual ~SoundSource() = default;
180
195 void setPitch(float pitch);
196
210 void setPan(float pan);
211
223 void setVolume(float volume);
224
238 void setSpatializationEnabled(bool enabled);
239
252 void setPosition(const Vector3f& position);
253
267 void setDirection(const Vector3f& direction);
268
280 void setCone(const Cone& cone);
281
295 void setVelocity(const Vector3f& velocity);
296
308 void setDopplerFactor(float factor);
309
325 void setDirectionalAttenuationFactor(float factor);
326
341 void setRelativeToListener(bool relative);
342
358 void setMinDistance(float distance);
359
375 void setMaxDistance(float distance);
376
389 void setMinGain(float gain);
390
403 void setMaxGain(float gain);
404
422 void setAttenuation(float attenuation);
423
433 virtual void setEffectProcessor(EffectProcessor effectProcessor);
434
443 [[nodiscard]] float getPitch() const;
444
453 [[nodiscard]] float getPan() const;
454
463 [[nodiscard]] float getVolume() const;
464
473 [[nodiscard]] bool isSpatializationEnabled() const;
474
483 [[nodiscard]] Vector3f getPosition() const;
484
493 [[nodiscard]] Vector3f getDirection() const;
494
503 [[nodiscard]] Cone getCone() const;
504
513 [[nodiscard]] Vector3f getVelocity() const;
514
523 [[nodiscard]] float getDopplerFactor() const;
524
533 [[nodiscard]] float getDirectionalAttenuationFactor() const;
534
544 [[nodiscard]] bool isRelativeToListener() const;
545
554 [[nodiscard]] float getMinDistance() const;
555
564 [[nodiscard]] float getMaxDistance() const;
565
574 [[nodiscard]] float getMinGain() const;
575
584 [[nodiscard]] float getMaxGain() const;
585
594 [[nodiscard]] float getAttenuation() const;
595
604 SoundSource& operator=(const SoundSource& right);
605
616 virtual void play() = 0;
617
627 virtual void pause() = 0;
628
639 virtual void stop() = 0;
640
647 [[nodiscard]] virtual Status getStatus() const = 0;
648
649protected:
656 SoundSource() = default;
657
658private:
665 [[nodiscard]] virtual void* getSound() const = 0;
666};
667
668// NOLINTEND(readability-make-member-function-const)
669} // namespace sf
670
671
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::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::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::Status::Stopped
@ Stopped
Sound is not playing.
Definition SoundSource.hpp:56
sf::SoundSource::Status::Playing
@ Playing
Sound is playing.
Definition SoundSource.hpp:58
sf::SoundSource::Status::Paused
@ Paused
Sound is paused.
Definition SoundSource.hpp:57
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
Definition AudioResource.hpp:36
sf::Vector3f
Vector3< float > Vector3f
Definition Vector3.hpp:306
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