Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6506


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

merged sound4 into sound5

Location:
code/branches/sound5
Files:
11 edited
1 copied

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}
  • code/branches/sound5/src/orxonox/sound/AmbientSound.h

    r6417 r6506  
    3131#define _AmbientSound_H__
    3232
    33 #include "OrxonoxPrereqs.h"
     33#include <boost/thread.hpp>
     34
     35#include "sound/SoundPrereqs.h"
    3436
    3537#include "core/BaseObject.h"
     
    7173        ~AmbientSound() { }
    7274
     75        void doPlay();
     76        void doStop();
     77
    7378    private:
    7479        void preDestroy();
     
    8388        std::string ambientSource_; //!< Analogous to source_, but mood independent
    8489        bool        bPlayOnLoad_;   //!< Play the sound immediately when loaded
     90
     91        boost::thread soundstreamthread_; // hacky solution for streaming
     92        void setStreamSource(const std::string& source);
    8593    };
    8694}
  • code/branches/sound5/src/orxonox/sound/BaseSound.cc

    r6502 r6506  
    9191            alSourcePlay(this->audioSource_);
    9292            if (int error = alGetError())
    93                 COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
     93                COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
    9494        }
    9595    }
     
    141141        alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);
    142142        if (ALint error = alGetError())
    143             COUT(2) << "Sound Warning: Setting source parameters to 0 failed: "
    144                     << SoundManager::getALErrorString(error) << std::endl;
     143            COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl;
    145144        assert(this->soundBuffer_ != NULL);
    146145        alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
    147146        if (ALuint error = alGetError())
    148             COUT(1) << "Sound Error: Could not set buffer \"" << this->source_ << "\": " << SoundManager::getALErrorString(error) << std::endl;
     147            COUT(1) << "Sound: Error: Could not set buffer \"" << this->source_ << "\": " << getALErrorString(error) << std::endl;
    149148    }
    150149
     
    153152        this->volume_ = clamp(vol, 0.0f, 1.0f);
    154153        if (this->volume_ != vol)
    155             COUT(2) << "Sound warning: volume out of range, clamping value." << std::endl;
     154            COUT(2) << "Sound: Warning: volume out of range, clamping value." << std::endl;
    156155        this->updateVolume();
    157156    }
     
    164163            alSourcef(this->audioSource_, AL_GAIN, volume);
    165164            if (int error = alGetError())
    166                 COUT(2) << "Sound: Error setting volume to " << volume
    167                         << ": " << SoundManager::getALErrorString(error) << std::endl;
     165                COUT(2) << "Sound: Error setting volume to " << volume << ": " << getALErrorString(error) << std::endl;
    168166        }
    169167    }
     
    180178        if (pitch > 2 || pitch < 0.5f)
    181179        {
    182             COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;
     180            COUT(2) << "Sound: Warning: pitch out of range, cropping value." << std::endl;
    183181            pitch = pitch > 2.0f ? 2.0f : pitch;
    184182            pitch = pitch < 0.5f ? 0.5f : pitch;
     
    189187            alSourcef(this->audioSource_, AL_PITCH, pitch);
    190188            if (int error = alGetError())
    191                 COUT(2) << "Sound: Error setting pitch: " << SoundManager::getALErrorString(error) << std::endl;
     189                COUT(2) << "Sound: Error setting pitch: " << getALErrorString(error) << std::endl;
    192190        }
    193191    }
     
    234232            if (ALuint error = alGetError())
    235233            {
    236                 COUT(1) << "Sound Error: Could not set buffer \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;
     234                COUT(1) << "Sound: Error: Could not set buffer \"" << source << "\": " << getALErrorString(error) << std::endl;
    237235                return;
    238236            }
     
    242240            alSourcePlay(this->audioSource_);
    243241            if (int error = alGetError())
    244                 COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
     242                COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
    245243            if (this->isPaused())
    246244                alSourcePause(this->audioSource_);
  • code/branches/sound5/src/orxonox/sound/BaseSound.h

    r6417 r6506  
    3030#define _BaseSound_H__
    3131
    32 #include "OrxonoxPrereqs.h"
     32#include "sound/SoundPrereqs.h"
    3333
    3434#include <string>
  • code/branches/sound5/src/orxonox/sound/SoundBuffer.h

    r6417 r6506  
    3030#define _SoundBuffer_H__
    3131
    32 #include "OrxonoxPrereqs.h"
     32#include "sound/SoundPrereqs.h"
    3333
    3434#include <list>
  • code/branches/sound5/src/orxonox/sound/SoundManager.cc

    r6417 r6506  
    4343#include "core/ScopedSingletonManager.h"
    4444#include "core/Resource.h"
    45 #include "SoundBuffer.h"
     45#include "SoundBuffer.h":
    4646#include "BaseSound.h"
    4747#include "AmbientSound.h"
     
    5252    ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
    5353
    54     std::string SoundManager::getALErrorString(ALenum code)
     54    // From SoundPrereqs.h
     55    std::string getALErrorString(ALenum code)
    5556    {
    5657        switch (code)
     
    7879
    7980        if (!alutInitWithoutContext(NULL, NULL))
    80             ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
     81            ThrowException(InitialisationFailed, "Sound: Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
    8182        Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
    8283
     
    110111            COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
    111112#endif
    112             ThrowException(InitialisationFailed, "Sound Error: Could not open sound device.");
     113            ThrowException(InitialisationFailed, "Sound: Error: Could not open sound device.");
    113114        }
    114115        Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
     
    117118        this->context_ = alcCreateContext(this->device_, NULL);
    118119        if (this->context_ == NULL)
    119             ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context");
     120            ThrowException(InitialisationFailed, "Sound: Error: Could not create ALC context");
    120121        Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
    121122        if (!alcMakeContextCurrent(this->context_))
    122             ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context");
     123            ThrowException(InitialisationFailed, "Sound: Error: Could not use ALC context");
    123124
    124125        GameMode::setPlaysSound(true);
     
    133134            COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl;
    134135        else
    135             COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
     136            COUT(2) << "Sound: Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
    136137
    137138        this->mute_[SoundType::All]     = 1.0f;
     
    147148            this->availableSoundSources_.push_back(source);
    148149        else
    149             ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source");
     150            ThrowException(InitialisationFailed, "Sound: Error: Could not create even a single source");
    150151        // Create a few initial sources
    151152        this->createSoundSources(this->minSources_ - 1);
     
    168169        // If there are still used buffers around, well, that's just very bad...
    169170        if (this->soundBuffers_.size() != this->effectsPool_.size())
    170             COUT(1) << "Sound Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
     171            COUT(1) << "Sound: Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
    171172        // Empty buffer pool and buffer list
    172173        this->effectsPool_.clear();
     
    175176        // There should not be any sources in use anymore
    176177        if (!this->usedSoundSources_.empty())
    177             COUT(1) << "Sound Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
     178            COUT(1) << "Sound: Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
    178179        while (!this->availableSoundSources_.empty())
    179180        {
     
    186187        // Relieve context to destroy it
    187188        if (!alcMakeContextCurrent(NULL))
    188             COUT(1) << "Sound Error: Could not unset ALC context" << std::endl;
     189            COUT(1) << "Sound: Error: Could not unset ALC context" << std::endl;
    189190        alcDestroyContext(this->context_);
    190191        if (ALCenum error = alcGetError(this->device_))
    191192        {
    192193            if (error == AL_INVALID_OPERATION)
    193                 COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl;
     194                COUT(1) << "Sound: Error: Could not destroy ALC context because it is the current one" << std::endl;
    194195            else
    195                 COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl;
     196                COUT(1) << "Sound: Error: Could not destroy ALC context because it is invalid" << std::endl;
    196197        }
    197198#ifdef AL_VERSION_1_1
    198199        if (!alcCloseDevice(this->device_))
    199             COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
     200            COUT(1) << "Sound: Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
    200201#else
    201202        alcCloseDevice(this->device_);
    202203#endif
    203204        if (!alutExit())
    204             COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
     205            COUT(1) << "Sound: Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
    205206    }
    206207
     
    248249        if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 )
    249250        {
    250             COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl;
     251            COUT(2) << "Sound: Warning: fade step out of range, ignoring change." << std::endl;
    251252            ResetConfigValue(crossFadeStep_);
    252253        }
     
    257258        float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f);
    258259        if (clampedVolume != this->volume_[type])
    259             COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
     260            COUT(2) << "Sound: Warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
    260261        this->updateVolume(type);
    261262    }
     
    349350                if (it->first == newAmbient)
    350351                {
    351                     COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl;
     352                    COUT(2) << "Sound: Warning: Will not play an AmbientSound twice." << std::endl;
    352353                    return;
    353354                }
     
    617618            alDeleteSources(1, &this->availableSoundSources_.back());
    618619            if (alGetError())
    619                 COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl;
     620                COUT(1) << "Sound: Error: Failed to delete a source --> lost forever" << std::endl;
    620621            this->availableSoundSources_.pop_back();
    621622        }
  • code/branches/sound5/src/orxonox/sound/SoundManager.h

    r6417 r6506  
    3131#define _SoundManager_H__
    3232
    33 #include "OrxonoxPrereqs.h"
     33#include "sound/SoundPrereqs.h"
    3434
    3535#include <list>
     
    9999        void releaseSoundSource(ALuint source);
    100100
    101         static std::string getALErrorString(ALenum error);
    102 
    103101    private:
    104102        void processCrossFading(float dt);
  • code/branches/sound5/src/orxonox/sound/SoundStreamer.cc

    r6417 r6506  
    3030#include <vorbis/vorbisfile.h>
    3131#include "SoundManager.h"
     32#include "util/Sleep.h"
    3233
    3334namespace orxonox
     
    9192            alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed);
    9293            if (ALint error = alGetError())
    93             COUT(2) << "Sound Warning: Couldn't get number of processed buffers: "
    94                     << SoundManager::getALErrorString(error) << std::endl;
     94            COUT(2) << "Sound Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;
    9595
    9696            if(processed > 0)
     
    9999                alSourceUnqueueBuffers(audioSource, processed, buffers);
    100100                if (ALint error = alGetError())
    101                     COUT(2) << "Sound Warning: Couldn't unqueue buffers: "
    102                     << SoundManager::getALErrorString(error) << std::endl;
     101                    COUT(2) << "Sound Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl;
    103102
    104103                for(int i = 0; i < processed; i++)
     
    121120                alSourceQueueBuffers(audioSource, processed, buffers);
    122121                if (ALint error = alGetError())
    123                     COUT(2) << "Sound Warning: Couldn't queue buffers: "
    124                     << SoundManager::getALErrorString(error) << std::endl;
     122                    COUT(2) << "Sound Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
    125123            }
     124            msleep(250); // perhaps another value here is better
    126125        }
    127126    }
  • code/branches/sound5/src/orxonox/sound/SoundStreamer.h

    r6417 r6506  
    2929#define _SoundStreamer_H__
    3030
    31 #include "OrxonoxPrereqs.h"
     31#include "sound/SoundPrereqs.h"
    3232
    3333#include <string>
  • code/branches/sound5/src/orxonox/sound/WorldSound.h

    r6417 r6506  
    3030#define _WorldSound_H__
    3131
    32 #include "OrxonoxPrereqs.h"
     32#include "sound/SoundPrereqs.h"
    3333
    3434#include "tools/interfaces/Tickable.h"
Note: See TracChangeset for help on using the changeset viewer.