Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6270


Ignore:
Timestamp:
Dec 8, 2009, 10:09:39 AM (15 years ago)
Author:
rgrieder
Message:

Switched from ResourceInfo to std::string for the buffer identification. That should speed up BaseSound::setSource() by factor 10 if the buffer already exists.

Location:
code/branches/presentation2/src/orxonox/sound
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/sound/BaseSound.cc

    r6260 r6270  
    6262    BaseSound::~BaseSound()
    6363    {
    64         this->setSource("");
     64        this->setSource(std::string());
    6565        if (GameMode::playsSound() && alIsSource(this->audioSource_))
    6666            alDeleteSources(1, &this->audioSource_);
     
    191191            return;
    192192
    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_);
    202194        if (this->soundBuffer_ == NULL)
    203195            return;
  • code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc

    r6260 r6270  
    4040namespace orxonox
    4141{
    42     SoundBuffer::SoundBuffer(shared_ptr<ResourceInfo> fileInfo)
    43         : fileInfo_(fileInfo)
     42    SoundBuffer::SoundBuffer(const std::string& filename)
     43        : filename_(filename)
    4444        , audioBuffer_(AL_NONE)
    4545    {
    46         if (this->fileInfo_ == NULL)
     46        if (this->filename_.empty())
    4747            ThrowException(General, "SoundBuffer construction: fileInfo was NULL");
    48         DataStreamPtr dataStream = Resource::open(this->fileInfo_);
    4948
    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));
    5160        if (getLowercase(extension) == "ogg")
    5261        {
    5362            // Try ogg loader
    54             this->loadOgg(dataStream);
     63            this->loadOgg(fileInfo, dataStream);
    5564        }
    5665        else
    5766        {
    5867            // Try standard OpenAL loader
    59             this->loadStandard(dataStream);
     68            this->loadStandard(fileInfo, dataStream);
    6069        }
    6170    }
     
    7786    }
    7887
    79     void SoundBuffer::loadStandard(DataStreamPtr dataStream)
     88    void SoundBuffer::loadStandard(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream)
    8089    {
    8190        // 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);
    8493        dataStream->seek(0);
    8594
    86         this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, this->fileInfo_->size);
     95        this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);
    8796        delete[] buffer;
    8897
     
    115124    }
    116125
    117     void SoundBuffer::loadOgg(DataStreamPtr dataStream)
     126    void SoundBuffer::loadOgg(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream)
    118127    {
    119128        char inbuffer[256*1024];
  • code/branches/presentation2/src/orxonox/sound/SoundBuffer.h

    r6254 r6270  
    4444
    4545    public:
    46         SoundBuffer(shared_ptr<ResourceInfo> fileInfo);
     46        SoundBuffer(const std::string& filename);
    4747        ~SoundBuffer();
    4848
     
    5252        unsigned int getSize() const;
    5353
    54         shared_ptr<ResourceInfo> getFileInfo() const
    55             { return this->fileInfo_; }
     54        const std::string& getFilename() const
     55            { return this->filename_; }
    5656
    5757        void setPooling(bool val)
     
    6161
    6262    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);
    6565
    66         shared_ptr<ResourceInfo> fileInfo_;
     66        std::string filename_;
    6767        ALuint audioBuffer_;
    6868        std::list<shared_ptr<SoundBuffer> >::iterator poolIterator_;
  • code/branches/presentation2/src/orxonox/sound/SoundManager.cc

    r6269 r6270  
    528528    }
    529529
    530     shared_ptr<SoundBuffer> SoundManager::getSoundBuffer(shared_ptr<ResourceInfo> fileInfo)
     530    shared_ptr<SoundBuffer> SoundManager::getSoundBuffer(const std::string& filename)
    531531    {
    532532        shared_ptr<SoundBuffer> buffer;
    533533        // Check active or pooled buffers
    534         SoundBufferMap::const_iterator it = this->soundBuffers_.find(fileInfo->group + '/' + fileInfo->filename);
     534        SoundBufferMap::const_iterator it = this->soundBuffers_.find(filename);
    535535        if (it != this->soundBuffers_.end())
    536536        {
     
    549549            try
    550550            {
    551                 buffer.reset(new SoundBuffer(fileInfo));
     551                buffer.reset(new SoundBuffer(filename));
    552552                buffer->poolIterator_ = this->effectsPool_.end();
    553553            }
     
    557557                return buffer;
    558558            }
    559             this->soundBuffers_[fileInfo->group + '/' + fileInfo->filename] = buffer;
     559            this->soundBuffers_[filename] = buffer;
    560560        }
    561561        return buffer;
     
    567567        if (buffer.use_count() != 2)
    568568            return;
    569         SoundBufferMap::iterator it = this->soundBuffers_.find(buffer->fileInfo_->group + '/' + buffer->fileInfo_->filename);
     569        SoundBufferMap::iterator it = this->soundBuffers_.find(buffer->getFilename());
    570570        if (it != this->soundBuffers_.end())
    571571        {
     
    580580                    this->effectsPool_.pop_back();
    581581                    // 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());
    583583                    if (itDel != this->soundBuffers_.end())
    584584                        this->soundBuffers_.erase(itDel);
  • code/branches/presentation2/src/orxonox/sound/SoundManager.h

    r6254 r6270  
    100100        bool getMute(SoundType::Value type); // tolua_export
    101101
    102         shared_ptr<SoundBuffer> getSoundBuffer(shared_ptr<ResourceInfo> fileInfo);
     102        shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename);
    103103        void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer);
    104104
Note: See TracChangeset for help on using the changeset viewer.