[Orxonox-commit 1484] r6202 - in code/branches/presentation2: data/levels/templates src/orxonox/items src/orxonox/sound
youngk at orxonox.net
youngk at orxonox.net
Wed Dec 2 16:52:42 CET 2009
Author: youngk
Date: 2009-12-02 16:52:42 +0100 (Wed, 02 Dec 2009)
New Revision: 6202
Modified:
code/branches/presentation2/data/levels/templates/spaceship_assff.oxt
code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc
code/branches/presentation2/src/orxonox/items/MultiStateEngine.h
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
code/branches/presentation2/src/orxonox/sound/BaseSound.h
Log:
Implemented speed dependent audio pitch. BUG: pitching doesn't currently work.
Modified: code/branches/presentation2/data/levels/templates/spaceship_assff.oxt
===================================================================
--- code/branches/presentation2/data/levels/templates/spaceship_assff.oxt 2009-12-02 15:39:26 UTC (rev 6201)
+++ code/branches/presentation2/data/levels/templates/spaceship_assff.oxt 2009-12-02 15:52:42 UTC (rev 6202)
@@ -63,6 +63,8 @@
speedleftright = 50
speedupdown = 50
+ defEngineSndNormal = "sounds/Engine_low.ogg"
+
accelerationfront = 500
accelerationbrake = 500
accelerationback = 125
@@ -80,7 +82,7 @@
-->
</EffectContainer>
<EffectContainer condition="normal or brake">
- <WorldSound mainstate="activity" source="sounds/Engine_low.ogg" loop=1 active=false/>
+ <!-- WorldSound mainstate="activity" source="sounds/Engine_low.ogg" loop=1 active=false -->
</EffectContainer>
<EffectContainer condition="normal or boost">
<Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
Modified: code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc
===================================================================
--- code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc 2009-12-02 15:39:26 UTC (rev 6201)
+++ code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc 2009-12-02 15:52:42 UTC (rev 6202)
@@ -40,10 +40,13 @@
#include "core/XMLPort.h"
#include "worldentities/EffectContainer.h"
#include "worldentities/pawns/SpaceShip.h"
+#include "sound/WorldSound.h"
namespace orxonox
{
static const float FORWARD_EFFECT_VELOCITY_THRESHOLD = 20;
+ static const float MAX_VELOCITY_NORMAL = 111;
+ static const float MAX_VELOCITY_BOOST = 221;
CreateFactory(MultiStateEngine);
@@ -51,6 +54,9 @@
{
RegisterObject(MultiStateEngine);
+ defEngineSndNormal_ = new WorldSound(this);
+ defEngineSndNormal_->setLooping(true);
+
this->lua_ = new LuaState();
this->state_ = 0;
@@ -65,6 +71,7 @@
for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2)
(*it2)->destroy();
+ delete this->defEngineSndNormal_;
delete this->lua_;
}
}
@@ -73,6 +80,7 @@
{
SUPER(MultiStateEngine, XMLPort, xmlelement, mode);
XMLPortObject(MultiStateEngine, EffectContainer, "", addEffectContainer, getEffectContainer, xmlelement, mode);
+ XMLPortParam(MultiStateEngine, "defEngineSndNormal", setDefEngSndNormal, getDefEngSndNormal, xmlelement, mode);
}
void MultiStateEngine::registerVariables()
@@ -91,13 +99,26 @@
const Vector3& direction = this->getDirection();
const Vector3& velocity = this->getShip()->getLocalVelocity();
+ float pitch = velocity.length();
bool forward = (direction.z < 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD);
int newState = 0;
if (this->getShip()->getBoost() && forward)
+ {
newState = Boost;
+ pitch = pitch/MAX_VELOCITY_BOOST + 1;
+ pitch = pitch > 2 ? 2 : pitch;
+ pitch = pitch < 0.5 ? 0.5 : pitch;
+ defEngineSndNormal_->setPitch(pitch);
+ }
else if (forward && !newState) // newState == Boost
+ {
newState = Normal;
+ pitch = pitch/MAX_VELOCITY_NORMAL + 1;
+ pitch = pitch > 2 ? 2 : pitch;
+ pitch = pitch < 0.5 ? 0.5 : pitch;
+ defEngineSndNormal_->setPitch(pitch);
+ }
else if (direction.z > 0 && velocity.z < 0)
newState = Brake;
else
@@ -115,6 +136,14 @@
{
lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal);
lua_setglobal(this->lua_->getInternalLuaState(), "normal");
+ if(newState & Normal)
+ {
+ defEngineSndNormal_->play();
+ }
+ else
+ {
+ defEngineSndNormal_->stop();
+ }
}
if (changes & Brake)
{
@@ -150,6 +179,8 @@
if (!ship)
return;
+ this->getShip()->attach(defEngineSndNormal_);
+
for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsEnd(); ++it2)
this->getShip()->attach(*it2);
@@ -178,4 +209,14 @@
}
return NULL;
}
+
+ void MultiStateEngine::setDefEngSndNormal(const std::string &engineSound)
+ {
+ defEngineSndNormal_->setSource(engineSound);
+ }
+
+ const std::string& MultiStateEngine::getDefEngSndNormal()
+ {
+ return defEngineSndNormal_->getSource();
+ }
}
Modified: code/branches/presentation2/src/orxonox/items/MultiStateEngine.h
===================================================================
--- code/branches/presentation2/src/orxonox/items/MultiStateEngine.h 2009-12-02 15:39:26 UTC (rev 6201)
+++ code/branches/presentation2/src/orxonox/items/MultiStateEngine.h 2009-12-02 15:52:42 UTC (rev 6202)
@@ -63,11 +63,14 @@
void addEffectContainer(EffectContainer* effect);
EffectContainer* getEffectContainer(unsigned int index) const;
+ void setDefEngSndNormal(const std::string& engineSound);
+ const std::string& getDefEngSndNormal();
private:
int state_;
LuaState* lua_;
std::vector<EffectContainer*> effectContainers_;
+ WorldSound* defEngineSndNormal_;
};
}
Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.cc 2009-12-02 15:39:26 UTC (rev 6201)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.cc 2009-12-02 15:52:42 UTC (rev 6202)
@@ -49,6 +49,9 @@
{
RegisterRootObject(BaseSound);
+ this->volume_ = 1;
+ this->pitch_ = 1;
+
if (GameMode::playsSound())
{
alGenSources(1, &this->audioSource_);
@@ -130,6 +133,19 @@
alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE));
}
+ void BaseSound::setPitch(float pitch)
+ {
+ if (pitch > 2 || pitch < 0.5)
+ {
+ COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;
+ pitch = pitch > 2 ? 2 : pitch;
+ pitch = pitch < 0.5 ? 0.5 : pitch;
+ }
+ this->pitch_ = pitch;
+ if (GameMode::playsSound())
+ alSourcei(this->audioSource_, AL_PITCH, pitch);
+ }
+
void BaseSound::setSource(const std::string& source)
{
if (!GameMode::playsSound() || source == this->source_)
@@ -193,6 +209,7 @@
alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0);
this->updateVolume();
+ this->setPitch(this->getPitch());
alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE));
if (this->isPlaying() || this->isPaused())
alSourcePlay(this->audioSource_);
Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.h 2009-12-02 15:39:26 UTC (rev 6201)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.h 2009-12-02 15:52:42 UTC (rev 6202)
@@ -73,6 +73,9 @@
bool getLooping() const { return this->bLoop_; }
void setLooping(bool val);
+ float getPitch() const { return this->pitch_; }
+ void setPitch(float pitch);
+
//ALuint getALAudioSource(void);
protected:
@@ -91,6 +94,7 @@
std::string source_;
float volume_;
+ float pitch_;
bool bLoop_;
State state_;
DataStreamPtr dataStream_;
More information about the Orxonox-commit
mailing list