NLSOUND::CSimpleSound Class Reference

#include <simple_sound.h>

Inheritance diagram for NLSOUND::CSimpleSound:

NLSOUND::CSound

Detailed Description

A sound buffer and its static properties
Author:
Boris Boucher

Nevrax France

Date:
2002

Definition at line 46 of file simple_sound.h.

Public Types

enum  TSOUND_TYPE { SOUND_SIMPLE, SOUND_COMPLEX, SOUND_BACKGROUND, SOUND_CONTEXT }

Public Member Functions

 CSimpleSound ()
 Constructor.

float getAlpha () const
 Return the alpha attenuation value.

IBuffergetBuffer ()
 Return the buffer and the buffername if not null.

const NLMISC::TStringIdgetBuffername () const
 Return the name of the buffer (must be unique).

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.

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

const NLMISC::TStringIdgetFilename () const
 Return the filename.

float getGain () const
 Return the gain.

bool getLooping () const
 Return the looping state.

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

float getMinDistance () const
 Return the min 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.

void getSubSoundList (std::vector< std::pair< std::string, CSound * > > &subsounds) const
 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.

bool isDetailed () const
 Return true if distance and cone are meaningful.

bool operator< (const CSound &otherSound) const
void serial (NLMISC::IStream &s)
void setBuffer (IBuffer *buffer)
 Change the buffer.

void setLooping (bool looping)
 Set looping.

virtual ~CSimpleSound ()
 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.


Private Member Functions

TSOUND_TYPE getSoundType ()
 Get the type of the sound.


Private Attributes

double _Alpha
IBuffer_Buffer
NLMISC::TStringId _Buffername
bool _Detailed
NLMISC::TStringId _Filename
float _MinDist
bool _NeedContext
bool _Registered


Member Enumeration Documentation

enum NLSOUND::CSound::TSOUND_TYPE [inherited]
 

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::CSimpleSound::CSimpleSound  ) 
 

Constructor.

Definition at line 45 of file simple_sound.cpp.

00045                            :
00046         _Buffer(NULL), 
00047         _MinDist(1.0f),
00048         _Detailed(false),
00049         _Registered(false),
00050         _NeedContext(false)
00051 {
00052 }

NLSOUND::CSimpleSound::~CSimpleSound  )  [virtual]
 

Destructor.

Definition at line 58 of file simple_sound.cpp.

00059 {
00060         if (_Buffer != NULL)
00061                 CSoundBank::instance()->unregisterBufferAssoc(this, _Buffer);
00062 }


Member Function Documentation

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

Factory for specialized sound.

Definition at line 43 of file sound.cpp.

References NLGEORGES::UFormElm::getDfnName(), NLGEORGES::UFormElm::getNodeByName(), NLSOUND::CSound::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::CSimpleSound::getAlpha  )  const [inline]
 

Return the alpha attenuation value.

Definition at line 69 of file simple_sound.h.

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

00069 { return float(_Alpha); }

IBuffer * NLSOUND::CSimpleSound::getBuffer  ) 
 

Return the buffer and the buffername if not null.

Definition at line 93 of file simple_sound.cpp.

References _Buffername, and _Registered.

Referenced by NLSOUND::CAudioMixerUser::createSource(), NLSOUND::CSimpleSource::getBuffer(), getDuration(), NLSOUND::CSimpleSource::play(), and NLSOUND::CSimpleSource::setDirection().

00094 { 
00095         if (_Buffer == 0)
00096         {
00097                 // try to find the sample buffer in the sample bank.
00098                 _Buffer = CSampleBank::get(_Buffername); 
00099                 CSoundBank::instance()->registerBufferAssoc(this, _Buffer);
00100                 _Registered = true;
00101         }
00102         return _Buffer;
00103 }

const NLMISC::TStringId& NLSOUND::CSimpleSound::getBuffername  )  const [inline]
 

Return the name of the buffer (must be unique).

Definition at line 75 of file simple_sound.h.

References _Buffername.

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

00075 { return _Buffername; }

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

Return the inner angle of the cone.

Definition at line 98 of file sound.h.

References NLSOUND::CSound::_ConeInnerAngle.

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

00098 { return _ConeInnerAngle; }

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

Return the outer angle of the cone.

Definition at line 100 of file sound.h.

References NLSOUND::CSound::_ConeOuterAngle.

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

00100 { return _ConeOuterAngle; }

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

Return the outer gain of the cone.

Definition at line 102 of file sound.h.

References NLSOUND::CSound::_ConeOuterGain.

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

00102 { return _ConeOuterGain; }

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

Return the direction vector.

Definition at line 104 of file sound.h.

00104 { return _Direction;}

uint32 NLSOUND::CSimpleSound::getDuration  )  [virtual]
 

Return the length of the sound in ms.

Implements NLSOUND::CSound.

Definition at line 109 of file simple_sound.cpp.

References buffer, getBuffer(), and uint32.

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

00110 {
00111         IBuffer* buffer = getBuffer();
00112 
00113         if ( buffer == NULL )
00114         {
00115                 return 0;
00116         }
00117         else
00118         {
00119                 return (uint32)(buffer->getDuration());
00120         }
00121 }

const NLMISC::TStringId& NLSOUND::CSimpleSound::getFilename  )  const [inline]
 

Return the filename.

Definition at line 73 of file simple_sound.h.

00073 { return _Filename; }

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

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, inherited]
 

Return the looping state.

Definition at line 88 of file sound.h.

References NLSOUND::CSound::_Looping.

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

00088 { return _Looping; }

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

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

float NLSOUND::CSimpleSound::getMinDistance  )  const [inline]
 

Return the min distance (if detailed()).

Definition at line 67 of file simple_sound.h.

References _MinDist.

Referenced by NLSOUND::CAudioMixerUser::getFreeTrack(), and NLSOUND::CSimpleSource::play().

00067 { return _MinDist; }

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

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, inherited]
 

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, inherited]
 

Return the initial priority.

Definition at line 94 of file sound.h.

References NLSOUND::CSound::_Priority, and NLSOUND::TSoundPriority.

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

00094 { return _Priority; }

TSOUND_TYPE NLSOUND::CSimpleSound::getSoundType  )  [inline, private, virtual]
 

Get the type of the sound.

Implements NLSOUND::CSound.

Definition at line 88 of file simple_sound.h.

00088 {return SOUND_SIMPLE;};

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

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

Implements NLSOUND::CSound.

Definition at line 82 of file simple_sound.cpp.

References _Buffername.

00083 {
00084         // A little hack, we use the reference vector to tag unavailable sample.
00085         if (!(_Buffername == CStringMapper::emptyId()) && const_cast<CSimpleSound*>(this)->getBuffer() == 0)
00086                 subsounds.push_back(pair<string, CSound*>(CStringMapper::unmap(_Buffername)+" (sample)", 0));
00087 }

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

Definition at line 121 of file sound.h.

References NLSOUND::CSound::_UserVarControler.

00121 { return _UserVarControler; }

void NLSOUND::CSimpleSound::importForm const std::string &  filename,
NLGEORGES::UFormElm formRoot
[virtual]
 

Load the sound parameters from georges' form.

Allow to load sound files when corresponding wave file is missing (default: false, i.e. an input serial or a load throws an exception ESoundFileNotFound)

Reimplemented from NLSOUND::CSound.

Definition at line 155 of file simple_sound.cpp.

References _Buffername, _MinDist, _NeedContext, NLGEORGES::UFormElm::getDfnName(), NLGEORGES::UFormElm::getNodeByName(), NLGEORGES::UFormElm::getValueByName(), nlassert, and setBuffer().

00156 {
00157         NLGEORGES::UFormElm *psoundType;
00158         std::string dfnName;
00159 
00160         // some basic checking.
00161         root.getNodeByName(&psoundType, ".SoundType");
00162         nlassert(psoundType != NULL);
00163         psoundType->getDfnName(dfnName);
00164         nlassert(dfnName == "simple_sound.dfn");
00165 
00166         // Call the base class
00167         CSound::importForm(filename, root);
00168 
00169         // Name
00170         _Filename = CStringMapper::map(filename);
00171 
00172         // Buffername
00173         std::string bufferName;
00174         root.getValueByName(bufferName, ".SoundType.Filename");
00175         bufferName = CFile::getFilenameWithoutExtension(bufferName);
00176         _Buffername = CStringMapper::map(bufferName);
00177 
00178         setBuffer(NULL);
00179 
00180         // contain % so it need a context to play
00181         if (bufferName.find ("%") != string::npos)
00182         {
00183                 _NeedContext = true;
00184         }
00185 
00186         // MaxDistance
00187         root.getValueByName(_MaxDist, ".SoundType.MaxDistance");
00188 
00189         // MinDistance
00190         root.getValueByName(_MinDist, ".SoundType.MinDistance");
00191 
00192         // Alpha
00193         root.getValueByName(_Alpha, ".SoundType.Alpha");
00194 
00195 }

bool NLSOUND::CSimpleSound::isDetailed  )  const [inline, virtual]
 

Return true if distance and cone are meaningful.

Implements NLSOUND::CSound.

Definition at line 65 of file simple_sound.h.

References _Detailed.

00065 { return _Detailed; }

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

Definition at line 123 of file sound.h.

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

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

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

Reimplemented from NLSOUND::CSound.

Definition at line 124 of file simple_sound.cpp.

References _Buffername, _MinDist, _NeedContext, s, and setBuffer().

00125 {
00126         std::string bufferName;
00127         CSound::serial(s);
00128         
00129         s.serial(_MinDist);
00130         s.serial(_Alpha);
00131 
00132         if (s.isReading())
00133         {
00134                 s.serial(bufferName);
00135                 _Buffername = CStringMapper::map(bufferName);
00136                 setBuffer(NULL);
00137 
00138                 // contain % so it need a context to play
00139                 if (bufferName.find ("%") != string::npos)
00140                 {
00141                         _NeedContext = true;
00142                 }
00143         }
00144         else
00145         {
00146                 bufferName = CStringMapper::unmap(_Buffername);
00147                 s.serial(bufferName);
00148         }
00149 }

void NLSOUND::CSimpleSound::setBuffer IBuffer buffer  ) 
 

Change the buffer.

Definition at line 64 of file simple_sound.cpp.

References _Registered, buffer, and NLSOUND::IBuffer::getName().

Referenced by NLSOUND::CSoundBank::bufferLoaded(), NLSOUND::CSoundBank::bufferUnloaded(), importForm(), and serial().

00065 {
00066         if (_Buffer != NULL && buffer != NULL && _Buffer->getName() != buffer->getName())
00067         {
00068                 // if buffer name change, update the registration/
00069                 CSoundBank::instance()->unregisterBufferAssoc(this, _Buffer);
00070                 CSoundBank::instance()->registerBufferAssoc(this, buffer);
00071         }
00072         else if (!_Registered && buffer != NULL)
00073         {
00074                 // creater initial registration.
00075                 CSoundBank::instance()->registerBufferAssoc(this, buffer);
00076                 _Registered = true;
00077         }
00078         _Buffer = buffer;
00079 }

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

Set looping.

Definition at line 113 of file sound.h.

References NLSOUND::CSound::_Looping.

00113 { _Looping = looping; }


Field Documentation

double NLSOUND::CSimpleSound::_Alpha [private]
 

Definition at line 101 of file simple_sound.h.

IBuffer* NLSOUND::CSimpleSound::_Buffer [private]
 

Definition at line 96 of file simple_sound.h.

NLMISC::TStringId NLSOUND::CSimpleSound::_Buffername [private]
 

Definition at line 110 of file simple_sound.h.

Referenced by getBuffer(), getBuffername(), getSubSoundList(), importForm(), and serial().

float NLSOUND::CSound::_ConeInnerAngle [protected, inherited]
 

Definition at line 134 of file sound.h.

Referenced by NLSOUND::CSound::getConeInnerAngle(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial().

float NLSOUND::CSound::_ConeOuterAngle [protected, inherited]
 

Definition at line 134 of file sound.h.

Referenced by NLSOUND::CSound::getConeOuterAngle(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial().

float NLSOUND::CSound::_ConeOuterGain [protected, inherited]
 

Definition at line 134 of file sound.h.

Referenced by NLSOUND::CSound::getConeOuterGain(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial().

bool NLSOUND::CSimpleSound::_Detailed [private]
 

Definition at line 99 of file simple_sound.h.

Referenced by isDetailed().

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

Definition at line 135 of file sound.h.

NLMISC::TStringId NLSOUND::CSimpleSound::_Filename [private]
 

Definition at line 109 of file simple_sound.h.

float NLSOUND::CSound::_Gain [protected, inherited]
 

Definition at line 131 of file sound.h.

bool NLSOUND::CSound::_Looping [protected, inherited]
 

Definition at line 137 of file sound.h.

Referenced by NLSOUND::CSound::getLooping(), NLSOUND::CSound::importForm(), NLSOUND::CSound::serial(), and NLSOUND::CSound::setLooping().

float NLSOUND::CSound::_MaxDist [protected, inherited]
 

Clipping distance for complex or backgound sound.

Definition at line 140 of file sound.h.

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

float NLSOUND::CSimpleSound::_MinDist [private]
 

Definition at line 100 of file simple_sound.h.

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

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

Definition at line 143 of file sound.h.

Referenced by NLSOUND::CSound::operator<().

bool NLSOUND::CSimpleSound::_NeedContext [private]
 

Definition at line 104 of file simple_sound.h.

Referenced by importForm(), and serial().

float NLSOUND::CSound::_Pitch [protected, inherited]
 

Definition at line 132 of file sound.h.

TSoundPriority NLSOUND::CSound::_Priority [protected, inherited]
 

Definition at line 133 of file sound.h.

Referenced by NLSOUND::CSound::getPriority(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial().

bool NLSOUND::CSimpleSound::_Registered [private]
 

Definition at line 93 of file simple_sound.h.

Referenced by getBuffer(), and setBuffer().

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

An optional user var controler.

Definition at line 145 of file sound.h.

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


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