NLSOUND::CSourceCommon Class Reference

#include <source_common.h>

Inheritance diagram for NLSOUND::CSourceCommon:

NLSOUND::USource NLSOUND::CBackgroundSource NLSOUND::CComplexSource NLSOUND::CSimpleSource

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::CClustergetCluster () 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::CVectorgetPos () 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

Member Enumeration Documentation

enum NLSOUND::CSourceCommon::TSOURCE_TYPE
 

Enumeration values:
SOURCE_SIMPLE 
SOURCE_COMPLEX 
SOURCE_BACKGROUND 

Definition at line 42 of file source_common.h.

00043         {
00044                 SOURCE_SIMPLE,
00045                 SOURCE_COMPLEX,
00046                 SOURCE_BACKGROUND
00047         };


Constructor & Destructor Documentation

NLSOUND::CSourceCommon::CSourceCommon TSoundId  id,
bool  spawn,
TSpawnEndCallback  cb,
void *  cbUserParam,
NL3D::CCluster cluster
 

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 }

NLSOUND::CSourceCommon::~CSourceCommon  ) 
 

Definition at line 67 of file source_common.cpp.

00068 {
00069         CAudioMixerUser::instance()->removeSource(this);
00070 }


Member Function Documentation

virtual void NLSOUND::CSourceCommon::checkup  )  [inline, virtual]
 

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 {};

void* NLSOUND::CSourceCommon::getCallbackUserParam void   )  const [inline]
 

return the user param for the user callback

Definition at line 74 of file source_common.h.

References _CbUserParam.

00074 { return _CbUserParam; }

NL3D::CCluster* NLSOUND::CSourceCommon::getCluster  )  const [inline]
 

Definition at line 98 of file source_common.h.

References _Cluster.

Referenced by NLSOUND::CSimpleSource::getVirtualPos(), and NLSOUND::CAudioMixerUser::update().

00098 { return _Cluster; } 

virtual void NLSOUND::CSourceCommon::getDirection NLMISC::CVector dir  )  const [inline, virtual]
 

Get the direction vector.

Implements NLSOUND::USource.

Definition at line 80 of file source_common.h.

00080 { dir = _Direction; }

virtual float NLSOUND::CSourceCommon::getGain void   )  const [inline, virtual]
 

Get the gain.

Implements NLSOUND::USource.

Definition at line 82 of file source_common.h.

Referenced by NLSOUND::CAudioMixerUser::update().

00082 { return _Gain; }

bool NLSOUND::CSourceCommon::getLooping  )  const [virtual]
 

Return the looping state.

Implements NLSOUND::USource.

Definition at line 99 of file source_common.cpp.

00100 {
00101         return _Looping;
00102 }

virtual float NLSOUND::CSourceCommon::getPitch void   )  const [inline, virtual]
 

Get the pitch.

Implements NLSOUND::USource.

Definition at line 84 of file source_common.h.

00084 { return _Pitch; }

const NLMISC::CVector & NLSOUND::CSourceCommon::getPos  )  const [virtual]
 

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 }

TSoundPriority NLSOUND::CSourceCommon::getPriority void   )  const [inline]
 

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; }

float NLSOUND::CSourceCommon::getRelativeGain  )  const [virtual]
 

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 }

virtual TSoundId NLSOUND::USource::getSound  )  [pure virtual, inherited]
 

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().

virtual bool NLSOUND::CSourceCommon::getSourceRelativeMode  )  const [inline, virtual]
 

Get the source relative mode.

Implements NLSOUND::USource.

Definition at line 86 of file source_common.h.

References _RelativeMode.

00086 { return _RelativeMode; }

uint32 NLSOUND::CSourceCommon::getTime  )  [virtual]
 

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.

00223 {
00224         if (!_Playing)
00225                 return 0;
00226         // default implementation
00227         return uint32(CTime::getLocalTime() - _PlayStart);
00228 }

virtual TSOURCE_TYPE NLSOUND::CSourceCommon::getType  )  const [pure virtual]
 

Get the type the the source.

Implemented in NLSOUND::CBackgroundSource, NLSOUND::CComplexSource, and NLSOUND::CSimpleSource.

Referenced by NLSOUND::CAudioMixerUser::getPlayingSoundsPos(), and NLSOUND::CBackgroundSoundManager::updateBackgroundStatus().

virtual void NLSOUND::CSourceCommon::getVelocity NLMISC::CVector vel  )  const [inline, virtual]
 

Get the velocity vector.

Implements NLSOUND::USource.

Definition at line 78 of file source_common.h.

References _Velocity.

00078 { vel = _Velocity; }

bool NLSOUND::CSourceCommon::isPlaying  )  [inline, virtual]
 

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; }

bool NLSOUND::CSourceCommon::isSpawn  )  const [inline]
 

Return the spawn state.

Definition at line 90 of file source_common.h.

00090 { return _Spawn; }

void NLSOUND::CSourceCommon::play  )  [virtual]
 

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 }

void NLSOUND::CSourceCommon::set3DPositionVector const NLMISC::CVector pos  )  [inline]
 

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; }

void NLSOUND::CSourceCommon::setDirection const NLMISC::CVector dir  )  [virtual]
 

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 }

void NLSOUND::CSourceCommon::setGain float  gain  )  [virtual]
 

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 }

void NLSOUND::CSourceCommon::setLooping bool  loop  )  [virtual]
 

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.

00092 {
00093         _Looping = l;
00094 }

void NLSOUND::CSourceCommon::setPitch float  pitch  )  [virtual]
 

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 }

void NLSOUND::CSourceCommon::setPos const NLMISC::CVector pos  )  [virtual]
 

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 }

void NLSOUND::CSourceCommon::setPriority TSoundPriority  pr  )  [virtual]
 

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 }

void NLSOUND::CSourceCommon::setRelativeGain float  gain  )  [virtual]
 

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 }

void NLSOUND::CSourceCommon::setSourceRelativeMode bool  mode  )  [virtual]
 

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 }

void NLSOUND::CSourceCommon::setVelocity const NLMISC::CVector vel  )  [virtual]
 

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 }

void NLSOUND::CSourceCommon::stop  )  [virtual]
 

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 }

virtual void NLSOUND::CSourceCommon::unregisterSpawnCallBack  )  [inline, virtual]
 

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; }


Friends And Related Function Documentation

friend class CAudioMixerUser [friend]
 

Definition at line 39 of file source_common.h.


Field Documentation

const NLMISC::CVector* NLSOUND::CSourceCommon::_3DPosition [protected]
 

Definition at line 125 of file source_common.h.

Referenced by getPos(), and set3DPositionVector().

void* NLSOUND::CSourceCommon::_CbUserParam [protected]
 

Definition at line 130 of file source_common.h.

Referenced by getCallbackUserParam().

NL3D::CCluster* NLSOUND::CSourceCommon::_Cluster [protected]
 

Definition at line 131 of file source_common.h.

Referenced by getCluster().

NLMISC::CVector NLSOUND::CSourceCommon::_Direction [protected]
 

Definition at line 113 of file source_common.h.

float NLSOUND::CSourceCommon::_Gain [protected]
 

Definition at line 114 of file source_common.h.

float NLSOUND::CSourceCommon::_InitialGain [protected]
 

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().

bool NLSOUND::CSourceCommon::_Looping [protected]
 

Definition at line 109 of file source_common.h.

float NLSOUND::CSourceCommon::_Pitch [protected]
 

Definition at line 115 of file source_common.h.

bool NLSOUND::CSourceCommon::_Playing [protected]
 

Definition at line 108 of file source_common.h.

NLMISC::TTime NLSOUND::CSourceCommon::_PlayStart [protected]
 

Definition at line 122 of file source_common.h.

Referenced by getTime(), and play().

NLMISC::CVector NLSOUND::CSourceCommon::_Position [protected]
 

Definition at line 111 of file source_common.h.

TSoundPriority NLSOUND::CSourceCommon::_Priority [protected]
 

Definition at line 107 of file source_common.h.

bool NLSOUND::CSourceCommon::_RelativeMode [protected]
 

Definition at line 116 of file source_common.h.

Referenced by getSourceRelativeMode(), and setSourceRelativeMode().

const bool NLSOUND::CSourceCommon::_Spawn [protected]
 

Definition at line 128 of file source_common.h.

TSpawnEndCallback NLSOUND::CSourceCommon::_SpawnEndCb [protected]
 

Definition at line 129 of file source_common.h.

Referenced by NLSOUND::CSimpleSource::play(), NLSOUND::CSimpleSource::stop(), and unregisterSpawnCallBack().

NLMISC::TStringId NLSOUND::CSourceCommon::_UserVarControler [protected]
 

An optional user var controler.

Definition at line 134 of file source_common.h.

NLMISC::CVector NLSOUND::CSourceCommon::_Velocity [protected]
 

Definition at line 112 of file source_common.h.

Referenced by getVelocity(), and setVelocity().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 14:47:11 2004 for NeL by doxygen 1.3.6