OpenAL for voicechat

"Peter Soxberger" <[email protected]>
Newsgroups gmane.comp.lib.openal
Message-ID <[email protected]>
Hi!

I'm using OpenAL for the output of a voicechat. It works great with 2 participants that talk to each other (=> only one stream is received per client). If a 3rd client connects and sends his stream (=> 2 streams are received per client) the final result is that both streams are played somehow cut (it's difficult to explain).

The technical stuff:
I'm using one source per received stream and each source uses a buffer queue with 4 buffers assigned. The stream is sent with udp over lan (100 Mbit => the problem is not caused by latency). I'm using OpenAL 1.1.

Ok, first of all I thought the packets aren't received correct anymore after the 3rd client connects. But then I wrote a [ms] timestamp into a logfile everytime I received a packat and they are still coming correctly.

=> The problem must be the output code somehow. Maybe I missed something so that the sources aren't correctly mixed together or something.

Here the important OpenAL code:
//------------------------------------------------------------
//Initializes OpenAL:
////////////////////////
pOutputDevice = alcOpenDevice(NULL); //Get handle to device
pOutputContext = alcCreateContext(pOutputDevice, NULL); //Create audio context
alcMakeContextCurrent(pOutputContext); //Set active context
if(alcGetError(pOutputDevice) != ALC_NO_ERROR) //Do an error check
{
	closesocket(voice_clientsock);
	voice_clientsock = 0;
	waveInClose(voice_recHandle);
	return _VAR(-1);
}
alGetError(); //Clear the bit

//Initializes the Listener:
ALfloat ListenerPos[] = {0.0, 0.0, 0.0};
ALfloat ListenerVel[] = {0.0, 0.0, 0.0};
ALfloat ListenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0};
alListenerfv(AL_POSITION, ListenerPos);
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);

//Initializes a OpenAL Source:
soundsOut_current->next = 0;
soundsOut_current->radioid = radioid;
soundsOut_current->clientid = sender_clientid;
//Create the buffers for playing the sound
alGenBuffers(outputBuffer_nBufs, soundsOut_current->buffers);
if (alGetError() != AL_NO_ERROR) return 0;

//Initialize all Buffers
for(int i=0;i<outputBuffer_nBufs;i++) alBufferData(soundsOut_current->buffers[i], AL_FORMAT_MONO16, decoded_buffer, voice_Bufsize, voice_SamplesPerSecond);

//Generate the sound source
alGenSources(1, &soundsOut_current->source);
if(alGetError() != AL_NO_ERROR) return 0;

//Inizializes the Bufferqueue
alSourceQueueBuffers(soundsOut_current->source, outputBuffer_nBufs, soundsOut_current->buffers);
alSourcef(soundsOut_current->source, AL_PITCH, 1.0f);
alSourcef(soundsOut_current->source, AL_GAIN, 1.0f);
//Create a normal 2D Sound
alSource3f(soundsOut_current->source, AL_POSITION, 0.0, 0.0, 0.0);
alSource3f(soundsOut_current->source, AL_VELOCITY, 0.0, 0.0, 0.0);
alSourcei(soundsOut_current->source, AL_SOURCE_RELATIVE, AL_TRUE);
alSourcei(soundsOut_current->source, AL_LOOPING, AL_FALSE);


//Updates the buffers everytime a packet is received:
//////////////////////////////////////////////////////

ALint processed, state;
alGetSourcei(soundsOut_current->source, AL_SOURCE_STATE, &state);
alGetSourcei(soundsOut_current->source, AL_BUFFERS_PROCESSED, &processed);

if(processed > 0) //If there is a free buffer
{
	ALuint buffer;
	alSourceUnqueueBuffers(soundsOut_current->source, 1, &buffer);
	//Fill the buffer with the received data
	alBufferData(buffer, AL_FORMAT_MONO16, decoded_buffer, voice_Bufsize, voice_SamplesPerSecond);
        alSourceQueueBuffers(soundsOut_current->source, 1, &buffer);
}
// Restart in case we didn't get more data in time
if(state != AL_PLAYING) alSourcePlay(soundsOut_current->source);

//--------------------------------------------------------------


Any ideas? I'm really getting stuck at this bug. I tested every possible reason of this problem with no success.

Thanks for your help!

Best regards,
Peter Soxberger

-- 
Nur noch bis 31.01.2010: DSL-Komplettpaket für 16,99 Euro/mtl.!*
http://portal.gmx.net/de/go/dsl02
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.