Changeset 6184
- Timestamp:
- Nov 30, 2009, 8:50:44 PM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/CMakeLists.txt
r6117 r6184 59 59 pickup/BaseItem.h 60 60 pickup/PickupInventory.h 61 sound/SoundManager.h 61 62 DEFINE_SYMBOL 62 63 "ORXONOX_SHARED_BUILD" -
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
r6127 r6184 109 109 this->volume_ = vol; 110 110 if (alIsSource(this->audioSource_)) 111 alSourcef(this->audioSource_, AL_GAIN, vol); 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_; 112 131 } 113 132 … … 181 200 182 201 alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0); 183 alSourcef (this->audioSource_, AL_GAIN, this-> volume_);202 alSourcef (this->audioSource_, AL_GAIN, this->getEffectiveVolume()); 184 203 alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE)); 185 204 if (this->isPlaying() || this->isPaused()) -
code/branches/presentation2/src/orxonox/sound/BaseSound.h
r6117 r6184 64 64 void setVolume(float vol); 65 65 float getVolume() const { return this->volume_; } 66 67 void setVolumeGain(float gain); 68 inline float getVolumeGain() 69 { return this->volumeGain_; } 70 71 float getEffectiveVolume(void); 66 72 67 73 bool getLooping() const { return this->bLoop_; } … … 86 92 std::string source_; 87 93 float volume_; 94 float volumeGain_; 88 95 bool bLoop_; 89 96 State state_; -
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 } -
code/branches/presentation2/src/orxonox/sound/SoundManager.h
r6183 r6184 35 35 #include <string> 36 36 #include "util/Singleton.h" 37 #include "core/OrxonoxClass.h" 37 38 39 // tolua_begin 38 40 namespace orxonox 39 41 { … … 43 45 * 44 46 */ 45 class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public OrxonoxClass 46 { 47 class _OrxonoxExport SoundManager 48 // tolua_end 49 : public Singleton<SoundManager>, public OrxonoxClass 50 { // tolua_export 47 51 friend class Singleton<SoundManager>; 48 52 … … 53 57 void preUpdate(const Clock& time); 54 58 void setConfigValues(); 59 60 static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); } // tolua_export 55 61 56 62 void setListenerPosition(const Vector3& position); … … 60 66 void unregisterAmbientSound(AmbientSound* oldAmbient); 61 67 void pauseAmbientSound(AmbientSound* ambient); 68 69 void setAmbientVolume(float vol); // tolua_export 70 void setEffectsVolume(float vol); // tolua_export 71 void setVolume(float vol); // tolua_export 72 73 float getAmbientVolume(void); // tolua_export 74 float getEffectsVolume(void); // tolua_export 75 float getVolume(void); // tolua_export 62 76 63 77 private: … … 67 81 68 82 void checkFadeStepValidity(); 83 void checkVolumeValidity(); 84 void checkAmbientVolumeValidity(); 85 void checkEffectsVolumeValidity(); 86 87 void updateAmbientVolume(void); 88 void updateEffectsVolume(void); 89 void updateVolume(void); 69 90 70 91 ALCdevice* device_; … … 78 99 std::list<AmbientSound*> fadeOutList_; 79 100 101 float ambientVolume_; 102 float effectsVolume_; 103 float volume_; 104 80 105 static SoundManager* singletonPtr_s; 81 }; 82 } 106 }; // tolua_export 107 } // tolua_export 83 108 84 109 #endif /* _SoundManager_H__ */
Note: See TracChangeset
for help on using the changeset viewer.