2
votes

I am trying to create a webcam chat program in C++, and while I have been able to get the images to be captured sent and played, I am having trouble with doing the same with the audio: the audio lags and very quickly goes out of sync with the video, even when I just played it to myself.

I found this answer and sample code to be really useful.

Are there any modifications I can make to this code to get it to be nearly lag free, or is OpenAL not right for this? I am using Windows, but I plan on making a linux version later.

1
Can you post the actual code you are currently using please? (Or is it literally a verbatim copy of the code in the linked post?)RJFalconer
"lag" - Does the audio stutter, or is it just delayed?RJFalconer
With the settings from the link, it's delayedryco117

1 Answers

0
votes

From the code linked:

ALCdevice* inputDevice = alcCaptureOpenDevice(NULL,FREQ,AL_FORMAT_MONO16,FREQ/2);

Try using a larger buffer:

ALCdevice* inputDevice = alcCaptureOpenDevice(NULL,FREQ,AL_FORMAT_MONO16,FREQ*4);

The polling is very aggressive. Try sleeping in the loop:

while (!done) {
    ...
}

To:

int sleepSeconds = 1;
while (!done) {
    ...
    Sleep(sleepSeconds/10) //windows, miliseconds
    //sleep(sleepSeconds) //linux, seconds
}