Changeset 6046 for code/branches
- Timestamp:
- Nov 11, 2009, 5:55:26 PM (15 years ago)
- Location:
- code/branches/sound3/src/orxonox/sound
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sound3/src/orxonox/sound/AmbientSound.cc
r6031 r6046 65 65 { 66 66 COUT(3) << this->getSource() << ": Playing" << std::endl; 67 SoundManager::getInstance().registerAmbientSound(this); 68 SUPER(AmbientSound, play); 67 if(GameMode::playsSound()) 68 { 69 SoundManager::getInstance().registerAmbientSound(this); 70 this->BaseSound::play(); 71 } 69 72 } 70 73 71 74 void AmbientSound::replay() 72 75 { 73 SUPER(AmbientSound, play);76 this->BaseSound::play(); 74 77 } 75 78 76 79 void AmbientSound::stop() 77 80 { 78 SUPER(AmbientSound, stop); 79 SoundManager::getInstance().unregisterAmbientSound(this); 81 if(GameMode::playsSound()) 82 { 83 SoundManager::getInstance().unregisterAmbientSound(this); 84 } 80 85 } 81 86 82 void AmbientSound:: pause()87 void AmbientSound::doStop() 83 88 { 84 SUPER(AmbientSound, pause);89 this->BaseSound::stop(); 85 90 } 86 91 87 92 void AmbientSound::setSource(const std::string& source) 88 93 { 89 if(source.find('/') == std::string.npos )94 if(source.find('/') == std::string.npos && GameMode::playsSound()) 90 95 { 91 96 std::string filePath = SoundManager::getInstance().getAmbientPath(source); 92 97 if(!(filePath.empty())) 93 98 { 94 BaseSound::setSource(filePath);99 this->BaseSound::setSource(filePath); 95 100 return; 96 101 } … … 102 107 { 103 108 COUT(3) << this->getSource() << ": ChangedActivity: " << this->isActive() << std::endl; 104 SUPER(AmbientSound, changedActivity);109 this->BaseObject::changedActivity(); 105 110 if(this->isActive()) 106 111 { … … 112 117 } 113 118 } 114 115 119 } -
code/branches/sound3/src/orxonox/sound/AmbientSound.h
r6031 r6046 48 48 49 49 virtual void play(); 50 v irtual void replay(); // is only needed for the AmbientSound list in SoundManager50 void replay(); // Continue playing without re-registering the sound 51 51 virtual void stop(); 52 v irtual void pause();52 void doStop(); 53 53 54 54 virtual void setSource(const std::string& source); -
code/branches/sound3/src/orxonox/sound/BaseSound.cc
r5982 r6046 70 70 } 71 71 72 void BaseSound::replay()73 {74 BaseSound::play();75 }76 77 72 void BaseSound::stop() 78 73 { … … 185 180 if (this->bPlayOnLoad_) 186 181 this->play(); 182 } 183 184 ALuint BaseSound::getALAudioSource() 185 { 186 return audioSource_; 187 187 } 188 188 -
code/branches/sound3/src/orxonox/sound/BaseSound.h
r6031 r6046 50 50 51 51 virtual void play(); 52 virtual void replay(); // is only needed for the AmbientSound list in SoundManager53 52 virtual void stop(); 54 v irtual void pause();53 void pause(); 55 54 56 55 bool isPlaying(); … … 66 65 bool getLoop() { return this->bLoop_; } 67 66 void setLoop(bool val) { this->bLoop_ = val; } 67 68 ALuint getALAudioSource(void); 68 69 69 70 protected: -
code/branches/sound3/src/orxonox/sound/SoundManager.cc
r6031 r6046 35 35 #include "util/ScopeGuard.h" 36 36 #include "util/StringUtils.h" 37 #include "util/Clock.h" 37 38 #include "core/GameMode.h" 38 39 #include "core/ScopedSingletonManager.h" 39 40 #include "core/Resource.h" 41 #include "core/ConfigValueIncludes.h" 40 42 #include "BaseSound.h" 41 43 #include "MoodManager.h" 44 #include "AmbientSound.h" 42 45 43 46 namespace orxonox … … 48 51 SoundManager::SoundManager() 49 52 { 53 RegisterRootObject(SoundManager); 54 50 55 if (!alutInitWithoutContext(NULL,NULL)) 51 56 ThrowException(InitialisationFailed, "Sound: OpenAL ALUT error: " << alutGetErrorString(alutGetError())); … … 86 91 closeDeviceGuard.Dismiss(); 87 92 desroyContextGuard.Dismiss(); 93 94 this->setConfigValues(); 88 95 } 89 96 … … 96 103 } 97 104 105 void SoundManager::update(const Clock &time) 106 { 107 this->fadeInAmbientSound(time.getDeltaTime()); 108 this->fadeOutAmbientSound(time.getDeltaTime()); 109 } 110 111 void SoundManager::setConfigValues() 112 { 113 SetConfigValue(fadeStep_, 0.2f) 114 .description("Determines how fast sounds should fade, per second.") 115 .callback(this, &SoundManager::checkFadeStepValidity); 116 } 117 98 118 void SoundManager::setListenerPosition(const Vector3& position) 99 119 { … … 119 139 } 120 140 121 void SoundManager::registerAmbientSound(BaseSound* newAmbient) 122 { 123 if (!(this->ambientSounds_.empty())) 124 { 125 this->ambientSounds_.front()->pause(); 126 } 127 this->ambientSounds_.push_front(newAmbient); 128 } 129 130 void SoundManager::unregisterAmbientSound(BaseSound* currentAmbient) 141 void SoundManager::registerAmbientSound(AmbientSound* newAmbient) 142 { 143 if(newAmbient != NULL) 144 { 145 if (!(this->ambientSounds_.empty())) 146 { 147 this->fadeOutList_.push_front(std::make_pair(this->ambientSounds_.front(), 1.0)); 148 } 149 this->fadeInList_.push_front(std::make_pair(newAmbient, 0.0)); 150 this->ambientSounds_.push_front(newAmbient); 151 } 152 } 153 154 void SoundManager::unregisterAmbientSound(AmbientSound* currentAmbient) 131 155 { 132 156 if(currentAmbient == NULL || ambientSounds_.empty()) … … 136 160 if(this->ambientSounds_.front() == currentAmbient) 137 161 { 162 this->fadeOutList_.push_front(std::make_pair(this->ambientSounds_.front(), 1.0)); 138 163 this->ambientSounds_.pop_front(); 139 164 if(!(this->ambientSounds_.empty())) 140 165 { 141 this-> ambientSounds_.front()->replay();166 this->fadeInList_.push_front(std::make_pair(this->ambientSounds_.front(), 0.0)); 142 167 } 143 168 } 144 169 else 145 170 { 146 for(std::list< BaseSound*>::iterator it= this->ambientSounds_.begin(); it != this->ambientSounds_.end(); it++)171 for(std::list<AmbientSound*>::iterator it= this->ambientSounds_.begin(); it != this->ambientSounds_.end(); it++) 147 172 { 148 173 if(*it == currentAmbient) 149 174 { 175 currentAmbient->doStop(); 150 176 this->ambientSounds_.erase(it); 151 177 break; … … 158 184 const std::string& SoundManager::getAmbientPath(const std::string& source) 159 185 { 160 lastReqPath = "ambient/" + MoodManager::getInstance().getMood() + "/" + source;161 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(lastReqPath );186 lastReqPath_ = "ambient/" + MoodManager::getInstance().getMood() + "/" + source; 187 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(lastReqPath_); 162 188 if(fileInfo == NULL) 163 189 { 164 190 return BLANKSTRING; 165 191 } 166 return lastReqPath; 192 return lastReqPath_; 193 } 194 195 void SoundManager::fadeInAmbientSound(float dt) 196 { 197 if(!(this->fadeInList_.empty())) 198 { 199 for(std::list<std::pair<AmbientSound*, float> >::iterator it= this->fadeInList_.begin(); it != this->fadeInList_.end(); it++) 200 { 201 it->second += fadeStep_ * dt; 202 alSourcef(it->first->getALAudioSource(), AL_GAIN, it->second); 203 } 204 if(this->fadeInList_.back().second >= 1) 205 { 206 this->fadeInList_.pop_back(); 207 } 208 } 209 } 210 211 void SoundManager::fadeOutAmbientSound(float dt) 212 { 213 if(!(this->fadeInList_.empty())) 214 { 215 for(std::list<std::pair<AmbientSound*, float> >::iterator it= this->fadeOutList_.begin(); it != this->fadeOutList_.end(); it++) 216 { 217 it->second -= fadeStep_ * dt; 218 alSourcef(it->first->getALAudioSource(), AL_GAIN, it->second); 219 } 220 if(this->fadeOutList_.back().second <= 0) 221 { 222 bool pauseTest = false; 223 224 for(std::list<AmbientSound*>::iterator it= this->ambientSounds_.begin(); it != this->ambientSounds_.end(); it++) 225 { 226 if(*it == this->fadeOutList_.back().first) 227 { 228 pauseTest = true; 229 break; 230 } 231 } 232 if(pauseTest) 233 { 234 this->fadeOutList_.back().first->pause(); 235 } 236 else 237 { 238 this->fadeOutList_.back().first->doStop(); 239 } 240 this->fadeOutList_.pop_back(); 241 } 242 } 243 } 244 245 void SoundManager::checkFadeStepValidity() 246 { 247 if(fadeStep_ <= 0.0 || fadeStep_ >= 1.0 ) 248 { 249 ResetConfigValue(fadeStep_); 250 } 251 COUT(0) << "SoundManager: fade step now set to " << fadeStep_ << std::endl; 252 return; 167 253 } 168 254 } -
code/branches/sound3/src/orxonox/sound/SoundManager.h
r6031 r6046 42 42 * 43 43 */ 44 class _OrxonoxExport SoundManager : public Singleton<SoundManager> 44 class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public OrxonoxClass 45 45 { 46 46 friend class Singleton<SoundManager>; … … 49 49 ~SoundManager(); 50 50 51 void update(const Clock &time); 52 void setConfigValues(void); 53 51 54 void setListenerPosition(const Vector3& position); 52 55 void setListenerOrientation(const Quaternion& orientation); 53 void registerAmbientSound(BaseSound* newAmbient); 54 void unregisterAmbientSound(BaseSound* currentAmbient); 56 57 void registerAmbientSound(AmbientSound* newAmbient); 58 void unregisterAmbientSound(AmbientSound* currentAmbient); 55 59 const std::string& getAmbientPath(const std::string& source); 60 void fadeInAmbientSound(float dt); 61 void fadeOutAmbientSound(float dt); 62 void checkFadeStepValidity(void); 56 63 57 64 private: 58 65 ALCdevice* device_; 59 66 ALCcontext* context_; 60 std::list<BaseSound*> ambientSounds_; 61 std::string lastReqPath; 67 68 std::list<AmbientSound*> ambientSounds_; 69 70 float fadeStep_; //per second 71 std::list<std::pair<AmbientSound*, float> > fadeInList_; 72 std::list<std::pair<AmbientSound*, float> > fadeOutList_; 73 74 std::string lastReqPath_; 62 75 63 76 static SoundManager* singletonPtr_s;
Note: See TracChangeset
for help on using the changeset viewer.