Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8006


Ignore:
Timestamp:
Mar 1, 2011, 5:16:52 AM (13 years ago)
Author:
rgrieder
Message:

Reverted last commit (forgot to tick "Switch working copy to new branch"…)

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

Legend:

Unmodified
Added
Removed
  • code/branches/usability

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

    r8005 r8006  
    5959    };
    6060
    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      */
     61    /*
     62    @brief
     63        The MoodManager class serves to allow for different musical themes in the game.
     64    */
    6865    class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass
    6966    {
  • code/branches/usability/src/orxonox/sound/AmbientSound.cc

    r8005 r8006  
    2323 *      Reto Grieder
    2424 *   Co-authors:
    25  *      Kevin Young
     25 *      ...
    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>
    3935
    4036namespace orxonox
    4137{
    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    
    4738    AmbientSound::AmbientSound()
    4839        : bPlayOnLoad_(false)
     
    5142
    5243        // Ambient sounds always fade in
    53         //this->setVolume(0);
     44        this->setVolume(0);
    5445    }
    5546
     
    6051            // Smoothly fade out by keeping a SmartPtr
    6152            SoundManager::getInstance().unregisterAmbientSound(this);
    62             this->soundstreamthread_.interrupt();
    6353        }
    6454    }
     
    7262    bool AmbientSound::stop()
    7363    {
    74         if (GameMode::playsSound()) 
     64        if (GameMode::playsSound())
    7565            SoundManager::getInstance().unregisterAmbientSound(this);
    7666        return false; // sound source not (yet) destroyed - return false
     
    10292            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
    10393            if (fileInfo != NULL)
    104                 this->setStreamSource(path);
     94                this->setSource(path);
    10595            else
    10696                COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl;
     
    114104            this->play();
    115105    }
    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     }
    254106}
  • code/branches/usability/src/orxonox/sound/AmbientSound.h

    r8005 r8006  
    2222 *   Author:
    2323 *      Reto Grieder
    24  *     
     24 *      Kevin Young
    2525 *   Co-authors:
    26  *      Kevin Young
     26 *      ...
    2727 *
    2828 */
     
    3131#define _AmbientSound_H__
    3232
    33 #include <boost/thread.hpp>
    34 
    35 #include "sound/SoundPrereqs.h"
     33#include "OrxonoxPrereqs.h"
    3634
    3735#include "BaseSound.h"
     
    4139{
    4240    /**
    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      *
     41     * The AmbientSound class is used to play background music. It can not be placed
     42     * directly in a level file, use WorldAmbientSound instead.
    4843     */
    4944    class _OrxonoxExport AmbientSound : public BaseSound, public MoodListener
     
    7065        ~AmbientSound() { }
    7166
    72         bool doStop();
    73         void doPlay();
    74 
    7567    private:
    7668        void preDestroy();
     
    8476        std::string ambientSource_; //!< Analogous to source_, but mood independent
    8577        bool        bPlayOnLoad_;   //!< Play the sound immediately when loaded
    86 
    87         boost::thread soundstreamthread_; // hacky solution for streaming
    88         void setStreamSource(const std::string& source);
    8978    };
    9079}
  • code/branches/usability/src/orxonox/sound/BaseSound.cc

    r8005 r8006  
    9292            alSourcePlay(this->audioSource_);
    9393            if (int error = alGetError())
    94                 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
     94                COUT(2) << "Sound: Error playing sound: " << SoundManager::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: " << getALErrorString(error) << std::endl;
    148         if(this->soundBuffer_ != NULL) {
    149             alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
    150         }
     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());
    151151        if (ALuint error = alGetError())
    152             COUT(1) << "Sound: Error: Could not set buffer \"" << this->source_ << "\": " << getALErrorString(error) << std::endl;
     152            COUT(1) << "Sound Error: Could not set buffer \"" << this->source_ << "\": " << SoundManager::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 << ": " << getALErrorString(error) << std::endl;
     170                COUT(2) << "Sound: Error setting volume to " << volume
     171                        << ": " << SoundManager::getALErrorString(error) << std::endl;
    171172        }
    172173    }
     
    183184        if (pitch > 2 || pitch < 0.5f)
    184185        {
    185             COUT(2) << "Sound: Warning: pitch out of range, cropping value." << std::endl;
     186            COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;
    186187            pitch = pitch > 2.0f ? 2.0f : pitch;
    187188            pitch = pitch < 0.5f ? 0.5f : pitch;
     
    192193            alSourcef(this->audioSource_, AL_PITCH, pitch);
    193194            if (int error = alGetError())
    194                 COUT(2) << "Sound: Error setting pitch: " << getALErrorString(error) << std::endl;
     195                COUT(2) << "Sound: Error setting pitch: " << SoundManager::getALErrorString(error) << std::endl;
    195196        }
    196197    }
     
    237238            if (ALuint error = alGetError())
    238239            {
    239                 COUT(1) << "Sound: Error: Could not set buffer \"" << source << "\": " << getALErrorString(error) << std::endl;
     240                COUT(1) << "Sound Error: Could not set buffer \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;
    240241                return;
    241242            }
     
    245246            alSourcePlay(this->audioSource_);
    246247            if (int error = alGetError())
    247                 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
     248                COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
    248249            if (this->isPaused())
    249250                alSourcePause(this->audioSource_);
  • code/branches/usability/src/orxonox/sound/BaseSound.h

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

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

    r8005 r8006  
    2222 *   Author:
    2323 *       Erwin 'vaiursch' Herrsche
    24  *       
    25  *   Co-authors:
    2624 *       Kevin Young
    2725 *       Reto Grieder
     26 *   Co-authors:
     27 *      ...
    2828 *
    2929 */
     
    5252    ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
    5353
    54     // From SoundPrereqs.h
    55     std::string getALErrorString(ALenum code)
     54    std::string SoundManager::getALErrorString(ALenum code)
    5655    {
    5756        switch (code)
     
    8180
    8281        if (!alutInitWithoutContext(NULL, NULL))
    83             ThrowException(InitialisationFailed, "Sound: Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
     82            ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
    8483        Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
    8584
     
    113112            COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
    114113#endif
    115             ThrowException(InitialisationFailed, "Sound: Error: Could not open sound device.");
     114            ThrowException(InitialisationFailed, "Sound Error: Could not open sound device.");
    116115        }
    117116        Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
    118117
    119118        // Create sound context and make it the currently used one
    120         const ALint contattr[]  = {ALC_SYNC, 1, 0};
    121         this->context_ = alcCreateContext(this->device_, contattr);
     119        this->context_ = alcCreateContext(this->device_, NULL);
    122120        if (this->context_ == NULL)
    123             ThrowException(InitialisationFailed, "Sound: Error: Could not create ALC context");
     121            ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context");
    124122        Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
    125123        if (!alcMakeContextCurrent(this->context_))
    126             ThrowException(InitialisationFailed, "Sound: Error: Could not use ALC context");
     124            ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context");
    127125
    128126        GameMode::setPlaysSound(true);
     
    137135            COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl;
    138136        else
    139             COUT(2) << "Sound: Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
     137            COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
    140138
    141139        this->mute_[SoundType::All]     = 1.0f;
     
    151149            this->availableSoundSources_.push_back(source);
    152150        else
    153             ThrowException(InitialisationFailed, "Sound: Error: Could not create even a single source");
     151            ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source");
    154152        // Create a few initial sources
    155153        this->createSoundSources(this->minSources_ - 1);
     
    173171        // If there are still used buffers around, well, that's just very bad...
    174172        if (this->soundBuffers_.size() != this->effectsPool_.size())
    175             COUT(1) << "Sound: Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
     173            COUT(1) << "Sound Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
    176174        // Empty buffer pool and buffer list
    177175        this->effectsPool_.clear();
     
    180178        // There should not be any sources in use anymore
    181179        if (!this->usedSoundSources_.empty())
    182             COUT(1) << "Sound: Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
     180            COUT(1) << "Sound Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
    183181        while (!this->availableSoundSources_.empty())
    184182        {
     
    191189        // Relieve context to destroy it
    192190        if (!alcMakeContextCurrent(NULL))
    193             COUT(1) << "Sound: Error: Could not unset ALC context" << std::endl;
     191            COUT(1) << "Sound Error: Could not unset ALC context" << std::endl;
    194192        alcDestroyContext(this->context_);
    195193        if (ALCenum error = alcGetError(this->device_))
    196194        {
    197195            if (error == AL_INVALID_OPERATION)
    198                 COUT(1) << "Sound: Error: Could not destroy ALC context because it is the current one" << std::endl;
     196                COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl;
    199197            else
    200                 COUT(1) << "Sound: Error: Could not destroy ALC context because it is invalid" << std::endl;
     198                COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl;
    201199        }
    202200#ifdef AL_VERSION_1_1
    203201        if (!alcCloseDevice(this->device_))
    204             COUT(1) << "Sound: Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
     202            COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
    205203#else
    206204        alcCloseDevice(this->device_);
    207205#endif
    208206        if (!alutExit())
    209             COUT(1) << "Sound: Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
     207            COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
    210208    }
    211209
     
    253251        if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 )
    254252        {
    255             COUT(2) << "Sound: Warning: fade step out of range, ignoring change." << std::endl;
     253            COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl;
    256254            ResetConfigValue(crossFadeStep_);
    257255        }
     
    262260        float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f);
    263261        if (clampedVolume != this->volume_[type])
    264             COUT(2) << "Sound: Warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
     262            COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
    265263        this->updateVolume(type);
    266264    }
     
    354352                if (it->first == newAmbient)
    355353                {
    356                     COUT(2) << "Sound: Warning: Will not play an AmbientSound twice." << std::endl;
     354                    COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl;
    357355                    return;
    358356                }
     
    622620            alDeleteSources(1, &this->availableSoundSources_.back());
    623621            if (alGetError())
    624                 COUT(1) << "Sound: Error: Failed to delete a source --> lost forever" << std::endl;
     622                COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl;
    625623            this->availableSoundSources_.pop_back();
    626624        }
  • code/branches/usability/src/orxonox/sound/SoundManager.h

    r8005 r8006  
    2222 *   Author:
    2323 *       Erwin 'vaiursch' Herrsche
    24  *       
    25  *   Co-authors:
    2624 *       Kevin Young
    2725 *       Reto Grieder
     26 *   Co-authors:
     27 *      ...
    2828 */
    2929
     
    3131#define _SoundManager_H__
    3232
    33 #include "sound/SoundPrereqs.h"
     33#include "OrxonoxPrereqs.h"
    3434
    3535#include <list>
     
    9999        void releaseSoundSource(ALuint source);
    100100
     101        static std::string getALErrorString(ALenum error);
     102
    101103    private:
    102104        void processCrossFading(float dt);
  • code/branches/usability/src/orxonox/sound/SoundStreamer.cc

    r8005 r8006  
    2727#include "SoundStreamer.h"
    2828
    29 #include <boost/thread.hpp>
    30 #include <AL/al.h>
    31 #include <AL/alc.h>
     29#include <al.h>
    3230#include <vorbis/vorbisfile.h>
    3331#include "SoundManager.h"
    34 #include "util/Sleep.h"
    3532
    3633namespace orxonox
     
    4138    long tellVorbis(void* datasource);
    4239
    43     void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section)
     40    void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream)
    4441    {
    45         char inbuffer[4096];
     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        }
    4657        vorbis_info* vorbisInfo;
    47         vorbisInfo = ov_info(vf, -1);
     58        vorbisInfo = ov_info(&vf, -1);
    4859        ALenum format;
    4960        if (vorbisInfo->channels == 1)
     
    5263            format = AL_FORMAT_STEREO16;
    5364
    54         while(true) // Stream forever, control through thread control
     65        char inbuffer[256*1024];
     66        ALuint initbuffers[4];
     67        alGenBuffers(4, initbuffers);
     68        int current_section;
     69
     70        for(int i = 0; i < 4; i++)
    5571        {
    56 
    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
     72            long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
     73            if (ret == 0)
    6274            {
    63                 COUT(4) << "Sound: " << dataStream->getName() << " is not playing." << std::endl;
     75                return;
    6476            }
    65 
    66             if(alcGetCurrentContext() == NULL)
     77            else if (ret < 0)
    6778            {
    68                 COUT(2) << "Sound: There is no context, terminating thread for " << dataStream->getName() << std::endl;
     79                COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
     80                ov_clear(&vf);
    6981                return;
    7082            }
    7183
     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        {
    7290            int processed;
    7391            alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed);
    7492            if (ALint error = alGetError())
    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;
     93            COUT(2) << "Sound Warning: Couldn't get number of processed buffers: "
     94                    << SoundManager::getALErrorString(error) << std::endl;
    7895
    7996            if(processed > 0)
     
    8299                alSourceUnqueueBuffers(audioSource, processed, buffers);
    83100                if (ALint error = alGetError())
    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;
     101                    COUT(2) << "Sound Warning: Couldn't unqueue buffers: "
     102                    << SoundManager::getALErrorString(error) << std::endl;
    91103
    92104                for(int i = 0; i < processed; i++)
    93105                {
    94                     long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
     106                    long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
    95107                    if (ret == 0)
    96108                    {
    97                         COUT(4) << "Sound: End of file " << dataStream->getName() << ", terminating thread" << std::endl;
    98109                        return;
    99110                    }
    100111                    else if (ret < 0)
    101112                    {
    102                         COUT(2) << "Sound: libvorbisfile: error reading the file " << dataStream->getName() << std::endl;
    103                         ov_clear(vf);
     113                        COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
     114                        ov_clear(&vf);
    104115                        return;
    105116                    }
    106117
    107118                    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                     }
    116119                }
    117             }
    118             else
    119             {
    120                 msleep(10); // perhaps another value here is better
    121             }
    122120
    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);
     121                alSourceQueueBuffers(audioSource, processed, buffers);
    130122                if (ALint error = alGetError())
    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;
     123                    COUT(2) << "Sound Warning: Couldn't queue buffers: "
     124                    << SoundManager::getALErrorString(error) << std::endl;
    138125            }
    139126        }
  • code/branches/usability/src/orxonox/sound/SoundStreamer.h

    r8005 r8006  
    2929#define _SoundStreamer_H__
    3030
    31 #include "sound/SoundPrereqs.h"
     31#include "OrxonoxPrereqs.h"
    3232
    3333#include <string>
    34 #include <vorbis/vorbisfile.h>
    3534#include <OgreDataStream.h>
    3635#include "core/CorePrereqs.h"
     
    4140    {
    4241    public:
    43         void operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section);
     42        void operator()(ALuint audioSource, DataStreamPtr dataStream);
    4443    };
    4544}
  • code/branches/usability/src/orxonox/sound/WorldSound.h

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

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

    r8005 r8006  
    2424 *      Fabian 'x3n' Landau
    2525 *   Co-authors:
    26  *      Kevin Young
     26 *      ...
    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      */
    4843    class _OrxonoxExport WeaponMode : public BaseObject
    4944    {
Note: See TracChangeset for help on using the changeset viewer.