Nebula
Loading...
Searching...
No Matches
Audio::AudioDevice Class Reference

#include <audiodevice.h>

Detailed Description

Central class of the core audio subsystem.

Currently implements Soloud as the audio engine.

Uses which ever audio backend that it is compiled with and that initializes properly.

Audio clips/resources are loaded and shared between audio emitters until their reference count is 0, upon which they are unloaded.

Inherits Core::RefCounted.

Classes

struct  Listener
 

Public Member Functions

 AudioDevice ()
 
 ~AudioDevice ()
 
bool Open ()
 Initialize the audio engine.
 
bool Close ()
 Shutdown the audio engine.
 
void OnFrame ()
 Called per frame to update spatial positions.
 
ClipId LoadClip (Resources::ResourceName const &name)
 Load a soundfile into memory.
 
void UnloadClip (ClipId const id)
 Unload a soundfile.
 
ClipInstanceId Play (ClipId clip, float volume, float pan, bool loop=false, float clock=0.0f)
 Play non-spatial audio clip. Returns the playing clip instance.
 
ClipInstanceId PlaySpatial (ClipId clip, float volume, Math::vec3 const &position, Math::vec3 const &velocity, float minDistance, float maxDistance, bool loop=false, float clock=0.0f)
 Play spatial audio clip that accounts for spatial position when playing. Returns the playing clip instance.
 
void StopInstance (ClipInstanceId id)
 Stop an instance of a clip.
 
void Stop (ClipId id)
 Stop all instances of a clip.
 
bool IsValid (ClipInstanceId id)
 Check if an instance is valid.
 
void UpdatePosition (ClipInstanceId id, Math::point const &pos)
 Update the spatial position of a sound instance in world space.
 
void UpdateVelocity (ClipInstanceId id, Math::vector const &vel)
 Update the spatial velocity of a sound instance.
 
void SetListenerTransform (Math::mat4 const &transform)
 Set the listener transform in world space.
 
void SetListenerVelocity (Math::vector const &velocity)
 Set the listeners velocity.
 
void ResetListener ()
 Reset listener.
 
void SetSpeedOfSound (float value=343.0f)
 Set the speed of sound constant. (default assumes 1 unit is 1 meter)
 
AudioEmitterId CreateAudioEmitter (Resources::ResourceName const &name)
 Load a soundfile into memory.
 
void DestroyAudioEmitter (AudioEmitterId const id)
 Destroy an audio emitter.
 
ClipInstanceId Play (AudioEmitterId id, bool loop=false)
 Play clip. Returns the playing clip instance.
 
void SetSpatialize (AudioEmitterId id, bool value)
 Set whether or not to account for spatial position when playing a sound.
 
void SetPosition (AudioEmitterId id, Math::point const &pos)
 Set spatial position of a sound in world space.
 
void SetVelocity (AudioEmitterId id, Math::vector const &vel)
 Set spatial velocity of a sound.
 
void SetMaxDistance (AudioEmitterId id, float value)
 Set the max audible distance of a sound.
 
void SetMinDistance (AudioEmitterId id, float value)
 Set the min audible distance of a sound.
 
void SetClock (AudioEmitterId id, float value)
 Set min delay between subsequent instances of an emitted sound (value of 0 disables)
 
void SetPan (AudioEmitterId id, float value)
 Set 2D pan for non spatialized sounds. (L = -1.0, R = 1.0)
 
- Public Member Functions inherited from Core::RefCounted
 RefCounted ()
 constructor
 
int GetRefCount () const
 get the current refcount
 
void AddRef ()
 increment refcount by one
 
void Release ()
 decrement refcount and destroy object if refcount is zero
 
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
 
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
 
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
 
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
 
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
 
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
 
const Util::StringGetClassName () const
 get the class name
 
Util::FourCC GetClassFourCC () const
 get the class FourCC code
 

Private Types

enum  EmitterSlot {
  CLIPID , POSITION , VELOCITY , VOLUME ,
  MINDISTANCE , MAXDISTANCE , PAN , SPATIALIZE ,
  CLOCK
}
 
enum  WavAllocator { WAV , REFCOUNT }
 

Private Member Functions

 __DeclareClass (AudioDevice)
 
 __DeclareSingleton (AudioDevice)
 

Private Attributes

Ids::IdAllocator< ClipId, Math::point, Math::vector, float, float, float, float, bool, float > emitterAllocator
 
Ids::IdAllocator< SoLoud::Wav, uintwavs
 Contains all wavs that are currently loaded.
 
Util::Dictionary< Resources::ResourceName, ClipIdclipMap
 resource -> clipid table
 
struct Audio::AudioDevice::Listener listener
 

Additional Inherited Members

- Static Public Member Functions inherited from Core::RefCounted
static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)
 
- Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
 

Member Enumeration Documentation

◆ EmitterSlot

Enumerator
CLIPID 
POSITION 
VELOCITY 
VOLUME 
MINDISTANCE 
MAXDISTANCE 
PAN 
SPATIALIZE 
CLOCK 

◆ WavAllocator

Enumerator
WAV 
REFCOUNT 

Constructor & Destructor Documentation

◆ AudioDevice()

Audio::AudioDevice::AudioDevice ( )

◆ ~AudioDevice()

Audio::AudioDevice::~AudioDevice ( )

Member Function Documentation

◆ __DeclareClass()

Audio::AudioDevice::__DeclareClass ( AudioDevice )
private

◆ __DeclareSingleton()

Audio::AudioDevice::__DeclareSingleton ( AudioDevice )
private

◆ Close()

bool Audio::AudioDevice::Close ( )

Shutdown the audio engine.

◆ CreateAudioEmitter()

AudioEmitterId Audio::AudioDevice::CreateAudioEmitter ( Resources::ResourceName const & name)

Load a soundfile into memory.

◆ DestroyAudioEmitter()

void Audio::AudioDevice::DestroyAudioEmitter ( AudioEmitterId const id)

Destroy an audio emitter.

◆ IsValid()

bool Audio::AudioDevice::IsValid ( ClipInstanceId id)

Check if an instance is valid.

◆ LoadClip()

ClipId Audio::AudioDevice::LoadClip ( Resources::ResourceName const & name)

Load a soundfile into memory.

◆ OnFrame()

void Audio::AudioDevice::OnFrame ( )

Called per frame to update spatial positions.

◆ Open()

bool Audio::AudioDevice::Open ( )

Initialize the audio engine.

◆ Play() [1/2]

ClipInstanceId Audio::AudioDevice::Play ( AudioEmitterId id,
bool loop = false )

Play clip. Returns the playing clip instance.

◆ Play() [2/2]

ClipInstanceId Audio::AudioDevice::Play ( ClipId clip,
float volume,
float pan,
bool loop = false,
float clock = 0.0f )

Play non-spatial audio clip. Returns the playing clip instance.

◆ PlaySpatial()

ClipInstanceId Audio::AudioDevice::PlaySpatial ( ClipId clip,
float volume,
Math::vec3 const & position,
Math::vec3 const & velocity,
float minDistance,
float maxDistance,
bool loop = false,
float clock = 0.0f )

Play spatial audio clip that accounts for spatial position when playing. Returns the playing clip instance.

◆ ResetListener()

void Audio::AudioDevice::ResetListener ( )

Reset listener.

◆ SetClock()

void Audio::AudioDevice::SetClock ( AudioEmitterId id,
float value )

Set min delay between subsequent instances of an emitted sound (value of 0 disables)

◆ SetListenerTransform()

void Audio::AudioDevice::SetListenerTransform ( Math::mat4 const & transform)

Set the listener transform in world space.

◆ SetListenerVelocity()

void Audio::AudioDevice::SetListenerVelocity ( Math::vector const & velocity)

Set the listeners velocity.

◆ SetMaxDistance()

void Audio::AudioDevice::SetMaxDistance ( AudioEmitterId id,
float value )

Set the max audible distance of a sound.

◆ SetMinDistance()

void Audio::AudioDevice::SetMinDistance ( AudioEmitterId id,
float value )

Set the min audible distance of a sound.

◆ SetPan()

void Audio::AudioDevice::SetPan ( AudioEmitterId id,
float value )

Set 2D pan for non spatialized sounds. (L = -1.0, R = 1.0)

◆ SetPosition()

void Audio::AudioDevice::SetPosition ( AudioEmitterId id,
Math::point const & pos )

Set spatial position of a sound in world space.

◆ SetSpatialize()

void Audio::AudioDevice::SetSpatialize ( AudioEmitterId id,
bool value )

Set whether or not to account for spatial position when playing a sound.

◆ SetSpeedOfSound()

void Audio::AudioDevice::SetSpeedOfSound ( float value = 343.0f)

Set the speed of sound constant. (default assumes 1 unit is 1 meter)

◆ SetVelocity()

void Audio::AudioDevice::SetVelocity ( AudioEmitterId id,
Math::vector const & vel )

Set spatial velocity of a sound.

◆ Stop()

void Audio::AudioDevice::Stop ( ClipId id)

Stop all instances of a clip.

◆ StopInstance()

void Audio::AudioDevice::StopInstance ( ClipInstanceId id)

Stop an instance of a clip.

◆ UnloadClip()

void Audio::AudioDevice::UnloadClip ( ClipId const id)

Unload a soundfile.

◆ UpdatePosition()

void Audio::AudioDevice::UpdatePosition ( ClipInstanceId id,
Math::point const & pos )

Update the spatial position of a sound instance in world space.

◆ UpdateVelocity()

void Audio::AudioDevice::UpdateVelocity ( ClipInstanceId id,
Math::vector const & vel )

Update the spatial velocity of a sound instance.

Member Data Documentation

◆ clipMap

Util::Dictionary<Resources::ResourceName, ClipId> Audio::AudioDevice::clipMap
private

resource -> clipid table

◆ emitterAllocator

Ids::IdAllocator<ClipId, Math::point, Math::vector, float, float, float, float, bool, float> Audio::AudioDevice::emitterAllocator
private

◆ listener

struct Audio::AudioDevice::Listener Audio::AudioDevice::listener
private

◆ wavs

Ids::IdAllocator<SoLoud::Wav, uint> Audio::AudioDevice::wavs
private

Contains all wavs that are currently loaded.

refcount will automatically unload wav if it is no longer in use by any emitters


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