Changeset 6506
- Timestamp:
- Mar 11, 2010, 3:16:12 PM (15 years ago)
- Location:
- code/branches/sound5
- Files:
-
- 11 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sound5
- Property svn:mergeinfo changed
/code/branches/sound4 (added) merged: 6435,6476,6504
- Property svn:mergeinfo changed
-
code/branches/sound5/src/orxonox/sound/AmbientSound.cc
r6417 r6506 35 35 #include "core/XMLPort.h" 36 36 #include "SoundManager.h" 37 #include "SoundStreamer.h" 37 38 38 39 namespace orxonox … … 120 121 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path); 121 122 if (fileInfo != NULL) 122 this->setS ource(path);123 this->setStreamSource(path); 123 124 else 124 125 COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl; … … 141 142 this->stop(); 142 143 } 144 145 // hacky solution for file streaming 146 void AmbientSound::setStreamSource(const std::string& source) 147 { 148 this->audioSource_ = SoundManager::getInstance().getSoundSource(this); 149 if (this->source_ == source) 150 { 151 return; 152 } 153 154 this->source_ = source; 155 // Don't load "" 156 if (source_.empty()) 157 return; 158 159 if (this->soundstreamthread_.get_id() != boost::thread::id()) 160 { 161 this->soundstreamthread_.interrupt(); // unhandled interruptions lead to thread terminating ;-) 162 } 163 // Get resource info 164 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source); 165 if (fileInfo == NULL) 166 { 167 COUT(2) << "Sound: Warning: Sound file '" << source << "' not found" << std::endl; 168 return; 169 } 170 // Open data stream 171 DataStreamPtr dataStream = Resource::open(fileInfo); 172 173 this->soundstreamthread_ = boost::thread(SoundStreamer(), this->audioSource_, dataStream); 174 this->initialiseSource(); 175 } 176 177 void AmbientSound::doStop() 178 { 179 SUPER(AmbientSound, doStop); 180 this->soundstreamthread_.interrupt(); 181 } 143 182 } -
code/branches/sound5/src/orxonox/sound/AmbientSound.h
r6417 r6506 31 31 #define _AmbientSound_H__ 32 32 33 #include "OrxonoxPrereqs.h" 33 #include <boost/thread.hpp> 34 35 #include "sound/SoundPrereqs.h" 34 36 35 37 #include "core/BaseObject.h" … … 71 73 ~AmbientSound() { } 72 74 75 void doPlay(); 76 void doStop(); 77 73 78 private: 74 79 void preDestroy(); … … 83 88 std::string ambientSource_; //!< Analogous to source_, but mood independent 84 89 bool bPlayOnLoad_; //!< Play the sound immediately when loaded 90 91 boost::thread soundstreamthread_; // hacky solution for streaming 92 void setStreamSource(const std::string& source); 85 93 }; 86 94 } -
code/branches/sound5/src/orxonox/sound/BaseSound.cc
r6502 r6506 91 91 alSourcePlay(this->audioSource_); 92 92 if (int error = alGetError()) 93 COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;93 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl; 94 94 } 95 95 } … … 141 141 alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0); 142 142 if (ALint error = alGetError()) 143 COUT(2) << "Sound Warning: Setting source parameters to 0 failed: " 144 << SoundManager::getALErrorString(error) << std::endl; 143 COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl; 145 144 assert(this->soundBuffer_ != NULL); 146 145 alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer()); 147 146 if (ALuint error = alGetError()) 148 COUT(1) << "Sound Error: Could not set buffer \"" << this->source_ << "\": " << SoundManager::getALErrorString(error) << std::endl;147 COUT(1) << "Sound: Error: Could not set buffer \"" << this->source_ << "\": " << getALErrorString(error) << std::endl; 149 148 } 150 149 … … 153 152 this->volume_ = clamp(vol, 0.0f, 1.0f); 154 153 if (this->volume_ != vol) 155 COUT(2) << "Sound warning: volume out of range, clamping value." << std::endl;154 COUT(2) << "Sound: Warning: volume out of range, clamping value." << std::endl; 156 155 this->updateVolume(); 157 156 } … … 164 163 alSourcef(this->audioSource_, AL_GAIN, volume); 165 164 if (int error = alGetError()) 166 COUT(2) << "Sound: Error setting volume to " << volume 167 << ": " << SoundManager::getALErrorString(error) << std::endl; 165 COUT(2) << "Sound: Error setting volume to " << volume << ": " << getALErrorString(error) << std::endl; 168 166 } 169 167 } … … 180 178 if (pitch > 2 || pitch < 0.5f) 181 179 { 182 COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;180 COUT(2) << "Sound: Warning: pitch out of range, cropping value." << std::endl; 183 181 pitch = pitch > 2.0f ? 2.0f : pitch; 184 182 pitch = pitch < 0.5f ? 0.5f : pitch; … … 189 187 alSourcef(this->audioSource_, AL_PITCH, pitch); 190 188 if (int error = alGetError()) 191 COUT(2) << "Sound: Error setting pitch: " << SoundManager::getALErrorString(error) << std::endl;189 COUT(2) << "Sound: Error setting pitch: " << getALErrorString(error) << std::endl; 192 190 } 193 191 } … … 234 232 if (ALuint error = alGetError()) 235 233 { 236 COUT(1) << "Sound Error: Could not set buffer \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;234 COUT(1) << "Sound: Error: Could not set buffer \"" << source << "\": " << getALErrorString(error) << std::endl; 237 235 return; 238 236 } … … 242 240 alSourcePlay(this->audioSource_); 243 241 if (int error = alGetError()) 244 COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;242 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl; 245 243 if (this->isPaused()) 246 244 alSourcePause(this->audioSource_); -
code/branches/sound5/src/orxonox/sound/BaseSound.h
r6417 r6506 30 30 #define _BaseSound_H__ 31 31 32 #include " OrxonoxPrereqs.h"32 #include "sound/SoundPrereqs.h" 33 33 34 34 #include <string> -
code/branches/sound5/src/orxonox/sound/SoundBuffer.h
r6417 r6506 30 30 #define _SoundBuffer_H__ 31 31 32 #include " OrxonoxPrereqs.h"32 #include "sound/SoundPrereqs.h" 33 33 34 34 #include <list> -
code/branches/sound5/src/orxonox/sound/SoundManager.cc
r6417 r6506 43 43 #include "core/ScopedSingletonManager.h" 44 44 #include "core/Resource.h" 45 #include "SoundBuffer.h" 45 #include "SoundBuffer.h": 46 46 #include "BaseSound.h" 47 47 #include "AmbientSound.h" … … 52 52 ManageScopedSingleton(SoundManager, ScopeID::Graphics, true); 53 53 54 std::string SoundManager::getALErrorString(ALenum code) 54 // From SoundPrereqs.h 55 std::string getALErrorString(ALenum code) 55 56 { 56 57 switch (code) … … 78 79 79 80 if (!alutInitWithoutContext(NULL, NULL)) 80 ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));81 ThrowException(InitialisationFailed, "Sound: Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError())); 81 82 Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit); 82 83 … … 110 111 COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl; 111 112 #endif 112 ThrowException(InitialisationFailed, "Sound Error: Could not open sound device.");113 ThrowException(InitialisationFailed, "Sound: Error: Could not open sound device."); 113 114 } 114 115 Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_); … … 117 118 this->context_ = alcCreateContext(this->device_, NULL); 118 119 if (this->context_ == NULL) 119 ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context");120 ThrowException(InitialisationFailed, "Sound: Error: Could not create ALC context"); 120 121 Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_); 121 122 if (!alcMakeContextCurrent(this->context_)) 122 ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context");123 ThrowException(InitialisationFailed, "Sound: Error: Could not use ALC context"); 123 124 124 125 GameMode::setPlaysSound(true); … … 133 134 COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl; 134 135 else 135 COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;136 COUT(2) << "Sound: Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl; 136 137 137 138 this->mute_[SoundType::All] = 1.0f; … … 147 148 this->availableSoundSources_.push_back(source); 148 149 else 149 ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source");150 ThrowException(InitialisationFailed, "Sound: Error: Could not create even a single source"); 150 151 // Create a few initial sources 151 152 this->createSoundSources(this->minSources_ - 1); … … 168 169 // If there are still used buffers around, well, that's just very bad... 169 170 if (this->soundBuffers_.size() != this->effectsPool_.size()) 170 COUT(1) << "Sound Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;171 COUT(1) << "Sound: Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl; 171 172 // Empty buffer pool and buffer list 172 173 this->effectsPool_.clear(); … … 175 176 // There should not be any sources in use anymore 176 177 if (!this->usedSoundSources_.empty()) 177 COUT(1) << "Sound Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;178 COUT(1) << "Sound: Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl; 178 179 while (!this->availableSoundSources_.empty()) 179 180 { … … 186 187 // Relieve context to destroy it 187 188 if (!alcMakeContextCurrent(NULL)) 188 COUT(1) << "Sound Error: Could not unset ALC context" << std::endl;189 COUT(1) << "Sound: Error: Could not unset ALC context" << std::endl; 189 190 alcDestroyContext(this->context_); 190 191 if (ALCenum error = alcGetError(this->device_)) 191 192 { 192 193 if (error == AL_INVALID_OPERATION) 193 COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl;194 COUT(1) << "Sound: Error: Could not destroy ALC context because it is the current one" << std::endl; 194 195 else 195 COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl;196 COUT(1) << "Sound: Error: Could not destroy ALC context because it is invalid" << std::endl; 196 197 } 197 198 #ifdef AL_VERSION_1_1 198 199 if (!alcCloseDevice(this->device_)) 199 COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;200 COUT(1) << "Sound: Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl; 200 201 #else 201 202 alcCloseDevice(this->device_); 202 203 #endif 203 204 if (!alutExit()) 204 COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;205 COUT(1) << "Sound: Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl; 205 206 } 206 207 … … 248 249 if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 ) 249 250 { 250 COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl;251 COUT(2) << "Sound: Warning: fade step out of range, ignoring change." << std::endl; 251 252 ResetConfigValue(crossFadeStep_); 252 253 } … … 257 258 float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f); 258 259 if (clampedVolume != this->volume_[type]) 259 COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl;260 COUT(2) << "Sound: Warning: Volume setting (" << type << ") out of range, clamping." << std::endl; 260 261 this->updateVolume(type); 261 262 } … … 349 350 if (it->first == newAmbient) 350 351 { 351 COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl;352 COUT(2) << "Sound: Warning: Will not play an AmbientSound twice." << std::endl; 352 353 return; 353 354 } … … 617 618 alDeleteSources(1, &this->availableSoundSources_.back()); 618 619 if (alGetError()) 619 COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl;620 COUT(1) << "Sound: Error: Failed to delete a source --> lost forever" << std::endl; 620 621 this->availableSoundSources_.pop_back(); 621 622 } -
code/branches/sound5/src/orxonox/sound/SoundManager.h
r6417 r6506 31 31 #define _SoundManager_H__ 32 32 33 #include " OrxonoxPrereqs.h"33 #include "sound/SoundPrereqs.h" 34 34 35 35 #include <list> … … 99 99 void releaseSoundSource(ALuint source); 100 100 101 static std::string getALErrorString(ALenum error);102 103 101 private: 104 102 void processCrossFading(float dt); -
code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
r6417 r6506 30 30 #include <vorbis/vorbisfile.h> 31 31 #include "SoundManager.h" 32 #include "util/Sleep.h" 32 33 33 34 namespace orxonox … … 91 92 alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed); 92 93 if (ALint error = alGetError()) 93 COUT(2) << "Sound Warning: Couldn't get number of processed buffers: " 94 << SoundManager::getALErrorString(error) << std::endl; 94 COUT(2) << "Sound Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl; 95 95 96 96 if(processed > 0) … … 99 99 alSourceUnqueueBuffers(audioSource, processed, buffers); 100 100 if (ALint error = alGetError()) 101 COUT(2) << "Sound Warning: Couldn't unqueue buffers: " 102 << SoundManager::getALErrorString(error) << std::endl; 101 COUT(2) << "Sound Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl; 103 102 104 103 for(int i = 0; i < processed; i++) … … 121 120 alSourceQueueBuffers(audioSource, processed, buffers); 122 121 if (ALint error = alGetError()) 123 COUT(2) << "Sound Warning: Couldn't queue buffers: " 124 << SoundManager::getALErrorString(error) << std::endl; 122 COUT(2) << "Sound Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl; 125 123 } 124 msleep(250); // perhaps another value here is better 126 125 } 127 126 } -
code/branches/sound5/src/orxonox/sound/SoundStreamer.h
r6417 r6506 29 29 #define _SoundStreamer_H__ 30 30 31 #include " OrxonoxPrereqs.h"31 #include "sound/SoundPrereqs.h" 32 32 33 33 #include <string> -
code/branches/sound5/src/orxonox/sound/WorldSound.h
r6417 r6506 30 30 #define _WorldSound_H__ 31 31 32 #include " OrxonoxPrereqs.h"32 #include "sound/SoundPrereqs.h" 33 33 34 34 #include "tools/interfaces/Tickable.h"
Note: See TracChangeset
for help on using the changeset viewer.