Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 11, 2010, 3:16:12 PM (14 years ago)
Author:
scheusso
Message:

merged sound4 into sound5

Location:
code/branches/sound5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/sound5

  • code/branches/sound5/src/orxonox/sound/AmbientSound.cc

    r6417 r6506  
    3535#include "core/XMLPort.h"
    3636#include "SoundManager.h"
     37#include "SoundStreamer.h"
    3738
    3839namespace orxonox
     
    120121            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
    121122            if (fileInfo != NULL)
    122                 this->setSource(path);
     123                this->setStreamSource(path);
    123124            else
    124125                COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl;
     
    141142            this->stop();
    142143    }
     144
     145    // hacky solution for file streaming
     146    void AmbientSound::setStreamSource(const std::string& source)
     147    {
     148        this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
     149        if (this->source_ == source)
     150        {
     151            return;
     152        }
     153
     154        this->source_ = source;
     155        // Don't load ""
     156        if (source_.empty())
     157            return;
     158
     159        if (this->soundstreamthread_.get_id() != boost::thread::id())
     160        {
     161            this->soundstreamthread_.interrupt(); // unhandled interruptions lead to thread terminating ;-)
     162        }
     163        // Get resource info
     164        shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source);
     165        if (fileInfo == NULL)
     166        {
     167            COUT(2) << "Sound: Warning: Sound file '" << source << "' not found" << std::endl;
     168            return;
     169        }
     170        // Open data stream
     171        DataStreamPtr dataStream = Resource::open(fileInfo);
     172
     173        this->soundstreamthread_ = boost::thread(SoundStreamer(), this->audioSource_, dataStream);
     174        this->initialiseSource();
     175    }
     176
     177    void AmbientSound::doStop()
     178    {
     179        SUPER(AmbientSound, doStop);
     180        this->soundstreamthread_.interrupt();
     181    }
    143182}
Note: See TracChangeset for help on using the changeset viewer.