Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2950


Ignore:
Timestamp:
May 4, 2009, 3:40:08 PM (16 years ago)
Author:
erwin
Message:

ambient sound loading for levels

Location:
code/branches/sound
Files:
1 added
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/sound/cmake/LibraryConfig.cmake

    r2711 r2950  
    111111FIND_PACKAGE(OGRE  1.4 EXACT REQUIRED)
    112112FIND_PACKAGE(ENet  1.1       REQUIRED)
    113 FIND_PACKAGE(Ogg             REQUIRED)
    114 FIND_PACKAGE(Vorbis          REQUIRED)
     113#FIND_PACKAGE(Ogg             REQUIRED)
     114#FIND_PACKAGE(Vorbis          REQUIRED)
    115115FIND_PACKAGE(ALUT            REQUIRED)
    116116FIND_PACKAGE(ZLIB            REQUIRED)
  • code/branches/sound/src/orxonox/CMakeLists.txt

    r2748 r2950  
    5858  core
    5959  network
    60   #audio
     60  sound
    6161)
    6262
  • code/branches/sound/src/orxonox/objects/Level.cc

    r2826 r2950  
    7777        XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode);
    7878        XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
     79       
     80        XMLPortParamLoadOnly(Level, "ambientsound", loadAmbientSound, xmlelement, mode);
    7981
    8082        XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
     
    148150    }
    149151
     152    void Level::loadAmbientSound(const std::string& filename)
     153    {
     154        if(filename == "") return;
     155        else
     156        {
     157            if(this->ambientsound_ == NULL)
     158            {
     159                this->ambientsound_ = new SoundBase();
     160                this->sndmgr_.addSound(this->ambientsound_);
     161            }
     162
     163            this->ambientsound_->loadFile(filename);
     164            this->ambientsound_->play();
     165        }
     166    }
     167
    150168    void Level::playerEntered(PlayerInfo* player)
    151169    {
  • code/branches/sound/src/orxonox/objects/Level.h

    r2826 r2950  
    3333
    3434#include "network/synchronisable/Synchronisable.h"
     35#include "sound/SoundBase.h"
     36#include "sound/SoundManager.h"
    3537#include "core/BaseObject.h"
    3638
     
    5052            inline const std::string& getDescription() const
    5153                { return this->description_; }
     54
     55            void loadAmbientSound(const std::string& filename);
    5256
    5357            void playerEntered(PlayerInfo* player);
     
    6973            XMLFile*               xmlfile_;
    7074            std::list<BaseObject*> objects_;
     75            SoundManager           sndmgr_;
     76            SoundBase*             ambientsound_;
    7177    };
    7278}
  • code/branches/sound/src/sound/SoundBase.cc

    r2932 r2950  
    3434namespace orxonox
    3535{
     36    SoundBase::SoundBase()
     37    {
     38        this->source_ = 0;
     39        this->buffer_ = 0;
     40        this->entity_ = NULL;
     41    }
    3642    SoundBase::SoundBase(WorldEntity* entity)
    3743    {
     
    3945        this->buffer_ = 0;
    4046        this->entity_ = entity;
    41 
    42         if(SoundBase::soundmanager_s == NULL)
    43             SoundBase::soundmanager_s = SoundManager::instance();
    4447    }
    4548
     
    5154
    5255    void SoundBase::update() {
    53         if(alIsSource(this->source_)) {
     56        if(this->entity_ != NULL && alIsSource(this->source_)) {
    5457            Vector3 pos = this->entity_->getPosition();
    5558            alSource3f(this->source_, AL_POSITION, pos.x, pos.y, pos.z);
     
    99102            return getSourceState() == AL_PLAYING;
    100103        }
     104        return false;
    101105    }
    102106
     
    105109            return getSourceState() == AL_PAUSED;
    106110        }
     111        return true;
    107112    }
    108113
     
    111116            return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;
    112117        }
     118        return true;
    113119    }
    114120
    115121    bool SoundBase::loadFile(std::string filename) {
     122        COUT(3) << "OpenAL ALUT: loading file " << filename << std::endl;
    116123        this->buffer_ = alutCreateBufferFromFile(filename.c_str());
    117124        if(this->buffer_ == AL_NONE) {
    118             COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError());
     125            COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    119126            return false;
    120127        }
     
    123130        alSourcei(this->source_, AL_BUFFER, this->buffer_);
    124131        if(alGetError() != AL_NO_ERROR) {
    125             COUT(2) << "OpenAL: Error loading sample file";
     132            COUT(2) << "OpenAL: Error loading sample file" << std::endl;
    126133            return false;
    127134        }
  • code/branches/sound/src/sound/SoundBase.h

    r2932 r2950  
    4545    {
    4646    public:
     47        SoundBase();
    4748        SoundBase(WorldEntity* entity);
    48         ~SoundBase();
    4949
    5050        void attachToEntity(WorldEntity* entity);
     
    6565        WorldEntity* entity_;
    6666
    67         static SoundManager* soundmanager_s;
    68 
    6967        ALint getSourceState();
    7068    }; // class SoundBase
  • code/branches/sound/src/sound/SoundManager.cc

    r2932 r2950  
    3838{
    3939    /**
    40      * Static function to get the singleton instance of SoundManager.
    41      *
    42      * @return The singleton instance
    43      */
    44     SoundManager* SoundManager::instance()
    45     {
    46         if(SoundManager::singleton_ == NULL)
    47         {
    48             SoundManager::singleton_ = new SoundManager();
    49         }
    50 
    51         return SoundManager::singleton_;
    52     }
    53 
    54     /**
    5540     * Default constructor
    5641     */
     
    5843    {
    5944        if(!alutInit(NULL,NULL)) {
    60             COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError());
     45            COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    6146        }
     47
     48        COUT(4) << "OpenAL ALUT version:" << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
     49        COUT(4) << "OpenAL ALUT supported MIME types:" << alutGetMIMETypes(ALUT_LOADER_BUFFER) << std::endl;
    6250    }
    6351
     
    9886        // update listener position
    9987        Camera* camera = CameraManager::getInstance().getActiveCamera();
     88        if(camera == NULL) return;
    10089        Vector3 pos = camera->getPosition();
    10190        alListener3f(AL_POSITION, pos.x, pos.y, pos.z);
  • code/branches/sound/src/sound/SoundManager.h

    r2932 r2950  
    4646    {
    4747    public:
    48         static SoundManager* instance();
    49        
     48        SoundManager();
    5049        void addSound(SoundBase* sound);
    5150        void removeSound(SoundBase* sound);
    52        
     51
    5352        virtual void tick(float dt);
    5453
    5554    private:
    56         SoundManager(); // private constructor -> singleton
    57         static SoundManager* singleton_;
    58 
    5955        std::list<SoundBase*> soundlist_;
    6056
Note: See TracChangeset for help on using the changeset viewer.