diff options
author | Chris Robinson <[email protected]> | 2012-11-04 08:35:39 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-11-04 08:35:39 -0800 |
commit | 92dde81296778ba9d8a58777c0de192f14e45387 (patch) | |
tree | 3f4f537966858024db34fc669c2dbeb0612ed8f0 /Alc | |
parent | e2368eb960ba1a43f365103a69e03803b8171731 (diff) |
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.
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/backends/mmdevapi.c | 17 |
1 files changed, 16 insertions, 1 deletions
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 }; |