Changeset 6409 for code/branches/presentation2/src
- Timestamp:
- Dec 24, 2009, 8:54:33 AM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox/sound
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
r6394 r6409 147 147 this->availableSoundSources_.push_back(source); 148 148 else 149 ThrowException(InitialisationFailed, "Sound Error: Could not even create a single source"); 150 // Get the rest of the sources 151 alGenSources(1, &source); 152 unsigned int count = 1; 153 while (alIsSource(source) && !alGetError() && count <= this->maxSources_) 154 { 155 this->availableSoundSources_.push_back(source); 156 alGenSources(1, &source); 157 ++count; 158 } 149 ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source"); 150 // Create a few initial sources 151 this->createSoundSources(this->minSources_ - 1); 159 152 160 153 // Disarm guards … … 190 183 if (!alutExit()) 191 184 COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl; 192 }193 194 void SoundManager::preUpdate(const Clock& time)195 {196 this->processCrossFading(time.getDeltaTime());197 198 // Check whether a sound object has stopped playing199 for (unsigned int i = 0; i < this->usedSoundSources_.size(); ++i)200 {201 ALint state;202 alGetSourcei(this->usedSoundSources_[i].first, AL_SOURCE_STATE, &state);203 if (state == AL_STOPPED)204 {205 this->usedSoundSources_[i].second->stop();206 --i;207 }208 }209 185 } 210 186 … … 225 201 .callback(this, &SoundManager::checkEffectsVolumeValidity); 226 202 203 SetConfigValue(minSources_, 16) 204 .description("Minimum number of sources being generated (if possible)"); 227 205 SetConfigValue(maxSources_, 1024) 228 206 .description("Maximum number of sources to be made available"); 207 } 208 209 void SoundManager::preUpdate(const Clock& time) 210 { 211 this->processCrossFading(time.getDeltaTime()); 212 213 // Check whether a sound object has stopped playing 214 for (unsigned int i = 0; i < this->usedSoundSources_.size(); ++i) 215 { 216 ALint state; 217 alGetSourcei(this->usedSoundSources_[i].first, AL_SOURCE_STATE, &state); 218 if (state == AL_STOPPED) 219 { 220 this->usedSoundSources_[i].second->stop(); 221 --i; 222 } 223 } 229 224 } 230 225 … … 559 554 else 560 555 { 556 if (this->usedSoundSources_.size() < this->maxSources_) 557 { 558 ALuint source; 559 alGenSources(1, &source); 560 // Try to create new sources (50% more, but at least one) 561 if (alIsSource(source) && !alGetError()) 562 { 563 this->usedSoundSources_.push_back(std::make_pair(source, object)); 564 return source; 565 } 566 } 561 567 // Return no source ID 562 568 ALuint source = 123456789; … … 582 588 } 583 589 } 590 int used = std::max(this->usedSoundSources_.size(), this->minSources_); 591 // Subtract those we added in the statement above trough std::max 592 int available = (int)this->availableSoundSources_.size() - (used - (int)this->usedSoundSources_.size()); 593 // Delete sources again to free resources if appropriate (more than 50% more available than used) 594 int toDelete = available - used / 2; 595 while (toDelete-- > 0) 596 { 597 alDeleteSources(1, &this->availableSoundSources_.back()); 598 if (alGetError()) 599 COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl; 600 this->availableSoundSources_.pop_back(); 601 } 602 } 603 604 unsigned int SoundManager::createSoundSources(unsigned int n) 605 { 606 unsigned int count = this->availableSoundSources_.size() + this->usedSoundSources_.size(); 607 while (count < this->maxSources_ && count <= n) 608 { 609 ALuint source; 610 alGenSources(1, &source); 611 if (alIsSource(source) && !alGetError()) 612 this->availableSoundSources_.push_back(source); 613 else 614 break; 615 ++count; 616 } 617 return count - this->availableSoundSources_.size() - this->usedSoundSources_.size(); 584 618 } 585 619 } -
code/branches/presentation2/src/orxonox/sound/SoundManager.h
r6391 r6409 114 114 void updateVolume(SoundType::Value type); 115 115 116 unsigned int createSoundSources(unsigned int n); 117 116 118 // OpenAL device/context related 117 119 std::vector<std::string> deviceNames_; … … 140 142 141 143 // Sound source related 144 unsigned int minSources_; 142 145 unsigned int maxSources_; 143 146 std::vector<ALuint> availableSoundSources_;
Note: See TracChangeset
for help on using the changeset viewer.