3DRadSpace 0.1.0Alpha
3DRadSpace is a free, simple to use, rapid application development game engine.
Loading...
Searching...
No Matches
Engine3DRadSpace.Objects.SoundSource Class Reference

Represents a 3D positional sound source that can be placed in the scene, using OpenAL-Soft's 3D audio spatialization. More...

#include <SoundSource.hpp>

Inheritance diagram for Engine3DRadSpace.Objects.SoundSource:
Collaboration diagram for Engine3DRadSpace.Objects.SoundSource:

Public Member Functions

 SoundSource ()
Sound GetSound ()
SoundInstance GetSoundInstance ()
 SoundSource ()
 Default constructor.
 SoundSource (const std::string &name, bool enabled, RefSound sound, const Math::Vector3 &position)
 Constructs a 3D sound source from a numerical asset identifier.
 SoundSource (const std::string &name, bool enabled, const std::filesystem::path &soundFile, const Math::Vector3 &position)
 Constructs a 3D sound source from a file path.
 SoundSource (SoundSource &&) noexcept=default
SoundSource & operator= (SoundSource &&) noexcept=default
void Draw3D () override
 Does nothing, as sound sources are not rendered visually.
float Intersects (const Math::Ray &r) const override
 Tests for intersections with the sound source's bounding volume.
Reflection::UUID GetUUID () const noexcept override
 Gets the UUID of the SoundSource type.
void Initialize () override
 Applies the initial 3D audio parameters (position, velocity, direction, distance/cone attenuation) to the underlying OpenAL-Soft source.
void Load () override
 Loads the sound asset.
void Load (const std::filesystem::path &path) override
 Loads a sound from a specified path.
void Update () override
 Updates the 3D position, velocity and direction of the sound source.
Objects::Gizmos::IGizmo * GetGizmo () const noexcept override
 Returns the gizmo object of this object, used for editor/debug rendering.
void Enable () override
 Plays the sound.
void Disable () override
 Pauses the sound.
bool Switch () override
 Plays the sound if stopped, and vice-versa.
RefSound GetSoundAsset () const noexcept
 Gets the underlying sound asset used by this object.
void SetSoundAsset (RefSound sound) noexcept
 Sets the underlying sound asset used by this object.
float GetVolume () const noexcept
 Gets the gain of the sound source.
void SetVolume (float volume) noexcept
 Sets the gain of the sound source. Range is [0.0, 1.0]. Default is 1.0.
float GetPitch () const noexcept
 Gets the pitch of the sound source.
void SetPitch (float pitch) noexcept
 Sets the pitch of the sound source. Default is 1.0. Range is [0.5, 2.0]. Values outside this range may cause audio distortion.
bool IsLooping () const noexcept
 Gets whether the sound source is looping.
void SetLooping (bool looping) noexcept
 Sets whether the sound source is looping.
Math::Vector3 GetVelocity () const noexcept
 Gets the velocity of the sound source, used by OpenAL-Soft to compute the Doppler effect.
void SetVelocity (const Math::Vector3 &velocity) noexcept
 Sets the velocity of the sound source, used by OpenAL-Soft to compute the Doppler effect.
Math::Vector3 GetDirection () const noexcept
 Gets the direction the sound source is facing, used for directional (cone-shaped) sound emission.
void SetDirection (const Math::Vector3 &direction) noexcept
 Sets the direction the sound source is facing, used for directional (cone-shaped) sound emission.
float GetMaxDistance () const noexcept
 Gets the maximum distance beyond which the sound source is no longer attenuated.
void SetMaxDistance (float dst) noexcept
 Sets the maximum distance beyond which the sound source is no longer attenuated. Default is the maximum representable float value.
float GetReferenceDistance () const noexcept
 Gets the reference distance at which the volume would be at its unattenuated value.
void SetReferenceDistance (float refDst) noexcept
 Sets the reference distance at which the volume would be at its unattenuated value. Default is 1.0.
float GetRolloffFactor () const noexcept
 Gets the rolloff factor, controlling how quickly the sound attenuates with distance.
void SetRolloffFactor (float rollOff) noexcept
 Sets the rolloff factor, controlling how quickly the sound attenuates with distance. Default is 1.0.
float GetConeInnerAngle () const noexcept
 Gets the inner angle, in degrees, of the sound cone within which the sound is emitted at full volume.
void SetConeInnerAngle (float innerAngle) noexcept
 Sets the inner angle, in degrees, of the sound cone within which the sound is emitted at full volume. Default is 360.0 (omnidirectional).
float GetConeOuterAngle () const noexcept
 Gets the outer angle, in degrees, of the sound cone outside of which the sound is attenuated by the cone outer gain.
void SetConeOuterAngle (float outerAngle) noexcept
 Sets the outer angle, in degrees, of the sound cone outside of which the sound is attenuated by the cone outer gain. Default is 360.0 (omnidirectional).
float GetConeOuterGain () const noexcept
 Gets the gain applied to the sound outside the outer cone angle.
void SetConeOuterGain (float outerGain) noexcept
 Sets the gain applied to the sound outside the outer cone angle. Default is 0.0.
Audio::Sound * GetSound () const noexcept
 Gets the underlying sound asset used by this object.
Audio::SoundInstance * GetInstance () const noexcept
 Gets the underlying sound instance used by this object.
 ~SoundSource ()=default
Public Member Functions inherited from Engine3DRadSpace.Objects.InstIObject3D
Matrix4x4 GetModelMatrix ()
float? Intersects (Ray ray)
 InstIObject3D (IntPtr natPtr)
Public Member Functions inherited from Engine3DRadSpace.NatPtrWrapper
virtual void Dispose ()
Public Member Functions inherited from Engine3DRadSpace.Objects.IObject3D
Matrix4x4 GetModelMatrix ()
float? Intersects (Ray ray)
virtual Math::Matrix4x4 GetModelMatrix () const
 Gets the world matrix of this object, considering the entire hierarchy of parent objects.
virtual Math::Matrix4x4 GetLocalMatrix () const
 Gets the local transformation matrix of this object, considering only its own position, rotation, and scale.
virtual Math::BoundingBox GetBoundingBox () const noexcept
 Gets the axis-aligned bounding box of this object in world space. Used for culling and intersections.
 ~IObject3D ()=default
Public Member Functions inherited from Engine3DRadSpace.Objects.IObject
void Enable ()
void Disable ()
bool Switch ()
void Show ()
void Hide ()
bool SwitchVisibility ()
IObject GetChild (int idx)
int GetChildrenCount ()
void InternalInitialize (IGame *game)
 Called by ObjectsList to set the _game Game instance. If there are objects manually managed, this MUST be called before Initialize or EditorInitialize.
Graphics::IGraphicsDevice * GetGraphicsDeviceHandle () const noexcept
 Returns the graphics device handle associated with this object.
IGame * GetGame () const noexcept
 Gets the game that this object belongs to.
IObject * operator[] (size_t idxChild) const
 Returns the idx-th child of this object.
IObject * GetParent () const noexcept
 Returns the parent of this object.
void SetParent (IObject *newParent) noexcept
 Sets the parent of this object.
bool HasParent () const noexcept
 Checks if this object has a parent.
size_t GetChildrenCount () const noexcept
 Returns the number of children of this object.
virtual void Show ()
 Shows this object.
virtual void Hide ()
 Hides this object.
virtual bool SwitchVisibility ()
 Switches the visibility state of this object.
void Uninitialize () override
 Called before the object has the destructor called.
virtual ~IObject ()
Public Member Functions inherited from Engine3DRadSpace.IInitializable
void Initialize ()
virtual ~IInitializable ()=default
Public Member Functions inherited from Engine3DRadSpace.IUpdateable
void Update ()
virtual ~IUpdateable ()=default
Public Member Functions inherited from Engine3DRadSpace.ILoadable
void Load ()
void Load (string path)
virtual ~ILoadable ()=default
Public Member Functions inherited from Engine3DRadSpace.IDrawable3D
void Draw3D ()
virtual ~IDrawable3D ()=default

Properties

uint SoundID [get, set]
float Volume [get, set]
float Pitch [get, set]
bool Looping [get, set]
unsafe Vector3 Velocity [get, set]
unsafe Vector3 Direction [get, set]
float MaxDistance [get, set]
float ReferenceDistance [get, set]
float RolloffFactor [get, set]
float ConeInnerAngle [get, set]
float ConeOuterAngle [get, set]
float ConeOuterGain [get, set]
Properties inherited from Engine3DRadSpace.Objects.InstIObject3D
Vector3 Position [get, set]
Vector3 RotationCenter [get, set]
Quaternion Rotation [get, set]
Vector3 Scale [get, set]
Properties inherited from Engine3DRadSpace.NatPtrWrapper
IntPtr Handle [get]
Properties inherited from Engine3DRadSpace.Objects.IObject3D
Vector3 Position [get, set]
Vector3 RotationCenter [get, set]
Quaternion Rotation [get, set]
Vector3 Scale [get, set]
Properties inherited from Engine3DRadSpace.Objects.IObject
string Name [get, set]
bool Enabled [get, set]
 Is this object enabled?
bool Visible [get, set]
 Is this object visible?
Reflection.UUID UUID [get]
IGame Game [get]
IGraphicsDevice GraphicsDevice [get]
IGizmo Gizmo [get]
ObjectCollection Children [get]
IObject Parent [get, set]

Additional Inherited Members

Public Attributes inherited from Engine3DRadSpace.Objects.IObject3D
Math::Vector3 Position
 Position in world space of this object.
Math::Vector3 RotationCenter
 Rotation pivot.
Math::Quaternion Rotation
 Rotation of this object. Default is (0,0,0,1) (identity quaternion).
Math::Vector3 Scale
 Scale of this object. Default is (1,1,1).
bool PostRender = false
 Forces a second draw pass after the main rendering passes completes.
Public Attributes inherited from Engine3DRadSpace.Objects.IObject
std::string Name
 Name of the object.
ChildObjectCollection Children
 Children of this object.
Protected Member Functions inherited from Engine3DRadSpace.NatPtrWrapper
 NatPtrWrapper (IntPtr handle, Action< IntPtr > fnDestroy)
 NatPtrWrapper (Action< IntPtr > fnDestroy)
void Reset (IntPtr newObj)
void Dispose (bool disposing)
Protected Member Functions inherited from Engine3DRadSpace.Objects.IObject3D
 IObject3D (const std::string &name="", bool enabled=false, bool visible=false, const Math::Vector3 &pos=Math::Vector3::Zero(), const Math::Vector3 &pivot=Math::Vector3::Zero(), const Math::Quaternion &rotation=Math::Quaternion(), const Math::Vector3 &scale=Math::Vector3::One())
 IObject3D (const IObject3D &) noexcept=delete
IObject3D & operator= (const IObject3D &) noexcept=delete
 IObject3D (IObject3D &&) noexcept=default
IObject3D & operator= (IObject3D &&) noexcept=default
Protected Member Functions inherited from Engine3DRadSpace.Objects.IObject
 IObject (const std::string &name="Empty", bool enabled=false, bool visible=false)
 Default constructor used for reflection. Objects created with this constructor are initially invalid, until internalInitialize() is called.
 IObject (const IObject &) noexcept=delete
IObject & operator= (const IObject &) noexcept=delete
 IObject (IObject &&) noexcept=default
IObject & operator= (IObject &&) noexcept=default
Protected Member Functions inherited from Engine3DRadSpace.IInitializable
 IInitializable ()=default
 IInitializable (const IInitializable &) noexcept=default
IInitializable & operator= (const IInitializable &) noexcept=default
 IInitializable (IInitializable &&) noexcept=default
IInitializable & operator= (IInitializable &&) noexcept=default
Protected Member Functions inherited from Engine3DRadSpace.IUpdateable
 IUpdateable ()=default
 IUpdateable (const IUpdateable &) noexcept=default
IUpdateable & operator= (const IUpdateable &) noexcept=default
 IUpdateable (IUpdateable &&) noexcept=default
IUpdateable & operator= (IUpdateable &&) noexcept=default
Protected Member Functions inherited from Engine3DRadSpace.ILoadable
 ILoadable ()=default
 ILoadable (const ILoadable &) noexcept=default
ILoadable & operator= (const ILoadable &) noexcept=default
 ILoadable (ILoadable &&) noexcept=default
ILoadable & operator= (ILoadable &&) noexcept=default
Protected Member Functions inherited from Engine3DRadSpace.IDrawable3D
 IDrawable3D ()=default
 IDrawable3D (const IDrawable3D &)=default
IDrawable3D & operator= (const IDrawable3D &)=default
 IDrawable3D (IDrawable3D &&) noexcept=default
IDrawable3D & operator= (IDrawable3D &&) noexcept=default
Protected Attributes inherited from Engine3DRadSpace.NatPtrWrapper
IntPtr _handle
bool _disposed
Protected Attributes inherited from Engine3DRadSpace.Objects.IObject
IGame * _game = nullptr
Graphics::IGraphicsDevice * _device = nullptr
IObject * _parent = nullptr

Detailed Description

Represents a 3D positional sound source that can be placed in the scene, using OpenAL-Soft's 3D audio spatialization.

Constructor & Destructor Documentation

◆ SoundSource() [1/5]

SoundSource.SoundSource ( )
inline

◆ SoundSource() [2/5]

◆ SoundSource() [3/5]

Engine3DRadSpace.Objects.SoundSource.SoundSource ( const std::string & name,
bool enabled,
RefSound sound,
const Math::Vector3 & position )

Constructs a 3D sound source from a numerical asset identifier.

Parameters
nameName of the object
enabledIs this object enabled?
soundNumerical asset identifier for the sound
positionInitial 3D position of the sound source

◆ SoundSource() [4/5]

Engine3DRadSpace.Objects.SoundSource.SoundSource ( const std::string & name,
bool enabled,
const std::filesystem::path & soundFile,
const Math::Vector3 & position )

Constructs a 3D sound source from a file path.

Parameters
nameName of the object
enabledIs this object enabled?
soundFileFile path to the sound(OGG or WAV)
positionInitial 3D position of the sound source

◆ SoundSource() [5/5]

◆ ~SoundSource()

Engine3DRadSpace.Objects.SoundSource.~SoundSource ( )
default

Member Function Documentation

◆ Disable()

void SoundSource::Disable ( )
overridevirtual

Pauses the sound.

Reimplemented from Engine3DRadSpace.Objects.IObject.

◆ Draw3D()

void Engine3DRadSpace.Objects.SoundSource.Draw3D ( )
overridevirtual

Does nothing, as sound sources are not rendered visually.

Implements Engine3DRadSpace.IDrawable3D.

◆ Enable()

void SoundSource::Enable ( )
overridevirtual

Plays the sound.

Reimplemented from Engine3DRadSpace.Objects.IObject.

◆ GetConeInnerAngle()

float Engine3DRadSpace.Objects.SoundSource.GetConeInnerAngle ( ) const
noexcept

Gets the inner angle, in degrees, of the sound cone within which the sound is emitted at full volume.

Returns
Cone inner angle, in degrees

◆ GetConeOuterAngle()

float Engine3DRadSpace.Objects.SoundSource.GetConeOuterAngle ( ) const
noexcept

Gets the outer angle, in degrees, of the sound cone outside of which the sound is attenuated by the cone outer gain.

Returns
Cone outer angle, in degrees

◆ GetConeOuterGain()

float Engine3DRadSpace.Objects.SoundSource.GetConeOuterGain ( ) const
noexcept

Gets the gain applied to the sound outside the outer cone angle.

Returns
Cone outer gain

◆ GetDirection()

Math::Vector3 Engine3DRadSpace.Objects.SoundSource.GetDirection ( ) const
noexcept

Gets the direction the sound source is facing, used for directional (cone-shaped) sound emission.

Returns
Direction vector

◆ GetGizmo()

Objects::Gizmos::IGizmo * SoundSource::GetGizmo ( ) const
overridevirtualnoexcept

Returns the gizmo object of this object, used for editor/debug rendering.

Returns
Pointer to a gizmo instance. Null if no gizmo is associated with this object.

Implements Engine3DRadSpace.Objects.IObject.

◆ GetInstance()

SoundInstance * SoundSource::GetInstance ( ) const
noexcept

Gets the underlying sound instance used by this object.

Returns
Pointer to the underlying sound instance

◆ GetMaxDistance()

float Engine3DRadSpace.Objects.SoundSource.GetMaxDistance ( ) const
noexcept

Gets the maximum distance beyond which the sound source is no longer attenuated.

Returns
Maximum distance

◆ GetPitch()

float Engine3DRadSpace.Objects.SoundSource.GetPitch ( ) const
noexcept

Gets the pitch of the sound source.

Returns
Pitch

◆ GetReferenceDistance()

float Engine3DRadSpace.Objects.SoundSource.GetReferenceDistance ( ) const
noexcept

Gets the reference distance at which the volume would be at its unattenuated value.

Returns
Reference distance

◆ GetRolloffFactor()

float Engine3DRadSpace.Objects.SoundSource.GetRolloffFactor ( ) const
noexcept

Gets the rolloff factor, controlling how quickly the sound attenuates with distance.

Returns
Rolloff factor

◆ GetSound() [1/2]

Sound Engine3DRadSpace.Objects.SoundSource.GetSound ( )
inline

◆ GetSound() [2/2]

Sound * SoundSource::GetSound ( ) const
noexcept

Gets the underlying sound asset used by this object.

Returns
Pointer to the underlying sound asset

◆ GetSoundAsset()

RefSound Engine3DRadSpace.Objects.SoundSource.GetSoundAsset ( ) const
noexcept

Gets the underlying sound asset used by this object.

Returns
Numerical reference to the sound asset

◆ GetSoundInstance()

SoundInstance Engine3DRadSpace.Objects.SoundSource.GetSoundInstance ( )
inline

◆ GetUUID()

Reflection::UUID SoundSource::GetUUID ( ) const
overridevirtualnoexcept

Gets the UUID of the SoundSource type.

Returns
{...}

Implements Engine3DRadSpace.Objects.IObject.

◆ GetVelocity()

Math::Vector3 Engine3DRadSpace.Objects.SoundSource.GetVelocity ( ) const
noexcept

Gets the velocity of the sound source, used by OpenAL-Soft to compute the Doppler effect.

Returns
Velocity vector

◆ GetVolume()

float Engine3DRadSpace.Objects.SoundSource.GetVolume ( ) const
noexcept

Gets the gain of the sound source.

Returns
Volume

◆ Initialize()

void SoundSource::Initialize ( )
overridevirtual

Applies the initial 3D audio parameters (position, velocity, direction, distance/cone attenuation) to the underlying OpenAL-Soft source.

Implements Engine3DRadSpace.IInitializable.

◆ Intersects()

float SoundSource::Intersects ( const Math::Ray & r) const
overridevirtual

Tests for intersections with the sound source's bounding volume.

Parameters
rRay to test against
Returns
Distance to the intersection point, or a negative value if there is no intersection

Implements Engine3DRadSpace.Objects.IObject3D.

◆ IsLooping()

bool Engine3DRadSpace.Objects.SoundSource.IsLooping ( ) const
noexcept

Gets whether the sound source is looping.

Returns
True if the sound source is looping, false otherwise

◆ Load() [1/2]

void SoundSource::Load ( )
overridevirtual

Loads the sound asset.

Implements Engine3DRadSpace.ILoadable.

◆ Load() [2/2]

void SoundSource::Load ( const std::filesystem::path & path)
overridevirtual

Loads a sound from a specified path.

Parameters
pathWAV or OGG file

Implements Engine3DRadSpace.ILoadable.

◆ operator=()

SoundSource & Engine3DRadSpace.Objects.SoundSource.operator= ( SoundSource && )
defaultnoexcept

◆ SetConeInnerAngle()

void Engine3DRadSpace.Objects.SoundSource.SetConeInnerAngle ( float innerAngle)
noexcept

Sets the inner angle, in degrees, of the sound cone within which the sound is emitted at full volume. Default is 360.0 (omnidirectional).

Parameters
innerAngleCone inner angle, in degrees

◆ SetConeOuterAngle()

void Engine3DRadSpace.Objects.SoundSource.SetConeOuterAngle ( float outerAngle)
noexcept

Sets the outer angle, in degrees, of the sound cone outside of which the sound is attenuated by the cone outer gain. Default is 360.0 (omnidirectional).

Parameters
outerAngleCone outer angle, in degrees

◆ SetConeOuterGain()

void Engine3DRadSpace.Objects.SoundSource.SetConeOuterGain ( float outerGain)
noexcept

Sets the gain applied to the sound outside the outer cone angle. Default is 0.0.

Parameters
outerGainCone outer gain

◆ SetDirection()

void Engine3DRadSpace.Objects.SoundSource.SetDirection ( const Math::Vector3 & direction)
noexcept

Sets the direction the sound source is facing, used for directional (cone-shaped) sound emission.

Parameters
directionDirection vector

◆ SetLooping()

void Engine3DRadSpace.Objects.SoundSource.SetLooping ( bool looping)
noexcept

Sets whether the sound source is looping.

Parameters
loopingTrue to make the sound source loop, false otherwise

◆ SetMaxDistance()

void Engine3DRadSpace.Objects.SoundSource.SetMaxDistance ( float dst)
noexcept

Sets the maximum distance beyond which the sound source is no longer attenuated. Default is the maximum representable float value.

Parameters
dstMaximum distance

◆ SetPitch()

void Engine3DRadSpace.Objects.SoundSource.SetPitch ( float pitch)
noexcept

Sets the pitch of the sound source. Default is 1.0. Range is [0.5, 2.0]. Values outside this range may cause audio distortion.

Parameters
pitchPitch

◆ SetReferenceDistance()

void Engine3DRadSpace.Objects.SoundSource.SetReferenceDistance ( float refDst)
noexcept

Sets the reference distance at which the volume would be at its unattenuated value. Default is 1.0.

Parameters
refDstReference distance

◆ SetRolloffFactor()

void Engine3DRadSpace.Objects.SoundSource.SetRolloffFactor ( float rollOff)
noexcept

Sets the rolloff factor, controlling how quickly the sound attenuates with distance. Default is 1.0.

Parameters
rollOffRolloff factor

◆ SetSoundAsset()

void Engine3DRadSpace.Objects.SoundSource.SetSoundAsset ( RefSound sound)
noexcept

Sets the underlying sound asset used by this object.

Parameters
soundNumerical reference to the sound asset

◆ SetVelocity()

void Engine3DRadSpace.Objects.SoundSource.SetVelocity ( const Math::Vector3 & velocity)
noexcept

Sets the velocity of the sound source, used by OpenAL-Soft to compute the Doppler effect.

Parameters
velocityVelocity vector

◆ SetVolume()

void Engine3DRadSpace.Objects.SoundSource.SetVolume ( float volume)
noexcept

Sets the gain of the sound source. Range is [0.0, 1.0]. Default is 1.0.

Parameters
volumeVolume

◆ Switch()

bool SoundSource::Switch ( )
overridevirtual

Plays the sound if stopped, and vice-versa.

Reimplemented from Engine3DRadSpace.Objects.IObject.

◆ Update()

void SoundSource::Update ( )
overridevirtual

Updates the 3D position, velocity and direction of the sound source.

Implements Engine3DRadSpace.IUpdateable.

Property Documentation

◆ ConeInnerAngle

float Engine3DRadSpace.Objects.SoundSource.ConeInnerAngle
getset

◆ ConeOuterAngle

float Engine3DRadSpace.Objects.SoundSource.ConeOuterAngle
getset

◆ ConeOuterGain

float Engine3DRadSpace.Objects.SoundSource.ConeOuterGain
getset

◆ Direction

unsafe Vector3 Engine3DRadSpace.Objects.SoundSource.Direction
getset

◆ Looping

bool Engine3DRadSpace.Objects.SoundSource.Looping
getset

◆ MaxDistance

float Engine3DRadSpace.Objects.SoundSource.MaxDistance
getset

◆ Pitch

float Engine3DRadSpace.Objects.SoundSource.Pitch
getset

◆ ReferenceDistance

float Engine3DRadSpace.Objects.SoundSource.ReferenceDistance
getset

◆ RolloffFactor

float Engine3DRadSpace.Objects.SoundSource.RolloffFactor
getset

◆ SoundID

uint Engine3DRadSpace.Objects.SoundSource.SoundID
getset

◆ Velocity

unsafe Vector3 Engine3DRadSpace.Objects.SoundSource.Velocity
getset

◆ Volume

float Engine3DRadSpace.Objects.SoundSource.Volume
getset

The documentation for this class was generated from the following files: