Nebula
|
#include <audiodevice.h>
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::String & | GetClassName () 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, uint > | wavs |
Contains all wavs that are currently loaded. | |
Util::Dictionary< Resources::ResourceName, ClipId > | clipMap |
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) | |
|
private |
|
private |
Audio::AudioDevice::AudioDevice | ( | ) |
Audio::AudioDevice::~AudioDevice | ( | ) |
|
private |
|
private |
bool Audio::AudioDevice::Close | ( | ) |
Shutdown the audio engine.
AudioEmitterId Audio::AudioDevice::CreateAudioEmitter | ( | Resources::ResourceName const & | name | ) |
Load a soundfile into memory.
void Audio::AudioDevice::DestroyAudioEmitter | ( | AudioEmitterId const | id | ) |
Destroy an audio emitter.
bool Audio::AudioDevice::IsValid | ( | ClipInstanceId | id | ) |
Check if an instance is valid.
ClipId Audio::AudioDevice::LoadClip | ( | Resources::ResourceName const & | name | ) |
Load a soundfile into memory.
void Audio::AudioDevice::OnFrame | ( | ) |
Called per frame to update spatial positions.
bool Audio::AudioDevice::Open | ( | ) |
Initialize the audio engine.
ClipInstanceId Audio::AudioDevice::Play | ( | AudioEmitterId | id, |
bool | loop = false ) |
Play clip. Returns the playing clip instance.
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.
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.
void Audio::AudioDevice::ResetListener | ( | ) |
Reset listener.
void Audio::AudioDevice::SetClock | ( | AudioEmitterId | id, |
float | value ) |
Set min delay between subsequent instances of an emitted sound (value of 0 disables)
void Audio::AudioDevice::SetListenerTransform | ( | Math::mat4 const & | transform | ) |
Set the listener transform in world space.
void Audio::AudioDevice::SetListenerVelocity | ( | Math::vector const & | velocity | ) |
Set the listeners velocity.
void Audio::AudioDevice::SetMaxDistance | ( | AudioEmitterId | id, |
float | value ) |
Set the max audible distance of a sound.
void Audio::AudioDevice::SetMinDistance | ( | AudioEmitterId | id, |
float | value ) |
Set the min audible distance of a sound.
void Audio::AudioDevice::SetPan | ( | AudioEmitterId | id, |
float | value ) |
Set 2D pan for non spatialized sounds. (L = -1.0, R = 1.0)
void Audio::AudioDevice::SetPosition | ( | AudioEmitterId | id, |
Math::point const & | pos ) |
Set spatial position of a sound in world space.
void Audio::AudioDevice::SetSpatialize | ( | AudioEmitterId | id, |
bool | value ) |
Set whether or not to account for spatial position when playing a sound.
void Audio::AudioDevice::SetSpeedOfSound | ( | float | value = 343.0f | ) |
Set the speed of sound constant. (default assumes 1 unit is 1 meter)
void Audio::AudioDevice::SetVelocity | ( | AudioEmitterId | id, |
Math::vector const & | vel ) |
Set spatial velocity of a sound.
void Audio::AudioDevice::Stop | ( | ClipId | id | ) |
Stop all instances of a clip.
void Audio::AudioDevice::StopInstance | ( | ClipInstanceId | id | ) |
Stop an instance of a clip.
void Audio::AudioDevice::UnloadClip | ( | ClipId const | id | ) |
Unload a soundfile.
void Audio::AudioDevice::UpdatePosition | ( | ClipInstanceId | id, |
Math::point const & | pos ) |
Update the spatial position of a sound instance in world space.
void Audio::AudioDevice::UpdateVelocity | ( | ClipInstanceId | id, |
Math::vector const & | vel ) |
Update the spatial velocity of a sound instance.
|
private |
resource -> clipid table
|
private |
|
private |
|
private |
Contains all wavs that are currently loaded.
refcount will automatically unload wav if it is no longer in use by any emitters