Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 19, 2009, 12:18:41 AM (15 years ago)
Author:
rgrieder
Message:

Several small changes in sound:

  • Fixed a bug that caused a sound source to be initialised on pause() even it already existed
  • The XML parameter is now called "looping" instead of "loop" because looping was used really all over the code
  • The "play" XML parameter doesn't exist anymore, use "playOnLoad" for AmbientSound only.
  • Added "pitch" XML parameter
  • Changes in synchronisation policy: Ambient sound should not synchronise the state but instead th new playOnLoad parameter
Location:
code/branches/presentation2
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/data/levels/presentationHS09b.oxw

    r6363 r6382  
    2525
    2626
    27 <AmbientSound ambientSource="Mars.ogg" loop="true" play="true" />
     27<AmbientSound ambientSource="Mars.ogg" looping="true" playOnLoad="true" />
    2828
    2929   <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
     
    258258
    259259
    260 <AmbientSound ambientSource="Earth.ogg" loop="true" play="false">
     260<AmbientSound ambientSource="Earth.ogg" looping="true" playOnLoad="false">
    261261       <events>
    262262          <activity>
  • code/branches/presentation2/data/levels/sound.oxw

    r6248 r6382  
    1818  >
    1919
    20   <AmbientSound ambientSource="Earth.ogg" loop="true" play="true" />
    21   <AmbientSound ambientSource="Mars.ogg" loop="true" play="false">
     20  <AmbientSound ambientSource="Earth.ogg" looping="true" playOnLoad="true" />
     21  <AmbientSound ambientSource="Mars.ogg" looping="true">
    2222        <events>
    2323                <activity>
     
    3030        </events>
    3131  </AmbientSound>
    32   <AmbientSound ambientSource="Jupiter.ogg" loop="true" play="false">
     32  <AmbientSound ambientSource="Jupiter.ogg" looping="true">
    3333        <events>
    3434                <activity>
  • code/branches/presentation2/data/levels/templates/spaceship_HXY.oxt

    r6363 r6382  
    6969  >
    7070    <EffectContainer condition="idle">
    71       <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" loop=1 active=false/>
     71      <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" looping=1 active=false/>
    7272    </EffectContainer>
    7373    <EffectContainer condition="not idle">
  • code/branches/presentation2/data/levels/templates/spaceship_Transporter.oxt

    r6363 r6382  
    6969  >
    7070    <EffectContainer condition="idle">
    71       <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" loop=1 active=false/>
     71      <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" looping=1 active=false/>
    7272    </EffectContainer>
    7373    <EffectContainer condition="not idle">
  • code/branches/presentation2/src/orxonox/sound/AmbientSound.cc

    r6370 r6382  
    4242
    4343    AmbientSound::AmbientSound(BaseObject* creator)
    44         : BaseObject(creator), Synchronisable(creator)
     44        : BaseObject(creator)
     45        , Synchronisable(creator)
     46        , bPlayOnLoad_(false)
    4547    {
    4648        RegisterObject(AmbientSound);
     
    4951        this->setVolume(0);
    5052        this->registerVariables();
    51     }
    52 
    53     AmbientSound::~AmbientSound()
    54     {
    5553    }
    5654
     
    6765    {
    6866        registerVariable(ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::ambientSourceChanged));
    69         registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::loopingChanged));
    70         registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::pitchChanged));
    71         registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::stateChanged));
     67        registerVariable(bLooping_,      ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::loopingChanged));
     68        registerVariable(pitch_,         ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::pitchChanged));
     69        registerVariable(bPlayOnLoad_,   ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::playOnLoadChanged));
    7270    }
    7371
     
    7674        SUPER(AmbientSound, XMLPort, xmlelement, mode);
    7775        BaseSound::XMLPortExtern(xmlelement, mode);
    78         XMLPortParam(AmbientSound, "ambientsource", setAmbientSource, getAmbientSource, xmlelement, mode);
     76        XMLPortParam(AmbientSound, "ambientSource", setAmbientSource, getAmbientSource, xmlelement, mode);
     77        XMLPortParam(AmbientSound, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
    7978    }
    8079
     
    8887    {
    8988        if (GameMode::playsSound())
    90         {
    9189            SoundManager::getInstance().registerAmbientSound(this);
    92         }
    93         else
    94             BaseSound::play();
    95     }
    96 
    97     void AmbientSound::doPlay()
    98     {
    99         BaseSound::play();
    10090    }
    10191
     
    10393    {
    10494        if (GameMode::playsSound())
    105         {
    10695            SoundManager::getInstance().unregisterAmbientSound(this);
    107         }
    108         else
    109             BaseSound::stop();
    110     }
    111 
    112     void AmbientSound::doStop()
    113     {
    114         BaseSound::stop();
    11596    }
    11697
     
    11899    {
    119100        if (GameMode::playsSound())
    120         {
    121101            SoundManager::getInstance().pauseAmbientSound(this);
    122         }
    123         else
    124             BaseSound::pause();
    125102    }
    126103   
     
    129106        assert(GameMode::playsSound());
    130107        return SoundManager::getInstance().getRealVolume(SoundType::Music);
    131     }
    132 
    133     void AmbientSound::doPause()
    134     {
    135         BaseSound::pause();
    136108    }
    137109
     
    150122    }
    151123
     124    void AmbientSound::setPlayOnLoad(bool val)
     125    {
     126        this->bPlayOnLoad_ = val;
     127        if (val)
     128            this->play();
     129    }
     130
    152131    void AmbientSound::changedActivity()
    153132    {
  • code/branches/presentation2/src/orxonox/sound/AmbientSound.h

    r6370 r6382  
    5050    public:
    5151        AmbientSound(BaseObject* creator);
    52         ~AmbientSound();
    5352
    5453        void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     
    6160
    6261        void setAmbientSource(const std::string& source);
    63         const std::string& getAmbientSource() const { return this->ambientSource_; }
    64         inline void ambientSourceChanged(){ this->setAmbientSource(this->ambientSource_); }
     62        inline const std::string& getAmbientSource() const
     63            { return this->ambientSource_; }
     64
     65        void setPlayOnLoad(bool val);
     66        bool getPlayOnLoad() const
     67            { return this->bPlayOnLoad_; }
     68
     69    protected:
     70        ~AmbientSound() { }
    6571
    6672    private:
    67         virtual void preDestroy();
    68         void doPlay();
    69         void doStop();
    70         void doPause();
     73        void preDestroy();
    7174        void registerVariables();
    7275        float getRealVolume();
     76        inline void ambientSourceChanged()
     77            { this->setAmbientSource(this->ambientSource_); }
     78        inline void playOnLoadChanged()
     79            { this->setPlayOnLoad(this->bPlayOnLoad_); }
    7380
    7481        std::string ambientSource_; //!< Analogous to source_, but mood independent
     82        bool        bPlayOnLoad_;   //!< Play the sound immediately when loaded
    7583    };
    7684}
  • code/branches/presentation2/src/orxonox/sound/BaseSound.cc

    r6372 r6382  
    6464    void BaseSound::XMLPortExtern(Element& xmlelement, XMLPort::Mode mode)
    6565    {
    66         XMLPortParam(BaseSound, "volume", setVolume,  getVolume,  xmlelement, mode);
    67         XMLPortParam(BaseSound, "loop",  setLooping, getLooping, xmlelement, mode);
    68         XMLPortParam(BaseSound, "play",   setPlaying, isPlaying,  xmlelement, mode);
    69         XMLPortParam(BaseSound, "source", setSource,  getSource,  xmlelement, mode);
    70     }
    71 
    72     void BaseSound::play()
     66        XMLPortParam(BaseSound, "volume",  setVolume,  getVolume,  xmlelement, mode);
     67        XMLPortParam(BaseSound, "looping", setLooping, getLooping, xmlelement, mode);
     68        XMLPortParam(BaseSound, "pitch",   setPitch,   getPitch,   xmlelement, mode);
     69        XMLPortParam(BaseSound, "source",  setSource,  getSource,  xmlelement, mode);
     70    }
     71
     72    void BaseSound::doPlay()
    7373    {
    7474        this->state_ = Playing;
     
    7676        {
    7777            if (!alIsSource(this->audioSource_))
     78            {
    7879                this->audioSource_ = SoundManager::getInstance().getSoundSource();
    79             if (!alIsSource(this->audioSource_))
    80                 return;
    81             this->initialiseSource();
     80                if (!alIsSource(this->audioSource_))
     81                    return;
     82                this->initialiseSource();
     83            }
    8284
    8385            alSourcePlay(this->audioSource_);
     
    8789    }
    8890
    89     void BaseSound::stop()
     91    void BaseSound::doStop()
    9092    {
    9193        this->state_ = Stopped;
     
    103105    }
    104106
    105     void BaseSound::pause()
     107    void BaseSound::doPause()
    106108    {
    107109        if (this->isStopped())
     
    242244            State state = this->state_; // save
    243245            if (this->isPlaying() || this->isPaused())
    244                 BaseSound::play();
     246                doPlay();
    245247            if (state == Paused)
    246248            {
    247249                this->state_ = Paused;
    248                 BaseSound::pause();
     250                doPause();
    249251            }
    250252        }
  • code/branches/presentation2/src/orxonox/sound/BaseSound.h

    r6370 r6382  
    5151    public:
    5252        BaseSound();
    53         virtual ~BaseSound();
    5453
    5554        void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode);
    5655
    57         virtual void play();
    58         virtual void stop();
    59         virtual void pause();
     56        virtual void play()  { this->doPlay(); }
     57        virtual void stop()  { this->doStop(); }
     58        virtual void pause() { this->doPause(); }
    6059
    6160        bool isPlaying() const { return this->state_ == Playing; }
    6261        bool isPaused()  const { return this->state_ == Paused; }
    6362        bool isStopped() const { return this->state_ == Stopped; }
    64 
    65         void setPlaying(bool val)
    66             { val ? this->play() : this->stop(); }
    6763
    6864        virtual void setSource(const std::string& source);
     
    9086            Paused
    9187        };
     88
     89        virtual ~BaseSound();
     90
     91        void doPlay();
     92        void doStop();
     93        void doPause();
    9294
    9395        // network callbacks
  • code/branches/presentation2/src/orxonox/sound/WorldSound.cc

    r6372 r6382  
    5151        this->registerVariables();
    5252    }
    53 
    54     WorldSound::~WorldSound()
    55     {
    56     }
    5753   
    5854    void WorldSound::registerVariables()
    5955    {
    60         registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::volumeChanged));
    61         registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::sourceChanged));
     56        registerVariable(volume_,   ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::volumeChanged));
     57        registerVariable(source_,   ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::sourceChanged));
    6258        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged));
     59        registerVariable(pitch_,    ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged));
    6360        registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
    64         registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged));
    6561    }
    6662
     
    125121    float WorldSound::getRealVolume()
    126122    {
     123        assert(GameMode::playsSound());
    127124        return SoundManager::getInstance().getRealVolume(SoundType::Effects);
    128125    }
  • code/branches/presentation2/src/orxonox/sound/WorldSound.h

    r6370 r6382  
    4646    public:
    4747        WorldSound(BaseObject* creator);
    48         ~WorldSound();
    4948
    5049        void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     
    5352
    5453        void tick(float dt);
     54
     55    protected:
     56        ~WorldSound() {}
    5557
    5658    private:
Note: See TracChangeset for help on using the changeset viewer.