- Timestamp:
- Nov 30, 2009, 8:50:44 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
r6183 r6184 43 43 #include "BaseSound.h" 44 44 #include "AmbientSound.h" 45 #include "WorldSound.h" 45 46 46 47 namespace orxonox … … 90 91 closeDeviceGuard.Dismiss(); 91 92 desroyContextGuard.Dismiss(); 93 94 this->volume_ = 1.0; 95 this->ambientVolume_ = 1.0; 96 this->effectsVolume_ = 1.0; 92 97 93 98 this->setConfigValues(); … … 112 117 .description("Determines how fast sounds should fade, per second.") 113 118 .callback(this, &SoundManager::checkFadeStepValidity); 119 120 SetConfigValue(volume_, 1.0f) 121 .description("Defines the overall volume.") 122 .callback(this, &SoundManager::checkVolumeValidity); 123 124 SetConfigValue(ambientVolume_, 1.0f) 125 .description("Defines the ambient volume.") 126 .callback(this, &SoundManager::checkAmbientVolumeValidity); 127 128 SetConfigValue(effectsVolume_, 1.0f) 129 .description("Defines the effects volume.") 130 .callback(this, &SoundManager::checkEffectsVolumeValidity); 114 131 } 115 132 … … 122 139 } 123 140 COUT(3) << "SoundManager: fade step set to " << crossFadeStep_ << std::endl; 141 return; 142 } 143 144 void SoundManager::checkVolumeValidity() 145 { 146 if(volume_ < 0.0 || volume_ > 1.0) 147 { 148 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 } 156 157 void SoundManager::checkAmbientVolumeValidity() 158 { 159 if(this->ambientVolume_ < 0.0 || this->ambientVolume_ > 1.0) 160 { 161 COUT(2) << "Sound warning: Ambient volume out of range, ignoring change." << std::endl; 162 ResetConfigValue(ambientVolume_); 163 } 164 165 this->updateAmbientVolume(); 166 COUT(3) << "SoundManager: Ambient volume set to " << this->ambientVolume_ << std::endl; 167 return; 168 } 169 170 void SoundManager::checkEffectsVolumeValidity() 171 { 172 if(this->effectsVolume_ < 0.0 || this->effectsVolume_ > 1.0) 173 { 174 COUT(2) << "Sound warning: effects volume out of range, ignoring change." << std::endl; 175 ResetConfigValue(effectsVolume_); 176 } 177 178 this->updateEffectsVolume(); 179 COUT(3) << "SoundManager: Effects volume set to " << this->effectsVolume_ << std::endl; 124 180 return; 125 181 } … … 218 274 } 219 275 } 276 } 277 278 void SoundManager::setAmbientVolume(float vol) 279 { 280 if (vol > 1 || vol < 0) 281 { 282 COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl; 283 vol = vol > 1 ? 1 : vol; 284 vol = vol < 0 ? 0 : vol; 285 } 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_; 220 330 } 221 331 … … 305 415 } 306 416 } 417 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 else 449 { 450 (*it)->setVolumeGain(this->volume_); 451 } 452 } 453 } 307 454 }
Note: See TracChangeset
for help on using the changeset viewer.