Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2931


Ignore:
Timestamp:
Apr 27, 2009, 2:41:50 PM (16 years ago)
Author:
erwin
Message:

Sound: SoundBase complete

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

Legend:

Unmodified
Added
Removed
  • code/branches/sound/src/sound/SoundBase.cc

    r2899 r2931  
    2727 */
    2828
    29 #include <SoundBase.h>
    30 #include <SoundManager.h>
    31 
    32 #include <Ogre/SceneNode.h>
     29#include "orxonox/objects/worldentities/WorldEntity.h"
     30#include "util/Math.h"
     31#include "SoundManager.h"
     32#include "SoundBase.h"
    3333
    3434namespace orxonox
    3535{
    36     SoundBase::SoundBase(Ogre::SceneNode* node)
     36    SoundBase::SoundBase(WorldEntity* entity)
    3737    {
    3838        this->source_ = 0;
    3939        this->buffer_ = 0;
    40         this->node_ = node;
     40        this->entity_ = entity;
    4141
    42         if(SoundBase::soundmanager_s == null)
    43             SoundBase::soundmanager_s == SoundManager::instance();
     42        if(SoundBase::soundmanager_s == NULL)
     43            SoundBase::soundmanager_s = SoundManager::instance();
    4444    }
    4545
    46     void SoundBase::attachToNode(Ogre::ScenceNode* node)
     46    void SoundBase::attachToEntity(WorldEntity* entity)
    4747    {
    48         this->node_ = node;
     48        this->entity_ = entity;
     49        this->update();
    4950    }
    5051
     52    void SoundBase::update() {
     53        if(alIsSource(this->source_)) {
     54            Vector3 pos = this->entity_->getPosition();
     55            alSource3f(this->source_, AL_POSITION, pos.x, pos.y, pos.z);
     56            ALenum error = alGetError();
     57            if(error == AL_INVALID_VALUE)
     58                COUT(2) << "OpenAL: Invalid sound position" << std::endl;
     59
     60            Vector3 vel = this->entity_->getVelocity();
     61            alSource3f(this->source_, AL_VELOCITY, vel.x, vel.y, vel.z);
     62            error = alGetError();
     63            if(error == AL_INVALID_VALUE)
     64                COUT(2) << "OpenAL: Invalid sound position" << std::endl;
     65
     66            Quaternion orient = this->entity_->getOrientation();
     67            Vector3 at = orient.zAxis();
     68            alSource3f(this->source_, AL_DIRECTION, at.x, at.y, at.z);
     69            error = alGetError();
     70            if(error == AL_INVALID_VALUE)
     71                COUT(2) << "OpenAL: Invalid sound position" << std::endl;
     72        }
     73    }
     74
     75    void SoundBase::play(bool loop) {
     76        if(alIsSource(this->source_)) {
     77            if(loop)
     78                alSourcei(this->source_, AL_LOOPING, AL_TRUE);
     79            else
     80                alSourcei(this->source_, AL_LOOPING, AL_FALSE);
     81            alSourcePlay(this->source_);
     82        }
     83    }
     84
     85    void SoundBase::stop() {
     86        if(alIsSource(this->source_)) {
     87            alSourceStop(this->source_);
     88        }
     89    }
     90
     91    void SoundBase::pause() {
     92        if(alIsSource(this->source_)) {
     93            alSourcePause(this->source_);
     94        }
     95    }
     96
     97    bool SoundBase::isPlaying() {
     98        if(alIsSource(this->source_)) {
     99            return getSourceState() == AL_PLAYING;
     100        }
     101    }
     102
     103    bool SoundBase::isPaused() {
     104        if(alIsSource(this->source_)) {
     105            return getSourceState() == AL_PAUSED;
     106        }
     107    }
     108
     109    bool SoundBase::isStopped() {
     110        if(alIsSource(this->source_)) {
     111            return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;
     112        }
     113    }
     114
     115    ALint SoundBase::getSourceState() {
     116        ALint state;
     117        alGetSourcei(this->source_, AL_SOURCE_STATE, &state);
     118        return state;
     119    }
    51120} // namespace: orxonox
  • code/branches/sound/src/sound/SoundBase.h

    r2930 r2931  
    3232#include <string>
    3333
    34 class Ogre::SceneNode;
    35 class Orxonox::SoundManager;
    36 
    3734namespace orxonox
    3835{
     36    class SoundManager;
     37    class WorldEntity;
    3938    /**
    4039     * The SoudBase class is the base class for all sound file loader classes.
     
    4544    {
    4645    public:
    47         SoundBase(Ogre::SceneNode* node);
     46        SoundBase(WorldEntity* entity);
    4847        ~SoundBase();
    4948
    50         void attachToNode(Ogre::SceneNode* node);
     49        void attachToEntity(WorldEntity* entity);
    5150        void update();
    5251        void play(bool loop);
     
    5554
    5655        bool isPlaying();
     56        bool isPaused();
     57        bool isStopped();
    5758
    5859        virtual void loadFile(std::string filename) = 0;
     
    6162        ALuint source_;
    6263        ALuint buffer_;
    63         Ogre::SceneNode* node_;
     64        WorldEntity* entity_;
    6465
    6566        static SoundManager* soundmanager_s;
     67
     68        ALint getSourceState();
    6669    }; // class SoundBase
    6770} // namepsace orxonox
  • code/branches/sound/src/sound/SoundManager.cc

    r2930 r2931  
    3232#include "orxonox/objects/worldentities/Camera.h"
    3333#include "util/Math.h"
     34#include "SoundBase.h"
    3435#include "SoundManager.h"
    3536
     
    108109        alListener3f(AL_POSITION, pos.x, pos.y, pos.z);
    109110        ALenum error = alGetError();
    110         if(error != AL_INVALID_VALUE)
     111        if(error == AL_INVALID_VALUE)
    111112            COUT(2) << "OpenAL: Invalid listener position" << std::endl;
    112113
     
    116117        Vector3 at = orient.zAxis();
    117118
    118         ALfloat* orientation = { at.x, at.y, at.z,
     119        ALfloat orientation[6] = { at.x, at.y, at.z,
    119120                                 up.x, up.y, up.z };
    120121
Note: See TracChangeset for help on using the changeset viewer.