Changeset 8005 for code/branches
- Timestamp:
- Mar 1, 2011, 5:10:29 AM (14 years ago)
- Location:
- code/branches/usability
- Files:
-
- 14 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability
- Property svn:mergeinfo changed
/code/branches/sound4 (added) merged: 6435,6476,6504 /code/branches/sound5 (added) merged: 6505-6511,6562,6674,6726,6729-6730,6733,6767,6769,6931,6962,7720
- Property svn:mergeinfo changed
-
code/branches/usability/src/orxonox/MoodManager.h
r7163 r8005 59 59 }; 60 60 61 /* 62 @brief 63 The MoodManager class serves to allow for different musical themes in the game. 64 */ 61 /** 62 * The MoodManager class enables the game to set different themes, i.e. audio themes, each 63 * with a set of different audio files. A theme (called mood) is set by the server and applies to 64 * all clients. Existing moods are currently hard-coded in function checkMoodValidity(). Each mood 65 * needs to have a folder with its name in "data_extern/audo/ambient/" containing sound files named like 66 * the ones in mood "default". 67 */ 65 68 class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass 66 69 { -
code/branches/usability/src/orxonox/sound/AmbientSound.cc
r7929 r8005 23 23 * Reto Grieder 24 24 * Co-authors: 25 * ...25 * Kevin Young 26 26 * 27 27 */ … … 33 33 #include "core/Resource.h" 34 34 #include "SoundManager.h" 35 #include "SoundStreamer.h" 36 #include "util/Sleep.h" 37 38 #include <AL/alut.h> 35 39 36 40 namespace orxonox 37 41 { 42 // vorbis callbacks 43 size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource); 44 int seekVorbis(void* datasource, ogg_int64_t offset, int whence); 45 long tellVorbis(void* datasource); 46 38 47 AmbientSound::AmbientSound() 39 48 : bPlayOnLoad_(false) … … 42 51 43 52 // Ambient sounds always fade in 44 this->setVolume(0);53 //this->setVolume(0); 45 54 } 46 55 … … 51 60 // Smoothly fade out by keeping a SmartPtr 52 61 SoundManager::getInstance().unregisterAmbientSound(this); 62 this->soundstreamthread_.interrupt(); 53 63 } 54 64 } … … 62 72 bool AmbientSound::stop() 63 73 { 64 if (GameMode::playsSound()) 74 if (GameMode::playsSound()) 65 75 SoundManager::getInstance().unregisterAmbientSound(this); 66 76 return false; // sound source not (yet) destroyed - return false … … 92 102 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path); 93 103 if (fileInfo != NULL) 94 this->setS ource(path);104 this->setStreamSource(path); 95 105 else 96 106 COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl; … … 104 114 this->play(); 105 115 } 116 117 // hacky solution for file streaming 118 void AmbientSound::setStreamSource(const std::string& source) 119 { 120 if (!GameMode::playsSound()) 121 { 122 this->source_ = source; 123 return; 124 } 125 126 if(!alIsSource(this->audioSource_)) 127 this->audioSource_ = SoundManager::getInstance().getSoundSource(this); 128 129 if (this->source_ == source) 130 { 131 return; 132 } 133 134 this->source_ = source; 135 // Don't load "" 136 if (source_.empty()) 137 return; 138 139 if (this->soundstreamthread_.get_id() != boost::thread::id()) 140 { 141 this->soundstreamthread_.interrupt(); // terminate an old thread if necessary 142 } 143 144 // queue some init buffers 145 COUT(4) << "Sound: Creating thread for " << source << std::endl; 146 // Get resource info 147 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source); 148 if (fileInfo == NULL) 149 { 150 COUT(2) << "Sound: Warning: Sound file '" << source << "' not found" << std::endl; 151 return; 152 } 153 // Open data stream 154 DataStreamPtr dataStream = Resource::open(fileInfo); 155 156 alSourcei(this->audioSource_, AL_BUFFER, 0); 157 158 // Open file with custom streaming 159 ov_callbacks vorbisCallbacks; 160 vorbisCallbacks.read_func = &readVorbis; 161 vorbisCallbacks.seek_func = &seekVorbis; 162 vorbisCallbacks.tell_func = &tellVorbis; 163 vorbisCallbacks.close_func = NULL; 164 165 OggVorbis_File* vf = new OggVorbis_File(); 166 int ret = ov_open_callbacks(dataStream.get(), vf, NULL, 0, vorbisCallbacks); 167 if (ret < 0) 168 { 169 COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl; 170 ov_clear(vf); 171 return; 172 } 173 vorbis_info* vorbisInfo; 174 vorbisInfo = ov_info(vf, -1); 175 ALenum format; 176 if (vorbisInfo->channels == 1) 177 format = AL_FORMAT_MONO16; 178 else 179 format = AL_FORMAT_STEREO16; 180 181 char inbuffer[4096]; 182 ALuint initbuffers[10]; 183 alGenBuffers(10, initbuffers); 184 if (ALint error = alGetError()) { 185 COUT(2) << "Sound: Streamer: Could not generate buffer:" << getALErrorString(error) << std::endl; 186 return; 187 } 188 int current_section; 189 190 for(int i = 0; i < 10; i++) 191 { 192 long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section); 193 if (ret == 0) 194 { 195 break; 196 } 197 else if (ret < 0) 198 { 199 COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl; 200 ov_clear(vf); 201 return; 202 } 203 204 alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate); 205 if(ALint error = alGetError()) { 206 COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl; 207 break; 208 } 209 alSourceQueueBuffers(this->audioSource_, 1, &initbuffers[i]); 210 if (ALint error = alGetError()) { 211 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl; 212 } 213 } 214 215 this->soundstreamthread_ = boost::thread(SoundStreamer(), this->audioSource_, dataStream, vf, current_section); 216 if(this->soundstreamthread_ == boost::thread()) 217 COUT(2) << "Sound: Failed to create thread." << std::endl; 218 //SoundStreamer streamer; 219 //streamer(this->audioSource_, dataStream); 220 221 alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0); 222 alSource3f(this->audioSource_, AL_VELOCITY, 0, 0, 0); 223 alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0); 224 if (ALint error = alGetError()) 225 COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl; 226 } 227 228 bool AmbientSound::doStop() 229 { 230 bool result = BaseSound::doStop(); 231 this->soundstreamthread_.interrupt(); 232 return result; 233 } 234 235 void AmbientSound::doPlay() 236 { 237 BaseSound::doPlay(); 238 239 if(GameMode::playsSound() && this->getSourceState() != AL_PLAYING) 240 { 241 if(!alIsSource(this->audioSource_)) 242 { 243 this->audioSource_ = SoundManager::getInstance().getSoundSource(this); 244 if(!alIsSource(this->audioSource_)) 245 return; 246 this->initialiseSource(); 247 } 248 249 alSourcePlay(this->audioSource_); 250 if(int error = alGetError()) 251 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl; 252 } 253 } 106 254 } -
code/branches/usability/src/orxonox/sound/AmbientSound.h
r7856 r8005 22 22 * Author: 23 23 * Reto Grieder 24 * 25 * Co-authors: 24 26 * Kevin Young 25 * Co-authors:26 * ...27 27 * 28 28 */ … … 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 "BaseSound.h" … … 39 41 { 40 42 /** 41 * The AmbientSound class is used to play background music. It can not be placed 42 * directly in a level file, use WorldAmbientSound instead. 43 * The AmbientSound class implements the non-3D sound, i.e. sound files that are used for atmospheric 44 * highlighting. 45 * It interfaces with BaseSound and is controllable by MoodManager. 46 * Ambient sounds are always cross-faded. New sounds are registered and activated/deactivated as needed. 47 * 43 48 */ 44 49 class _OrxonoxExport AmbientSound : public BaseSound, public MoodListener … … 65 70 ~AmbientSound() { } 66 71 72 bool doStop(); 73 void doPlay(); 74 67 75 private: 68 76 void preDestroy(); … … 76 84 std::string ambientSource_; //!< Analogous to source_, but mood independent 77 85 bool bPlayOnLoad_; //!< Play the sound immediately when loaded 86 87 boost::thread soundstreamthread_; // hacky solution for streaming 88 void setStreamSource(const std::string& source); 78 89 }; 79 90 } -
code/branches/usability/src/orxonox/sound/BaseSound.cc
r7858 r8005 92 92 alSourcePlay(this->audioSource_); 93 93 if (int error = alGetError()) 94 COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;94 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl; 95 95 } 96 96 } … … 145 145 alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0); 146 146 if (ALint error = alGetError()) 147 COUT(2) << "Sound Warning: Setting source parameters to 0 failed: "148 << SoundManager::getALErrorString(error) << std::endl;149 assert(this->soundBuffer_ != NULL);150 alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());147 COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl; 148 if(this->soundBuffer_ != NULL) { 149 alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer()); 150 } 151 151 if (ALuint error = alGetError()) 152 COUT(1) << "Sound Error: Could not set buffer \"" << this->source_ << "\": " << SoundManager::getALErrorString(error) << std::endl;152 COUT(1) << "Sound: Error: Could not set buffer \"" << this->source_ << "\": " << getALErrorString(error) << std::endl; 153 153 } 154 154 … … 157 157 this->volume_ = clamp(vol, 0.0f, 1.0f); 158 158 if (this->volume_ != vol) 159 COUT(2) << "Sound warning: volume out of range, clamping value." << std::endl;159 COUT(2) << "Sound: Warning: volume out of range, clamping value." << std::endl; 160 160 this->updateVolume(); 161 161 } … … 168 168 alSourcef(this->audioSource_, AL_GAIN, volume); 169 169 if (int error = alGetError()) 170 COUT(2) << "Sound: Error setting volume to " << volume 171 << ": " << SoundManager::getALErrorString(error) << std::endl; 170 COUT(2) << "Sound: Error setting volume to " << volume << ": " << getALErrorString(error) << std::endl; 172 171 } 173 172 } … … 184 183 if (pitch > 2 || pitch < 0.5f) 185 184 { 186 COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;185 COUT(2) << "Sound: Warning: pitch out of range, cropping value." << std::endl; 187 186 pitch = pitch > 2.0f ? 2.0f : pitch; 188 187 pitch = pitch < 0.5f ? 0.5f : pitch; … … 193 192 alSourcef(this->audioSource_, AL_PITCH, pitch); 194 193 if (int error = alGetError()) 195 COUT(2) << "Sound: Error setting pitch: " << SoundManager::getALErrorString(error) << std::endl;194 COUT(2) << "Sound: Error setting pitch: " << getALErrorString(error) << std::endl; 196 195 } 197 196 } … … 238 237 if (ALuint error = alGetError()) 239 238 { 240 COUT(1) << "Sound Error: Could not set buffer \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;239 COUT(1) << "Sound: Error: Could not set buffer \"" << source << "\": " << getALErrorString(error) << std::endl; 241 240 return; 242 241 } … … 246 245 alSourcePlay(this->audioSource_); 247 246 if (int error = alGetError()) 248 COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;247 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl; 249 248 if (this->isPaused()) 250 249 alSourcePause(this->audioSource_); -
code/branches/usability/src/orxonox/sound/BaseSound.h
r7856 r8005 30 30 #define _BaseSound_H__ 31 31 32 #include " OrxonoxPrereqs.h"32 #include "sound/SoundPrereqs.h" 33 33 34 34 #include <string> … … 85 85 virtual ~BaseSound(); 86 86 87 v oid doPlay();88 bool doStop(); // returns true if the sound source was destroyed89 v oid doPause();87 virtual void doPlay(); 88 virtual bool doStop(); // returns true if the sound source was destroyed 89 virtual void doPause(); 90 90 91 91 // network callbacks -
code/branches/usability/src/orxonox/sound/SoundBuffer.h
r6764 r8005 30 30 #define _SoundBuffer_H__ 31 31 32 #include " OrxonoxPrereqs.h"32 #include "sound/SoundPrereqs.h" 33 33 34 34 #include <list> -
code/branches/usability/src/orxonox/sound/SoundManager.cc
r7858 r8005 22 22 * Author: 23 23 * Erwin 'vaiursch' Herrsche 24 * 25 * Co-authors: 24 26 * Kevin Young 25 27 * Reto Grieder 26 * Co-authors:27 * ...28 28 * 29 29 */ … … 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) … … 80 81 81 82 if (!alutInitWithoutContext(NULL, NULL)) 82 ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));83 ThrowException(InitialisationFailed, "Sound: Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError())); 83 84 Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit); 84 85 … … 112 113 COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl; 113 114 #endif 114 ThrowException(InitialisationFailed, "Sound Error: Could not open sound device.");115 ThrowException(InitialisationFailed, "Sound: Error: Could not open sound device."); 115 116 } 116 117 Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_); 117 118 118 119 // Create sound context and make it the currently used one 119 this->context_ = alcCreateContext(this->device_, NULL); 120 const ALint contattr[] = {ALC_SYNC, 1, 0}; 121 this->context_ = alcCreateContext(this->device_, contattr); 120 122 if (this->context_ == NULL) 121 ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context");123 ThrowException(InitialisationFailed, "Sound: Error: Could not create ALC context"); 122 124 Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_); 123 125 if (!alcMakeContextCurrent(this->context_)) 124 ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context");126 ThrowException(InitialisationFailed, "Sound: Error: Could not use ALC context"); 125 127 126 128 GameMode::setPlaysSound(true); … … 135 137 COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl; 136 138 else 137 COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;139 COUT(2) << "Sound: Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl; 138 140 139 141 this->mute_[SoundType::All] = 1.0f; … … 149 151 this->availableSoundSources_.push_back(source); 150 152 else 151 ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source");153 ThrowException(InitialisationFailed, "Sound: Error: Could not create even a single source"); 152 154 // Create a few initial sources 153 155 this->createSoundSources(this->minSources_ - 1); … … 171 173 // If there are still used buffers around, well, that's just very bad... 172 174 if (this->soundBuffers_.size() != this->effectsPool_.size()) 173 COUT(1) << "Sound Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;175 COUT(1) << "Sound: Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl; 174 176 // Empty buffer pool and buffer list 175 177 this->effectsPool_.clear(); … … 178 180 // There should not be any sources in use anymore 179 181 if (!this->usedSoundSources_.empty()) 180 COUT(1) << "Sound Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;182 COUT(1) << "Sound: Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl; 181 183 while (!this->availableSoundSources_.empty()) 182 184 { … … 189 191 // Relieve context to destroy it 190 192 if (!alcMakeContextCurrent(NULL)) 191 COUT(1) << "Sound Error: Could not unset ALC context" << std::endl;193 COUT(1) << "Sound: Error: Could not unset ALC context" << std::endl; 192 194 alcDestroyContext(this->context_); 193 195 if (ALCenum error = alcGetError(this->device_)) 194 196 { 195 197 if (error == AL_INVALID_OPERATION) 196 COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl;198 COUT(1) << "Sound: Error: Could not destroy ALC context because it is the current one" << std::endl; 197 199 else 198 COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl;200 COUT(1) << "Sound: Error: Could not destroy ALC context because it is invalid" << std::endl; 199 201 } 200 202 #ifdef AL_VERSION_1_1 201 203 if (!alcCloseDevice(this->device_)) 202 COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;204 COUT(1) << "Sound: Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl; 203 205 #else 204 206 alcCloseDevice(this->device_); 205 207 #endif 206 208 if (!alutExit()) 207 COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;209 COUT(1) << "Sound: Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl; 208 210 } 209 211 … … 251 253 if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 ) 252 254 { 253 COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl;255 COUT(2) << "Sound: Warning: fade step out of range, ignoring change." << std::endl; 254 256 ResetConfigValue(crossFadeStep_); 255 257 } … … 260 262 float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f); 261 263 if (clampedVolume != this->volume_[type]) 262 COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl;264 COUT(2) << "Sound: Warning: Volume setting (" << type << ") out of range, clamping." << std::endl; 263 265 this->updateVolume(type); 264 266 } … … 352 354 if (it->first == newAmbient) 353 355 { 354 COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl;356 COUT(2) << "Sound: Warning: Will not play an AmbientSound twice." << std::endl; 355 357 return; 356 358 } … … 620 622 alDeleteSources(1, &this->availableSoundSources_.back()); 621 623 if (alGetError()) 622 COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl;624 COUT(1) << "Sound: Error: Failed to delete a source --> lost forever" << std::endl; 623 625 this->availableSoundSources_.pop_back(); 624 626 } -
code/branches/usability/src/orxonox/sound/SoundManager.h
r7858 r8005 22 22 * Author: 23 23 * Erwin 'vaiursch' Herrsche 24 * 25 * Co-authors: 24 26 * Kevin Young 25 27 * Reto Grieder 26 * Co-authors:27 * ...28 28 */ 29 29 … … 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/usability/src/orxonox/sound/SoundStreamer.cc
r7163 r8005 27 27 #include "SoundStreamer.h" 28 28 29 #include <al.h> 29 #include <boost/thread.hpp> 30 #include <AL/al.h> 31 #include <AL/alc.h> 30 32 #include <vorbis/vorbisfile.h> 31 33 #include "SoundManager.h" 34 #include "util/Sleep.h" 32 35 33 36 namespace orxonox … … 38 41 long tellVorbis(void* datasource); 39 42 40 void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream )43 void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section) 41 44 { 42 // Open file with custom streaming 43 ov_callbacks vorbisCallbacks; 44 vorbisCallbacks.read_func = &readVorbis; 45 vorbisCallbacks.seek_func = &seekVorbis; 46 vorbisCallbacks.tell_func = &tellVorbis; 47 vorbisCallbacks.close_func = NULL; 48 49 OggVorbis_File vf; 50 int ret = ov_open_callbacks(dataStream.get(), &vf, NULL, 0, vorbisCallbacks); 51 if (ret < 0) 52 { 53 COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl; 54 ov_clear(&vf); 55 return; 56 } 45 char inbuffer[4096]; 57 46 vorbis_info* vorbisInfo; 58 vorbisInfo = ov_info( &vf, -1);47 vorbisInfo = ov_info(vf, -1); 59 48 ALenum format; 60 49 if (vorbisInfo->channels == 1) … … 63 52 format = AL_FORMAT_STEREO16; 64 53 65 char inbuffer[256*1024]; 66 ALuint initbuffers[4]; 67 alGenBuffers(4, initbuffers); 68 int current_section; 54 while(true) // Stream forever, control through thread control 55 { 69 56 70 for(int i = 0; i < 4; i++) 71 { 72 long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section); 73 if (ret == 0) 57 int info; 58 alGetSourcei(audioSource, AL_SOURCE_STATE, &info); 59 if(info == AL_PLAYING) 60 COUT(4) << "Sound: " << dataStream->getName() << " is playing." << std::endl; 61 else 74 62 { 75 return;63 COUT(4) << "Sound: " << dataStream->getName() << " is not playing." << std::endl; 76 64 } 77 else if (ret < 0) 65 66 if(alcGetCurrentContext() == NULL) 78 67 { 79 COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl; 80 ov_clear(&vf); 68 COUT(2) << "Sound: There is no context, terminating thread for " << dataStream->getName() << std::endl; 81 69 return; 82 70 } 83 71 84 alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);85 }86 alSourceQueueBuffers(audioSource, 4, initbuffers);87 88 while(true) // Stream forever, control through thread control89 {90 72 int processed; 91 73 alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed); 92 74 if (ALint error = alGetError()) 93 COUT(2) << "Sound Warning: Couldn't get number of processed buffers: " 94 << SoundManager::getALErrorString(error) << std::endl; 75 COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl; 76 77 COUT(4) << "Sound: processed buffers: " << processed << std::endl; 95 78 96 79 if(processed > 0) … … 99 82 alSourceUnqueueBuffers(audioSource, processed, buffers); 100 83 if (ALint error = alGetError()) 101 COUT(2) << "Sound Warning: Couldn't unqueue buffers: " 102 << SoundManager::getALErrorString(error) << std::endl; 84 COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl; 85 86 int queued; 87 alGetSourcei(audioSource, AL_BUFFERS_QUEUED, &queued); 88 if (ALint error = alGetError()) 89 COUT(2) << "Sound: Warning: Couldn't get number of queued buffers: " << getALErrorString(error) << std::endl; 90 COUT(4) << "Sound: queued buffers: " << queued << std::endl; 103 91 104 92 for(int i = 0; i < processed; i++) 105 93 { 106 long ret = ov_read( &vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);94 long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section); 107 95 if (ret == 0) 108 96 { 97 COUT(4) << "Sound: End of file " << dataStream->getName() << ", terminating thread" << std::endl; 109 98 return; 110 99 } 111 100 else if (ret < 0) 112 101 { 113 COUT(2) << "Sound: libvorbisfile: error reading the file "<< std::endl;114 ov_clear( &vf);102 COUT(2) << "Sound: libvorbisfile: error reading the file " << dataStream->getName() << std::endl; 103 ov_clear(vf); 115 104 return; 116 105 } 117 106 118 107 alBufferData(buffers[i], format, &inbuffer, ret, vorbisInfo->rate); 108 if(ALint error = alGetError()) { 109 COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl; 110 break; 111 } 112 alSourceQueueBuffers(audioSource, 1, &buffers[i]); 113 if (ALint error = alGetError()) { 114 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl; 115 } 119 116 } 117 } 118 else 119 { 120 msleep(10); // perhaps another value here is better 121 } 120 122 121 alSourceQueueBuffers(audioSource, processed, buffers); 123 try { 124 boost::this_thread::interruption_point(); 125 } 126 catch(boost::thread_interrupted) { 127 COUT(4) << "Sound: Catched interruption. Terminating thread for " << dataStream->getName() << std::endl; 128 ALuint* buffers = new ALuint[5]; 129 alSourceUnqueueBuffers(audioSource, 5, buffers); 122 130 if (ALint error = alGetError()) 123 COUT(2) << "Sound Warning: Couldn't queue buffers: " 124 << SoundManager::getALErrorString(error) << std::endl; 131 COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl; 132 133 alDeleteBuffers(5, buffers); 134 if (ALint error = alGetError()) 135 COUT(2) << "Sound: Warning: Couldn't delete buffers: " << getALErrorString(error) << std::endl; 136 137 return; 125 138 } 126 139 } -
code/branches/usability/src/orxonox/sound/SoundStreamer.h
r7163 r8005 29 29 #define _SoundStreamer_H__ 30 30 31 #include " OrxonoxPrereqs.h"31 #include "sound/SoundPrereqs.h" 32 32 33 33 #include <string> 34 #include <vorbis/vorbisfile.h> 34 35 #include <OgreDataStream.h> 35 36 #include "core/CorePrereqs.h" … … 40 41 { 41 42 public: 42 void operator()(ALuint audioSource, DataStreamPtr dataStream );43 void operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section); 43 44 }; 44 45 } -
code/branches/usability/src/orxonox/sound/WorldSound.h
r7854 r8005 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" -
code/branches/usability/src/orxonox/weaponsystem/WeaponMode.cc
r7847 r8005 24 24 * Fabian 'x3n' Landau 25 25 * Co-authors: 26 * ...26 * Kevin Young 27 27 * 28 28 */ -
code/branches/usability/src/orxonox/weaponsystem/WeaponMode.h
r7163 r8005 24 24 * Fabian 'x3n' Landau 25 25 * Co-authors: 26 * ...26 * Kevin Young 27 27 * 28 28 */ … … 41 41 namespace orxonox 42 42 { 43 /** 44 * The WeaponMode class enables the developer, amongst other things, to attach a sound file 45 * to the firing event of a weapon. The default firing sound is chosen by each weapon (ex. 46 * HsW01), hard-coded for now. 47 */ 43 48 class _OrxonoxExport WeaponMode : public BaseObject 44 49 {
Note: See TracChangeset
for help on using the changeset viewer.