Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 9, 2009, 10:09:27 PM (14 years ago)
Author:
scheusso
Message:

Approach to make sounds synchronisable (not yet working)

Location:
code/branches/presentation2/src/orxonox/sound
Files:
6 edited

Legend:

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

    r6203 r6307  
    4242
    4343    AmbientSound::AmbientSound(BaseObject* creator)
    44         : BaseObject(creator)
     44        : BaseObject(creator), Synchronisable(creator)
    4545    {
    4646        RegisterObject(AmbientSound);
     
    4848        // Ambient sounds always fade in
    4949        this->setVolume(0);
     50        this->registerVariables();
    5051    }
    5152
    5253    AmbientSound::~AmbientSound()
    5354    {
     55    }
     56   
     57    void AmbientSound::registerVariables()
     58    {
     59        registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::volumeChanged));
     60//         registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::sourceChanged));
     61        registerVariable(ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::ambientSourceChanged));
     62        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::loopingChanged));
     63        registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::pitchChanged));
     64        registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient);
    5465    }
    5566
  • code/branches/presentation2/src/orxonox/sound/AmbientSound.h

    r6186 r6307  
    3535#include "core/BaseObject.h"
    3636#include "sound/BaseSound.h"
     37#include "network/synchronisable/Synchronisable.h"
    3738
    3839namespace orxonox
     
    4344     *
    4445     */
    45     class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject
     46    class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable
    4647    {
    4748        friend class SoundManager;
     
    6364        virtual void setAmbientSource(const std::string& source);
    6465        const std::string& getAmbientSource() const { return this->ambientSource_; }
     66        inline void ambientSourceChanged(){ this->setAmbientSource(this->ambientSource_); }
    6567
    6668    private:
     
    6870        void doStop();
    6971        void doPause();
     72       
     73        void registerVariables();
    7074
    7175        std::string ambientSource_; //!< Analogous to source_, but mood independent
  • code/branches/presentation2/src/orxonox/sound/BaseSound.cc

    r6285 r6307  
    4646        , bPooling_(false)
    4747        , volume_(1.0)
    48         , bLoop_(false)
     48        , bLooping_(false)
    4949        , state_(Stopped)
    5050        , pitch_ (1.0)
     
    151151    void BaseSound::setLooping(bool val)
    152152    {
    153         this->bLoop_ = val;
     153        this->bLooping_ = val;
    154154        if (GameMode::playsSound() && alIsSource(this->audioSource_))
    155155            alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE));
     
    204204        if (ALuint error = alGetError())
    205205        {
    206             COUT(1) << "Sound Error: Could not load file \"" << source << "\": " << SoundManager::getALErrorString << std::endl;
     206            COUT(1) << "Sound Error: Could not load file \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;
    207207            return;
    208208        }
  • code/branches/presentation2/src/orxonox/sound/BaseSound.h

    r6255 r6307  
    6868        virtual void setSource(const std::string& source);
    6969        virtual const std::string& getSource() const { return this->source_; }
     70        inline void sourceChanged(){ this->setSource(this->source_); }
    7071
    7172        void setVolume(float vol);
    7273        float getVolume() const { return this->volume_; }
     74        inline void volumeChanged(){ this->setVolume(this->volume_); }
    7375       
    7476        virtual float getVolumeGain();
    7577        void updateVolume(void);
    7678
    77         bool getLooping() const   { return this->bLoop_; }
     79        bool getLooping() const   { return this->bLooping_; }
    7880        void setLooping(bool val);
     81        inline void loopingChanged(){ this->setLooping(this->bLooping_); }
    7982
    8083        float getPitch() const   { return this->pitch_; }
    8184        void setPitch(float pitch);
     85        inline void pitchChanged(){ this->setPitch(this->pitch_); }
    8286
    8387        //ALuint getALAudioSource(void);
    8488
    8589    protected:
    86         ALint getSourceState() const;
    87 
    88         ALuint          audioSource_;
    89         bool            bPooling_;
    90         shared_ptr<SoundBuffer> soundBuffer_;
    91 
    92     private:
    9390        enum State
    9491        {
     
    9794            Paused
    9895        };
     96        ALint getSourceState() const;
    9997
     98        ALuint          audioSource_;
     99        bool            bPooling_;
     100        shared_ptr<SoundBuffer> soundBuffer_;
    100101        std::string     source_;
    101102        float           volume_;
    102         bool            bLoop_;
     103        bool            bLooping_;
    103104        State           state_;
    104105        float           pitch_;
     106
     107    private:
    105108        DataStreamPtr   dataStream_;
    106109    };
  • code/branches/presentation2/src/orxonox/sound/WorldSound.cc

    r6269 r6307  
    3636#include "core/XMLPort.h"
    3737#include "SoundManager.h"
     38#include <core/ConsoleCommandCompilation.h>
    3839
    3940namespace orxonox
     
    4748        // WorldSound buffers should be pooled when they're not used anymore
    4849        this->bPooling_ = true;
     50        this->registerVariables();
    4951    }
    5052
    5153    WorldSound::~WorldSound()
    5254    {
     55    }
     56   
     57    void WorldSound::registerVariables()
     58    {
     59        registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::volumeChanged));
     60        registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::sourceChanged));
     61        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::loopingChanged));
     62        registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient);
     63        registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::pitchChanged));
    5364    }
    5465
  • code/branches/presentation2/src/orxonox/sound/WorldSound.h

    r6186 r6307  
    5757
    5858    private:
     59        void registerVariables();
    5960    };
    6061}
Note: See TracChangeset for help on using the changeset viewer.