From 8f82dc92aa288659284b46ed4c233970fbd28903 Mon Sep 17 00:00:00 2001 From: LAGonauta Date: Wed, 28 Mar 2018 11:09:19 -0300 Subject: ao/openal: Add OpenAL Soft extension to get the correct latency OpenAL Soft's AL_SOFT_source_latency extension allows one to correctly get the device output latency, facilitating the syncronization with video. Also added a simpler generic fallback that does not take into account latency of the device. --- audio/out/ao_openal.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'audio/out/ao_openal.c') diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c index ab61c80763..c23fd27b90 100644 --- a/audio/out/ao_openal.c +++ b/audio/out/ao_openal.c @@ -435,7 +435,22 @@ static double get_delay(struct ao *ao) ALint queued; unqueue_buffers(); alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); - return queued * CHUNK_SAMPLES / (double)ao->samplerate; + + double soft_source_latency = 0; + if(alIsExtensionPresent("AL_SOFT_source_latency")) { + ALdouble offsets[2]; + LPALGETSOURCEDVSOFT alGetSourcedvSOFT = alGetProcAddress("alGetSourcedvSOFT"); + alGetSourcedvSOFT(source, AL_SEC_OFFSET_LATENCY_SOFT, offsets); + // Additional latency to the play buffer, the remaining seconds to be + // played minus the offset (seconds already played) + soft_source_latency = offsets[1] - offsets[0]; + } else { + float offset = 0; + alGetSourcef(source, AL_SEC_OFFSET, &offset); + soft_source_latency = -offset; + } + + return (queued * CHUNK_SAMPLES / (double)ao->samplerate) + soft_source_latency; } #define OPT_BASE_STRUCT struct priv -- cgit v1.2.3