- Timestamp:
- May 4, 2009, 3:40:08 PM (16 years ago)
- Location:
- code/branches/sound
- Files:
-
- 1 added
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sound/cmake/LibraryConfig.cmake
r2711 r2950 111 111 FIND_PACKAGE(OGRE 1.4 EXACT REQUIRED) 112 112 FIND_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) 115 115 FIND_PACKAGE(ALUT REQUIRED) 116 116 FIND_PACKAGE(ZLIB REQUIRED) -
code/branches/sound/src/orxonox/CMakeLists.txt
r2748 r2950 58 58 core 59 59 network 60 #audio60 sound 61 61 ) 62 62 -
code/branches/sound/src/orxonox/objects/Level.cc
r2826 r2950 77 77 XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode); 78 78 XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype"); 79 80 XMLPortParamLoadOnly(Level, "ambientsound", loadAmbientSound, xmlelement, mode); 79 81 80 82 XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false); … … 148 150 } 149 151 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 150 168 void Level::playerEntered(PlayerInfo* player) 151 169 { -
code/branches/sound/src/orxonox/objects/Level.h
r2826 r2950 33 33 34 34 #include "network/synchronisable/Synchronisable.h" 35 #include "sound/SoundBase.h" 36 #include "sound/SoundManager.h" 35 37 #include "core/BaseObject.h" 36 38 … … 50 52 inline const std::string& getDescription() const 51 53 { return this->description_; } 54 55 void loadAmbientSound(const std::string& filename); 52 56 53 57 void playerEntered(PlayerInfo* player); … … 69 73 XMLFile* xmlfile_; 70 74 std::list<BaseObject*> objects_; 75 SoundManager sndmgr_; 76 SoundBase* ambientsound_; 71 77 }; 72 78 } -
code/branches/sound/src/sound/SoundBase.cc
r2932 r2950 34 34 namespace orxonox 35 35 { 36 SoundBase::SoundBase() 37 { 38 this->source_ = 0; 39 this->buffer_ = 0; 40 this->entity_ = NULL; 41 } 36 42 SoundBase::SoundBase(WorldEntity* entity) 37 43 { … … 39 45 this->buffer_ = 0; 40 46 this->entity_ = entity; 41 42 if(SoundBase::soundmanager_s == NULL)43 SoundBase::soundmanager_s = SoundManager::instance();44 47 } 45 48 … … 51 54 52 55 void SoundBase::update() { 53 if( alIsSource(this->source_)) {56 if(this->entity_ != NULL && alIsSource(this->source_)) { 54 57 Vector3 pos = this->entity_->getPosition(); 55 58 alSource3f(this->source_, AL_POSITION, pos.x, pos.y, pos.z); … … 99 102 return getSourceState() == AL_PLAYING; 100 103 } 104 return false; 101 105 } 102 106 … … 105 109 return getSourceState() == AL_PAUSED; 106 110 } 111 return true; 107 112 } 108 113 … … 111 116 return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED; 112 117 } 118 return true; 113 119 } 114 120 115 121 bool SoundBase::loadFile(std::string filename) { 122 COUT(3) << "OpenAL ALUT: loading file " << filename << std::endl; 116 123 this->buffer_ = alutCreateBufferFromFile(filename.c_str()); 117 124 if(this->buffer_ == AL_NONE) { 118 COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) ;125 COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl; 119 126 return false; 120 127 } … … 123 130 alSourcei(this->source_, AL_BUFFER, this->buffer_); 124 131 if(alGetError() != AL_NO_ERROR) { 125 COUT(2) << "OpenAL: Error loading sample file" ;132 COUT(2) << "OpenAL: Error loading sample file" << std::endl; 126 133 return false; 127 134 } -
code/branches/sound/src/sound/SoundBase.h
r2932 r2950 45 45 { 46 46 public: 47 SoundBase(); 47 48 SoundBase(WorldEntity* entity); 48 ~SoundBase();49 49 50 50 void attachToEntity(WorldEntity* entity); … … 65 65 WorldEntity* entity_; 66 66 67 static SoundManager* soundmanager_s;68 69 67 ALint getSourceState(); 70 68 }; // class SoundBase -
code/branches/sound/src/sound/SoundManager.cc
r2932 r2950 38 38 { 39 39 /** 40 * Static function to get the singleton instance of SoundManager.41 *42 * @return The singleton instance43 */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 /**55 40 * Default constructor 56 41 */ … … 58 43 { 59 44 if(!alutInit(NULL,NULL)) { 60 COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) ;45 COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl; 61 46 } 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; 62 50 } 63 51 … … 98 86 // update listener position 99 87 Camera* camera = CameraManager::getInstance().getActiveCamera(); 88 if(camera == NULL) return; 100 89 Vector3 pos = camera->getPosition(); 101 90 alListener3f(AL_POSITION, pos.x, pos.y, pos.z); -
code/branches/sound/src/sound/SoundManager.h
r2932 r2950 46 46 { 47 47 public: 48 static SoundManager* instance(); 49 48 SoundManager(); 50 49 void addSound(SoundBase* sound); 51 50 void removeSound(SoundBase* sound); 52 51 53 52 virtual void tick(float dt); 54 53 55 54 private: 56 SoundManager(); // private constructor -> singleton57 static SoundManager* singleton_;58 59 55 std::list<SoundBase*> soundlist_; 60 56
Note: See TracChangeset
for help on using the changeset viewer.