简体   繁体   中英

Syncing audio and video playback with OpenAL & C++

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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM