Changeset 6674 for code/branches/sound5/src
- Timestamp:
- Apr 1, 2010, 4:24:59 PM (15 years ago)
- Location:
- code/branches/sound5/src/orxonox/sound
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sound5/src/orxonox/sound/AmbientSound.cc
r6562 r6674 194 194 this->soundstreamthread_.interrupt(); 195 195 } 196 197 void AmbientSound::doPlay() 198 { 199 BaseSound::doPlay(); 200 201 if(GameMode::playsSound() && this->getSourceState() != AL_PLAYING) 202 { 203 if(!alIsSource(this->audioSource_)) 204 { 205 this->audioSource_ = SoundManager::getInstance().getSoundSource(this); 206 if(!alIsSource(this->audioSource_)) 207 return; 208 this->initialiseSource(); 209 } 210 211 alSourcePlay(this->audioSource_); 212 if(int error = alGetError()) 213 COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl; 214 } 215 } 196 216 } -
code/branches/sound5/src/orxonox/sound/AmbientSound.h
r6508 r6674 74 74 75 75 void doStop(); 76 void doPlay(); 76 77 77 78 private: -
code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
r6562 r6674 27 27 #include "SoundStreamer.h" 28 28 29 #include <boost/thread.hpp> 29 30 #include <al.h> 30 31 #include <alc.h> … … 42 43 void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream) 43 44 { 45 COUT(4) << "Sound: Creating thread for " << dataStream->getName() << std::endl; 44 46 // Open file with custom streaming 45 47 ov_callbacks vorbisCallbacks; … … 65 67 format = AL_FORMAT_STEREO16; 66 68 67 char inbuffer[ 256*1024];68 ALuint initbuffers[ 4];69 alGenBuffers( 4, initbuffers);69 char inbuffer[4096]; 70 ALuint initbuffers[20]; 71 alGenBuffers(20, initbuffers); 70 72 if (ALint error = alGetError()) { 71 73 COUT(2) << "Sound: Streamer: Could not generate buffer:" << getALErrorString(error) << std::endl; … … 74 76 int current_section; 75 77 76 for(int i = 0; i < 4; i++)78 for(int i = 0; i < 20; i++) 77 79 { 78 80 long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section); 79 81 if (ret == 0) 80 82 { 81 return;83 break; 82 84 } 83 85 else if (ret < 0) … … 89 91 90 92 alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate); 91 alGetError(); 92 } 93 alSourceQueueBuffers(audioSource, 4, initbuffers); 94 if (ALint error = alGetError()) { 95 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl; 93 if(ALint error = alGetError()) { 94 COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl; 95 break; 96 } 97 alSourceQueueBuffers(audioSource, 1, &initbuffers[i]); 98 if (ALint error = alGetError()) { 99 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl; 100 } 101 COUT(4) << "Sound: " << ret << std::endl; 96 102 } 97 103 … … 100 106 int processed; 101 107 102 if(alcGetCurrentContext() == NULL) 103 COUT(2) << "This should not be!" << std::endl; 108 if(alcGetCurrentContext() == NULL) 109 { 110 COUT(2) << "Sound: There is no context, terminating thread" << std::endl; 111 return; 112 } 104 113 105 114 alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed); 106 115 if (ALint error = alGetError()) 107 COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;116 COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl; 108 117 118 COUT(2) << "Sound: Blub: " << processed << std::endl; 109 119 if(processed > 0) 110 120 { 121 COUT(4) << "Sound: " << processed << std::endl; 111 122 ALuint* buffers = new ALuint[processed]; 112 123 alSourceUnqueueBuffers(audioSource, processed, buffers); … … 119 130 if (ret == 0) 120 131 { 121 return;132 break; 122 133 } 123 134 else if (ret < 0) … … 129 140 130 141 alBufferData(buffers[i], format, &inbuffer, ret, vorbisInfo->rate); 131 alGetError(); 142 if(ALint error = alGetError()) { 143 COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl; 144 break; 145 } 146 alSourceQueueBuffers(audioSource, 1, &buffers[i]); 147 if (ALint error = alGetError()) { 148 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl; 149 } 132 150 } 133 134 alSourceQueueBuffers(audioSource, processed, buffers); 135 if (ALint error = alGetError()) 136 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl; 151 } 152 try { 153 boost::this_thread::interruption_point(); 154 } 155 catch(boost::thread_interrupted) { 156 COUT(4) << "Sound: Catched interruption. Terminating thread for " << dataStream->getName() << std::endl; 157 return; 137 158 } 138 159 msleep(100); // perhaps another value here is better
Note: See TracChangeset
for help on using the changeset viewer.