Changeset 6254 for code/branches/presentation2/src/orxonox/sound
- Timestamp:
- Dec 6, 2009, 5:02:11 PM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox/sound
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
r6234 r6254 44 44 BaseSound::BaseSound() 45 45 : audioSource_(0) 46 , bPooling_(false) 46 47 , volume_(1.0) 47 48 , bLoop_(false) … … 166 167 // Unload old sound first 167 168 alSourcei(this->audioSource_, AL_BUFFER, 0); 169 SoundManager::getInstance().releaseSoundBuffer(this->soundBuffer_, this->bPooling_); 168 170 this->soundBuffer_.reset(); 169 171 } -
code/branches/presentation2/src/orxonox/sound/BaseSound.h
r6231 r6254 86 86 ALuint loadOggFile(); 87 87 88 ALuint audioSource_; 88 ALuint audioSource_; 89 bool bPooling_; 89 90 shared_ptr<SoundBuffer> soundBuffer_; 90 91 -
code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
r6232 r6254 63 63 SoundBuffer::~SoundBuffer() 64 64 { 65 // Unregister buffer from SoundManager66 SoundManager::getInstance().removeBuffer(this->fileInfo_);67 68 65 // Destroy buffer 69 66 alDeleteBuffers(1, &this->audioBuffer_); 67 } 68 69 unsigned int SoundBuffer::getSize() const 70 { 71 ALint size; 72 alGetBufferi(this->audioBuffer_, AL_SIZE, &size); 73 if (!alGetError()) 74 return size; 75 else 76 return 0; 70 77 } 71 78 -
code/branches/presentation2/src/orxonox/sound/SoundBuffer.h
r6203 r6254 41 41 class _OrxonoxExport SoundBuffer 42 42 { 43 friend class SoundManager; 44 43 45 public: 44 46 SoundBuffer(shared_ptr<ResourceInfo> fileInfo); … … 48 50 { return this->audioBuffer_; } 49 51 52 unsigned int getSize() const; 53 54 shared_ptr<ResourceInfo> getFileInfo() const 55 { return this->fileInfo_; } 56 57 void setPooling(bool val) 58 { this->bPooling_ = true; } 59 bool getPooling() const 60 { return this->bPooling_; } 61 50 62 private: 51 63 void loadStandard(DataStreamPtr dataStream); … … 54 66 shared_ptr<ResourceInfo> fileInfo_; 55 67 ALuint audioBuffer_; 68 std::list<shared_ptr<SoundBuffer> >::iterator poolIterator_; 69 bool bPooling_; 56 70 }; 57 71 } -
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
r6244 r6254 52 52 53 53 SoundManager::SoundManager() 54 : effectsPoolSize_(0) 54 55 { 55 56 RegisterRootObject(SoundManager); … … 529 530 shared_ptr<SoundBuffer> SoundManager::getSoundBuffer(shared_ptr<ResourceInfo> fileInfo) 530 531 { 531 std::map<std::string, weak_ptr<SoundBuffer> >::const_iterator it 532 = this->soundBuffers_.find(fileInfo->group + '/' + fileInfo->filename); 532 shared_ptr<SoundBuffer> buffer; 533 // Check active or pooled buffers 534 SoundBufferMap::const_iterator it = this->soundBuffers_.find(fileInfo->group + '/' + fileInfo->filename); 533 535 if (it != this->soundBuffers_.end()) 534 return it->second.lock(); 536 { 537 buffer = it->second; 538 539 // Remove from effects pool if not active used before 540 if (buffer->poolIterator_ != this->effectsPool_.end()) 541 { 542 this->effectsPoolSize_ -= buffer->getSize(); 543 this->effectsPool_.erase(buffer->poolIterator_); 544 buffer->poolIterator_ = this->effectsPool_.end(); 545 } 546 } 535 547 else 536 548 { 537 shared_ptr<SoundBuffer> buffer;538 549 try 539 550 { 540 551 buffer.reset(new SoundBuffer(fileInfo)); 552 buffer->poolIterator_ = this->effectsPool_.end(); 541 553 } 542 554 catch (...) 543 555 { 544 556 COUT(1) << Exception::handleMessage() << std::endl; 545 return shared_ptr<SoundBuffer>();557 return buffer; 546 558 } 547 559 this->soundBuffers_[fileInfo->group + '/' + fileInfo->filename] = buffer; 548 return buffer; 549 } 550 } 551 552 void SoundManager::removeBuffer(shared_ptr<ResourceInfo> fileInfo) 553 { 554 std::map<std::string, weak_ptr<SoundBuffer> >::iterator it 555 = this->soundBuffers_.find(fileInfo->group + '/' + fileInfo->filename); 560 } 561 return buffer; 562 } 563 564 void SoundManager::releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer) 565 { 566 // Check if others are still using the buffer 567 if (buffer.use_count() != 2) 568 return; 569 SoundBufferMap::iterator it = this->soundBuffers_.find(buffer->fileInfo_->group + '/' + buffer->fileInfo_->filename); 556 570 if (it != this->soundBuffers_.end()) 557 this->soundBuffers_.erase(it); 571 { 572 if (bPoolBuffer) 573 { 574 // Pool already too large? 575 while (this->effectsPoolSize_ + it->second->getSize() > this->maxEffectsPoolSize_s && !this->effectsPool_.empty()) 576 { 577 shared_ptr<SoundBuffer> bufferDel = this->effectsPool_.back(); 578 this->effectsPoolSize_ -= bufferDel->getSize(); 579 bufferDel->poolIterator_ = this->effectsPool_.end(); 580 this->effectsPool_.pop_back(); 581 // Remove from buffer map too 582 SoundBufferMap::iterator itDel = this->soundBuffers_.find(bufferDel->fileInfo_->group + '/' + bufferDel->fileInfo_->filename); 583 if (itDel != this->soundBuffers_.end()) 584 this->soundBuffers_.erase(itDel); 585 } 586 // Put buffer into the pool 587 this->effectsPoolSize_ += it->second->getSize(); 588 this->effectsPool_.push_front(it->second); 589 it->second->poolIterator_ = this->effectsPool_.begin(); 590 COUT(0) << "pool size: " << this->effectsPoolSize_ << std::endl; 591 } 592 else 593 this->soundBuffers_.erase(it); 594 } 558 595 } 559 596 } -
code/branches/presentation2/src/orxonox/sound/SoundManager.h
r6244 r6254 36 36 #include <map> 37 37 #include <string> 38 #include <boost/ weak_ptr.hpp>38 #include <boost/shared_ptr.hpp> 39 39 40 40 #include "util/Singleton.h" … … 101 101 102 102 shared_ptr<SoundBuffer> getSoundBuffer(shared_ptr<ResourceInfo> fileInfo); 103 void re moveBuffer(shared_ptr<ResourceInfo> fileInfo);103 void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer); 104 104 105 105 static std::string getALErrorString(ALenum error); … … 139 139 std::map<SoundType::Value, bool> mute_; 140 140 141 std::map<std::string, weak_ptr<SoundBuffer> > soundBuffers_; 141 static const unsigned int maxEffectsPoolSize_s = 40 * 1024 * 1024; 142 unsigned int effectsPoolSize_; 143 typedef std::list<shared_ptr<SoundBuffer> > EffectsPoolList; 144 EffectsPoolList effectsPool_; 145 typedef std::map<std::string, shared_ptr<SoundBuffer> > SoundBufferMap; 146 SoundBufferMap soundBuffers_; 142 147 143 148 static SoundManager* singletonPtr_s; -
code/branches/presentation2/src/orxonox/sound/WorldSound.cc
r6204 r6254 45 45 { 46 46 RegisterObject(WorldSound); 47 // WorldSound buffers should be pooled when they're not used anymore 48 this->bPooling_ = true; 47 49 } 48 50
Note: See TracChangeset
for help on using the changeset viewer.