From 2448f88e70f6207ad5743f0a55eaa5de7cbce737 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 18 Feb 2017 16:55:48 -0800 Subject: Return some device latency by default A device will never have 0 latency. OpenAL Soft itself uses a sample buffer length of UpdateSize*NumUpdates, and during playback will have about (NumUpdates-1) periods filled, more or less. Without a more accurate measurement from the playback system, this is better than reporting 0. --- Alc/backends/base.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Alc') diff --git a/Alc/backends/base.c b/Alc/backends/base.c index ff808f53..e4305653 100644 --- a/Alc/backends/base.c +++ b/Alc/backends/base.c @@ -4,6 +4,7 @@ #include #include "alMain.h" +#include "alu.h" #include "backends/base.h" @@ -45,8 +46,12 @@ ClockLatency ALCbackend_getClockLatency(ALCbackend *self) almtx_lock(&self->mMutex); ret.ClockTime = GetDeviceClockTime(device); - // TODO: Perhaps should be NumUpdates-1 worth of UpdateSize? - ret.Latency = 0; + /* NOTE: The device will generally have about all but one periods filled at + * any given time during playback. Without a more accurate measurement from + * the output, this is an okay approximation. + */ + ret.Latency = device->UpdateSize * DEVICE_CLOCK_RES / device->Frequency * + maxu(device->NumUpdates-1, 1); almtx_unlock(&self->mMutex); return ret; -- cgit v1.2.3