- Timestamp:
- Dec 17, 2009, 11:10:39 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
r6349 r6370 51 51 ManageScopedSingleton(SoundManager, ScopeID::Graphics, true); 52 52 53 std::string SoundManager::getALErrorString(ALenum code) 54 { 55 switch (code) 56 { 57 case AL_NO_ERROR: return "No error"; 58 case AL_INVALID_NAME: return "Invalid AL parameter name"; 59 case AL_INVALID_ENUM: return "Invalid AL enum"; 60 case AL_INVALID_VALUE: return "Invalid AL value"; 61 case AL_INVALID_OPERATION: return "Invalid AL operation"; 62 case AL_OUT_OF_MEMORY: return "AL reports out of memory"; 63 default: return "Unknown AL error"; 64 } 65 } 66 53 67 SoundManager::SoundManager() 54 68 : effectsPoolSize_(0) … … 114 128 COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl; 115 129 116 this->setVolumeInternal(1.0, SoundType::none); 117 this->setVolumeInternal(1.0, SoundType::ambient); 118 this->setVolumeInternal(1.0, SoundType::effects); 119 120 this->mute_[SoundType::none] = false; 121 this->mute_[SoundType::ambient] = false; 122 this->mute_[SoundType::effects] = false; 130 this->mute_[SoundType::All] = 1.0f; 131 this->mute_[SoundType::Music] = 1.0f; 132 this->mute_[SoundType::Effects] = 1.0f; 123 133 124 134 this->setConfigValues(); … … 186 196 .callback(this, &SoundManager::checkFadeStepValidity); 187 197 188 SetConfigValue (soundVolume_, 1.0f)198 SetConfigValueAlias(volume_[SoundType::All], "soundVolume_", 1.0f) 189 199 .description("Defines the overall volume.") 190 200 .callback(this, &SoundManager::checkSoundVolumeValidity); 191 192 SetConfigValue(ambientVolume_, 1.0f) 201 SetConfigValueAlias(volume_[SoundType::Music], "ambientVolume_", 1.0f) 193 202 .description("Defines the ambient volume.") 194 203 .callback(this, &SoundManager::checkAmbientVolumeValidity); 195 196 SetConfigValue(effectsVolume_, 1.0f) 204 SetConfigValueAlias(volume_[SoundType::Effects], "effectsVolume_", 1.0f) 197 205 .description("Defines the effects volume.") 198 206 .callback(this, &SoundManager::checkEffectsVolumeValidity); … … 202 210 } 203 211 204 std::string SoundManager::getALErrorString(ALenum code)205 {206 switch (code)207 {208 case AL_NO_ERROR: return "No error";209 case AL_INVALID_NAME: return "Invalid AL parameter name";210 case AL_INVALID_ENUM: return "Invalid AL enum";211 case AL_INVALID_VALUE: return "Invalid AL value";212 case AL_INVALID_OPERATION: return "Invalid AL operation";213 case AL_OUT_OF_MEMORY: return "AL reports out of memory";214 default: return "Unknown AL error";215 }216 }217 218 212 void SoundManager::checkFadeStepValidity() 219 213 { 220 214 if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 ) 221 215 { 222 COUT(2) << "Sound warning: Soundstep out of range, ignoring change." << std::endl;216 COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl; 223 217 ResetConfigValue(crossFadeStep_); 224 218 } 225 COUT(3) << "SoundManager: fade step set to " << crossFadeStep_ << std::endl; 226 return; 227 } 228 229 bool SoundManager::checkVolumeValidity(SoundType::Value type) 230 { 231 bool valid = true; 232 233 if(this->getVolumeInternal(type) < 0.0 || this->getVolumeInternal(type) > 1.0) 234 { 235 COUT(2) << "Sound warning: Sound volume out of range, ignoring change." << std::endl; 236 valid = false; 237 } 238 219 } 220 221 void SoundManager::checkVolumeValidity(SoundType::Value type) 222 { 223 float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f); 224 if (clampedVolume != this->volume_[type]) 225 COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl; 239 226 this->updateVolume(type); 240 COUT(4) << "SoundManager: volume set to " << this->getVolumeInternal(type) << std::endl; 241 return valid; 242 } 243 244 void SoundManager::checkSoundVolumeValidity() 245 { 246 if(!checkVolumeValidity(SoundType::none)) 247 { 248 ResetConfigValue(soundVolume_); 249 } 250 } 251 252 void SoundManager::checkAmbientVolumeValidity() 253 { 254 if(!checkVolumeValidity(SoundType::ambient)) 255 { 256 ResetConfigValue(ambientVolume_); 257 } 258 } 259 260 void SoundManager::checkEffectsVolumeValidity() 261 { 262 if(!checkVolumeValidity(SoundType::effects)) 263 { 264 ResetConfigValue(effectsVolume_); 265 } 227 } 228 229 void SoundManager::setVolume(float vol, SoundType::Value type) 230 { 231 if (type < 0 || type > SoundType::Effects) 232 return; 233 this->volume_[type] = vol; 234 this->checkVolumeValidity(type); 235 } 236 237 float SoundManager::getVolume(SoundType::Value type) 238 { 239 if (type < 0 || type > SoundType::Effects) 240 return 0.0f; 241 return this->volume_[type]; 242 } 243 244 float SoundManager::getRealVolume(SoundType::Value type) 245 { 246 if (type != SoundType::Music && type != SoundType::Effects) 247 return 0.0f; 248 return this->volume_[SoundType::All] * this->mute_[SoundType::All] * this->volume_[type] * this->mute_[type]; 249 } 250 251 void SoundManager::updateVolume(SoundType::Value type) 252 { 253 switch(type) 254 { 255 case SoundType::All: 256 for (ObjectList<BaseSound>::iterator it = ObjectList<BaseSound>::begin(); it != ObjectList<BaseSound>::end(); ++it) 257 (*it)->updateVolume(); 258 break; 259 case SoundType::Music: 260 for (ObjectList<AmbientSound>::iterator it = ObjectList<AmbientSound>::begin(); it != ObjectList<AmbientSound>::end(); ++it) 261 (*it)->updateVolume(); 262 break; 263 case SoundType::Effects: 264 for (ObjectList<WorldSound>::iterator it = ObjectList<WorldSound>::begin(); it != ObjectList<WorldSound>::end(); ++it) 265 (*it)->updateVolume(); 266 break; 267 default: 268 assert(false); 269 } 270 } 271 272 void SoundManager::toggleMute(SoundType::Value type) 273 { 274 if (type < 0 || type > SoundType::Effects) 275 return; 276 this->mute_[type] = (this->mute_[type] == 0) ? 1.0f : 0.0f; 277 this->updateVolume(type); 278 } 279 280 bool SoundManager::getMute(SoundType::Value type) 281 { 282 if (type < 0 || type > SoundType::Effects) 283 return true; 284 return (this->mute_[type] == 0); 266 285 } 267 286 … … 358 377 } 359 378 } 360 361 362 void SoundManager::setVolume(float vol, SoundType::Value type)363 {364 vol = this->checkVolumeRange(vol);365 366 this->setVolumeInternal(vol, type);367 368 this->updateVolume(type);369 }370 371 float SoundManager::checkVolumeRange(float vol)372 {373 if(vol < 0.0 || vol > 1.0)374 {375 COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl;376 vol = vol > 1 ? 1 : vol;377 vol = vol < 0 ? 0 : vol;378 }379 380 return vol;381 }382 383 void SoundManager::updateVolume(SoundType::Value type)384 {385 switch(type)386 {387 case SoundType::none:388 for (ObjectList<BaseSound>::iterator it = ObjectList<BaseSound>::begin(); it != ObjectList<BaseSound>::end(); ++it)389 {390 (*it)->updateVolume();391 }392 break;393 case SoundType::ambient:394 for (ObjectList<AmbientSound>::iterator it = ObjectList<AmbientSound>::begin(); it != ObjectList<AmbientSound>::end(); ++it)395 {396 (*it)->updateVolume();397 }398 break;399 case SoundType::effects:400 for (ObjectList<WorldSound>::iterator it = ObjectList<WorldSound>::begin(); it != ObjectList<WorldSound>::end(); ++it)401 {402 (*it)->updateVolume();403 }404 break;405 default:406 COUT(2) << "Invalid SoundType in SoundManager::updateVolume() - Not updating!" << std::endl;407 }408 }409 410 void SoundManager::setVolumeInternal(float vol, SoundType::Value type)411 {412 switch(type)413 {414 case SoundType::none:415 this->soundVolume_ = vol;416 break;417 case SoundType::ambient:418 this->ambientVolume_ = vol;419 break;420 case SoundType::effects:421 this->effectsVolume_ = vol;422 break;423 default:424 COUT(2) << "Invalid SoundType in SoundManager::setVolumeInternal() - Not setting any volume!" << std::endl;425 }426 }427 428 float SoundManager::getVolumeInternal(SoundType::Value type)429 {430 switch(type)431 {432 case SoundType::none:433 return this->soundVolume_;434 case SoundType::ambient:435 return this->ambientVolume_;436 case SoundType::effects:437 return this->effectsVolume_;438 default:439 COUT(2) << "Invalid SoundType in SoundManager::setVolumeInternal() - Returning 0.0!" << std::endl;440 return 0.0;441 }442 }443 444 float SoundManager::getVolume(SoundType::Value type)445 {446 if(this->mute_[SoundType::none] || this->mute_[type])447 return 0.0;448 449 if(type == SoundType::none)450 return this->getVolumeInternal(type);451 452 return this->getVolumeInternal(SoundType::none)*this->getVolumeInternal(type);453 }454 455 void SoundManager::toggleMute(SoundType::Value type)456 {457 bool mute = !this->mute_[type];458 this->mute_[type] = mute;459 460 this->updateVolume(type);461 }462 463 bool SoundManager::getMute(SoundType::Value type)464 {465 return this->mute_[type];466 }467 468 379 469 380 void SoundManager::fadeIn(const SmartPtr<AmbientSound>& sound)
Note: See TracChangeset
for help on using the changeset viewer.