aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-02-18 16:55:48 -0800
committerChris Robinson <[email protected]>2017-02-18 16:55:48 -0800
commit2448f88e70f6207ad5743f0a55eaa5de7cbce737 (patch)
tree135d60ee0a486d70ab5482011041d4a363c78537 /Alc
parentd8c42918f46e2439c81c4d4562df8fa7ad2e01fd (diff)
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.
Diffstat (limited to 'Alc')
-rw-r--r--Alc/backends/base.c9
1 files changed, 7 insertions, 2 deletions
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 <stdlib.h>
#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;