#include <sound_bank.h>
Nevrax France
Definition at line 50 of file sound_bank.h.
Public Member Functions | |
void | addSound (CSound *sound) |
void | bufferLoaded (const NLMISC::TStringId &bufferName, IBuffer *buffer) |
void | bufferUnloaded (const NLMISC::TStringId &bufferName) |
uint | countSounds () |
Return the number of sounds in this bank. | |
void | getNames (std::vector< NLMISC::TStringId > &names) |
Return the names of the sounds. | |
CSound * | getSound (const NLMISC::TStringId &name) |
Return a sound corresponding to a name. | |
bool | isLoaded () |
Returns true if the sounds in this bank have been loaded. | |
void | load () |
Load all the sounds. | |
void | registerBufferAssoc (CSimpleSound *sound, IBuffer *buffer) |
void | removeSound (const NLMISC::TStringId &name) |
void | unload () |
Remove all the sounds in this bank. | |
void | unregisterBufferAssoc (CSimpleSound *sound, IBuffer *buffer) |
virtual | ~CSoundBank () |
Destructor. | |
Static Public Member Functions | |
CSoundBank * | instance () |
Release all the loaded sound banks. | |
void | release () |
Private Types | |
typedef std::hash_map< NLMISC::TStringId, TSimpleSoundContainer > | TBufferAssocContainer |
typedef std::hash_set< class CSimpleSound *, THashPtr< CSimpleSound * > > | TSimpleSoundContainer |
typedef std::hash_map< NLMISC::TStringId, CSound * > | TSoundTable |
Sound names hash map. | |
Private Member Functions | |
CSoundBank () | |
Constructor. | |
Private Attributes | |
TBufferAssocContainer | _BufferAssoc |
Assoc from buffer to sound. Used for sound unloading. | |
bool | _Loaded |
TSoundTable | _Sounds |
Static Private Attributes | |
CSoundBank * | _Instance |
CSoundBank singleton instance. |
|
Definition at line 107 of file sound_bank.h. |
|
Definition at line 105 of file sound_bank.h. |
|
Sound names hash map.
Definition at line 110 of file sound_bank.h. |
|
Destructor.
Definition at line 146 of file sound_bank.cpp. References unload().
00147 { 00148 unload(); 00149 } |
|
Constructor.
Definition at line 99 of file sound_bank.h. Referenced by instance().
00099 : _Loaded(false) {}; |
|
Definition at line 151 of file sound_bank.cpp. References NLSOUND::CSound::getName(), and nlassert. Referenced by load().
|
|
Called by CSampleBank when a sample(buffer) is loaded. Regenerate link between CSound and IBuffer. Definition at line 89 of file sound_bank.cpp. References _BufferAssoc, buffer, and NLSOUND::CSimpleSound::setBuffer().
00090 { 00091 // std::map<std::string, std::vector<TBufferAssoc> >::iterator it(_BufferAssoc.find(buffer->getName())); 00092 TBufferAssocContainer::iterator it(_BufferAssoc.find(buffer->getName())); 00093 00094 if (it != _BufferAssoc.end()) 00095 { 00096 // ok, found some sound associated with this buffer. 00097 // update all sounds. 00098 TSimpleSoundContainer::iterator first(it->second.begin()), last(it->second.end()); 00099 for (; first != last; ++first) 00100 { 00101 CSimpleSound *ss = const_cast<CSimpleSound*>(*(it->second.begin())); 00102 // restore the associated buffer. 00103 ss->setBuffer(buffer); 00104 } 00105 } 00106 00107 } |
|
Called by CSampleBank when a sample(buffer) is unloaded. Remove link from CSound to unloaded IBuffer. Definition at line 70 of file sound_bank.cpp. References _BufferAssoc, and NLSOUND::CSimpleSound::setBuffer().
00071 { 00072 TBufferAssocContainer::iterator it(_BufferAssoc.find(bufferName)); 00073 00074 if (it != _BufferAssoc.end()) 00075 { 00076 // ok, found some sound associated with this buffer. 00077 // update all sounds. 00078 TSimpleSoundContainer::iterator first(it->second.begin()), last(it->second.end()); 00079 for (; first != last; ++first) 00080 { 00081 // remove the associated buffer. 00082 CSimpleSound *ss = const_cast<CSimpleSound*>(*(first)); 00083 ss->setBuffer(NULL); 00084 } 00085 } 00086 } |
|
Return the number of sounds in this bank.
Definition at line 380 of file sound_bank.cpp. References uint.
00381 { 00382 return _Sounds.size(); 00383 } |
|
Return the names of the sounds. Return the names of the sounds Definition at line 367 of file sound_bank.cpp.
|
|
Return a sound corresponding to a name.
Definition at line 350 of file sound_bank.cpp.
|
|
Release all the loaded sound banks.
Definition at line 54 of file sound_bank.cpp. References CSoundBank().
00055 { 00056 NL_ALLOC_CONTEXT(NLSOUND_CSoundBank); 00057 if (_Instance == 0) 00058 _Instance = new CSoundBank(); 00059 return _Instance; 00060 } |
|
Returns true if the sounds in this bank have been loaded.
Definition at line 342 of file sound_bank.cpp.
00343 { 00344 return _Loaded; 00345 } |
|
Load all the sounds. Load all the sound samples. Can throw EPathNotFound or ESoundFileNotFound (check Exception) Definition at line 277 of file sound_bank.cpp. References addSound(), NLSOUND::Container, and nlassert.
00278 { 00279 // this structure is fill by the loadForm() function and will contain all you need 00280 std::map<std::string, CSoundSerializer> Container; 00281 nlassert(!_Loaded); 00282 // Just call the GEORGE::loadFrom method to read all available sounds 00283 ::loadForm("sound", CAudioMixerUser::instance()->getPackedSheetPath()+"sounds.packed_sheets", Container, CAudioMixerUser::instance()->getPackedSheetUpdate(), false); 00284 _Loaded = true; 00285 00286 // add all the loaded sound in the sound banks 00287 std::map<std::string, CSoundSerializer>::iterator first(Container.begin()), last(Container.end()); 00288 for (; first != last; ++first) 00289 { 00290 if (first->second.Sound != 0) 00291 addSound(first->second.Sound); 00292 } 00293 00294 Container.clear(); 00295 } |
|
Definition at line 109 of file sound_bank.cpp. References _BufferAssoc, and buffer.
00110 { 00111 if (buffer != NULL) 00112 { 00113 const NLMISC::TStringId &bufferName = buffer->getName(); 00114 _BufferAssoc[bufferName].insert(sound); 00115 } 00116 } |
|
Definition at line 62 of file sound_bank.cpp.
|
|
Definition at line 158 of file sound_bank.cpp.
00159 { 00160 _Sounds.erase(name); 00161 } |
|
Remove all the sounds in this bank.
Definition at line 301 of file sound_bank.cpp. References nlassert. Referenced by ~CSoundBank().
00302 { 00303 nlassert(_Loaded); 00304 00305 TSoundTable::iterator first(_Sounds.begin()), last(_Sounds.end()); 00306 for (; first != last; ++first) 00307 { 00308 delete first->second; 00309 } 00310 00311 _Sounds.clear(); 00312 _Loaded = false; 00313 00314 /* vector<CSound*> vec; 00315 00316 00317 TSoundTable::iterator map_iter; 00318 00319 for (map_iter = _Sounds.begin(); map_iter != _Sounds.end(); ++map_iter) 00320 { 00321 // We can't delete directly second because the map is based on second->getName() 00322 vec.push_back( (*map_iter).second ); 00323 } 00324 00325 _Sounds.clear(); 00326 00327 vector<CSound*>::iterator vec_iter; 00328 00329 for (vec_iter = vec.begin(); vec_iter != vec.end(); ++vec_iter) 00330 { 00331 CSound *sound = *vec_iter; 00332 delete sound; 00333 } 00334 00335 _Loaded = false; 00336 */ 00337 } |
|
Definition at line 118 of file sound_bank.cpp. References _BufferAssoc, buffer, and nlassert.
00119 { 00120 if (buffer != NULL) 00121 { 00122 const TStringId &bufferName = buffer->getName(); 00123 TBufferAssocContainer::iterator it(_BufferAssoc.find(bufferName)); 00124 00125 if (it != _BufferAssoc.end()) 00126 { 00127 TSimpleSoundContainer::iterator it2(it->second.find(sound)); 00128 00129 nlassert(it2 != it->second.end()); 00130 it->second.erase(it2); 00131 00132 if (it->second.empty()) 00133 { 00134 // last sound refenrecing this buffer 00135 _BufferAssoc.erase(it); 00136 } 00137 00138 } 00139 } 00140 } |
|
Assoc from buffer to sound. Used for sound unloading.
Definition at line 113 of file sound_bank.h. Referenced by bufferLoaded(), bufferUnloaded(), registerBufferAssoc(), and unregisterBufferAssoc(). |
|
CSoundBank singleton instance.
Definition at line 50 of file sound_bank.cpp. |
|
Definition at line 119 of file sound_bank.h. |
|
Definition at line 116 of file sound_bank.h. |