From 92dde81296778ba9d8a58777c0de192f14e45387 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 4 Nov 2012 08:35:39 -0800 Subject: Add rudimentary latency tracking for mmdevapi This won't be as granular as it could be, since it only updates when the wakeup event trips (which may or may not happen more often than OpenAL's mix updates). A more correct method would be to query GetCurrentPadding directly, but that would require sending a message to the processing thread and waiting for a reply, since we can't guarantee COM on the calling thread. --- Alc/backends/mmdevapi.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'Alc/backends') diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index 24314164..9db83003 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -66,6 +66,8 @@ typedef struct { HANDLE MsgEvent; + volatile UINT32 Padding; + volatile int killNow; ALvoid *thread; } MMDevApiData; @@ -252,6 +254,7 @@ static ALuint MMDevApiProc(ALvoid *ptr) aluHandleDisconnect(device); break; } + data->Padding = written; len = buffer_len - written; if(len < update_size) @@ -267,7 +270,10 @@ static ALuint MMDevApiProc(ALvoid *ptr) hr = IAudioRenderClient_GetBuffer(data->render, len, &buffer); if(SUCCEEDED(hr)) { + ALCdevice_Lock(device); aluMixData(device, buffer, len); + data->Padding = written + len; + ALCdevice_Unlock(device); hr = IAudioRenderClient_ReleaseBuffer(data->render, len, 0); } if(FAILED(hr)) @@ -277,6 +283,7 @@ static ALuint MMDevApiProc(ALvoid *ptr) break; } } + data->Padding = 0; CoUninitialize(); return 0; @@ -936,6 +943,14 @@ static void MMDevApiStopPlayback(ALCdevice *device) } +static ALint64 MMDevApiGetLatency(ALCdevice *device) +{ + MMDevApiData *data = device->ExtraData; + + return (ALint64)data->Padding * 1000000000 / device->Frequency; +} + + static const BackendFuncs MMDevApiFuncs = { MMDevApiOpenPlayback, MMDevApiClosePlayback, @@ -950,7 +965,7 @@ static const BackendFuncs MMDevApiFuncs = { NULL, ALCdevice_LockDefault, ALCdevice_UnlockDefault, - ALCdevice_GetLatencyDefault + MMDevApiGetLatency }; -- cgit v1.2.3