Re: OpenAL for voicechat

Daniel PEACOCK <[email protected]>
Newsgroups gmane.comp.lib.openal
Message-ID <OFE78170F7.F0115C30-ON802576B7.00341D85-802576B7.00352A5E@cli.creaf.com>



Hi Peter,

I think you should probably change ...

> 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);
> }

to

while (processed) // while there are processed buffers
{
    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);
    processed--;
}

(You will need to have more data to fill each buffer of course)

What values are using for the Buffer Size ( voice_Bufsize ) and sample-rate
( voice_SamplesPerSecond ) ?

> 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).

It would be helpful to know if OpenAL is being starved of data.  You can
detect this by adding a check after this statement ...

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

if (processed == outputBuffer_nBufs)
      print("Ooops - AL ran out of data");

Dan
Creative Labs (UK) Ltd.

Notice
The information in this message is confidential and may be legally
privileged.  It is intended solely for the addressee.  Access to this
message by anyone else is unauthorized.  If you are not the intended
recipient,  any disclosure,  copying or distribution of the message,  or
any action taken by you in reliance on it,  is prohibited and may be
unlawful.  If you have received this message in error,  please delete it
and contact the sender immediately.  Thank you.

Creative Labs UK Ltd company number 2658256 registered in England and Wales
at 79 Knightsbridge, London SW1X 7RB


[email protected] wrote on 01/25/2010 09:36:05 PM:

> 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

> ForwardSourceID:NT00079396


_______________________________________________
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.