Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 19, 2009, 10:14:08 PM (14 years ago)
Author:
rgrieder
Message:

Fixed a major sound issue: The state gets reset to 'Stopped' when the sound has finished playing (unless in loop mode of course).

File:
1 edited

Legend:

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

    r6378 r6383  
    145145        alGenSources(1, &source);
    146146        if (!alGetError() && alIsSource(source))
    147             this->soundSources_.push_back(source);
     147            this->availableSoundSources_.push_back(source);
    148148        else
    149149            ThrowException(InitialisationFailed, "Sound Error: Could not even create a single source");
     
    153153        while (alIsSource(source) && !alGetError() && count <= this->maxSources_)
    154154        {
    155             this->soundSources_.push_back(source);
     155            this->availableSoundSources_.push_back(source);
    156156            alGenSources(1, &source);
    157157            ++count;
     
    195195    {
    196196        this->processCrossFading(time.getDeltaTime());
     197
     198        // Check whether a sound object has stopped playing
     199        for (unsigned int i = 0; i < this->usedSoundSources_.size(); ++i)
     200        {
     201            ALint state;
     202            alGetSourcei(this->usedSoundSources_[i].first, AL_SOURCE_STATE, &state);
     203            if (state == AL_STOPPED)
     204            {
     205                this->usedSoundSources_[i].second->stop();
     206                --i;
     207            }
     208        }
    197209    }
    198210
     
    536548    }
    537549
    538     ALuint SoundManager::getSoundSource()
    539     {
    540         if (!this->soundSources_.empty())
    541         {
    542             ALuint source = this->soundSources_.back();
    543             this->soundSources_.pop_back();
     550    ALuint SoundManager::getSoundSource(BaseSound* object)
     551    {
     552        if (!this->availableSoundSources_.empty())
     553        {
     554            ALuint source = this->availableSoundSources_.back();
     555            this->availableSoundSources_.pop_back();
     556            this->usedSoundSources_.push_back(std::make_pair(source, object));
    544557            return source;
    545558        }
     
    556569    {
    557570#ifndef NDEBUG
    558         for (std::vector<ALuint>::const_iterator it = this->soundSources_.begin(); it != this->soundSources_.end(); ++it)
     571        for (std::vector<ALuint>::const_iterator it = this->availableSoundSources_.begin(); it != this->availableSoundSources_.end(); ++it)
    559572            assert((*it) != source);
    560573#endif
    561         this->soundSources_.push_back(source);
     574        this->availableSoundSources_.push_back(source);
     575        for (std::vector<std::pair<ALuint, BaseSound*> >::iterator it = this->usedSoundSources_.begin();
     576            it != this->usedSoundSources_.end(); ++it)
     577        {
     578            if (it->first == source)
     579            {
     580                this->usedSoundSources_.erase(it);
     581                break;
     582            }
     583        }
    562584    }
    563585}
Note: See TracChangeset for help on using the changeset viewer.