Ticket #1766: soundManagerEntity.patch
File soundManagerEntity.patch, 24.8 KB (added by , 11 years ago) |
---|
-
source/simulation2/components/CCmpSoundManager.cpp
135 135 sourcePos = CVector3D(cmpPosition->GetPosition()); 136 136 } 137 137 138 group->PlayNext(sourcePos );138 group->PlayNext(sourcePos, source); 139 139 } 140 140 #else // !CONFIG2_AUDIO 141 141 UNUSED2(name); -
source/soundmanager/SoundManager.cpp
34 34 35 35 CSoundManager* g_SoundManager = NULL; 36 36 37 #define SOURCE_NUM 128 37 38 39 #if CONFIG2_AUDIO 40 38 41 class CSoundManagerWorker 39 42 { 40 43 public: … … 83 86 ItemsList::iterator lstr = m_Items->begin(); 84 87 while (lstr != m_Items->end()) 85 88 { 86 (*lstr)->Stop();87 89 delete *lstr; 88 90 lstr++; 89 91 } … … 115 117 m_DeadItems->clear(); 116 118 } 117 119 118 void DeleteItem(long itemNum)119 {120 CScopeLock lock(m_WorkerMutex);121 AL_CHECK122 ItemsList::iterator lstr = m_Items->begin();123 lstr += itemNum;124 125 delete *lstr;126 AL_CHECK127 128 m_Items->erase(lstr);129 }130 131 132 120 private: 133 121 static void* RunThread(void* data) 134 122 { … … 146 134 // Wait until the main thread wakes us up 147 135 while ( true ) 148 136 { 137 g_Profiler2.RecordRegionLeave("semaphore wait"); 138 149 139 // Handle shutdown requests as soon as possible 150 140 if (GetShutdown()) 151 141 return; … … 155 145 continue; 156 146 157 147 int pauseTime = 1000; 148 if ( g_SoundManager->InDistress() ) 149 pauseTime = 50; 150 158 151 { 159 152 CScopeLock lock(m_WorkerMutex); 160 153 … … 164 157 165 158 while (lstr != m_Items->end()) { 166 159 160 AL_CHECK 167 161 if ((*lstr)->IdleTask()) 168 162 { 169 if ( ( *lstr)->IsFading() )163 if ( (pauseTime == 1000) && (*lstr)->IsFading() ) 170 164 pauseTime = 100; 165 171 166 nextItemList->push_back(*lstr); 172 167 } 173 168 else … … 217 212 bool m_Enabled; 218 213 bool m_Shutdown; 219 214 }; 215 #endif 220 216 221 217 void CSoundManager::ScriptingInit() 222 218 { … … 229 225 230 226 #if CONFIG2_AUDIO 231 227 228 232 229 void CSoundManager::CreateSoundManager() 233 230 { 234 231 g_SoundManager = new CSoundManager(); … … 260 257 261 258 CSoundManager::CSoundManager() 262 259 { 263 m_CurrentEnvirons = NULL; 264 m_CurrentTune = NULL; 260 m_CurrentEnvirons = 0; 261 m_ALSourceBuffer = NULL; 262 m_CurrentTune = 0; 265 263 m_Gain = 1; 266 264 m_MusicGain = 1; 267 265 m_AmbientGain = 1; … … 269 267 m_BufferCount = 50; 270 268 m_BufferSize = 65536; 271 269 m_MusicEnabled = true; 270 m_DistressTime = 0; 271 m_DistressErrCount = 0; 272 272 273 m_Enabled = AlcInit() == INFO::OK; 273 274 InitListener(); 274 275 … … 286 287 } 287 288 288 289 290 289 291 Status CSoundManager::AlcInit() 290 292 { 291 293 Status ret = INFO::OK; … … 297 299 m_Context = alcCreateContext(m_Device, &attribs[0]); 298 300 299 301 if(m_Context) 302 { 300 303 alcMakeContextCurrent(m_Context); 304 m_ALSourceBuffer = new ALSourceHolder[SOURCE_NUM]; 305 ALuint* sourceList = new ALuint[SOURCE_NUM]; 306 307 alGenSources( SOURCE_NUM, sourceList); 308 ALCenum err = alcGetError(m_Device); 309 if ( err == ALC_NO_ERROR ) 310 { 311 for ( int x=0; x<SOURCE_NUM;x++) 312 { 313 m_ALSourceBuffer[x].ALSource = sourceList[x]; 314 m_ALSourceBuffer[x].SourceItem = NULL; 315 316 } 317 } 318 else 319 { 320 LOGERROR(L"error in gensource = %d", err); 321 } 322 delete[] sourceList; 323 } 301 324 } 302 325 303 326 // check if init succeeded. … … 311 334 else 312 335 { 313 336 LOGERROR(L"Sound: AlcInit failed, m_Device=%p m_Context=%p dev_name=%hs err=%d\n", m_Device, m_Context, dev_name, err); 337 338 339 314 340 // FIXME Hack to get around exclusive access to the sound device 315 341 #if OS_UNIX 316 342 ret = INFO::OK; … … 321 347 322 348 return ret; 323 349 } 350 351 bool CSoundManager::InDistress() 352 { 353 CScopeLock lock(m_DistressMutex); 354 355 if ( m_DistressTime == 0 ) 356 return false; 357 else if ( (timer_Time() - m_DistressTime) > 10 ) 358 { 359 m_DistressTime = 0; 360 LOGERROR(L"Sound: Coming out of distress mode suffering %ld errors\n", m_DistressErrCount); 361 m_DistressErrCount = 0; 362 return false; 363 } 364 else 365 { 366 // LOGERROR(L"Sound: Still in distress mode suffering %ld errors at %ld time\n", m_DistressErrCount, m_DistressTime); 367 } 368 369 370 return true; 371 } 372 373 void CSoundManager::SetDistressThroughShortage() 374 { 375 CScopeLock lock(m_DistressMutex); 376 377 if ( m_DistressTime == 0 ) 378 LOGERROR(L"Sound: Entering distress mode through shortage\n", 0); 379 380 m_DistressTime = timer_Time(); 381 } 382 383 void CSoundManager::SetDistressThroughError() 384 { 385 CScopeLock lock(m_DistressMutex); 386 387 if ( m_DistressTime == 0 ) 388 LOGERROR(L"Sound: Entering distress mode through error\n", 0); 389 390 m_DistressTime = timer_Time(); 391 m_DistressErrCount++; 392 } 393 394 395 396 ALuint CSoundManager::GetALSource( ISoundItem* anItem) 397 { 398 for ( int x=0; x<SOURCE_NUM;x++) 399 { 400 if ( ! m_ALSourceBuffer[x].SourceItem ) 401 { 402 m_ALSourceBuffer[x].SourceItem = anItem; 403 return m_ALSourceBuffer[x].ALSource; 404 } 405 } 406 SetDistressThroughShortage(); 407 return 0; 408 } 409 410 void CSoundManager::ReleaseALSource(ALuint theSource) 411 { 412 for ( int x=0; x<SOURCE_NUM;x++) 413 { 414 if ( m_ALSourceBuffer[x].ALSource == theSource ) 415 { 416 m_ALSourceBuffer[x].SourceItem = NULL; 417 return; 418 } 419 } 420 } 421 324 422 void CSoundManager::SetMemoryUsage(long bufferSize, int bufferCount) 325 423 { 326 424 m_BufferCount = bufferCount; … … 361 459 AL_CHECK 362 460 363 461 CSoundData* itemData = CSoundData::SoundDataFromFile(itemPath); 462 463 AL_CHECK 464 if ( itemData ) 465 return CSoundManager::ItemForData( itemData ); 466 467 return NULL; 468 } 469 470 ISoundItem* CSoundManager::ItemForData(CSoundData* itemData) 471 { 472 AL_CHECK 364 473 ISoundItem* answer = NULL; 365 474 366 475 AL_CHECK … … 392 501 AL_CHECK 393 502 if (m_CurrentTune) 394 503 m_CurrentTune->EnsurePlay(); 504 AL_CHECK 395 505 if (m_CurrentEnvirons) 396 506 m_CurrentEnvirons->EnsurePlay(); 397 507 AL_CHECK 398 508 if (m_Worker) 399 509 m_Worker->CleanupItems(); 510 AL_CHECK 400 511 } 401 512 402 void CSoundManager::DeleteItem(long itemNum)513 ISoundItem* CSoundManager::ItemForEntity( entity_id_t source, CSoundData* sndData) 403 514 { 404 if (m_Worker) 405 m_Worker->DeleteItem(itemNum); 515 return ItemForData( sndData ); 406 516 } 407 517 408 518 … … 431 541 } 432 542 } 433 543 } 434 void CSoundManager::PlayGroupItem(ISoundItem* anItem, ALfloat groupGain )544 void CSoundManager::PlayGroupItem(ISoundItem* anItem, ALfloat groupGain ) 435 545 { 436 546 if (anItem) 437 547 { 438 548 if (m_Enabled && (m_ActionGain > 0)) { 439 549 anItem->SetGain(m_ActionGain * groupGain); 440 anItem->Play ();550 anItem->PlayAndDelete(); 441 551 AL_CHECK 442 552 } 443 553 } -
source/soundmanager/SoundManager.h
24 24 25 25 #include "lib/file/vfs/vfs_path.h" 26 26 #include "soundmanager/items/ISoundItem.h" 27 #include "simulation2/system/Entity.h" 28 #include "soundmanager/data/SoundData.h" 29 #include "ps/Profiler2.h" 27 30 28 31 #include <vector> 29 32 #include <map> … … 31 34 #define AL_CHECK CSoundManager::al_check(__func__, __LINE__); 32 35 33 36 typedef std::vector<ISoundItem*> ItemsList; 37 typedef std::map<entity_id_t, ISoundItem*> ItemsMap; 34 38 35 39 class CSoundManagerWorker; 36 40 41 42 struct ALSourceHolder 43 { 44 /// Title of the column 45 ALuint ALSource; 46 ISoundItem* SourceItem; 47 }; 48 37 49 class CSoundManager 38 50 { 39 51 protected: … … 44 56 ISoundItem* m_CurrentTune; 45 57 ISoundItem* m_CurrentEnvirons; 46 58 CSoundManagerWorker* m_Worker; 59 CMutex m_DistressMutex; 60 47 61 float m_Gain; 48 62 float m_MusicGain; 49 63 float m_AmbientGain; … … 54 68 bool m_MusicEnabled; 55 69 bool m_SoundEnabled; 56 70 71 long m_DistressErrCount; 72 long m_DistressTime; 73 74 ALSourceHolder* m_ALSourceBuffer; 75 57 76 public: 58 77 CSoundManager(); 59 78 virtual ~CSoundManager(); 60 79 61 80 ISoundItem* LoadItem(const VfsPath& itemPath); 81 ISoundItem* ItemForData(CSoundData* itemData); 82 ISoundItem* ItemForEntity( entity_id_t source, CSoundData* sndData); 62 83 63 84 static void ScriptingInit(); 64 85 static void CreateSoundManager(); … … 70 91 void SetMusicEnabled (bool isEnabled); 71 92 void setSoundEnabled( bool enabled ); 72 93 94 ALuint GetALSource(ISoundItem* anItem); 95 void ReleaseALSource(ALuint theSource); 96 ISoundItem* ItemFromData(CSoundData* itemData); 97 73 98 ISoundItem* ItemFromWAV(VfsPath& fname); 74 99 ISoundItem* ItemFromOgg(VfsPath& fname); 75 100 76 101 ISoundItem* GetSoundItem(unsigned long itemRow); 77 102 unsigned long Count(); 78 103 void IdleTask(); 79 void DeleteItem(long itemNum);80 104 81 105 void SetMemoryUsage(long bufferSize, int bufferCount); 82 106 long GetBufferCount(); … … 91 115 void SetMusicGain(float gain); 92 116 void SetAmbientGain(float gain); 93 117 void SetActionGain(float gain); 94 118 bool InDistress(); 119 void SetDistressThroughShortage(); 120 void SetDistressThroughError(); 121 95 122 protected: 96 123 void InitListener(); 97 124 virtual Status AlcInit(); -
source/soundmanager/data/OggData.cpp
34 34 35 35 COggData::~COggData() 36 36 { 37 ogg->Close(); 38 37 39 alDeleteBuffers(m_BuffersUsed, m_Buffer); 38 40 } 39 41 -
source/soundmanager/data/SoundData.cpp
35 35 36 36 CSoundData::~CSoundData() 37 37 { 38 // LOGERROR(L"Sound data deleted %ls\n", m_FileName->c_str() ); 39 38 40 if (m_ALBuffer != 0) 39 41 alDeleteBuffers(1, &m_ALBuffer); 42 40 43 delete m_FileName; 41 44 } 42 45 -
source/soundmanager/data/ogg.cpp
28 28 #include "lib/file/file_system.h" 29 29 30 30 #include "lib/file/vfs/vfs_util.h" 31 #include "ps/CLogger.h" 31 32 #include "ps/Filesystem.h" 32 33 33 34 … … 219 220 m_fileEOF = false; 220 221 } 221 222 223 Status Close() 224 { 225 ov_clear( &vf ); 226 return 0; 227 } 228 222 229 Status Open() 223 230 { 224 231 ov_callbacks callbacks; -
source/soundmanager/data/ogg.h
32 32 virtual ALsizei SamplingRate() = 0; 33 33 virtual bool atFileEOF() = 0; 34 34 virtual Status ResetFile() = 0; 35 virtual Status Close() = 0; 35 36 36 37 /** 37 38 * @return bytes read (<= size) or a (negative) Status -
source/soundmanager/items/CBufferItem.cpp
36 36 37 37 CBufferItem::~CBufferItem() 38 38 { 39 AL_CHECK 39 } 40 40 41 Stop(); 42 if (m_ALSource != 0) 41 42 void CBufferItem::ReleaseOpenAL() 43 { 44 int num_processed; 45 alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed); 46 47 if (num_processed > 0) 43 48 { 44 49 int num_processed; 45 50 alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed); … … 53 58 delete[] al_buf; 54 59 } 55 60 } 61 62 CSoundBase::ReleaseOpenAL(); 56 63 } 57 64 58 59 65 bool CBufferItem::IdleTask() 60 66 { 67 if ( m_ALSource == 0 ) 68 return false; 69 61 70 HandleFade(); 62 if (m_ALSource != 0) 71 72 if (m_LastPlay) 63 73 { 64 if (m_LastPlay) 74 int proc_state; 75 alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state); 76 AL_CHECK 77 return (proc_state != AL_STOPPED); 78 } 79 80 if (GetLooping()) 81 { 82 int num_processed; 83 alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed); 84 85 for (int i = 0; i < num_processed; i++) 65 86 { 66 87 int proc_state; 67 88 alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state); … … 91 112 92 113 void CBufferItem::Attach(CSoundData* itemData) 93 114 { 115 AL_CHECK 116 if ( m_ALSource == 0 ) 117 return; 118 94 119 AL_CHECK 95 if ( (itemData != NULL) && (m_ALSource != 0))120 if (m_SoundData != NULL) 96 121 { 122 CSoundData::ReleaseSoundData(m_SoundData); 123 m_SoundData = 0; 124 } 125 AL_CHECK 126 if (itemData != NULL) 127 { 97 128 m_SoundData = itemData->IncrementCount(); 98 129 alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(),(const ALuint *) m_SoundData->GetBufferPtr()); 99 130 AL_CHECK -
source/soundmanager/items/CBufferItem.h
27 27 class CBufferItem : public CSoundBase 28 28 { 29 29 public: 30 CBufferItem(CSoundData* sndData); 31 virtual ~CBufferItem(); 32 33 virtual void SetLooping(bool loops); 34 virtual bool IdleTask(); 35 36 protected: 37 virtual void Attach(CSoundData* itemData); 30 CBufferItem(CSoundData* sndData); 31 virtual ~CBufferItem(); 32 33 virtual void SetLooping(bool loops); 34 virtual bool IdleTask(); 35 virtual void Attach(CSoundData* itemData); 38 36 39 37 protected: 38 virtual void ReleaseOpenAL(); 39 40 40 }; 41 41 42 42 #endif // CONFIG2_AUDIO -
source/soundmanager/items/CSoundBase.cpp
36 36 CSoundBase::~CSoundBase() 37 37 { 38 38 Stop(); 39 ReleaseOpenAL(); 40 } 41 42 void CSoundBase::ReleaseOpenAL() 43 { 39 44 if (m_ALSource != 0) 40 45 { 41 alDeleteSources(1, &m_ALSource); 46 alSourcei(m_ALSource, AL_BUFFER, 0); 47 g_SoundManager->ReleaseALSource(m_ALSource); 42 48 m_ALSource = 0; 43 49 } 44 50 if (m_SoundData != 0) … … 48 54 } 49 55 } 50 56 57 void CSoundBase::Attach(CSoundData* itemData) 58 { 59 60 } 61 51 62 void CSoundBase::ResetVars() 52 63 { 53 64 m_ALSource = 0; … … 71 82 m_ShouldBePlaying = false; 72 83 } 73 84 85 86 bool CSoundBase::InitOpenAL() 87 { 88 alGetError(); /* clear error */ 89 m_ALSource = g_SoundManager->GetALSource( this ); 90 91 AL_CHECK 92 93 if ( m_ALSource ) 94 { 95 alSourcef(m_ALSource,AL_PITCH,1.0f); 96 AL_CHECK 97 alSourcef(m_ALSource,AL_GAIN,1.0f); 98 AL_CHECK 99 alSourcei(m_ALSource,AL_LOOPING,AL_FALSE); 100 AL_CHECK 101 return true; 102 } 103 else 104 { 105 // LOGERROR(L"Source not allocated by SOundManager\n", 0); 106 } 107 return false; 108 } 109 110 74 111 void CSoundBase::SetGain(ALfloat gain) 75 112 { 76 113 AL_CHECK … … 84 121 85 122 void CSoundBase::SetRollOff(ALfloat rolls) 86 123 { 87 if ( m_ALSource ) 88 124 if ( m_ALSource ) 125 { 89 126 alSourcef(m_ALSource, AL_REFERENCE_DISTANCE, 70.0f); 90 127 AL_CHECK 91 128 alSourcef(m_ALSource, AL_MAX_DISTANCE, 200.0); … … 133 170 } 134 171 } 135 172 136 bool CSoundBase::InitOpenAL()137 {138 alGetError(); /* clear error */139 alGenSources(1, &m_ALSource);140 ALenum anErr = alGetError();141 173 142 if (anErr == AL_NO_ERROR)143 {144 alSourcef(m_ALSource,AL_PITCH,1.0f);145 AL_CHECK146 alSourcef(m_ALSource,AL_GAIN,1.0f);147 AL_CHECK148 alSourcei(m_ALSource,AL_LOOPING,AL_FALSE);149 AL_CHECK150 return true;151 }152 else153 {154 CSoundManager::al_ReportError( anErr, __func__, __LINE__);155 }156 return false;157 }158 159 174 bool CSoundBase::IsPlaying() 160 175 { 161 ALenum proc_state = AL_STOPPED; 162 if ( m_ALSource != 0 ) 176 if ( m_ALSource ) 163 177 { 178 int proc_state; 164 179 alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state); 165 180 AL_CHECK 181 182 return (proc_state == AL_PLAYING); 166 183 } 167 168 return (proc_state == AL_PLAYING); 184 return false; 169 185 } 170 186 171 187 void CSoundBase::SetLastPlay(bool last) … … 178 194 return true; 179 195 } 180 196 197 181 198 void CSoundBase::SetLocation (const CVector3D& position) 182 199 { 183 200 if ( m_ALSource != 0 ) … … 237 254 void CSoundBase::Play() 238 255 { 239 256 m_ShouldBePlaying = true; 257 AL_CHECK 240 258 if (m_ALSource != 0) 259 { 241 260 alSourcePlay(m_ALSource); 242 AL_CHECK 261 ALenum err = alGetError(); 262 if (err != AL_NO_ERROR) 263 { 264 if (err == AL_INVALID) 265 g_SoundManager->SetDistressThroughError(); 266 else 267 g_SoundManager->al_ReportError(err, __func__, __LINE__); 268 } 269 } 243 270 } 244 271 245 272 void CSoundBase::PlayAndDelete() … … 248 275 Play(); 249 276 } 250 277 278 251 279 void CSoundBase::FadeAndDelete(double fadeTime) 252 280 { 253 281 SetLastPlay(true); -
source/soundmanager/items/CSoundBase.h
23 23 #if CONFIG2_AUDIO 24 24 25 25 #include "lib/external_libraries/openal.h" 26 #include "ps/ThreadUtil.h" 26 27 #include "soundmanager/items/ISoundItem.h" 27 28 #include "soundmanager/data/SoundData.h" 28 29 … … 39 40 40 41 double m_StartFadeTime; 41 42 double m_EndFadeTime; 43 42 44 ALfloat m_StartVolume; 43 45 ALfloat m_EndVolume; 44 46 … … 57 59 virtual void SetDirection(const CVector3D& direction); 58 60 virtual void SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain); 59 61 virtual void SetLastPlay(bool last); 62 virtual void ReleaseOpenAL(); 63 60 64 virtual bool IsFading(); 61 65 62 66 void Play(); … … 66 70 void Stop(); 67 71 void StopAndDelete(); 68 72 void FadeToIn(ALfloat newVolume, double fadeDuration); 73 void Attach(CSoundData* itemData); 69 74 70 75 void PlayAsMusic(); 71 76 void PlayAsAmbient(); -
source/soundmanager/items/CSoundItem.cpp
40 40 41 41 CSoundItem::~CSoundItem() 42 42 { 43 AL_CHECK 44 45 Stop(); 43 } 46 44 47 if (m_ALSource != 0)48 49 50 AL_CHECK 51 }45 void CSoundItem::ReleaseOpenAL() 46 { 47 alSourcei(m_ALSource, AL_BUFFER, 0); 48 49 CSoundBase::ReleaseOpenAL(); 52 50 } 53 51 54 52 bool CSoundItem::IdleTask() 55 53 { 54 if ( m_ALSource == 0 ) 55 return false; 56 56 57 HandleFade(); 57 58 58 if (m_LastPlay && (m_ALSource != 0))59 if (m_LastPlay && m_ALSource) 59 60 { 60 61 int proc_state; 61 alGetSourcei v(m_ALSource, AL_SOURCE_STATE, &proc_state);62 alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state); 62 63 AL_CHECK 63 64 return (proc_state != AL_STOPPED); 64 65 } … … 67 68 68 69 void CSoundItem::Attach(CSoundData* itemData) 69 70 { 70 if (itemData != NULL && (m_ALSource != 0) ) 71 AL_CHECK 72 if (m_SoundData != NULL) 71 73 { 74 CSoundData::ReleaseSoundData(m_SoundData); 75 m_SoundData = 0; 76 } 77 AL_CHECK 78 if (itemData != NULL) 79 { 80 alSourcei(m_ALSource, AL_BUFFER, 0); 81 AL_CHECK 72 82 m_SoundData = itemData->IncrementCount(); 73 83 alSourcei(m_ALSource, AL_BUFFER, m_SoundData->GetBuffer()); 74 84 -
source/soundmanager/items/CSoundItem.h
28 28 class CSoundItem : public CSoundBase 29 29 { 30 30 public: 31 CSoundItem(); 32 CSoundItem(CSoundData* sndData); 33 34 virtual ~CSoundItem(); 35 void Attach(CSoundData* itemData); 36 bool IdleTask(); 31 CSoundItem(); 32 CSoundItem(CSoundData* sndData); 33 34 virtual ~CSoundItem(); 35 void Attach(CSoundData* itemData); 37 36 37 bool IdleTask(); 38 void ReleaseOpenAL(); 39 38 40 }; 39 41 40 42 #endif // CONFIG2_AUDIO -
source/soundmanager/items/CStreamItem.cpp
35 35 36 36 CStreamItem::~CStreamItem() 37 37 { 38 Stop(); 38 } 39 40 void CStreamItem::ReleaseOpenAL() 41 { 42 int num_processed; 43 alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed); 39 44 40 45 if (m_ALSource != 0) 41 46 { … … 50 55 delete[] al_buf; 51 56 } 52 57 } 58 CSoundBase::ReleaseOpenAL(); 53 59 } 54 60 55 61 bool CStreamItem::IdleTask() 56 62 { 57 63 AL_CHECK 64 58 65 HandleFade(); 59 66 AL_CHECK 60 67 … … 101 108 102 109 void CStreamItem::Attach(CSoundData* itemData) 103 110 { 104 if ( itemData != NULL && (m_ALSource != 0))111 if (m_SoundData != NULL) 105 112 { 113 CSoundData::ReleaseSoundData(m_SoundData); 114 m_SoundData = 0; 115 } 116 117 if (itemData != NULL) 118 { 106 119 m_SoundData = itemData->IncrementCount(); 107 120 alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(), (const ALuint *)m_SoundData->GetBufferPtr()); 108 121 AL_CHECK -
source/soundmanager/items/CStreamItem.h
28 28 class CStreamItem : public CSoundBase 29 29 { 30 30 public: 31 CStreamItem(CSoundData* sndData); 32 virtual ~CStreamItem(); 33 34 virtual void SetLooping(bool loops); 35 virtual bool IdleTask(); 36 37 protected: 38 virtual void Attach(CSoundData* itemData); 31 CStreamItem(CSoundData* sndData); 32 virtual ~CStreamItem(); 33 34 virtual void SetLooping(bool loops); 35 virtual bool IdleTask(); 39 36 37 virtual void Attach(CSoundData* itemData); 38 39 protected: 40 virtual void ReleaseOpenAL(); 40 41 }; 41 42 42 43 #endif // CONFIG2_AUDIO -
source/soundmanager/items/ISoundItem.h
25 25 #include "lib/external_libraries/openal.h" 26 26 #include "maths/Vector3D.h" 27 27 #include "ps/CStr.h" 28 #include "soundmanager/data/SoundData.h" 28 29 29 30 class ISoundItem 30 31 { … … 43 44 virtual void Play() = 0; 44 45 virtual void Stop() = 0; 45 46 47 virtual void Attach(CSoundData* itemData) = 0; 48 46 49 virtual void EnsurePlay() = 0; 47 50 virtual void PlayAsMusic() = 0; 48 51 virtual void PlayAsAmbient() = 0; -
source/soundmanager/js/SoundGroup.cpp
157 157 return answer; 158 158 } 159 159 160 void CSoundGroup::UploadPropertiesAndPlay( unsigned int theIndex, const CVector3D& position)160 void CSoundGroup::UploadPropertiesAndPlay(int theIndex, const CVector3D& position, entity_id_t source) 161 161 { 162 162 #if CONFIG2_AUDIO 163 163 if ( g_SoundManager ) … … 175 175 176 176 if ( snd_group.size() > theIndex ) 177 177 { 178 if ( ISoundItem* hSound= snd_group[theIndex] )178 if ( CSoundData* sndData = snd_group[theIndex] ) 179 179 { 180 180 CVector3D origin = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); 181 181 float sndDist = origin.Y; 182 182 183 ISoundItem* hSound = g_SoundManager->ItemForEntity( source, sndData); 184 183 185 if (!TestFlag(eOmnipresent)) 184 186 { 185 187 if (TestFlag(eDistanceless)) … … 208 210 #else // !CONFIG2_AUDIO 209 211 UNUSED2(theIndex); 210 212 UNUSED2(position); 213 UNUSED2(source); 211 214 #endif // !CONFIG2_AUDIO 212 215 } 213 216 … … 219 222 LOGERROR(L"%ls: pathname=%ls, error=%ls", message.c_str(), pathname.string().c_str(), ErrorString(err)); 220 223 } 221 224 222 void CSoundGroup::PlayNext(const CVector3D& position )225 void CSoundGroup::PlayNext(const CVector3D& position, entity_id_t source) 223 226 { 224 227 // if no sounds, return 225 228 if (filenames.size() == 0) 226 229 return; 227 230 228 231 m_index = (size_t)rand(0, (size_t)filenames.size()); 229 UploadPropertiesAndPlay(m_index, position );232 UploadPropertiesAndPlay(m_index, position, source); 230 233 } 231 234 232 235 void CSoundGroup::Reload() … … 234 237 m_index = 0; // reset our index 235 238 236 239 #if CONFIG2_AUDIO 237 snd_group.clear();240 ReleaseGroup(); 238 241 239 242 if ( g_SoundManager ) { 240 243 for (size_t i = 0; i < filenames.size(); i++) 241 244 { 242 245 VfsPath thePath = m_filepath/filenames[i]; 243 ISoundItem* temp = g_SoundManager->LoadItem(thePath);246 CSoundData* itemData = CSoundData::SoundDataFromFile(thePath); 244 247 245 if ( temp== NULL)248 if (itemData == NULL) 246 249 HandleError(L"error loading sound", thePath, ERR::FAIL); 247 250 else 248 snd_group.push_back( temp);251 snd_group.push_back(itemData->IncrementCount()); 249 252 } 250 253 251 254 if (TestFlag(eRandOrder)) … … 259 262 #if CONFIG2_AUDIO 260 263 for (size_t i = 0; i < snd_group.size(); i++) 261 264 { 262 snd_group[i]->FadeAndDelete(0.2);265 CSoundData::ReleaseSoundData( snd_group[i] ); 263 266 } 264 267 snd_group.clear(); 265 268 #endif // CONFIG2_AUDIO -
source/soundmanager/js/SoundGroup.h
54 54 55 55 #include "lib/config2.h" 56 56 #include "lib/file/vfs/vfs_path.h" 57 #include "simulation2/system/Entity.h" 58 #include "soundmanager/data/SoundData.h" 57 59 58 60 #include <vector> 59 61 … … 82 84 // Play next sound in group 83 85 // @param position world position of the entity generating the sound 84 86 // (ignored if the eOmnipresent flag is set) 85 void PlayNext(const CVector3D& position );87 void PlayNext(const CVector3D& position, entity_id_t source); 86 88 87 89 float RadiansOffCenter(const CVector3D& position, bool& onScreen, float& itemRollOff); 88 90 … … 105 107 106 108 private: 107 109 void SetGain(float gain); 108 void UploadPropertiesAndPlay(unsigned int theIndex, const CVector3D& position); 110 111 void UploadPropertiesAndPlay(int theIndex, const CVector3D& position, entity_id_t source); 112 109 113 void SetDefaultValues(); 110 114 111 size_t m_index; // index of the next sound to play115 int m_index; // index of the next sound to play 112 116 113 117 #if CONFIG2_AUDIO 114 std::vector< ISoundItem*> snd_group; // we store the handles so we can load now and play later118 std::vector<CSoundData*> snd_group; // we store the handles so we can load now and play later 115 119 #endif 116 120 std::vector<std::wstring> filenames; // we need the filenames so we can reload when necessary. 117 121