#include <source_common.h>
Inheritance diagram for NLSOUND::CSourceCommon:
Public Types | |
enum | TSOURCE_TYPE { SOURCE_SIMPLE, SOURCE_COMPLEX, SOURCE_BACKGROUND } |
Public Member Functions | |
virtual void | checkup () |
CSourceCommon (TSoundId id, bool spawn, TSpawnEndCallback cb, void *cbUserParam, NL3D::CCluster *cluster) | |
void * | getCallbackUserParam (void) const |
return the user param for the user callback | |
NL3D::CCluster * | getCluster () const |
virtual void | getDirection (NLMISC::CVector &dir) const |
Get the direction vector. | |
virtual float | getGain () const |
Get the gain. | |
bool | getLooping () const |
Return the looping state. | |
virtual float | getPitch () const |
Get the pitch. | |
const NLMISC::CVector & | getPos () const |
Get the position vector (3D mode only). | |
TSoundPriority | getPriority () const |
Return the priority. | |
float | getRelativeGain () const |
Return the relative gain (see setRelativeGain()), or the absolute gain if getSource() is null. | |
virtual TSoundId | getSound ()=0 |
Return the sound binded to the source (or NULL if there is no sound). | |
virtual bool | getSourceRelativeMode () const |
Get the source relative mode. | |
virtual uint32 | getTime () |
Returns the number of milliseconds the source has been playing. | |
virtual TSOURCE_TYPE | getType () const=0 |
Get the type the the source. | |
virtual void | getVelocity (NLMISC::CVector &vel) const |
Get the velocity vector. | |
bool | isPlaying () |
Get playing state. Return false even if the source has stopped on its own. | |
bool | isSpawn () const |
Return the spawn state. | |
void | play () |
Play. | |
void | set3DPositionVector (const NLMISC::CVector *pos) |
Set the position vector to return for a stereo source (default: NULL). | |
void | setDirection (const NLMISC::CVector &dir) |
Set the direction vector (3D mode only, ignored in stereo mode) (default: (0,0,0) as non-directional). | |
void | setGain (float gain) |
void | setLooping (bool loop) |
Set looping on/off for future playbacks (default: off). | |
virtual void | setPitch (float pitch) |
void | setPos (const NLMISC::CVector &pos) |
void | setPriority (TSoundPriority pr) |
Change the priority of the source. | |
void | setRelativeGain (float gain) |
void | setSourceRelativeMode (bool mode) |
Set the source relative mode. If true, positions are interpreted relative to the listener position (default: false). | |
void | setVelocity (const NLMISC::CVector &vel) |
Set the velocity vector (3D mode only, ignored in stereo mode) (default: (0,0,0)). | |
void | stop () |
Stop playing. | |
virtual void | unregisterSpawnCallBack () |
Tells this source not to call its callbacks when it ends. This is valid for spawned sources only. | |
~CSourceCommon () | |
Protected Attributes | |
const NLMISC::CVector * | _3DPosition |
void * | _CbUserParam |
NL3D::CCluster * | _Cluster |
NLMISC::CVector | _Direction |
float | _Gain |
float | _InitialGain |
Gain not affected by setRelativeGain and used to compute _Gain. | |
bool | _Looping |
float | _Pitch |
bool | _Playing |
NLMISC::TTime | _PlayStart |
NLMISC::CVector | _Position |
TSoundPriority | _Priority |
bool | _RelativeMode |
const bool | _Spawn |
TSpawnEndCallback | _SpawnEndCb |
NLMISC::TStringId | _UserVarControler |
An optional user var controler. | |
NLMISC::CVector | _Velocity |
Friends | |
class | CAudioMixerUser |
|
Definition at line 42 of file source_common.h.
00043 { 00044 SOURCE_SIMPLE, 00045 SOURCE_COMPLEX, 00046 SOURCE_BACKGROUND 00047 }; |
|
Definition at line 37 of file source_common.cpp. References _InitialGain, id, NLSOUND::MidPri, NLSOUND::TSoundId, and NLSOUND::TSpawnEndCallback.
00038 : _Priority(MidPri), 00039 _Playing(false), 00040 _Looping(false), 00041 _Position(CVector::Null), 00042 _Velocity(CVector::Null), 00043 _Direction(CVector::Null), 00044 _Gain(1.0f), 00045 _InitialGain(1.0f), 00046 _Pitch(1.0f), 00047 _RelativeMode(false), 00048 _3DPosition(NULL), 00049 _PlayStart(0), 00050 _Spawn(spawn), 00051 _SpawnEndCb(cb), 00052 _CbUserParam(cbUserParam), 00053 _Cluster(cluster), 00054 _UserVarControler(id->getUserVarControler()) 00055 { 00056 CAudioMixerUser::instance()->addSource(this); 00057 00058 // get a local copy of the sound parameter 00059 _InitialGain = _Gain = id->getGain(); 00060 _Pitch = id->getPitch(); 00061 _Looping = id->getLooping(); 00062 _Priority = id->getPriority(); 00063 _Direction = id->getDirectionVector(); 00064 00065 } |
|
Definition at line 67 of file source_common.cpp.
00068 {
00069 CAudioMixerUser::instance()->removeSource(this);
00070 }
|
|
This method is called from backgroup sound to check if subsound need to be restarted (ie subsound in loop mode). Reimplemented in NLSOUND::CComplexSource. Definition at line 103 of file source_common.h. Referenced by NLSOUND::CBackgroundSoundManager::updateBackgroundStatus().
00103 {}; |
|
return the user param for the user callback
Definition at line 74 of file source_common.h. References _CbUserParam.
00074 { return _CbUserParam; } |
|
Definition at line 98 of file source_common.h. References _Cluster. Referenced by NLSOUND::CSimpleSource::getVirtualPos(), and NLSOUND::CAudioMixerUser::update().
00098 { return _Cluster; } |
|
Get the direction vector.
Implements NLSOUND::USource. Definition at line 80 of file source_common.h.
00080 { dir = _Direction; } |
|
Get the gain.
Implements NLSOUND::USource. Definition at line 82 of file source_common.h. Referenced by NLSOUND::CAudioMixerUser::update().
00082 { return _Gain; } |
|
Return the looping state.
Implements NLSOUND::USource. Definition at line 99 of file source_common.cpp.
00100 { 00101 return _Looping; 00102 } |
|
Get the pitch.
Implements NLSOUND::USource. Definition at line 84 of file source_common.h.
00084 { return _Pitch; } |
|
Get the position vector (3D mode only).
Implements NLSOUND::USource. Definition at line 141 of file source_common.cpp. References _3DPosition. Referenced by NLSOUND::CAudioMixerUser::getFreeTrack(), NLSOUND::CAudioMixerUser::getPlayingSoundsPos(), NLSOUND::CSimpleSource::getVirtualPos(), NLSOUND::CompareSources::operator()(), and NLSOUND::CAudioMixerUser::update().
00142 { 00143 if ( _3DPosition == NULL ) 00144 { 00145 return _Position; 00146 } 00147 else 00148 { 00149 return *_3DPosition; 00150 } 00151 00152 } |
|
Return the priority.
Definition at line 59 of file source_common.h. References NLSOUND::TSoundPriority. Referenced by NLSOUND::CAudioMixerUser::freeTrack(), NLSOUND::CAudioMixerUser::getFreeTrack(), and NLSOUND::CompareSources::operator()().
00059 { return _Priority; } |
|
Return the relative gain (see setRelativeGain()), or the absolute gain if getSource() is null.
Implements NLSOUND::USource. Definition at line 205 of file source_common.cpp. References _InitialGain. Referenced by NLSOUND::CAudioMixerUser::addUserControledSource(), and NLSOUND::CAudioMixerUser::update().
00206 { 00207 if (_InitialGain == 0.0f) 00208 return 0.0f; 00209 else 00210 return _Gain / _InitialGain; 00211 } |
|
Return the sound binded to the source (or NULL if there is no sound).
Implemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Referenced by NLSOUND::CAudioMixerUser::addUserControledSource(), NLSOUND::CComplexSource::checkup(), NLSOUND::CComplexSource::onEvent(), NLSOUND::CComplexSource::onUpdate(), NLSOUND::CComplexSource::playStuf(), and NLSOUND::CBackgroundSource::updateFilterValues(). |
|
Get the source relative mode.
Implements NLSOUND::USource. Definition at line 86 of file source_common.h. References _RelativeMode.
00086 { return _RelativeMode; } |
|
Returns the number of milliseconds the source has been playing.
Implements NLSOUND::USource. Reimplemented in NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Definition at line 222 of file source_common.cpp. References _PlayStart, and uint32.
|
|
Get the type the the source.
Implemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Referenced by NLSOUND::CAudioMixerUser::getPlayingSoundsPos(), and NLSOUND::CBackgroundSoundManager::updateBackgroundStatus(). |
|
Get the velocity vector.
Implements NLSOUND::USource. Definition at line 78 of file source_common.h. References _Velocity.
00078 { vel = _Velocity; } |
|
Get playing state. Return false even if the source has stopped on its own.
Implements NLSOUND::USource. Reimplemented in NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Definition at line 64 of file source_common.h. Referenced by NLSOUND::CAudioMixerUser::reset(), and NLSOUND::CBackgroundSoundManager::updateBackgroundStatus().
00064 { return _Playing; } |
|
Return the spawn state.
Definition at line 90 of file source_common.h.
00090 { return _Spawn; } |
|
Play.
Implements NLSOUND::USource. Reimplemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Definition at line 107 of file source_common.cpp. References _PlayStart. Referenced by NLSOUND::CBackgroundSoundManager::updateBackgroundStatus().
00108 { 00109 CAudioMixerUser::instance()->incPlayingSource(); 00110 _Playing = true; 00111 _PlayStart = CTime::getLocalTime(); 00112 00113 if (_UserVarControler != CStringMapper::emptyId()) 00114 CAudioMixerUser::instance()->addUserControledSource(this, _UserVarControler); 00115 } |
|
Set the position vector to return for a stereo source (default: NULL).
Definition at line 88 of file source_common.h. References _3DPosition. Referenced by NLSOUND::CAudioMixerUser::createSource(), and NLSOUND::CAmbiantSource::initPos().
00088 { _3DPosition = pos; } |
|
Set the direction vector (3D mode only, ignored in stereo mode) (default: (0,0,0) as non-directional).
Implements NLSOUND::USource. Reimplemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Definition at line 175 of file source_common.cpp.
00176 { 00177 _Direction = dir; 00178 } |
|
Set the gain (volume value inside [0 , 1]). (default: 1) 0.0 -> silence 0.5 -> -6dB 1.0 -> no attenuation values > 1 (amplification) not supported by most drivers Implements NLSOUND::USource. Reimplemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Definition at line 186 of file source_common.cpp. References _InitialGain, and nlassert. Referenced by NLSOUND::CAudioMixerUser::addUserControledSource().
00187 { 00188 nlassert( (gain >= 0.0f) && (gain <= 1.0f ) ); 00189 _InitialGain = _Gain = gain; 00190 } |
|
Set looping on/off for future playbacks (default: off).
Implements NLSOUND::USource. Reimplemented in NLSOUND::CSimpleSource. Definition at line 91 of file source_common.cpp.
|
|
Shift the frequency. 1.0f equals identity, each reduction of 50% equals a pitch shift of one octave. 0 is not a legal value. Implements NLSOUND::USource. Reimplemented in NLSOUND::CSimpleSource. Definition at line 157 of file source_common.cpp. Referenced by NLSOUND::CAudioMixerUser::addUserControledSource().
00158 { 00159 // nlassert( (pitch > 0) && (pitch <= 1.0f ) ); 00160 _Pitch = pitch; 00161 } |
|
Set the position vector (default: (0,0,0)). 3D mode -> 3D position st mode -> x is the pan value (from left (-1) to right (1)), set y and z to 0 Implements NLSOUND::USource. Reimplemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Definition at line 133 of file source_common.cpp. Referenced by NLSOUND::CBackgroundSoundManager::updateBackgroundStatus().
00134 { 00135 _Position = pos; 00136 } |
|
Change the priority of the source.
Implements NLSOUND::USource. Definition at line 76 of file source_common.cpp. Referenced by NLSOUND::CAmbiantSource::enable(), NLSOUND::CAmbiantSource::initPos(), and NLSOUND::CAmbiantSource::update().
00077 { 00078 _Priority = pr; 00079 00080 // The AudioMixer redispatches as necessary in the update() function [PH] 00081 // Redispatch the tracks if needed 00082 //if ( redispatch ) 00083 //{ 00084 // CAudioMixerUser::instance()->balanceSources(); 00085 //} 00086 } |
|
Set the gain amount (value inside [0, 1]) to map between 0 and the nominal gain (which is getSource()->getGain()). Does nothing if getSource() is null. Implements NLSOUND::USource. Reimplemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Definition at line 195 of file source_common.cpp. References _InitialGain, and nlassert. Referenced by NLSOUND::CAudioMixerUser::addUserControledSource(), and NLSOUND::CBackgroundSoundManager::updateBackgroundStatus().
00196 { 00197 nlassert( (gain >= 0.0f) && (gain <= 1.0f ) ); 00198 00199 _Gain = _InitialGain * gain; 00200 } |
|
Set the source relative mode. If true, positions are interpreted relative to the listener position (default: false).
Implements NLSOUND::USource. Reimplemented in NLSOUND::CSimpleSource. Definition at line 216 of file source_common.cpp. References _RelativeMode.
00217 { 00218 _RelativeMode = mode; 00219 } |
|
Set the velocity vector (3D mode only, ignored in stereo mode) (default: (0,0,0)).
Implements NLSOUND::USource. Reimplemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Definition at line 167 of file source_common.cpp. References _Velocity.
00168 { 00169 _Velocity = vel; 00170 } |
|
Stop playing.
Implements NLSOUND::USource. Reimplemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource. Definition at line 120 of file source_common.cpp. Referenced by NLSOUND::CAudioMixerUser::reset(), and NLSOUND::CBackgroundSoundManager::updateBackgroundStatus().
00121 { 00122 CAudioMixerUser::instance()->decPlayingSource(); 00123 _Playing = false; 00124 00125 if (_UserVarControler != CStringMapper::emptyId()) 00126 CAudioMixerUser::instance()->removeUserControledSource(this, _UserVarControler); 00127 } |
|
Tells this source not to call its callbacks when it ends. This is valid for spawned sources only.
Implements NLSOUND::USource. Definition at line 76 of file source_common.h. References _SpawnEndCb.
00076 { _SpawnEndCb = NULL; } |
|
Definition at line 39 of file source_common.h. |
|
Definition at line 125 of file source_common.h. Referenced by getPos(), and set3DPositionVector(). |
|
Definition at line 130 of file source_common.h. Referenced by getCallbackUserParam(). |
|
Definition at line 131 of file source_common.h. Referenced by getCluster(). |
|
Definition at line 113 of file source_common.h. |
|
Definition at line 114 of file source_common.h. |
|
Gain not affected by setRelativeGain and used to compute _Gain.
Definition at line 119 of file source_common.h. Referenced by CSourceCommon(), getRelativeGain(), setGain(), and setRelativeGain(). |
|
Definition at line 109 of file source_common.h. |
|
Definition at line 115 of file source_common.h. |
|
Definition at line 108 of file source_common.h. |
|
Definition at line 122 of file source_common.h. |
|
Definition at line 111 of file source_common.h. |
|
Definition at line 107 of file source_common.h. |
|
Definition at line 116 of file source_common.h. Referenced by getSourceRelativeMode(), and setSourceRelativeMode(). |
|
Definition at line 128 of file source_common.h. |
|
Definition at line 129 of file source_common.h. Referenced by NLSOUND::CSimpleSource::play(), NLSOUND::CSimpleSource::stop(), and unregisterSpawnCallBack(). |
|
An optional user var controler.
Definition at line 134 of file source_common.h. |
|
Definition at line 112 of file source_common.h. Referenced by getVelocity(), and setVelocity(). |