Changeset 6270 for code/branches/presentation2
- Timestamp:
- Dec 8, 2009, 10:09:39 AM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox/sound
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
r6260 r6270 62 62 BaseSound::~BaseSound() 63 63 { 64 this->setSource( "");64 this->setSource(std::string()); 65 65 if (GameMode::playsSound() && alIsSource(this->audioSource_)) 66 66 alDeleteSources(1, &this->audioSource_); … … 191 191 return; 192 192 193 // Get DataStream from the resources 194 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source); 195 if (fileInfo == NULL) 196 { 197 COUT(2) << "Sound: Warning: Sound file '" << source << "' not found" << std::endl; 198 return; 199 } 200 201 this->soundBuffer_ = SoundManager::getInstance().getSoundBuffer(fileInfo); 193 this->soundBuffer_ = SoundManager::getInstance().getSoundBuffer(this->source_); 202 194 if (this->soundBuffer_ == NULL) 203 195 return; -
code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
r6260 r6270 40 40 namespace orxonox 41 41 { 42 SoundBuffer::SoundBuffer( shared_ptr<ResourceInfo> fileInfo)43 : file Info_(fileInfo)42 SoundBuffer::SoundBuffer(const std::string& filename) 43 : filename_(filename) 44 44 , audioBuffer_(AL_NONE) 45 45 { 46 if (this->file Info_ == NULL)46 if (this->filename_.empty()) 47 47 ThrowException(General, "SoundBuffer construction: fileInfo was NULL"); 48 DataStreamPtr dataStream = Resource::open(this->fileInfo_);49 48 50 std::string extension(this->fileInfo_->basename.substr(this->fileInfo_->basename.find_last_of('.') + 1)); 49 // Get resource info 50 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(filename); 51 if (fileInfo == NULL) 52 { 53 COUT(2) << "Sound: Warning: Sound file '" << filename << "' not found" << std::endl; 54 return; 55 } 56 // Open data stream 57 DataStreamPtr dataStream = Resource::open(fileInfo); 58 59 std::string extension(this->filename_.substr(this->filename_.find_last_of('.') + 1)); 51 60 if (getLowercase(extension) == "ogg") 52 61 { 53 62 // Try ogg loader 54 this->loadOgg( dataStream);63 this->loadOgg(fileInfo, dataStream); 55 64 } 56 65 else 57 66 { 58 67 // Try standard OpenAL loader 59 this->loadStandard( dataStream);68 this->loadStandard(fileInfo, dataStream); 60 69 } 61 70 } … … 77 86 } 78 87 79 void SoundBuffer::loadStandard( DataStreamPtr dataStream)88 void SoundBuffer::loadStandard(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream) 80 89 { 81 90 // Read everything into a temporary buffer 82 char* buffer = new char[ this->fileInfo_->size];83 dataStream->read(buffer, this->fileInfo_->size);91 char* buffer = new char[fileInfo->size]; 92 dataStream->read(buffer, fileInfo->size); 84 93 dataStream->seek(0); 85 94 86 this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, this->fileInfo_->size);95 this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size); 87 96 delete[] buffer; 88 97 … … 115 124 } 116 125 117 void SoundBuffer::loadOgg( DataStreamPtr dataStream)126 void SoundBuffer::loadOgg(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream) 118 127 { 119 128 char inbuffer[256*1024]; -
code/branches/presentation2/src/orxonox/sound/SoundBuffer.h
r6254 r6270 44 44 45 45 public: 46 SoundBuffer( shared_ptr<ResourceInfo> fileInfo);46 SoundBuffer(const std::string& filename); 47 47 ~SoundBuffer(); 48 48 … … 52 52 unsigned int getSize() const; 53 53 54 shared_ptr<ResourceInfo> getFileInfo() const55 { return this->file Info_; }54 const std::string& getFilename() const 55 { return this->filename_; } 56 56 57 57 void setPooling(bool val) … … 61 61 62 62 private: 63 void loadStandard( DataStreamPtr dataStream);64 void loadOgg( DataStreamPtr dataStream);63 void loadStandard(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream); 64 void loadOgg(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream); 65 65 66 s hared_ptr<ResourceInfo> fileInfo_;66 std::string filename_; 67 67 ALuint audioBuffer_; 68 68 std::list<shared_ptr<SoundBuffer> >::iterator poolIterator_; -
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
r6269 r6270 528 528 } 529 529 530 shared_ptr<SoundBuffer> SoundManager::getSoundBuffer( shared_ptr<ResourceInfo> fileInfo)530 shared_ptr<SoundBuffer> SoundManager::getSoundBuffer(const std::string& filename) 531 531 { 532 532 shared_ptr<SoundBuffer> buffer; 533 533 // Check active or pooled buffers 534 SoundBufferMap::const_iterator it = this->soundBuffers_.find(file Info->group + '/' + fileInfo->filename);534 SoundBufferMap::const_iterator it = this->soundBuffers_.find(filename); 535 535 if (it != this->soundBuffers_.end()) 536 536 { … … 549 549 try 550 550 { 551 buffer.reset(new SoundBuffer(file Info));551 buffer.reset(new SoundBuffer(filename)); 552 552 buffer->poolIterator_ = this->effectsPool_.end(); 553 553 } … … 557 557 return buffer; 558 558 } 559 this->soundBuffers_[file Info->group + '/' + fileInfo->filename] = buffer;559 this->soundBuffers_[filename] = buffer; 560 560 } 561 561 return buffer; … … 567 567 if (buffer.use_count() != 2) 568 568 return; 569 SoundBufferMap::iterator it = this->soundBuffers_.find(buffer-> fileInfo_->group + '/' + buffer->fileInfo_->filename);569 SoundBufferMap::iterator it = this->soundBuffers_.find(buffer->getFilename()); 570 570 if (it != this->soundBuffers_.end()) 571 571 { … … 580 580 this->effectsPool_.pop_back(); 581 581 // Remove from buffer map too 582 SoundBufferMap::iterator itDel = this->soundBuffers_.find(bufferDel-> fileInfo_->group + '/' + bufferDel->fileInfo_->filename);582 SoundBufferMap::iterator itDel = this->soundBuffers_.find(bufferDel->getFilename()); 583 583 if (itDel != this->soundBuffers_.end()) 584 584 this->soundBuffers_.erase(itDel); -
code/branches/presentation2/src/orxonox/sound/SoundManager.h
r6254 r6270 100 100 bool getMute(SoundType::Value type); // tolua_export 101 101 102 shared_ptr<SoundBuffer> getSoundBuffer( shared_ptr<ResourceInfo> fileInfo);102 shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename); 103 103 void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer); 104 104
Note: See TracChangeset
for help on using the changeset viewer.