Changeset 6186 for code/branches
- Timestamp:
- Nov 30, 2009, 11:50:17 PM (15 years ago)
- Location:
- code/branches/presentation2
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/data/gui/scripts/NewAudioMenu.lua
r6150 r6186 23 23 24 24 function P.AudioMuteMusicCheckbox_clicked(e) 25 -- mute music 25 soundMgr = orxonox.SoundManager:getInstance() 26 soundMgr:toggleMute(orxonox.SoundType.ambient) 26 27 debug("event: mute music") 27 28 end 28 29 29 30 function P.AudioMuteSoundCheckbox_clicked(e) 30 -- mute sound 31 soundMgr = orxonox.SoundManager:getInstance() 32 soundMgr:toggleMute(orxonox.SoundType.none) 31 33 debug("event: mute sound") 32 34 end -
code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
r6117 r6186 101 101 } 102 102 } 103 104 float AmbientSound::getVolumeGain() 105 { 106 return SoundManager::getInstance().getVolume(SoundType::ambient); 107 } 103 108 104 109 void AmbientSound::doPause() -
code/branches/presentation2/src/orxonox/sound/AmbientSound.h
r6117 r6186 58 58 virtual void stop(); 59 59 virtual void pause(); 60 61 virtual float getVolumeGain(); 60 62 61 63 virtual void setAmbientSource(const std::string& source); -
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
r6184 r6186 38 38 #include "core/Resource.h" 39 39 #include "core/XMLPort.h" 40 #include "SoundManager.h" 40 41 41 42 namespace orxonox … … 54 55 assert(this->audioSource_ != 0); 55 56 } 57 56 58 } 57 59 … … 108 110 } 109 111 this->volume_ = vol; 112 113 this->updateVolume(); 114 } 115 116 float BaseSound::getVolumeGain() 117 { 118 return SoundManager::getInstance().getVolume(SoundType::none); 119 } 120 121 void BaseSound::updateVolume(void) 122 { 110 123 if (alIsSource(this->audioSource_)) 111 alSourcef(this->audioSource_, AL_GAIN, this->getEffectiveVolume()); 112 } 113 114 void BaseSound::setVolumeGain(float gain) 115 { 116 COUT(1) << "blubb: " << gain << std::endl; 117 if (gain > 1 || gain < 0) 118 { 119 COUT(2) << "Sound warning: volume gain out of range, cropping value." << std::endl; 120 gain = gain > 1 ? 1 : gain; 121 gain = gain < 0 ? 0 : gain; 122 } 123 this->volumeGain_ = gain; 124 if (alIsSource(this->audioSource_)) 125 alSourcef(this->audioSource_, AL_GAIN, this->getEffectiveVolume()); 126 } 127 128 float BaseSound::getEffectiveVolume(void) 129 { 130 return this->volume_*this->volumeGain_; 124 alSourcef(this->audioSource_, AL_GAIN, this->volume_*this->getVolumeGain()); 131 125 } 132 126 … … 200 194 201 195 alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0); 202 alSourcef (this->audioSource_, AL_GAIN, this->getEffectiveVolume());196 this->updateVolume(); 203 197 alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE)); 204 198 if (this->isPlaying() || this->isPaused()) -
code/branches/presentation2/src/orxonox/sound/BaseSound.h
r6184 r6186 65 65 float getVolume() const { return this->volume_; } 66 66 67 void setVolumeGain(float gain); 68 inline float getVolumeGain() 69 { return this->volumeGain_; } 70 71 float getEffectiveVolume(void); 67 virtual float getVolumeGain(); 68 void updateVolume(void); 72 69 73 70 bool getLooping() const { return this->bLoop_; } … … 92 89 std::string source_; 93 90 float volume_; 94 float volumeGain_;95 91 bool bLoop_; 96 92 State state_; -
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
r6184 r6186 92 92 desroyContextGuard.Dismiss(); 93 93 94 this->volume_ = 1.0; 95 this->ambientVolume_ = 1.0; 96 this->effectsVolume_ = 1.0; 94 this->setVolumeInternal(1.0, SoundType::none); 95 this->setVolumeInternal(1.0, SoundType::ambient); 96 this->setVolumeInternal(1.0, SoundType::effects); 97 98 this->mute_[SoundType::none] = false; 99 this->mute_[SoundType::ambient] = false; 100 this->mute_[SoundType::effects] = false; 97 101 98 102 this->setConfigValues(); … … 118 122 .callback(this, &SoundManager::checkFadeStepValidity); 119 123 120 SetConfigValue( volume_, 1.0f)124 SetConfigValue(soundVolume_, 1.0f) 121 125 .description("Defines the overall volume.") 122 .callback(this, &SoundManager::check VolumeValidity);126 .callback(this, &SoundManager::checkSoundVolumeValidity); 123 127 124 128 SetConfigValue(ambientVolume_, 1.0f) … … 142 146 } 143 147 144 void SoundManager::checkVolumeValidity() 145 { 146 if(volume_ < 0.0 || volume_ > 1.0) 148 bool SoundManager::checkVolumeValidity(SoundType::Value type) 149 { 150 bool valid = true; 151 152 if(this->getVolumeInternal(type) < 0.0 || this->getVolumeInternal(type) > 1.0) 147 153 { 148 154 COUT(2) << "Sound warning: Sound volume out of range, ignoring change." << std::endl; 149 ResetConfigValue(volume_); 150 } 151 152 this->updateVolume(); 153 COUT(3) << "SoundManager: Overall volume set to " << volume_ << std::endl; 154 return; 155 valid = false; 156 } 157 158 this->updateVolume(type); 159 COUT(3) << "SoundManager: volume set to " << this->getVolumeInternal(type) << std::endl; 160 return valid; 161 } 162 163 void SoundManager::checkSoundVolumeValidity() 164 { 165 if(this->soundVolume_ < 0.0 || this->soundVolume_ > 1.0) 166 { 167 COUT(2) << "Sound warning: Sound volume out of range, ignoring change." << std::endl; 168 ResetConfigValue(soundVolume_); 169 } 170 171 this->updateVolume(SoundType::none); 172 COUT(3) << "SoundManager: volume set to " << this->soundVolume_ << std::endl; 173 155 174 } 156 175 … … 159 178 if(this->ambientVolume_ < 0.0 || this->ambientVolume_ > 1.0) 160 179 { 161 COUT(2) << "Sound warning: Ambientvolume out of range, ignoring change." << std::endl;180 COUT(2) << "Sound warning: Sound volume out of range, ignoring change." << std::endl; 162 181 ResetConfigValue(ambientVolume_); 163 182 } 164 183 165 this->updateAmbientVolume(); 166 COUT(3) << "SoundManager: Ambient volume set to " << this->ambientVolume_ << std::endl; 167 return; 184 this->updateVolume(SoundType::ambient); 185 COUT(3) << "SoundManager: volume set to " << this->ambientVolume_ << std::endl; 168 186 } 169 187 … … 172 190 if(this->effectsVolume_ < 0.0 || this->effectsVolume_ > 1.0) 173 191 { 174 COUT(2) << "Sound warning: effectsvolume out of range, ignoring change." << std::endl;192 COUT(2) << "Sound warning: Sound volume out of range, ignoring change." << std::endl; 175 193 ResetConfigValue(effectsVolume_); 176 194 } 177 195 178 this->updateEffectsVolume(); 179 COUT(3) << "SoundManager: Effects volume set to " << this->effectsVolume_ << std::endl; 180 return; 181 } 196 this->updateVolume(SoundType::effects); 197 COUT(3) << "SoundManager: volume set to " << this->effectsVolume_ << std::endl; 198 } 199 200 // void SoundManager::checkSoundVolumeValidity() 201 // { 202 // if(!checkVolumeValidity(SoundType::none)) 203 // ResetConfigValue(soundVolume_) 204 // } 205 // 206 // void SoundManager::checkAmbientVolumeValidity() 207 // { 208 // if(!checkVolumeValidity(SoundType::ambient)) 209 // ResetConfigValue(ambientVolume_); 210 // } 211 // 212 // void SoundManager::checkEffectsVolumeValidity() 213 // { 214 // if(!checkVolumeValidity(SoundType::effects)) 215 // ResetConfigValue(effectsVolume_); 216 // } 182 217 183 218 void SoundManager::setListenerPosition(const Vector3& position) … … 276 311 } 277 312 278 void SoundManager::setAmbientVolume(float vol) 279 { 280 if (vol > 1 || vol < 0) 313 314 void SoundManager::setVolume(float vol, SoundType::Value type) 315 { 316 vol = this->checkVolumeRange(vol); 317 318 this->setVolumeInternal(vol, type); 319 320 this->updateVolume(type); 321 } 322 323 float SoundManager::checkVolumeRange(float vol) 324 { 325 if(vol < 0.0 || vol > 1.0) 281 326 { 282 327 COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl; … … 284 329 vol = vol < 0 ? 0 : vol; 285 330 } 286 this->ambientVolume_ = vol; 287 288 this->updateAmbientVolume(); 289 } 290 291 void SoundManager::setEffectsVolume(float vol) 292 { 293 if (vol > 1 || vol < 0) 294 { 295 COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl; 296 vol = vol > 1 ? 1 : vol; 297 vol = vol < 0 ? 0 : vol; 298 } 299 this->effectsVolume_ = vol; 300 301 this->updateEffectsVolume(); 302 } 303 304 void SoundManager::setVolume(float vol) 305 { 306 if (vol > 1 || vol < 0) 307 { 308 COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl; 309 vol = vol > 1 ? 1 : vol; 310 vol = vol < 0 ? 0 : vol; 311 } 312 this->volume_ = vol; 313 314 this->updateVolume(); 315 } 316 317 float SoundManager::getAmbientVolume(void) 318 { 319 return this->ambientVolume_; 320 } 321 322 float SoundManager::getEffectsVolume(void) 323 { 324 return this->effectsVolume_; 325 } 326 327 float SoundManager::getVolume(void) 328 { 329 return this->volume_; 330 } 331 332 return vol; 333 } 334 335 void SoundManager::updateVolume(SoundType::Value type) 336 { 337 switch(type) 338 { 339 case SoundType::none: 340 for (ObjectList<BaseSound>::iterator it = ObjectList<BaseSound>::begin(); it != ObjectList<BaseSound>::end(); ++it) 341 { 342 (*it)->updateVolume(); 343 } 344 break; 345 case SoundType::ambient: 346 for (ObjectList<AmbientSound>::iterator it = ObjectList<AmbientSound>::begin(); it != ObjectList<AmbientSound>::end(); ++it) 347 { 348 (*it)->updateVolume(); 349 } 350 break; 351 case SoundType::effects: 352 for (ObjectList<WorldSound>::iterator it = ObjectList<WorldSound>::begin(); it != ObjectList<WorldSound>::end(); ++it) 353 { 354 (*it)->updateVolume(); 355 } 356 break; 357 default: 358 COUT(2) << "Invalid SoundType in SoundManager::updateVolume() - Not updating!" << std::endl; 359 } 360 } 361 362 void SoundManager::setVolumeInternal(float vol, SoundType::Value type) 363 { 364 switch(type) 365 { 366 case SoundType::none: 367 this->soundVolume_ = vol; 368 break; 369 case SoundType::ambient: 370 this->ambientVolume_ = vol; 371 break; 372 case SoundType::effects: 373 this->effectsVolume_ = vol; 374 break; 375 default: 376 COUT(2) << "Invalid SoundType in SoundManager::setVolumeInternal() - Not setting any volume!" << std::endl; 377 } 378 } 379 380 float SoundManager::getVolumeInternal(SoundType::Value type) 381 { 382 switch(type) 383 { 384 case SoundType::none: 385 return this->soundVolume_; 386 case SoundType::ambient: 387 return this->ambientVolume_; 388 case SoundType::effects: 389 return this->effectsVolume_; 390 default: 391 COUT(2) << "Invalid SoundType in SoundManager::setVolumeInternal() - Returning 0.0!" << std::endl; 392 return 0.0; 393 } 394 } 395 396 float SoundManager::getVolume(SoundType::Value type) 397 { 398 if(this->mute_[SoundType::none] || this->mute_[type]) 399 return 0.0; 400 401 if(type == SoundType::none) 402 return this->getVolumeInternal(type); 403 404 return this->getVolumeInternal(SoundType::none)*this->getVolumeInternal(type); 405 } 406 407 void SoundManager::toggleMute(SoundType::Value type) 408 { 409 bool mute = !this->mute_[type]; 410 this->mute_[type] = mute; 411 412 this->updateVolume(type); 413 } 414 415 bool SoundManager::getMute(SoundType::Value type) 416 { 417 return this->mute_[type]; 418 } 419 331 420 332 421 void SoundManager::fadeIn(AmbientSound* sound) … … 416 505 } 417 506 418 void SoundManager::updateAmbientVolume(void)419 {420 for(ObjectList<AmbientSound>::iterator it = ObjectList<AmbientSound>::begin(); it != ObjectList<AmbientSound>::end(); ++it)421 {422 (*it)->setVolumeGain(this->volume_*this->ambientVolume_);423 }424 }425 426 void SoundManager::updateEffectsVolume(void)427 {428 for (ObjectList<WorldSound>::iterator it = ObjectList<WorldSound>::begin(); it != ObjectList<WorldSound>::end(); ++it)429 {430 (*it)->setVolumeGain(this->volume_*this->effectsVolume_);431 }432 }433 434 void SoundManager::updateVolume(void)435 {436 for (ObjectList<BaseSound>::iterator it = ObjectList<BaseSound>::begin(); it != ObjectList<BaseSound>::end(); ++it)437 {438 AmbientSound* ambient = dynamic_cast<AmbientSound*>(*it);439 WorldSound* world = dynamic_cast<WorldSound*>(*it);440 if(ambient != NULL)441 {442 ambient->setVolumeGain(this->volume_*this->ambientVolume_);443 }444 else if(world != NULL)445 {446 world->setVolumeGain(this->volume_*this->effectsVolume_);447 }448 else449 {450 (*it)->setVolumeGain(this->volume_);451 }452 }453 }454 507 } -
code/branches/presentation2/src/orxonox/sound/SoundManager.h
r6184 r6186 34 34 #include <list> 35 35 #include <string> 36 #include <map> 36 37 #include "util/Singleton.h" 37 38 #include "core/OrxonoxClass.h" … … 40 41 namespace orxonox 41 42 { 43 44 //! Enum for the sound type. 45 namespace SoundType 46 { 47 enum Value 48 { 49 none, 50 ambient, 51 effects 52 }; 53 } 54 42 55 /** 43 56 * The SoundManager class manages the OpenAL device, context and listener … … 67 80 void pauseAmbientSound(AmbientSound* ambient); 68 81 69 void setAmbientVolume(float vol); // tolua_export 70 void setEffectsVolume(float vol); // tolua_export 71 void setVolume(float vol); // tolua_export 82 void setVolume(float vol, SoundType::Value type); // tolua_export 83 float getVolume(SoundType::Value type); // tolua_export 72 84 73 float getAmbientVolume(void); // tolua_export 74 float getEffectsVolume(void); // tolua_export 75 float getVolume(void); // tolua_export 85 void toggleMute(SoundType::Value type); // tolua_export 86 bool getMute(SoundType::Value type); // tolua_export 76 87 77 88 private: … … 81 92 82 93 void checkFadeStepValidity(); 83 void checkVolumeValidity(); 84 void checkAmbientVolumeValidity(); 85 void checkEffectsVolumeValidity(); 94 bool checkVolumeValidity(SoundType::Value type); 95 void checkSoundVolumeValidity(void); 96 void checkAmbientVolumeValidity(void); 97 void checkEffectsVolumeValidity(void); 86 98 87 void updateAmbientVolume(void); 88 void updateEffectsVolume(void); 89 void updateVolume(void); 99 float checkVolumeRange(float vol); 100 101 void updateVolume(SoundType::Value type); 102 103 void setVolumeInternal(float vol, SoundType::Value type); 104 float getVolumeInternal(SoundType::Value type); 90 105 91 106 ALCdevice* device_; … … 99 114 std::list<AmbientSound*> fadeOutList_; 100 115 116 float soundVolume_; 101 117 float ambientVolume_; 102 118 float effectsVolume_; 103 float volume_;119 std::map<SoundType::Value, bool> mute_; 104 120 105 121 static SoundManager* singletonPtr_s; -
code/branches/presentation2/src/orxonox/sound/WorldSound.cc
r6117 r6186 35 35 #include "core/EventIncludes.h" 36 36 #include "core/XMLPort.h" 37 #include "SoundManager.h" 37 38 38 39 namespace orxonox … … 95 96 this->stop(); 96 97 } 98 99 float WorldSound::getVolumeGain() 100 { 101 return SoundManager::getInstance().getVolume(SoundType::effects); 102 } 97 103 } -
code/branches/presentation2/src/orxonox/sound/WorldSound.h
r6117 r6186 51 51 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 52 52 virtual void changedActivity(); 53 54 virtual float getVolumeGain(); 53 55 54 56 virtual void tick(float dt);
Note: See TracChangeset
for help on using the changeset viewer.