Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8005 for code


Ignore:
Timestamp:
Mar 1, 2011, 5:10:29 AM (14 years ago)
Author:
rgrieder
Message:

Merged sound5 into sound6 branch.

Location:
code/branches/usability
Files:
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/branches/usability

  • code/branches/usability/src/orxonox/MoodManager.h

    r7163 r8005  
    5959    };
    6060
    61     /*
    62     @brief
    63         The MoodManager class serves to allow for different musical themes in the game.
    64     */
     61    /**
     62     * The MoodManager class enables the game to set different themes, i.e. audio themes, each
     63     * with a set of different audio files. A theme (called mood) is set by the server and applies to
     64     * all clients. Existing moods are currently hard-coded in function checkMoodValidity(). Each mood
     65     * needs to have a folder with its name in "data_extern/audo/ambient/" containing sound files named like
     66     * the ones in mood "default".
     67     */
    6568    class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass
    6669    {
  • code/branches/usability/src/orxonox/sound/AmbientSound.cc

    r7929 r8005  
    2323 *      Reto Grieder
    2424 *   Co-authors:
    25  *      ...
     25 *      Kevin Young
    2626 *
    2727 */
     
    3333#include "core/Resource.h"
    3434#include "SoundManager.h"
     35#include "SoundStreamer.h"
     36#include "util/Sleep.h"
     37
     38#include <AL/alut.h>
    3539
    3640namespace orxonox
    3741{
     42    // vorbis callbacks
     43    size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource);
     44    int seekVorbis(void* datasource, ogg_int64_t offset, int whence);
     45    long tellVorbis(void* datasource);
     46   
    3847    AmbientSound::AmbientSound()
    3948        : bPlayOnLoad_(false)
     
    4251
    4352        // Ambient sounds always fade in
    44         this->setVolume(0);
     53        //this->setVolume(0);
    4554    }
    4655
     
    5160            // Smoothly fade out by keeping a SmartPtr
    5261            SoundManager::getInstance().unregisterAmbientSound(this);
     62            this->soundstreamthread_.interrupt();
    5363        }
    5464    }
     
    6272    bool AmbientSound::stop()
    6373    {
    64         if (GameMode::playsSound())
     74        if (GameMode::playsSound()) 
    6575            SoundManager::getInstance().unregisterAmbientSound(this);
    6676        return false; // sound source not (yet) destroyed - return false
     
    92102            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
    93103            if (fileInfo != NULL)
    94                 this->setSource(path);
     104                this->setStreamSource(path);
    95105            else
    96106                COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl;
     
    104114            this->play();
    105115    }
     116
     117    // hacky solution for file streaming
     118    void AmbientSound::setStreamSource(const std::string& source)
     119    {
     120        if (!GameMode::playsSound())
     121        {
     122            this->source_ = source;
     123            return;
     124        }
     125
     126        if(!alIsSource(this->audioSource_))
     127            this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
     128
     129        if (this->source_ == source)
     130        {
     131            return;
     132        }
     133
     134        this->source_ = source;
     135        // Don't load ""
     136        if (source_.empty())
     137            return;
     138
     139        if (this->soundstreamthread_.get_id() != boost::thread::id())
     140        {
     141            this->soundstreamthread_.interrupt(); // terminate an old thread if necessary
     142        }
     143
     144        // queue some init buffers
     145        COUT(4) << "Sound: Creating thread for " << source << std::endl;
     146        // Get resource info
     147        shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source);
     148        if (fileInfo == NULL)
     149        {
     150            COUT(2) << "Sound: Warning: Sound file '" << source << "' not found" << std::endl;
     151            return;
     152        }
     153        // Open data stream
     154        DataStreamPtr dataStream = Resource::open(fileInfo);
     155       
     156        alSourcei(this->audioSource_, AL_BUFFER, 0);
     157
     158        // Open file with custom streaming
     159        ov_callbacks vorbisCallbacks;
     160        vorbisCallbacks.read_func  = &readVorbis;
     161        vorbisCallbacks.seek_func  = &seekVorbis;
     162        vorbisCallbacks.tell_func  = &tellVorbis;
     163        vorbisCallbacks.close_func = NULL;
     164
     165        OggVorbis_File* vf = new OggVorbis_File();
     166        int ret = ov_open_callbacks(dataStream.get(), vf, NULL, 0, vorbisCallbacks);
     167        if (ret < 0)
     168        {
     169            COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl;
     170            ov_clear(vf);
     171            return;
     172        }
     173        vorbis_info* vorbisInfo;
     174        vorbisInfo = ov_info(vf, -1);
     175        ALenum format;
     176        if (vorbisInfo->channels == 1)
     177            format = AL_FORMAT_MONO16;
     178        else
     179            format = AL_FORMAT_STEREO16;
     180
     181        char inbuffer[4096];
     182        ALuint initbuffers[10];
     183        alGenBuffers(10, initbuffers);
     184        if (ALint error = alGetError()) {
     185            COUT(2) << "Sound: Streamer: Could not generate buffer:" << getALErrorString(error) << std::endl;
     186            return;
     187        }
     188        int current_section;
     189
     190        for(int i = 0; i < 10; i++)
     191        {
     192            long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
     193            if (ret == 0)
     194            {
     195                break;
     196            }
     197            else if (ret < 0)
     198            {
     199                COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
     200                ov_clear(vf);
     201                return;
     202            }
     203
     204            alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);
     205            if(ALint error = alGetError()) {
     206                COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
     207                break;
     208             }
     209             alSourceQueueBuffers(this->audioSource_, 1, &initbuffers[i]);
     210             if (ALint error = alGetError()) {
     211                 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
     212             }
     213        }
     214       
     215        this->soundstreamthread_ = boost::thread(SoundStreamer(), this->audioSource_, dataStream, vf, current_section);
     216        if(this->soundstreamthread_ == boost::thread())
     217            COUT(2) << "Sound: Failed to create thread." << std::endl;
     218        //SoundStreamer streamer;
     219        //streamer(this->audioSource_, dataStream);
     220
     221        alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
     222        alSource3f(this->audioSource_, AL_VELOCITY,  0, 0, 0);
     223        alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);
     224        if (ALint error = alGetError())
     225            COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl;
     226    }
     227
     228    bool AmbientSound::doStop()
     229    {
     230        bool result = BaseSound::doStop();
     231        this->soundstreamthread_.interrupt();
     232        return result;
     233    }
     234
     235    void AmbientSound::doPlay()
     236    {
     237        BaseSound::doPlay();
     238
     239        if(GameMode::playsSound() && this->getSourceState() != AL_PLAYING)
     240        {
     241            if(!alIsSource(this->audioSource_))
     242            {
     243                this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
     244                if(!alIsSource(this->audioSource_))
     245                    return;
     246                this->initialiseSource();
     247            }
     248
     249            alSourcePlay(this->audioSource_);
     250            if(int error = alGetError())
     251                COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
     252        }
     253    }
    106254}
  • code/branches/usability/src/orxonox/sound/AmbientSound.h

    r7856 r8005  
    2222 *   Author:
    2323 *      Reto Grieder
     24 *     
     25 *   Co-authors:
    2426 *      Kevin Young
    25  *   Co-authors:
    26  *      ...
    2727 *
    2828 */
     
    3131#define _AmbientSound_H__
    3232
    33 #include "OrxonoxPrereqs.h"
     33#include <boost/thread.hpp>
     34
     35#include "sound/SoundPrereqs.h"
    3436
    3537#include "BaseSound.h"
     
    3941{
    4042    /**
    41      * The AmbientSound class is used to play background music. It can not be placed
    42      * directly in a level file, use WorldAmbientSound instead.
     43     * The AmbientSound class implements the non-3D sound, i.e. sound files that are used for atmospheric
     44     * highlighting.
     45     * It interfaces with BaseSound and is controllable by MoodManager.
     46     * Ambient sounds are always cross-faded. New sounds are registered and activated/deactivated as needed.
     47     *
    4348     */
    4449    class _OrxonoxExport AmbientSound : public BaseSound, public MoodListener
     
    6570        ~AmbientSound() { }
    6671
     72        bool doStop();
     73        void doPlay();
     74
    6775    private:
    6876        void preDestroy();
     
    7684        std::string ambientSource_; //!< Analogous to source_, but mood independent
    7785        bool        bPlayOnLoad_;   //!< Play the sound immediately when loaded
     86
     87        boost::thread soundstreamthread_; // hacky solution for streaming
     88        void setStreamSource(const std::string& source);
    7889    };
    7990}
  • code/branches/usability/src/orxonox/sound/BaseSound.cc

    r7858 r8005  
    9292            alSourcePlay(this->audioSource_);
    9393            if (int error = alGetError())
    94                 COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
     94                COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
    9595        }
    9696    }
     
    145145        alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);
    146146        if (ALint error = alGetError())
    147             COUT(2) << "Sound Warning: Setting source parameters to 0 failed: "
    148                     << SoundManager::getALErrorString(error) << std::endl;
    149         assert(this->soundBuffer_ != NULL);
    150         alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
     147            COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl;
     148        if(this->soundBuffer_ != NULL) {
     149            alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
     150        }
    151151        if (ALuint error = alGetError())
    152             COUT(1) << "Sound Error: Could not set buffer \"" << this->source_ << "\": " << SoundManager::getALErrorString(error) << std::endl;
     152            COUT(1) << "Sound: Error: Could not set buffer \"" << this->source_ << "\": " << getALErrorString(error) << std::endl;
    153153    }
    154154
     
    157157        this->volume_ = clamp(vol, 0.0f, 1.0f);
    158158        if (this->volume_ != vol)
    159             COUT(2) << "Sound warning: volume out of range, clamping value." << std::endl;
     159            COUT(2) << "Sound: Warning: volume out of range, clamping value." << std::endl;
    160160        this->updateVolume();
    161161    }
     
    168168            alSourcef(this->audioSource_, AL_GAIN, volume);
    169169            if (int error = alGetError())
    170                 COUT(2) << "Sound: Error setting volume to " << volume
    171                         << ": " << SoundManager::getALErrorString(error) << std::endl;
     170                COUT(2) << "Sound: Error setting volume to " << volume << ": " << getALErrorString(error) << std::endl;
    172171        }
    173172    }
     
    184183        if (pitch > 2 || pitch < 0.5f)
    185184        {
    186             COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;
     185            COUT(2) << "Sound: Warning: pitch out of range, cropping value." << std::endl;
    187186            pitch = pitch > 2.0f ? 2.0f : pitch;
    188187            pitch = pitch < 0.5f ? 0.5f : pitch;
     
    193192            alSourcef(this->audioSource_, AL_PITCH, pitch);
    194193            if (int error = alGetError())
    195                 COUT(2) << "Sound: Error setting pitch: " << SoundManager::getALErrorString(error) << std::endl;
     194                COUT(2) << "Sound: Error setting pitch: " << getALErrorString(error) << std::endl;
    196195        }
    197196    }
     
    238237            if (ALuint error = alGetError())
    239238            {
    240                 COUT(1) << "Sound Error: Could not set buffer \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;
     239                COUT(1) << "Sound: Error: Could not set buffer \"" << source << "\": " << getALErrorString(error) << std::endl;
    241240                return;
    242241            }
     
    246245            alSourcePlay(this->audioSource_);
    247246            if (int error = alGetError())
    248                 COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
     247                COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
    249248            if (this->isPaused())
    250249                alSourcePause(this->audioSource_);
  • code/branches/usability/src/orxonox/sound/BaseSound.h

    r7856 r8005  
    3030#define _BaseSound_H__
    3131
    32 #include "OrxonoxPrereqs.h"
     32#include "sound/SoundPrereqs.h"
    3333
    3434#include <string>
     
    8585        virtual ~BaseSound();
    8686
    87         void doPlay();
    88         bool doStop(); // returns true if the sound source was destroyed
    89         void doPause();
     87        virtual void doPlay();
     88        virtual bool doStop(); // returns true if the sound source was destroyed
     89        virtual void doPause();
    9090
    9191        // network callbacks
  • code/branches/usability/src/orxonox/sound/SoundBuffer.h

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

    r7858 r8005  
    2222 *   Author:
    2323 *       Erwin 'vaiursch' Herrsche
     24 *       
     25 *   Co-authors:
    2426 *       Kevin Young
    2527 *       Reto Grieder
    26  *   Co-authors:
    27  *      ...
    2828 *
    2929 */
     
    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)
     
    8081
    8182        if (!alutInitWithoutContext(NULL, NULL))
    82             ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
     83            ThrowException(InitialisationFailed, "Sound: Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
    8384        Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
    8485
     
    112113            COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
    113114#endif
    114             ThrowException(InitialisationFailed, "Sound Error: Could not open sound device.");
     115            ThrowException(InitialisationFailed, "Sound: Error: Could not open sound device.");
    115116        }
    116117        Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
    117118
    118119        // Create sound context and make it the currently used one
    119         this->context_ = alcCreateContext(this->device_, NULL);
     120        const ALint contattr[]  = {ALC_SYNC, 1, 0};
     121        this->context_ = alcCreateContext(this->device_, contattr);
    120122        if (this->context_ == NULL)
    121             ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context");
     123            ThrowException(InitialisationFailed, "Sound: Error: Could not create ALC context");
    122124        Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
    123125        if (!alcMakeContextCurrent(this->context_))
    124             ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context");
     126            ThrowException(InitialisationFailed, "Sound: Error: Could not use ALC context");
    125127
    126128        GameMode::setPlaysSound(true);
     
    135137            COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl;
    136138        else
    137             COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
     139            COUT(2) << "Sound: Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
    138140
    139141        this->mute_[SoundType::All]     = 1.0f;
     
    149151            this->availableSoundSources_.push_back(source);
    150152        else
    151             ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source");
     153            ThrowException(InitialisationFailed, "Sound: Error: Could not create even a single source");
    152154        // Create a few initial sources
    153155        this->createSoundSources(this->minSources_ - 1);
     
    171173        // If there are still used buffers around, well, that's just very bad...
    172174        if (this->soundBuffers_.size() != this->effectsPool_.size())
    173             COUT(1) << "Sound Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
     175            COUT(1) << "Sound: Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
    174176        // Empty buffer pool and buffer list
    175177        this->effectsPool_.clear();
     
    178180        // There should not be any sources in use anymore
    179181        if (!this->usedSoundSources_.empty())
    180             COUT(1) << "Sound Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
     182            COUT(1) << "Sound: Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
    181183        while (!this->availableSoundSources_.empty())
    182184        {
     
    189191        // Relieve context to destroy it
    190192        if (!alcMakeContextCurrent(NULL))
    191             COUT(1) << "Sound Error: Could not unset ALC context" << std::endl;
     193            COUT(1) << "Sound: Error: Could not unset ALC context" << std::endl;
    192194        alcDestroyContext(this->context_);
    193195        if (ALCenum error = alcGetError(this->device_))
    194196        {
    195197            if (error == AL_INVALID_OPERATION)
    196                 COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl;
     198                COUT(1) << "Sound: Error: Could not destroy ALC context because it is the current one" << std::endl;
    197199            else
    198                 COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl;
     200                COUT(1) << "Sound: Error: Could not destroy ALC context because it is invalid" << std::endl;
    199201        }
    200202#ifdef AL_VERSION_1_1
    201203        if (!alcCloseDevice(this->device_))
    202             COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
     204            COUT(1) << "Sound: Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
    203205#else
    204206        alcCloseDevice(this->device_);
    205207#endif
    206208        if (!alutExit())
    207             COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
     209            COUT(1) << "Sound: Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
    208210    }
    209211
     
    251253        if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 )
    252254        {
    253             COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl;
     255            COUT(2) << "Sound: Warning: fade step out of range, ignoring change." << std::endl;
    254256            ResetConfigValue(crossFadeStep_);
    255257        }
     
    260262        float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f);
    261263        if (clampedVolume != this->volume_[type])
    262             COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
     264            COUT(2) << "Sound: Warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
    263265        this->updateVolume(type);
    264266    }
     
    352354                if (it->first == newAmbient)
    353355                {
    354                     COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl;
     356                    COUT(2) << "Sound: Warning: Will not play an AmbientSound twice." << std::endl;
    355357                    return;
    356358                }
     
    620622            alDeleteSources(1, &this->availableSoundSources_.back());
    621623            if (alGetError())
    622                 COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl;
     624                COUT(1) << "Sound: Error: Failed to delete a source --> lost forever" << std::endl;
    623625            this->availableSoundSources_.pop_back();
    624626        }
  • code/branches/usability/src/orxonox/sound/SoundManager.h

    r7858 r8005  
    2222 *   Author:
    2323 *       Erwin 'vaiursch' Herrsche
     24 *       
     25 *   Co-authors:
    2426 *       Kevin Young
    2527 *       Reto Grieder
    26  *   Co-authors:
    27  *      ...
    2828 */
    2929
     
    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/usability/src/orxonox/sound/SoundStreamer.cc

    r7163 r8005  
    2727#include "SoundStreamer.h"
    2828
    29 #include <al.h>
     29#include <boost/thread.hpp>
     30#include <AL/al.h>
     31#include <AL/alc.h>
    3032#include <vorbis/vorbisfile.h>
    3133#include "SoundManager.h"
     34#include "util/Sleep.h"
    3235
    3336namespace orxonox
     
    3841    long tellVorbis(void* datasource);
    3942
    40     void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream)
     43    void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section)
    4144    {
    42         // Open file with custom streaming
    43         ov_callbacks vorbisCallbacks;
    44         vorbisCallbacks.read_func  = &readVorbis;
    45         vorbisCallbacks.seek_func  = &seekVorbis;
    46         vorbisCallbacks.tell_func  = &tellVorbis;
    47         vorbisCallbacks.close_func = NULL;
    48 
    49         OggVorbis_File vf;
    50         int ret = ov_open_callbacks(dataStream.get(), &vf, NULL, 0, vorbisCallbacks);
    51         if (ret < 0)
    52         {
    53             COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl;
    54             ov_clear(&vf);
    55             return;
    56         }
     45        char inbuffer[4096];
    5746        vorbis_info* vorbisInfo;
    58         vorbisInfo = ov_info(&vf, -1);
     47        vorbisInfo = ov_info(vf, -1);
    5948        ALenum format;
    6049        if (vorbisInfo->channels == 1)
     
    6352            format = AL_FORMAT_STEREO16;
    6453
    65         char inbuffer[256*1024];
    66         ALuint initbuffers[4];
    67         alGenBuffers(4, initbuffers);
    68         int current_section;
     54        while(true) // Stream forever, control through thread control
     55        {
    6956
    70         for(int i = 0; i < 4; i++)
    71         {
    72             long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
    73             if (ret == 0)
     57            int info;
     58            alGetSourcei(audioSource, AL_SOURCE_STATE, &info);
     59            if(info == AL_PLAYING)
     60                COUT(4) << "Sound: " << dataStream->getName() << " is playing." << std::endl;
     61            else
    7462            {
    75                 return;
     63                COUT(4) << "Sound: " << dataStream->getName() << " is not playing." << std::endl;
    7664            }
    77             else if (ret < 0)
     65
     66            if(alcGetCurrentContext() == NULL)
    7867            {
    79                 COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
    80                 ov_clear(&vf);
     68                COUT(2) << "Sound: There is no context, terminating thread for " << dataStream->getName() << std::endl;
    8169                return;
    8270            }
    8371
    84             alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);
    85         }
    86         alSourceQueueBuffers(audioSource, 4, initbuffers);
    87 
    88         while(true) // Stream forever, control through thread control
    89         {
    9072            int processed;
    9173            alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed);
    9274            if (ALint error = alGetError())
    93             COUT(2) << "Sound Warning: Couldn't get number of processed buffers: "
    94                     << SoundManager::getALErrorString(error) << std::endl;
     75                COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;
     76
     77            COUT(4) << "Sound: processed buffers: " << processed << std::endl;
    9578
    9679            if(processed > 0)
     
    9982                alSourceUnqueueBuffers(audioSource, processed, buffers);
    10083                if (ALint error = alGetError())
    101                     COUT(2) << "Sound Warning: Couldn't unqueue buffers: "
    102                     << SoundManager::getALErrorString(error) << std::endl;
     84                    COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl;
     85           
     86                int queued;
     87                alGetSourcei(audioSource, AL_BUFFERS_QUEUED, &queued);
     88                if (ALint error = alGetError())
     89                    COUT(2) << "Sound: Warning: Couldn't get number of queued buffers: " << getALErrorString(error) << std::endl;
     90                COUT(4) << "Sound: queued buffers: " << queued << std::endl;
    10391
    10492                for(int i = 0; i < processed; i++)
    10593                {
    106                     long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
     94                    long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
    10795                    if (ret == 0)
    10896                    {
     97                        COUT(4) << "Sound: End of file " << dataStream->getName() << ", terminating thread" << std::endl;
    10998                        return;
    11099                    }
    111100                    else if (ret < 0)
    112101                    {
    113                         COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
    114                         ov_clear(&vf);
     102                        COUT(2) << "Sound: libvorbisfile: error reading the file " << dataStream->getName() << std::endl;
     103                        ov_clear(vf);
    115104                        return;
    116105                    }
    117106
    118107                    alBufferData(buffers[i], format, &inbuffer, ret, vorbisInfo->rate);
     108                    if(ALint error = alGetError()) {
     109                        COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
     110                        break;
     111                    }
     112                    alSourceQueueBuffers(audioSource, 1, &buffers[i]);
     113                    if (ALint error = alGetError()) {
     114                        COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
     115                    }
    119116                }
     117            }
     118            else
     119            {
     120                msleep(10); // perhaps another value here is better
     121            }
    120122
    121                 alSourceQueueBuffers(audioSource, processed, buffers);
     123            try {
     124                boost::this_thread::interruption_point();
     125            }
     126            catch(boost::thread_interrupted) {
     127                COUT(4) << "Sound: Catched interruption. Terminating thread for " << dataStream->getName() << std::endl;
     128                ALuint* buffers = new ALuint[5];
     129                alSourceUnqueueBuffers(audioSource, 5, buffers);
    122130                if (ALint error = alGetError())
    123                     COUT(2) << "Sound Warning: Couldn't queue buffers: "
    124                     << SoundManager::getALErrorString(error) << std::endl;
     131                    COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl;
     132
     133                alDeleteBuffers(5, buffers);
     134                if (ALint error = alGetError())
     135                    COUT(2) << "Sound: Warning: Couldn't delete buffers: " << getALErrorString(error) << std::endl;
     136
     137                return;
    125138            }
    126139        }
  • code/branches/usability/src/orxonox/sound/SoundStreamer.h

    r7163 r8005  
    2929#define _SoundStreamer_H__
    3030
    31 #include "OrxonoxPrereqs.h"
     31#include "sound/SoundPrereqs.h"
    3232
    3333#include <string>
     34#include <vorbis/vorbisfile.h>
    3435#include <OgreDataStream.h>
    3536#include "core/CorePrereqs.h"
     
    4041    {
    4142    public:
    42         void operator()(ALuint audioSource, DataStreamPtr dataStream);
     43        void operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section);
    4344    };
    4445}
  • code/branches/usability/src/orxonox/sound/WorldSound.h

    r7854 r8005  
    3030#define _WorldSound_H__
    3131
    32 #include "OrxonoxPrereqs.h"
     32#include "sound/SoundPrereqs.h"
    3333
    3434#include "tools/interfaces/Tickable.h"
  • code/branches/usability/src/orxonox/weaponsystem/WeaponMode.cc

    r7847 r8005  
    2424 *      Fabian 'x3n' Landau
    2525 *   Co-authors:
    26  *      ...
     26 *      Kevin Young
    2727 *
    2828 */
  • code/branches/usability/src/orxonox/weaponsystem/WeaponMode.h

    r7163 r8005  
    2424 *      Fabian 'x3n' Landau
    2525 *   Co-authors:
    26  *      ...
     26 *      Kevin Young
    2727 *
    2828 */
     
    4141namespace orxonox
    4242{
     43    /**
     44     * The WeaponMode class enables the developer, amongst other things, to attach a sound file
     45     * to the firing event of a weapon. The default firing sound is chosen by each weapon (ex.
     46     * HsW01), hard-coded for now.
     47     */
    4348    class _OrxonoxExport WeaponMode : public BaseObject
    4449    {
Note: See TracChangeset for help on using the changeset viewer.