Changeset 8006 for code/branches/usability/src/orxonox/sound
- Timestamp:
- Mar 1, 2011, 5:16:52 AM (14 years ago)
- Location:
- code/branches/usability
- Files:
-
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability
- Property svn:mergeinfo changed
/code/branches/sound4 removed /code/branches/sound5 removed
- Property svn:mergeinfo changed
-
code/branches/usability/src/orxonox/sound/AmbientSound.cc
r8005 r8006 23 23 * Reto Grieder 24 24 * Co-authors: 25 * Kevin Young25 * ... 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>39 35 40 36 namespace orxonox 41 37 { 42 // vorbis callbacks43 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 47 38 AmbientSound::AmbientSound() 48 39 : bPlayOnLoad_(false) … … 51 42 52 43 // Ambient sounds always fade in 53 //this->setVolume(0);44 this->setVolume(0); 54 45 } 55 46 … … 60 51 // Smoothly fade out by keeping a SmartPtr 61 52 SoundManager::getInstance().unregisterAmbientSound(this); 62 this->soundstreamthread_.interrupt();63 53 } 64 54 } … … 72 62 bool AmbientSound::stop() 73 63 { 74 if (GameMode::playsSound()) 64 if (GameMode::playsSound()) 75 65 SoundManager::getInstance().unregisterAmbientSound(this); 76 66 return false; // sound source not (yet) destroyed - return false … … 102 92 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path); 103 93 if (fileInfo != NULL) 104 this->setS treamSource(path);94 this->setSource(path); 105 95 else 106 96 COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl; … … 114 104 this->play(); 115 105 } 116 117 // hacky solution for file streaming118 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 necessary142 }143 144 // queue some init buffers145 COUT(4) << "Sound: Creating thread for " << source << std::endl;146 // Get resource info147 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 stream154 DataStreamPtr dataStream = Resource::open(fileInfo);155 156 alSourcei(this->audioSource_, AL_BUFFER, 0);157 158 // Open file with custom streaming159 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 else179 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 }254 106 } -
code/branches/usability/src/orxonox/sound/AmbientSound.h
r8005 r8006 22 22 * Author: 23 23 * Reto Grieder 24 * 24 * Kevin Young 25 25 * Co-authors: 26 * Kevin Young26 * ... 27 27 * 28 28 */ … … 31 31 #define _AmbientSound_H__ 32 32 33 #include <boost/thread.hpp> 34 35 #include "sound/SoundPrereqs.h" 33 #include "OrxonoxPrereqs.h" 36 34 37 35 #include "BaseSound.h" … … 41 39 { 42 40 /** 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 * 41 * The AmbientSound class is used to play background music. It can not be placed 42 * directly in a level file, use WorldAmbientSound instead. 48 43 */ 49 44 class _OrxonoxExport AmbientSound : public BaseSound, public MoodListener … … 70 65 ~AmbientSound() { } 71 66 72 bool doStop();73 void doPlay();74 75 67 private: 76 68 void preDestroy(); … … 84 76 std::string ambientSource_; //!< Analogous to source_, but mood independent 85 77 bool bPlayOnLoad_; //!< Play the sound immediately when loaded 86 87 boost::thread soundstreamthread_; // hacky solution for streaming88 void setStreamSource(const std::string& source);89 78 }; 90 79 } -
code/branches/usability/src/orxonox/sound/BaseSound.cc
r8005 r8006 92 92 alSourcePlay(this->audioSource_); 93 93 if (int error = alGetError()) 94 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;94 COUT(2) << "Sound: Error playing sound: " << SoundManager::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: " << getALErrorString(error) << std::endl;148 if(this->soundBuffer_ != NULL) {149 alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());150 }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()); 151 151 if (ALuint error = alGetError()) 152 COUT(1) << "Sound : Error: Could not set buffer \"" << this->source_ << "\": " <<getALErrorString(error) << std::endl;152 COUT(1) << "Sound Error: Could not set buffer \"" << this->source_ << "\": " << SoundManager::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 << ": " << getALErrorString(error) << std::endl; 170 COUT(2) << "Sound: Error setting volume to " << volume 171 << ": " << SoundManager::getALErrorString(error) << std::endl; 171 172 } 172 173 } … … 183 184 if (pitch > 2 || pitch < 0.5f) 184 185 { 185 COUT(2) << "Sound : Warning: pitch out of range, cropping value." << std::endl;186 COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl; 186 187 pitch = pitch > 2.0f ? 2.0f : pitch; 187 188 pitch = pitch < 0.5f ? 0.5f : pitch; … … 192 193 alSourcef(this->audioSource_, AL_PITCH, pitch); 193 194 if (int error = alGetError()) 194 COUT(2) << "Sound: Error setting pitch: " << getALErrorString(error) << std::endl;195 COUT(2) << "Sound: Error setting pitch: " << SoundManager::getALErrorString(error) << std::endl; 195 196 } 196 197 } … … 237 238 if (ALuint error = alGetError()) 238 239 { 239 COUT(1) << "Sound : Error: Could not set buffer \"" << source << "\": " <<getALErrorString(error) << std::endl;240 COUT(1) << "Sound Error: Could not set buffer \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl; 240 241 return; 241 242 } … … 245 246 alSourcePlay(this->audioSource_); 246 247 if (int error = alGetError()) 247 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;248 COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl; 248 249 if (this->isPaused()) 249 250 alSourcePause(this->audioSource_); -
code/branches/usability/src/orxonox/sound/BaseSound.h
r8005 r8006 30 30 #define _BaseSound_H__ 31 31 32 #include " sound/SoundPrereqs.h"32 #include "OrxonoxPrereqs.h" 33 33 34 34 #include <string> … … 85 85 virtual ~BaseSound(); 86 86 87 v irtual void doPlay();88 virtualbool doStop(); // returns true if the sound source was destroyed89 v irtual void doPause();87 void doPlay(); 88 bool doStop(); // returns true if the sound source was destroyed 89 void doPause(); 90 90 91 91 // network callbacks -
code/branches/usability/src/orxonox/sound/SoundBuffer.h
r8005 r8006 30 30 #define _SoundBuffer_H__ 31 31 32 #include " sound/SoundPrereqs.h"32 #include "OrxonoxPrereqs.h" 33 33 34 34 #include <list> -
code/branches/usability/src/orxonox/sound/SoundManager.cc
r8005 r8006 22 22 * Author: 23 23 * Erwin 'vaiursch' Herrsche 24 *25 * Co-authors:26 24 * Kevin Young 27 25 * Reto Grieder 26 * Co-authors: 27 * ... 28 28 * 29 29 */ … … 52 52 ManageScopedSingleton(SoundManager, ScopeID::Graphics, true); 53 53 54 // From SoundPrereqs.h 55 std::string getALErrorString(ALenum code) 54 std::string SoundManager::getALErrorString(ALenum code) 56 55 { 57 56 switch (code) … … 81 80 82 81 if (!alutInitWithoutContext(NULL, NULL)) 83 ThrowException(InitialisationFailed, "Sound :Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));82 ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError())); 84 83 Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit); 85 84 … … 113 112 COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl; 114 113 #endif 115 ThrowException(InitialisationFailed, "Sound :Error: Could not open sound device.");114 ThrowException(InitialisationFailed, "Sound Error: Could not open sound device."); 116 115 } 117 116 Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_); 118 117 119 118 // Create sound context and make it the currently used one 120 const ALint contattr[] = {ALC_SYNC, 1, 0}; 121 this->context_ = alcCreateContext(this->device_, contattr); 119 this->context_ = alcCreateContext(this->device_, NULL); 122 120 if (this->context_ == NULL) 123 ThrowException(InitialisationFailed, "Sound :Error: Could not create ALC context");121 ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context"); 124 122 Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_); 125 123 if (!alcMakeContextCurrent(this->context_)) 126 ThrowException(InitialisationFailed, "Sound :Error: Could not use ALC context");124 ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context"); 127 125 128 126 GameMode::setPlaysSound(true); … … 137 135 COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl; 138 136 else 139 COUT(2) << "Sound :Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;137 COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl; 140 138 141 139 this->mute_[SoundType::All] = 1.0f; … … 151 149 this->availableSoundSources_.push_back(source); 152 150 else 153 ThrowException(InitialisationFailed, "Sound :Error: Could not create even a single source");151 ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source"); 154 152 // Create a few initial sources 155 153 this->createSoundSources(this->minSources_ - 1); … … 173 171 // If there are still used buffers around, well, that's just very bad... 174 172 if (this->soundBuffers_.size() != this->effectsPool_.size()) 175 COUT(1) << "Sound :Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;173 COUT(1) << "Sound Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl; 176 174 // Empty buffer pool and buffer list 177 175 this->effectsPool_.clear(); … … 180 178 // There should not be any sources in use anymore 181 179 if (!this->usedSoundSources_.empty()) 182 COUT(1) << "Sound :Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;180 COUT(1) << "Sound Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl; 183 181 while (!this->availableSoundSources_.empty()) 184 182 { … … 191 189 // Relieve context to destroy it 192 190 if (!alcMakeContextCurrent(NULL)) 193 COUT(1) << "Sound :Error: Could not unset ALC context" << std::endl;191 COUT(1) << "Sound Error: Could not unset ALC context" << std::endl; 194 192 alcDestroyContext(this->context_); 195 193 if (ALCenum error = alcGetError(this->device_)) 196 194 { 197 195 if (error == AL_INVALID_OPERATION) 198 COUT(1) << "Sound :Error: Could not destroy ALC context because it is the current one" << std::endl;196 COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl; 199 197 else 200 COUT(1) << "Sound :Error: Could not destroy ALC context because it is invalid" << std::endl;198 COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl; 201 199 } 202 200 #ifdef AL_VERSION_1_1 203 201 if (!alcCloseDevice(this->device_)) 204 COUT(1) << "Sound :Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;202 COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl; 205 203 #else 206 204 alcCloseDevice(this->device_); 207 205 #endif 208 206 if (!alutExit()) 209 COUT(1) << "Sound :Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;207 COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl; 210 208 } 211 209 … … 253 251 if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 ) 254 252 { 255 COUT(2) << "Sound : Warning: fade step out of range, ignoring change." << std::endl;253 COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl; 256 254 ResetConfigValue(crossFadeStep_); 257 255 } … … 262 260 float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f); 263 261 if (clampedVolume != this->volume_[type]) 264 COUT(2) << "Sound : Warning: Volume setting (" << type << ") out of range, clamping." << std::endl;262 COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl; 265 263 this->updateVolume(type); 266 264 } … … 354 352 if (it->first == newAmbient) 355 353 { 356 COUT(2) << "Sound : Warning: Will not play an AmbientSound twice." << std::endl;354 COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl; 357 355 return; 358 356 } … … 622 620 alDeleteSources(1, &this->availableSoundSources_.back()); 623 621 if (alGetError()) 624 COUT(1) << "Sound :Error: Failed to delete a source --> lost forever" << std::endl;622 COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl; 625 623 this->availableSoundSources_.pop_back(); 626 624 } -
code/branches/usability/src/orxonox/sound/SoundManager.h
r8005 r8006 22 22 * Author: 23 23 * Erwin 'vaiursch' Herrsche 24 *25 * Co-authors:26 24 * Kevin Young 27 25 * Reto Grieder 26 * Co-authors: 27 * ... 28 28 */ 29 29 … … 31 31 #define _SoundManager_H__ 32 32 33 #include " sound/SoundPrereqs.h"33 #include "OrxonoxPrereqs.h" 34 34 35 35 #include <list> … … 99 99 void releaseSoundSource(ALuint source); 100 100 101 static std::string getALErrorString(ALenum error); 102 101 103 private: 102 104 void processCrossFading(float dt); -
code/branches/usability/src/orxonox/sound/SoundStreamer.cc
r8005 r8006 27 27 #include "SoundStreamer.h" 28 28 29 #include <boost/thread.hpp> 30 #include <AL/al.h> 31 #include <AL/alc.h> 29 #include <al.h> 32 30 #include <vorbis/vorbisfile.h> 33 31 #include "SoundManager.h" 34 #include "util/Sleep.h"35 32 36 33 namespace orxonox … … 41 38 long tellVorbis(void* datasource); 42 39 43 void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream , OggVorbis_File* vf, int current_section)40 void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream) 44 41 { 45 char inbuffer[4096]; 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 } 46 57 vorbis_info* vorbisInfo; 47 vorbisInfo = ov_info( vf, -1);58 vorbisInfo = ov_info(&vf, -1); 48 59 ALenum format; 49 60 if (vorbisInfo->channels == 1) … … 52 63 format = AL_FORMAT_STEREO16; 53 64 54 while(true) // Stream forever, control through thread control 65 char inbuffer[256*1024]; 66 ALuint initbuffers[4]; 67 alGenBuffers(4, initbuffers); 68 int current_section; 69 70 for(int i = 0; i < 4; i++) 55 71 { 56 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 72 long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section); 73 if (ret == 0) 62 74 { 63 COUT(4) << "Sound: " << dataStream->getName() << " is not playing." << std::endl;75 return; 64 76 } 65 66 if(alcGetCurrentContext() == NULL) 77 else if (ret < 0) 67 78 { 68 COUT(2) << "Sound: There is no context, terminating thread for " << dataStream->getName() << std::endl; 79 COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl; 80 ov_clear(&vf); 69 81 return; 70 82 } 71 83 84 alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate); 85 } 86 alSourceQueueBuffers(audioSource, 4, initbuffers); 87 88 while(true) // Stream forever, control through thread control 89 { 72 90 int processed; 73 91 alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed); 74 92 if (ALint error = alGetError()) 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; 93 COUT(2) << "Sound Warning: Couldn't get number of processed buffers: " 94 << SoundManager::getALErrorString(error) << std::endl; 78 95 79 96 if(processed > 0) … … 82 99 alSourceUnqueueBuffers(audioSource, processed, buffers); 83 100 if (ALint error = alGetError()) 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; 101 COUT(2) << "Sound Warning: Couldn't unqueue buffers: " 102 << SoundManager::getALErrorString(error) << std::endl; 91 103 92 104 for(int i = 0; i < processed; i++) 93 105 { 94 long ret = ov_read( vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);106 long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section); 95 107 if (ret == 0) 96 108 { 97 COUT(4) << "Sound: End of file " << dataStream->getName() << ", terminating thread" << std::endl;98 109 return; 99 110 } 100 111 else if (ret < 0) 101 112 { 102 COUT(2) << "Sound: libvorbisfile: error reading the file " << dataStream->getName()<< std::endl;103 ov_clear( vf);113 COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl; 114 ov_clear(&vf); 104 115 return; 105 116 } 106 117 107 118 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 }116 119 } 117 }118 else119 {120 msleep(10); // perhaps another value here is better121 }122 120 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); 121 alSourceQueueBuffers(audioSource, processed, buffers); 130 122 if (ALint error = alGetError()) 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; 123 COUT(2) << "Sound Warning: Couldn't queue buffers: " 124 << SoundManager::getALErrorString(error) << std::endl; 138 125 } 139 126 } -
code/branches/usability/src/orxonox/sound/SoundStreamer.h
r8005 r8006 29 29 #define _SoundStreamer_H__ 30 30 31 #include " sound/SoundPrereqs.h"31 #include "OrxonoxPrereqs.h" 32 32 33 33 #include <string> 34 #include <vorbis/vorbisfile.h>35 34 #include <OgreDataStream.h> 36 35 #include "core/CorePrereqs.h" … … 41 40 { 42 41 public: 43 void operator()(ALuint audioSource, DataStreamPtr dataStream , OggVorbis_File* vf, int current_section);42 void operator()(ALuint audioSource, DataStreamPtr dataStream); 44 43 }; 45 44 } -
code/branches/usability/src/orxonox/sound/WorldSound.h
r8005 r8006 30 30 #define _WorldSound_H__ 31 31 32 #include " sound/SoundPrereqs.h"32 #include "OrxonoxPrereqs.h" 33 33 34 34 #include "tools/interfaces/Tickable.h"
Note: See TracChangeset
for help on using the changeset viewer.