SFML 3.0.0

- Main Page
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

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
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
Base class for classes that require an audio device.
Definition AudioResource.hpp:42
sf::SoundSource
Base class defining a sound's properties.
Definition SoundSource.hpp:48
sf::SoundSource::SoundSource
SoundSource(SoundSource &&) noexcept=default
Move constructor.
sf::SoundSource::SoundSource
SoundSource(const SoundSource &)=default
Copy constructor.
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::Status
Status
Enumeration of the sound source states.
Definition SoundSource.hpp:55
sf::Vector3< float >
sf
Definition AudioResource.hpp:36
sf::SoundSource::Cone
Structure defining the properties of a directional cone.
Definition SoundSource.hpp:73
sf::SoundSource::Cone::innerAngle
Angle innerAngle
Inner angle.
Definition SoundSource.hpp:74
sf::SoundSource::Cone::outerAngle
Angle outerAngle
Outer angle.
Definition SoundSource.hpp:75