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
33
34#include <SFML/System/Angle.hpp>
36
37#include <functional>
38
39
40namespace sf
41{
42// NOLINTBEGIN(readability-make-member-function-const)
48{
49public:
54 enum class Status
55 {
56 Stopped,
57 Paused,
58 Playing
59 };
60
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
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
#define SFML_AUDIO_API
Represents an angle value.
Definition Angle.hpp:35
AudioResource(const AudioResource &)=default
Copy constructor.
float getVolume() const
Get the volume of the sound.
virtual void stop()=0
Stop playing the sound source.
float getMinGain() const
Get the minimum gain of the sound.
float getPan() const
Get the pan of the sound.
void setPosition(const Vector3f &position)
Set the 3D position of the sound in the audio scene.
virtual void pause()=0
Pause the sound source.
void setDopplerFactor(float factor)
Set the doppler factor of the sound.
Vector3f getDirection() const
Get the 3D direction of the sound in the audio scene.
void setVolume(float volume)
Set the volume of the sound.
void setVelocity(const Vector3f &velocity)
Set the 3D velocity of the sound in the audio scene.
float getMaxDistance() const
Get the maximum distance of the sound.
float getPitch() const
Get the pitch of the sound.
void setMaxDistance(float distance)
Set the maximum distance of the sound.
SoundSource(SoundSource &&) noexcept=default
Move constructor.
float getMinDistance() const
Get the minimum distance of the sound.
void setSpatializationEnabled(bool enabled)
Set whether spatialization of the sound is enabled.
SoundSource(const SoundSource &)=default
Copy constructor.
virtual void play()=0
Start or resume playing the sound source.
float getMaxGain() const
Get the maximum gain of the sound.
void setPitch(float pitch)
Set the pitch of the sound.
void setMinDistance(float distance)
Set the minimum distance of the sound.
bool isSpatializationEnabled() const
Tell whether spatialization of the sound is enabled.
float getAttenuation() const
Get the attenuation factor of the sound.
Vector3f getPosition() const
Get the 3D position of the sound in the audio scene.
virtual void setEffectProcessor(EffectProcessor effectProcessor)
Set the effect processor to be applied to the sound.
Vector3f getVelocity() const
Get the 3D velocity of the sound in the audio scene.
float getDirectionalAttenuationFactor() const
Get the directional attenuation factor of the sound.
void setAttenuation(float attenuation)
Set the attenuation factor of the sound.
void setMaxGain(float gain)
Set the maximum gain of the sound.
virtual Status getStatus() const =0
Get the current status of the sound (stopped, paused, playing).
void setCone(const Cone &cone)
Set the cone properties of the sound in the audio scene.
Status
Enumeration of the sound source states.
void setDirection(const Vector3f &direction)
Set the 3D direction of the sound in the audio scene.
void setRelativeToListener(bool relative)
Make the sound's position relative to the listener or absolute.
void setPan(float pan)
Set the pan of the sound.
bool isRelativeToListener() const
Tell whether the sound's position is relative to the listener or is absolute.
Cone getCone() const
Get the cone properties of the sound in the audio scene.
void setMinGain(float gain)
Set the minimum gain of the sound.
void setDirectionalAttenuationFactor(float factor)
Set the directional attenuation factor of the sound.
float getDopplerFactor() const
Get the doppler factor of the sound.
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.
Vector3< float > Vector3f
Definition Vector3.hpp:309
Structure defining the properties of a directional cone.
float outerGain
Outer gain.
Angle innerAngle
Inner angle.
Angle outerAngle
Outer angle.