[Orxonox-commit 1957] r6674 - code/branches/sound5/src/orxonox/sound
erwin at orxonox.net
erwin at orxonox.net
Thu Apr 1 16:24:59 CEST 2010
Author: erwin
Date: 2010-04-01 16:24:59 +0200 (Thu, 01 Apr 2010)
New Revision: 6674
Modified:
code/branches/sound5/src/orxonox/sound/AmbientSound.cc
code/branches/sound5/src/orxonox/sound/AmbientSound.h
code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
Log:
A few new tries to fix the sound problem: no success
Modified: code/branches/sound5/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/sound5/src/orxonox/sound/AmbientSound.cc 2010-04-01 14:20:47 UTC (rev 6673)
+++ code/branches/sound5/src/orxonox/sound/AmbientSound.cc 2010-04-01 14:24:59 UTC (rev 6674)
@@ -193,4 +193,24 @@
BaseSound::doStop();
this->soundstreamthread_.interrupt();
}
+
+ void AmbientSound::doPlay()
+ {
+ BaseSound::doPlay();
+
+ if(GameMode::playsSound() && this->getSourceState() != AL_PLAYING)
+ {
+ if(!alIsSource(this->audioSource_))
+ {
+ this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
+ if(!alIsSource(this->audioSource_))
+ return;
+ this->initialiseSource();
+ }
+
+ alSourcePlay(this->audioSource_);
+ if(int error = alGetError())
+ COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
+ }
+ }
}
Modified: code/branches/sound5/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/sound5/src/orxonox/sound/AmbientSound.h 2010-04-01 14:20:47 UTC (rev 6673)
+++ code/branches/sound5/src/orxonox/sound/AmbientSound.h 2010-04-01 14:24:59 UTC (rev 6674)
@@ -73,6 +73,7 @@
~AmbientSound() { }
void doStop();
+ void doPlay();
private:
void preDestroy();
Modified: code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
===================================================================
--- code/branches/sound5/src/orxonox/sound/SoundStreamer.cc 2010-04-01 14:20:47 UTC (rev 6673)
+++ code/branches/sound5/src/orxonox/sound/SoundStreamer.cc 2010-04-01 14:24:59 UTC (rev 6674)
@@ -26,6 +26,7 @@
*/
#include "SoundStreamer.h"
+#include <boost/thread.hpp>
#include <al.h>
#include <alc.h>
#include <vorbis/vorbisfile.h>
@@ -41,6 +42,7 @@
void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream)
{
+ COUT(4) << "Sound: Creating thread for " << dataStream->getName() << std::endl;
// Open file with custom streaming
ov_callbacks vorbisCallbacks;
vorbisCallbacks.read_func = &readVorbis;
@@ -64,21 +66,21 @@
else
format = AL_FORMAT_STEREO16;
- char inbuffer[256*1024];
- ALuint initbuffers[4];
- alGenBuffers(4, initbuffers);
+ char inbuffer[4096];
+ ALuint initbuffers[20];
+ alGenBuffers(20, initbuffers);
if (ALint error = alGetError()) {
COUT(2) << "Sound: Streamer: Could not generate buffer:" << getALErrorString(error) << std::endl;
return;
}
int current_section;
- for(int i = 0; i < 4; i++)
+ for(int i = 0; i < 20; i++)
{
long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);
if (ret == 0)
{
- return;
+ break;
}
else if (ret < 0)
{
@@ -88,26 +90,35 @@
}
alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);
- alGetError();
+ if(ALint error = alGetError()) {
+ COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
+ break;
+ }
+ alSourceQueueBuffers(audioSource, 1, &initbuffers[i]);
+ if (ALint error = alGetError()) {
+ COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
+ }
+ COUT(4) << "Sound: " << ret << std::endl;
}
- alSourceQueueBuffers(audioSource, 4, initbuffers);
- if (ALint error = alGetError()) {
- COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
- }
while(true) // Stream forever, control through thread control
{
int processed;
- if(alcGetCurrentContext() == NULL)
- COUT(2) << "This should not be!" << std::endl;
+ if(alcGetCurrentContext() == NULL)
+ {
+ COUT(2) << "Sound: There is no context, terminating thread" << std::endl;
+ return;
+ }
alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed);
if (ALint error = alGetError())
- COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;
+ COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;
+ COUT(2) << "Sound: Blub: " << processed << std::endl;
if(processed > 0)
{
+ COUT(4) << "Sound: " << processed << std::endl;
ALuint* buffers = new ALuint[processed];
alSourceUnqueueBuffers(audioSource, processed, buffers);
if (ALint error = alGetError())
@@ -118,7 +129,7 @@
long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);
if (ret == 0)
{
- return;
+ break;
}
else if (ret < 0)
{
@@ -128,13 +139,23 @@
}
alBufferData(buffers[i], format, &inbuffer, ret, vorbisInfo->rate);
- alGetError();
+ if(ALint error = alGetError()) {
+ COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
+ break;
+ }
+ alSourceQueueBuffers(audioSource, 1, &buffers[i]);
+ if (ALint error = alGetError()) {
+ COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
+ }
}
-
- alSourceQueueBuffers(audioSource, processed, buffers);
- if (ALint error = alGetError())
- COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
}
+ try {
+ boost::this_thread::interruption_point();
+ }
+ catch(boost::thread_interrupted) {
+ COUT(4) << "Sound: Catched interruption. Terminating thread for " << dataStream->getName() << std::endl;
+ return;
+ }
msleep(100); // perhaps another value here is better
}
}
More information about the Orxonox-commit
mailing list