Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6202


Ignore:
Timestamp:
Dec 2, 2009, 4:52:42 PM (15 years ago)
Author:
youngk
Message:

Implemented speed dependent audio pitch. BUG pitching doesn't currently work.

Location:
code/branches/presentation2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/data/levels/templates/spaceship_assff.oxt

    r6187 r6202  
    6464   speedupdown    =  50
    6565
     66   defEngineSndNormal = "sounds/Engine_low.ogg"
     67
    6668   accelerationfront     = 500
    6769   accelerationbrake     = 500
     
    8183    </EffectContainer>
    8284    <EffectContainer condition="normal or brake">
    83       <WorldSound mainstate="activity" source="sounds/Engine_low.ogg" loop=1 active=false/>
     85      <!-- WorldSound mainstate="activity" source="sounds/Engine_low.ogg" loop=1 active=false -->
    8486    </EffectContainer>
    8587    <EffectContainer condition="normal or boost">
  • code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc

    r6187 r6202  
    4141#include "worldentities/EffectContainer.h"
    4242#include "worldentities/pawns/SpaceShip.h"
     43#include "sound/WorldSound.h"
    4344
    4445namespace orxonox
    4546{
    4647    static const float FORWARD_EFFECT_VELOCITY_THRESHOLD = 20;
     48    static const float MAX_VELOCITY_NORMAL = 111;
     49    static const float MAX_VELOCITY_BOOST = 221;
    4750
    4851    CreateFactory(MultiStateEngine);
     
    5154    {
    5255        RegisterObject(MultiStateEngine);
     56
     57        defEngineSndNormal_ = new WorldSound(this);
     58        defEngineSndNormal_->setLooping(true);
    5359
    5460        this->lua_ = new LuaState();
     
    6672                for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2)
    6773                    (*it2)->destroy();
     74            delete this->defEngineSndNormal_;
    6875            delete this->lua_;
    6976        }
     
    7481        SUPER(MultiStateEngine, XMLPort, xmlelement, mode);
    7582        XMLPortObject(MultiStateEngine, EffectContainer, "",  addEffectContainer,  getEffectContainer,  xmlelement, mode);
     83        XMLPortParam(MultiStateEngine, "defEngineSndNormal",  setDefEngSndNormal,  getDefEngSndNormal,  xmlelement, mode);
    7684    }
    7785
     
    92100                const Vector3& velocity = this->getShip()->getLocalVelocity();
    93101
     102                float pitch = velocity.length();
    94103                bool forward = (direction.z < 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD);
    95104
    96105                int newState = 0;
    97106                if (this->getShip()->getBoost() && forward)
     107                {
    98108                    newState = Boost;
     109                    pitch = pitch/MAX_VELOCITY_BOOST + 1;
     110                    pitch = pitch > 2 ? 2 : pitch;
     111                    pitch = pitch < 0.5 ? 0.5 : pitch;
     112                    defEngineSndNormal_->setPitch(pitch);
     113                }
    99114                else if (forward && !newState) // newState == Boost
     115                {
    100116                    newState = Normal;
     117                    pitch = pitch/MAX_VELOCITY_NORMAL + 1;
     118                    pitch = pitch > 2 ? 2 : pitch;
     119                    pitch = pitch < 0.5 ? 0.5 : pitch;
     120                    defEngineSndNormal_->setPitch(pitch);
     121                }
    101122                else if (direction.z > 0 && velocity.z < 0)
    102123                    newState = Brake;
     
    116137                        lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal);
    117138                        lua_setglobal(this->lua_->getInternalLuaState(), "normal");
     139                        if(newState & Normal)
     140                        {
     141                            defEngineSndNormal_->play();
     142                        }
     143                        else
     144                        {
     145                            defEngineSndNormal_->stop();
     146                        }
    118147                    }
    119148                    if (changes & Brake)
     
    150179        if (!ship)
    151180            return;
     181
     182        this->getShip()->attach(defEngineSndNormal_);
    152183
    153184        for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
     
    179210        return NULL;
    180211    }
     212
     213    void MultiStateEngine::setDefEngSndNormal(const std::string &engineSound)
     214    {
     215        defEngineSndNormal_->setSource(engineSound);
     216    }
     217
     218    const std::string& MultiStateEngine::getDefEngSndNormal()
     219    {
     220        return defEngineSndNormal_->getSource();
     221    }
    181222}
  • code/branches/presentation2/src/orxonox/items/MultiStateEngine.h

    r6187 r6202  
    6464            void addEffectContainer(EffectContainer* effect);
    6565            EffectContainer* getEffectContainer(unsigned int index) const;
     66            void setDefEngSndNormal(const std::string& engineSound);
     67            const std::string& getDefEngSndNormal();
    6668
    6769        private:
     
    6971            LuaState* lua_;
    7072            std::vector<EffectContainer*> effectContainers_;
     73            WorldSound* defEngineSndNormal_;
    7174    };
    7275}
  • code/branches/presentation2/src/orxonox/sound/BaseSound.cc

    r6190 r6202  
    5050        RegisterRootObject(BaseSound);
    5151
     52        this->volume_ = 1;
     53        this->pitch_ = 1;
     54
    5255        if (GameMode::playsSound())
    5356        {
     
    129132        if (GameMode::playsSound())
    130133            alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE));
     134    }
     135
     136    void BaseSound::setPitch(float pitch)
     137    {
     138        if (pitch > 2 || pitch < 0.5)
     139        {
     140            COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;
     141            pitch = pitch > 2 ? 2 : pitch;
     142            pitch = pitch < 0.5 ? 0.5 : pitch;
     143        }       
     144        this->pitch_ = pitch;
     145        if (GameMode::playsSound())
     146            alSourcei(this->audioSource_, AL_PITCH, pitch);
    131147    }
    132148
     
    194210        alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
    195211        this->updateVolume();
     212        this->setPitch(this->getPitch());
    196213        alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE));
    197214        if (this->isPlaying() || this->isPaused())
  • code/branches/presentation2/src/orxonox/sound/BaseSound.h

    r6188 r6202  
    7474        void setLooping(bool val);
    7575
     76        float getPitch() const   { return this->pitch_; }
     77        void setPitch(float pitch);
     78
    7679        //ALuint getALAudioSource(void);
    7780
     
    9295        std::string     source_;
    9396        float           volume_;
     97        float           pitch_;
    9498        bool            bLoop_;
    9599        State           state_;
Note: See TracChangeset for help on using the changeset viewer.