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-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 <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 {
59 };
60
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
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
#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.
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.
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.
@ Stopped
Sound is not playing.
@ Playing
Sound is playing.
@ Paused
Sound is paused.
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.
Vector3< float > Vector3f
Definition Vector3.hpp:306
Structure defining the properties of a directional cone.
float outerGain
Outer gain.
Angle innerAngle
Inner angle.
Angle outerAngle
Outer angle.