Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6674


Ignore:
Timestamp:
Apr 1, 2010, 4:24:59 PM (15 years ago)
Author:
erwin
Message:

A few new tries to fix the sound problem: no success

Location:
code/branches/sound5/src/orxonox/sound
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/sound5/src/orxonox/sound/AmbientSound.cc

    r6562 r6674  
    194194        this->soundstreamthread_.interrupt();
    195195    }
     196
     197    void AmbientSound::doPlay()
     198    {
     199        BaseSound::doPlay();
     200
     201        if(GameMode::playsSound() && this->getSourceState() != AL_PLAYING)
     202        {
     203            if(!alIsSource(this->audioSource_))
     204            {
     205                this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
     206                if(!alIsSource(this->audioSource_))
     207                    return;
     208                this->initialiseSource();
     209            }
     210
     211            alSourcePlay(this->audioSource_);
     212            if(int error = alGetError())
     213                COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
     214        }
     215    }
    196216}
  • code/branches/sound5/src/orxonox/sound/AmbientSound.h

    r6508 r6674  
    7474
    7575        void doStop();
     76        void doPlay();
    7677
    7778    private:
  • code/branches/sound5/src/orxonox/sound/SoundStreamer.cc

    r6562 r6674  
    2727#include "SoundStreamer.h"
    2828
     29#include <boost/thread.hpp>
    2930#include <al.h>
    3031#include <alc.h>
     
    4243    void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream)
    4344    {
     45        COUT(4) << "Sound: Creating thread for " << dataStream->getName() << std::endl;
    4446        // Open file with custom streaming
    4547        ov_callbacks vorbisCallbacks;
     
    6567            format = AL_FORMAT_STEREO16;
    6668
    67         char inbuffer[256*1024];
    68         ALuint initbuffers[4];
    69         alGenBuffers(4, initbuffers);
     69        char inbuffer[4096];
     70        ALuint initbuffers[20];
     71        alGenBuffers(20, initbuffers);
    7072        if (ALint error = alGetError()) {
    7173            COUT(2) << "Sound: Streamer: Could not generate buffer:" << getALErrorString(error) << std::endl;
     
    7476        int current_section;
    7577
    76         for(int i = 0; i < 4; i++)
     78        for(int i = 0; i < 20; i++)
    7779        {
    7880            long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
    7981            if (ret == 0)
    8082            {
    81                 return;
     83                break;
    8284            }
    8385            else if (ret < 0)
     
    8991
    9092            alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);
    91             alGetError();
    92         }
    93         alSourceQueueBuffers(audioSource, 4, initbuffers);
    94         if (ALint error = alGetError()) {
    95             COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
     93            if(ALint error = alGetError()) {
     94                COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
     95                break;
     96             }
     97             alSourceQueueBuffers(audioSource, 1, &initbuffers[i]);
     98             if (ALint error = alGetError()) {
     99                 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
     100             }
     101             COUT(4) << "Sound: " << ret << std::endl;
    96102        }
    97103
     
    100106            int processed;
    101107
    102         if(alcGetCurrentContext() == NULL)
    103             COUT(2) << "This should not be!" << std::endl;
     108            if(alcGetCurrentContext() == NULL)
     109            {
     110                COUT(2) << "Sound: There is no context, terminating thread" << std::endl;
     111                return;
     112            }
    104113
    105114            alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed);
    106115            if (ALint error = alGetError())
    107             COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;
     116                COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;
    108117
     118            COUT(2) << "Sound: Blub: " << processed << std::endl;
    109119            if(processed > 0)
    110120            {
     121                COUT(4) << "Sound: " << processed << std::endl;
    111122                ALuint* buffers = new ALuint[processed];
    112123                alSourceUnqueueBuffers(audioSource, processed, buffers);
     
    119130                    if (ret == 0)
    120131                    {
    121                         return;
     132                        break;
    122133                    }
    123134                    else if (ret < 0)
     
    129140
    130141                    alBufferData(buffers[i], format, &inbuffer, ret, vorbisInfo->rate);
    131                     alGetError();
     142                    if(ALint error = alGetError()) {
     143                        COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
     144                        break;
     145                    }
     146                    alSourceQueueBuffers(audioSource, 1, &buffers[i]);
     147                    if (ALint error = alGetError()) {
     148                        COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
     149                    }
    132150                }
    133 
    134                 alSourceQueueBuffers(audioSource, processed, buffers);
    135                 if (ALint error = alGetError())
    136                     COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
     151            }
     152            try {
     153                boost::this_thread::interruption_point();
     154            }
     155            catch(boost::thread_interrupted) {
     156                COUT(4) << "Sound: Catched interruption. Terminating thread for " << dataStream->getName() << std::endl;
     157                return;
    137158            }
    138159            msleep(100); // perhaps another value here is better
Note: See TracChangeset for help on using the changeset viewer.