NLSOUND::CSound Class Reference

#include <sound.h>

Inheritance diagram for NLSOUND::CSound:

NLSOUND::CBackgroundSound NLSOUND::CComplexSound NLSOUND::CContextSound NLSOUND::CSimpleSound

Detailed Description

A sound base class and its static properties
Author:
Olivier Cado

Nevrax France

Date:
2001

Definition at line 60 of file sound.h.

Public Types

enum  TSOUND_TYPE { SOUND_SIMPLE, SOUND_COMPLEX, SOUND_BACKGROUND, SOUND_CONTEXT }

Public Member Functions

 CSound ()
 Constructor.

float getConeInnerAngle () const
 Return the inner angle of the cone.

float getConeOuterAngle () const
 Return the outer angle of the cone.

float getConeOuterGain () const
 Return the outer gain of the cone.

const NLMISC::CVectorgetDirectionVector () const
 Return the direction vector.

virtual uint32 getDuration ()=0
 Return the length of the sound in ms.

float getGain () const
 Return the gain.

bool getLooping () const
 Return the looping state.

virtual float getMaxDistance () const
 Return the max distance (if detailed()).

const NLMISC::TStringIdgetName () const
 Return the name (must be unique).

float getPitch () const
 Return the pitch.

TSoundPriority getPriority () const
 Return the initial priority.

virtual TSOUND_TYPE getSoundType ()=0
 Get the type of the sound.

virtual void getSubSoundList (std::vector< std::pair< std::string, CSound * > > &subsounds) const=0
 Used by the george sound plugin to check sound recursion (ie sound 'toto' use sound 'titi' witch also use sound 'toto' ...).

NLMISC::TStringId getUserVarControler ()
virtual void importForm (const std::string &filename, NLGEORGES::UFormElm &formRoot)
 Load the sound parameters from georges' form.

virtual bool isDetailed () const=0
 Return true if cone is meaningful.

bool operator< (const CSound &otherSound) const
virtual void serial (NLMISC::IStream &s)
void setLooping (bool looping)
 Set looping.

virtual ~CSound ()
 Destructor.


Static Public Member Functions

CSoundcreateSound (const std::string &filename, NLGEORGES::UFormElm &formRoot)
 Factory for specialized sound.


Protected Attributes

float _ConeInnerAngle
float _ConeOuterAngle
float _ConeOuterGain
NLMISC::CVector _Direction
float _Gain
bool _Looping
float _MaxDist
 Clipping distance for complex or backgound sound.

NLMISC::TStringId _Name
float _Pitch
TSoundPriority _Priority
NLMISC::TStringId _UserVarControler
 An optional user var controler.


Friends

class CAudioMixerUser


Member Enumeration Documentation

enum NLSOUND::CSound::TSOUND_TYPE
 

Enumeration values:
SOUND_SIMPLE 
SOUND_COMPLEX 
SOUND_BACKGROUND 
SOUND_CONTEXT 

Definition at line 67 of file sound.h.

00068         {
00069                 SOUND_SIMPLE,
00070                 SOUND_COMPLEX,
00071                 SOUND_BACKGROUND,
00072                 SOUND_CONTEXT
00073         };


Constructor & Destructor Documentation

NLSOUND::CSound::CSound  ) 
 

Constructor.

Definition at line 97 of file sound.cpp.

References NLSOUND::MidPri.

00097                : 
00098         _Gain(1.0f), 
00099         _Pitch(1.0f),
00100         _MaxDist(1000000.0f),
00101         _Priority(MidPri), 
00102         _Looping(false),
00103         _ConeInnerAngle(6.283185f), 
00104         _ConeOuterAngle(6.283185f), 
00105         _ConeOuterGain( 1.0f ),
00106         _UserVarControler(CStringMapper::emptyId())
00107 {
00108 }

NLSOUND::CSound::~CSound  )  [virtual]
 

Destructor.

Definition at line 110 of file sound.cpp.

00111 {}


Member Function Documentation

CSound * NLSOUND::CSound::createSound const std::string &  filename,
NLGEORGES::UFormElm formRoot
[static]
 

Factory for specialized sound.

Definition at line 43 of file sound.cpp.

References NLGEORGES::UFormElm::getDfnName(), NLGEORGES::UFormElm::getNodeByName(), importForm(), nlassertex, and nlwarning.

00044 {
00045         NL_ALLOC_CONTEXT(NLSOUND_CSound);
00046         CSound *ret = NULL;
00047         string  soundType;
00048 
00049         NLGEORGES::UFormElm *psoundType;
00050 
00051         if (!formRoot.getNodeByName(&psoundType, ".SoundType"))
00052         {
00053                 nlwarning("No SoundType in : %s", filename.c_str());
00054                 return 0;
00055         }
00056 
00057         if (psoundType != NULL)
00058         {
00059                 std::string dfnName;
00060                 psoundType->getDfnName(dfnName);
00061 
00062                 if (dfnName == "simple_sound.dfn")
00063                 {
00064                         ret = new CSimpleSound();
00065                         ret->importForm(filename, formRoot);
00066                 }
00067                 else if (dfnName == "complex_sound.dfn")
00068                 {
00069                         ret = new CComplexSound();
00070                         ret->importForm(filename, formRoot);
00071                 }
00072                 else if (dfnName == "background_sound.dfn")
00073                 {
00074                         ret = new CBackgroundSound();
00075                         ret->importForm(filename, formRoot);
00076                 }
00077                 else if (dfnName == "context_sound.dfn")
00078                 {
00079                         ret = new CContextSound();
00080                         ret->importForm(filename, formRoot);
00081                 }
00082                 else
00083                 {
00084                         nlassertex(false, ("SoundType unsuported : %s", dfnName.c_str()));
00085                 }
00086                         
00087         }
00088 
00089         return ret;
00090 }

float NLSOUND::CSound::getConeInnerAngle  )  const [inline]
 

Return the inner angle of the cone.

Definition at line 98 of file sound.h.

References _ConeInnerAngle.

Referenced by NLSOUND::CSimpleSource::setDirection().

00098 { return _ConeInnerAngle; }

float NLSOUND::CSound::getConeOuterAngle  )  const [inline]
 

Return the outer angle of the cone.

Definition at line 100 of file sound.h.

References _ConeOuterAngle.

Referenced by NLSOUND::CSimpleSource::setDirection().

00100 { return _ConeOuterAngle; }

float NLSOUND::CSound::getConeOuterGain  )  const [inline]
 

Return the outer gain of the cone.

Definition at line 102 of file sound.h.

References _ConeOuterGain.

Referenced by NLSOUND::CSimpleSource::setDirection().

00102 { return _ConeOuterGain; }

const NLMISC::CVector& NLSOUND::CSound::getDirectionVector  )  const [inline]
 

Return the direction vector.

Definition at line 104 of file sound.h.

00104 { return _Direction;}

virtual uint32 NLSOUND::CSound::getDuration  )  [pure virtual]
 

Return the length of the sound in ms.

Implemented in NLSOUND::CBackgroundSound, NLSOUND::CComplexSound, NLSOUND::CContextSound, and NLSOUND::CSimpleSound.

Referenced by NLSOUND::CAmbiantSource::calcRandomSparseSoundTime(), NLSOUND::CComplexSound::getDuration(), NLSOUND::CBackgroundSound::getDuration(), NLSOUND::CComplexSource::onEvent(), NLSOUND::CComplexSource::onUpdate(), and NLSOUND::CComplexSource::playStuf().

float NLSOUND::CSound::getGain void   )  const [inline]
 

Return the gain.

Definition at line 90 of file sound.h.

Referenced by NLSOUND::CAudioMixerUser::addUserControledSource(), NLSOUND::CComplexSource::CComplexSource(), NLSOUND::CAudioMixerUser::createSource(), and NLSOUND::CBackgroundSource::updateFilterValues().

00090 { return _Gain; }

bool NLSOUND::CSound::getLooping  )  const [inline]
 

Return the looping state.

Definition at line 88 of file sound.h.

References _Looping.

Referenced by NLSOUND::CComplexSource::CComplexSource(), and NLSOUND::CComplexSource::checkup().

00088 { return _Looping; }

virtual float NLSOUND::CSound::getMaxDistance  )  const [inline, virtual]
 

Return the max distance (if detailed()).

Reimplemented in NLSOUND::CBackgroundSound, NLSOUND::CComplexSound, and NLSOUND::CContextSound.

Definition at line 110 of file sound.h.

Referenced by NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::addSound(), NLSOUND::CBackgroundSoundManager::addSound(), NLSOUND::CAudioMixerUser::getFreeTrack(), NLSOUND::CComplexSound::getMaxDistance(), NLSOUND::CBackgroundSound::getMaxDistance(), and NLSOUND::CSimpleSource::play().

00110 { return _MaxDist; }

const NLMISC::TStringId& NLSOUND::CSound::getName void   )  const [inline]
 

Return the name (must be unique).

Definition at line 108 of file sound.h.

Referenced by NLSOUND::CSoundBank::addSound(), NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::addSound(), and NLSOUND::CComplexSource::onUpdate().

00108 { return _Name; }

float NLSOUND::CSound::getPitch void   )  const [inline]
 

Return the pitch.

Definition at line 92 of file sound.h.

Referenced by NLSOUND::CComplexSource::CComplexSource(), NLSOUND::CAudioMixerUser::createSource(), NLSOUND::CComplexSource::onEvent(), NLSOUND::CComplexSource::playStuf(), and NLSOUND::CBackgroundSource::updateFilterValues().

00092 { return _Pitch; }

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

Return the initial priority.

Definition at line 94 of file sound.h.

References _Priority, and NLSOUND::TSoundPriority.

Referenced by NLSOUND::CComplexSource::CComplexSource().

00094 { return _Priority; }

virtual TSOUND_TYPE NLSOUND::CSound::getSoundType  )  [pure virtual]
 

Get the type of the sound.

Implemented in NLSOUND::CBackgroundSound, NLSOUND::CComplexSound, NLSOUND::CContextSound, and NLSOUND::CSimpleSound.

Referenced by NLSOUND::CSoundSerializer::serial().

virtual void NLSOUND::CSound::getSubSoundList std::vector< std::pair< std::string, CSound * > > &  subsounds  )  const [pure virtual]
 

Used by the george sound plugin to check sound recursion (ie sound 'toto' use sound 'titi' witch also use sound 'toto' ...).

Implemented in NLSOUND::CBackgroundSound, NLSOUND::CComplexSound, NLSOUND::CContextSound, and NLSOUND::CSimpleSound.

NLMISC::TStringId NLSOUND::CSound::getUserVarControler  )  [inline]
 

Definition at line 121 of file sound.h.

References _UserVarControler.

00121 { return _UserVarControler; }

void NLSOUND::CSound::importForm const std::string &  filename,
NLGEORGES::UFormElm root
[virtual]
 

Load the sound parameters from georges' form.

Load the sound parameters from georges' form

Reimplemented in NLSOUND::CBackgroundSound, NLSOUND::CComplexSound, NLSOUND::CContextSound, and NLSOUND::CSimpleSound.

Definition at line 140 of file sound.cpp.

References _ConeInnerAngle, _ConeOuterAngle, _ConeOuterGain, _Looping, _Priority, NLGEORGES::UFormElm::getValueByName(), NLSOUND::HighestPri, NLSOUND::HighPri, NLSOUND::LowPri, NLSOUND::MidPri, NLMISC::Pi, sint32, NLSOUND::Sqrt12_2, uint32, x, y, and z.

Referenced by createSound().

00141 {
00142         // Name
00143         _Name = CStringMapper::map(CFile::getFilenameWithoutExtension(filename));       
00144 
00145         // InternalConeAngle
00146         uint32 inner;
00147         root.getValueByName(inner, ".InternalConeAngle");
00148         if (inner > 360)
00149         {
00150                 inner = 360;
00151         }
00152         _ConeInnerAngle = (float) (Pi * inner / 180.0f);  // convert to radians
00153 
00154         // ExternalConeAngle
00155         uint32 outer;
00156         root.getValueByName(outer, ".ExternalConeAngle");
00157         if (outer > 360)
00158         {
00159                 outer = 360;
00160         }
00161         _ConeOuterAngle= (float) (Pi * outer / 180.0f);  // convert to radians
00162 
00163         // Loop
00164         root.getValueByName(_Looping, ".Loop");
00165 
00166         // Gain
00167         sint32 gain;
00168         root.getValueByName(gain, ".Gain");
00169         if (gain > 0)
00170         {
00171                 gain = 0;
00172         }
00173         if (gain < -100)
00174         {
00175                 gain = -100;
00176         }
00177         _Gain = (float) pow(10.0, gain / 20.0); // convert dB to linear gain
00178 
00179         // External gain
00180         root.getValueByName(gain, ".ExternalGain");
00181         if (gain > 0)
00182         {
00183                 gain = 0;
00184         }
00185         if (gain < -100)
00186         {
00187                 gain = -100;
00188         }
00189         _ConeOuterGain = (float) pow(10.0, gain / 20.0); // convert dB to linear gain
00190 
00191         // Direction
00192         float x, y, z;
00193 
00194         root.getValueByName(x, ".Direction.X");
00195         root.getValueByName(y, ".Direction.Y");
00196         root.getValueByName(z, ".Direction.Z");
00197         _Direction = CVector(x, y, z);
00198 
00199 
00200         // Pitch
00201         sint32 trans;
00202         root.getValueByName(trans, ".Transpose");
00203         _Pitch =  (float) pow(Sqrt12_2, trans); // convert semi-tones to playback speed
00204 
00205         // Priority
00206         uint32 prio = 0;
00207         root.getValueByName(prio, ".Priority");
00208         switch (prio)
00209         {
00210         case 0:         
00211                 _Priority = LowPri; 
00212                 break;
00213         case 1:         
00214                 _Priority = MidPri; 
00215                 break;
00216         case 2:         
00217                 _Priority = HighPri; 
00218                 break;
00219         case 3:         
00220                 _Priority = HighestPri; 
00221                 break;
00222         default:        
00223                 _Priority = MidPri;
00224         }
00225 }

virtual bool NLSOUND::CSound::isDetailed  )  const [pure virtual]
 

Return true if cone is meaningful.

Implemented in NLSOUND::CBackgroundSound, NLSOUND::CComplexSound, NLSOUND::CContextSound, and NLSOUND::CSimpleSound.

bool NLSOUND::CSound::operator< const CSound otherSound  )  const [inline]
 

Definition at line 123 of file sound.h.

References _Name, and NLMISC::CStringMapper::unmap().

00124         {
00125                 return NLMISC::CStringMapper::unmap(_Name) < NLMISC::CStringMapper::unmap(otherSound._Name);
00126         }

void NLSOUND::CSound::serial NLMISC::IStream s  )  [virtual]
 

Reimplemented in NLSOUND::CBackgroundSound, NLSOUND::CComplexSound, NLSOUND::CContextSound, and NLSOUND::CSimpleSound.

Definition at line 114 of file sound.cpp.

References _ConeInnerAngle, _ConeOuterAngle, _ConeOuterGain, _Looping, _Priority, and s.

Referenced by NLSOUND::CSoundSerializer::serial().

00115 {
00116         s.serial(_Gain);
00117         s.serial(_Pitch);
00118         s.serialEnum(_Priority);
00119         s.serial(_ConeInnerAngle, _ConeOuterAngle, _ConeOuterGain);
00120         s.serial(_Direction);
00121         s.serial(_Looping);
00122         s.serial(_MaxDist);
00123         if (s.isReading())
00124         {
00125                 std::string name;
00126                 s.serial(name);
00127                 _Name = CStringMapper::map(name);
00128         }
00129         else
00130         {
00131                 std::string name = CStringMapper::unmap(_Name);
00132                 s.serial(name);
00133         }
00134 }

void NLSOUND::CSound::setLooping bool  looping  )  [inline]
 

Set looping.

Definition at line 113 of file sound.h.

References _Looping.

00113 { _Looping = looping; }


Friends And Related Function Documentation

friend class CAudioMixerUser [friend]
 

Definition at line 62 of file sound.h.


Field Documentation

float NLSOUND::CSound::_ConeInnerAngle [protected]
 

Definition at line 134 of file sound.h.

Referenced by getConeInnerAngle(), importForm(), and serial().

float NLSOUND::CSound::_ConeOuterAngle [protected]
 

Definition at line 134 of file sound.h.

Referenced by getConeOuterAngle(), importForm(), and serial().

float NLSOUND::CSound::_ConeOuterGain [protected]
 

Definition at line 134 of file sound.h.

Referenced by getConeOuterGain(), importForm(), and serial().

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

Definition at line 135 of file sound.h.

float NLSOUND::CSound::_Gain [protected]
 

Definition at line 131 of file sound.h.

bool NLSOUND::CSound::_Looping [protected]
 

Definition at line 137 of file sound.h.

Referenced by getLooping(), importForm(), serial(), and setLooping().

float NLSOUND::CSound::_MaxDist [protected]
 

Clipping distance for complex or backgound sound.

Definition at line 140 of file sound.h.

Referenced by NLSOUND::CComplexSound::getMaxDistance().

NLMISC::TStringId NLSOUND::CSound::_Name [protected]
 

Definition at line 143 of file sound.h.

Referenced by operator<().

float NLSOUND::CSound::_Pitch [protected]
 

Definition at line 132 of file sound.h.

TSoundPriority NLSOUND::CSound::_Priority [protected]
 

Definition at line 133 of file sound.h.

Referenced by getPriority(), importForm(), and serial().

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

An optional user var controler.

Definition at line 145 of file sound.h.

Referenced by getUserVarControler(), and NLSOUND::CAudioMixerUser::initUserVar().


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