#include <background_source.h>
Inheritance diagram for NLSOUND::CBackgroundSource:
Nevrax
Definition at line 44 of file background_source.h.
Public Types | |
enum | TSOURCE_TYPE { SOURCE_SIMPLE, SOURCE_COMPLEX, SOURCE_BACKGROUND } |
Public Member Functions | |
CBackgroundSource (CBackgroundSound *backgroundSound=NULL, bool spawn=false, TSpawnEndCallback cb=0, void *cbUserParam=0, NL3D::CCluster *cluster=0) | |
Constructor. | |
virtual void | checkup () |
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 () |
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. | |
TSOURCE_TYPE | getType () const |
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. | |
virtual 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)). | |
virtual 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. | |
void | updateFilterValues (const float *filterValues) |
~CBackgroundSource () | |
Destructor. | |
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 |
Private Types | |
enum | TSubSourceStatus { SUB_STATUS_PLAY, SUB_STATUS_STOP, SUB_STATUS_PLAY_FAIL } |
Sub source possible status. More... | |
Private Member Functions | |
void | onUpdate () |
Mixer update. | |
Private Attributes | |
CBackgroundSound * | _BackgroundSound |
The sound static data. | |
std::vector< TSubSource > | _Sources |
The sub sources container. |
|
Definition at line 42 of file source_common.h.
00043 { 00044 SOURCE_SIMPLE, 00045 SOURCE_COMPLEX, 00046 SOURCE_BACKGROUND 00047 }; |
|
Sub source possible status.
Definition at line 77 of file background_source.h.
00078 { 00080 SUB_STATUS_PLAY, 00082 SUB_STATUS_STOP, 00084 SUB_STATUS_PLAY_FAIL 00085 }; |
|
Constructor.
Definition at line 38 of file background_source.cpp. References _BackgroundSound, and NLSOUND::TSpawnEndCallback.
00039 : CSourceCommon(backgroundSound, spawn, cb, cbUserParam, cluster) 00040 { 00041 _BackgroundSound = backgroundSound; 00042 } |
|
Destructor.
Definition at line 44 of file background_source.cpp. References stop().
|
|
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 NLSOUND::CSourceCommon::_CbUserParam.
00074 { return _CbUserParam; } |
|
Definition at line 98 of file source_common.h. References NLSOUND::CSourceCommon::_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 NLSOUND::CSourceCommon::_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 NLSOUND::CSourceCommon::_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).
Implements NLSOUND::USource. Definition at line 50 of file background_source.cpp. References NLSOUND::TSoundId.
00051 {
00052 return NULL;
00053 }
|
|
Get the source relative mode.
Implements NLSOUND::USource. Definition at line 86 of file source_common.h. References NLSOUND::CSourceCommon::_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 NLSOUND::CSourceCommon::_PlayStart, and uint32.
|
|
Get the type the the source.
Implements NLSOUND::CSourceCommon. Definition at line 59 of file background_source.h.
00059 {return SOURCE_BACKGROUND;} |
|
Get the velocity vector.
Implements NLSOUND::USource. Definition at line 78 of file source_common.h. References NLSOUND::CSourceCommon::_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; } |
|
Mixer update.
Implements NLSOUND::CAudioMixerUser::IMixerUpdate. Definition at line 222 of file background_source.cpp. References NLSOUND::USource::isPlaying(), NLSOUND::USource::play(), NLSOUND::CBackgroundSource::TSubSource::Source, NLSOUND::CBackgroundSource::TSubSource::Status, SUB_STATUS_PLAY, and SUB_STATUS_PLAY_FAIL.
00223 { 00224 bool needUpdate = false; 00225 // Some sub source are distance clipped, so retry to start them. 00226 std::vector<TSubSource>::iterator first(_Sources.begin()), last(_Sources.end()); 00227 for (; first != last; ++first) 00228 { 00229 TSubSource &ss = *first; 00230 if (ss.Status == SUB_STATUS_PLAY_FAIL) 00231 { 00232 ss.Source->play(); 00233 // some sub sound can be too far from the listener, 00234 // we must handle this in order to start them when the listener 00235 // is closer 00236 ss.Status = ss.Source->isPlaying() ? SUB_STATUS_PLAY : SUB_STATUS_PLAY_FAIL; 00237 00238 needUpdate |= (ss.Status == SUB_STATUS_PLAY_FAIL); 00239 } 00240 } 00241 00242 // no more update needed ? 00243 if (!needUpdate) 00244 CAudioMixerUser::instance()->unregisterUpdate(this); 00245 } |
|
Play.
Reimplemented from NLSOUND::CSourceCommon. Definition at line 119 of file background_source.cpp. References _BackgroundSound, NLSOUND::CAudioMixerUser::createSource(), NLSOUND::CBackgroundSource::TSubSource::Filter, NLSOUND::CAudioMixerUser::getBackgroundSoundManager(), NLSOUND::CBackgroundSoundManager::getFilterValues(), NLSOUND::CBackgroundSound::getSounds(), NLSOUND::USource::setPriority(), NLSOUND::CBackgroundSource::TSubSource::Source, NLSOUND::CBackgroundSource::TSubSource::Status, stop(), SUB_STATUS_STOP, and updateFilterValues().
00120 { 00121 if (_Playing) 00122 stop(); 00123 00124 CAudioMixerUser *mixer = CAudioMixerUser::instance(); 00125 00126 const vector<CBackgroundSound::TSoundInfo> &sounds = _BackgroundSound->getSounds(); 00127 vector<CBackgroundSound::TSoundInfo>::const_iterator first(sounds.begin()), last(sounds.end()); 00128 00129 for (; first != last; ++first) 00130 { 00131 TSubSource subSource; 00132 subSource.Source = mixer->createSource(first->SoundName, false, 0, 0, _Cluster, 0); 00133 if (subSource.Source != NULL) 00134 subSource.Source->setPriority(_Priority); 00135 subSource.Filter = first->Filter; 00136 subSource.Status = SUB_STATUS_STOP; 00137 _Sources.push_back(subSource); 00138 } 00139 00140 updateFilterValues(mixer->getBackgroundSoundManager()->getFilterValues()); 00141 00142 CSourceCommon::play(); 00143 } |
|
Set the position vector to return for a stereo source (default: NULL).
Definition at line 88 of file source_common.h. References NLSOUND::CSourceCommon::_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).
Reimplemented from NLSOUND::CSourceCommon. Definition at line 105 of file background_source.cpp.
|
|
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 Reimplemented from NLSOUND::CSourceCommon. Definition at line 55 of file background_source.cpp.
00056 { 00057 CSourceCommon::setGain(gain); 00058 00059 std::vector<TSubSource>::iterator first(_Sources.begin()), last(_Sources.end()); 00060 for (; first != last; ++first) 00061 { 00062 if (first->Source != 0) 00063 { 00064 first->Source->setGain(first->Source->getSound()->getGain() * gain); 00065 first->Source->setRelativeGain(_Gain); 00066 } 00067 // first->Source->setRelativeGain(_Gain); 00068 } 00069 } |
|
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 Reimplemented from NLSOUND::CSourceCommon. Definition at line 82 of file background_source.cpp.
|
|
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. Reimplemented from NLSOUND::CSourceCommon. Definition at line 70 of file background_source.cpp.
|
|
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 NLSOUND::CSourceCommon::_RelativeMode.
00217 { 00218 _RelativeMode = mode; 00219 } |
|
Set the velocity vector (3D mode only, ignored in stereo mode) (default: (0,0,0)).
Reimplemented from NLSOUND::CSourceCommon. Definition at line 94 of file background_source.cpp.
|
|
Stop playing.
Reimplemented from NLSOUND::CSourceCommon. Definition at line 145 of file background_source.cpp. References NLSOUND::CBackgroundSource::TSubSource::Source. Referenced by play(), and ~CBackgroundSource().
00146 { 00147 if (_Playing) 00148 { 00149 while (!_Sources.empty()) 00150 { 00151 TSubSource &subSource = _Sources.back(); 00152 if (subSource.Source != NULL) 00153 { 00154 delete subSource.Source; 00155 } 00156 _Sources.pop_back(); 00157 } 00158 } 00159 00160 CSourceCommon::stop(); 00161 00162 CAudioMixerUser::instance()->unregisterUpdate(this); 00163 } |
|
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 NLSOUND::CSourceCommon::_SpawnEndCb.
00076 { _SpawnEndCb = NULL; } |
|
Definition at line 165 of file background_source.cpp. References NLSOUND::CBackgroundSource::TSubSource::Filter, NLSOUND::UAudioMixer::TBackgroundFlags::Flags, NLSOUND::CSound::getGain(), NLSOUND::CSound::getPitch(), NLSOUND::USource::getSound(), NLSOUND::USource::isPlaying(), NLSOUND::USource::play(), NLSOUND::USource::setGain(), NLSOUND::USource::setPitch(), NLSOUND::USource::setPos(), NLSOUND::USource::setRelativeGain(), NLSOUND::CBackgroundSource::TSubSource::Source, NLSOUND::CBackgroundSource::TSubSource::Status, NLSOUND::USource::stop(), SUB_STATUS_PLAY, SUB_STATUS_PLAY_FAIL, SUB_STATUS_STOP, and uint. Referenced by play().
00166 { 00167 bool needUpdate = false; 00168 std::vector<TSubSource>::iterator first(_Sources.begin()), last(_Sources.end()); 00169 for (; first != last; ++first) 00170 { 00171 TSubSource &ss = *first; 00172 if (ss.Source != 0) 00173 { 00174 float gain = 1.0f; 00175 for (uint i=0; i<UAudioMixer::TBackgroundFlags::NB_BACKGROUND_FLAGS; ++i) 00176 { 00177 if (ss.Filter.Flags[i]) 00178 { 00179 // this filter is used 00180 gain *= filterValues[i]; 00181 } 00182 } 00183 00184 if (gain == 0 && ss.Status != SUB_STATUS_STOP) 00185 { 00186 // need to completely stop the sound 00187 if (ss.Source->isPlaying()) 00188 ss.Source->stop(); 00189 ss.Status = SUB_STATUS_STOP; 00190 } 00191 else if (gain > 0 && ss.Status != SUB_STATUS_PLAY) 00192 { 00193 // need to restard the sound 00194 // ss.Source->setRelativeGain(gain * _Gain); 00195 ss.Source->setGain(ss.Source->getSound()->getGain() * gain); 00196 ss.Source->setRelativeGain(_Gain); 00197 ss.Source->setPitch(ss.Source->getSound()->getPitch() * _Pitch); 00198 ss.Source->setPos(_Position); 00199 ss.Source->play(); 00200 // some sub sound can be too far from the listener, 00201 // we must handle this in order to start them when the listener 00202 // is closer 00203 ss.Status = ss.Source->isPlaying() ? SUB_STATUS_PLAY : SUB_STATUS_PLAY_FAIL; 00204 00205 needUpdate |= (ss.Status == SUB_STATUS_PLAY_FAIL); 00206 } 00207 else //if (ss.Status == SUB_STATUS_PLAY) 00208 { 00209 // just update the gain 00210 ss.Source->setGain(ss.Source->getSound()->getGain() * gain); 00211 ss.Source->setRelativeGain(_Gain); 00212 } 00213 } 00214 } 00215 00216 // if some some sub sound fail to play... 00217 if (needUpdate) 00218 CAudioMixerUser::instance()->registerUpdate(this); 00219 00220 } |
|
Definition at line 125 of file source_common.h. Referenced by NLSOUND::CSourceCommon::getPos(), and NLSOUND::CSourceCommon::set3DPositionVector(). |
|
The sound static data.
Definition at line 99 of file background_source.h. Referenced by CBackgroundSource(), and play(). |
|
Definition at line 130 of file source_common.h. Referenced by NLSOUND::CSourceCommon::getCallbackUserParam(). |
|
Definition at line 131 of file source_common.h. Referenced by NLSOUND::CSourceCommon::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 NLSOUND::CSourceCommon::CSourceCommon(), NLSOUND::CSourceCommon::getRelativeGain(), NLSOUND::CSourceCommon::setGain(), and NLSOUND::CSourceCommon::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. Referenced by NLSOUND::CSourceCommon::getTime(), and NLSOUND::CSourceCommon::play(). |
|
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 NLSOUND::CSourceCommon::getSourceRelativeMode(), and NLSOUND::CSourceCommon::setSourceRelativeMode(). |
|
The sub sources container.
Definition at line 102 of file background_source.h. |
|
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 NLSOUND::CSourceCommon::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 NLSOUND::CSourceCommon::getVelocity(), and NLSOUND::CSourceCommon::setVelocity(). |