1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-17 12:25:03 +00:00

ao_wasapi: Use double math for QueryPerformanceCounter correction

The uint64_t math would cause overflow at long enough system uptimes
(...such as 3 days), and any precision error given by the double math will
be under one milisecond.
This commit is contained in:
Diogo Franco (Kovensky) 2014-03-09 17:52:53 -03:00
parent a84e25eb59
commit 5c9c81efcc

View File

@ -1381,9 +1381,9 @@ static float get_device_delay(struct wasapi_state *state) {
LARGE_INTEGER qpc_count;
QueryPerformanceCounter(&qpc_count);
UINT64 qpc_diff = (qpc_count.QuadPart * 10000000 / state->qpc_frequency.QuadPart) - qpc_position;
double qpc_diff = (qpc_count.QuadPart * 1e7 / state->qpc_frequency.QuadPart) - qpc_position;
position += state->clock_frequency * qpc_diff / 10000000;
position += state->clock_frequency * (uint64_t)(qpc_diff / 1e7);
/* convert position to the same base as sample_count */
position = position * state->format.Format.nSamplesPerSec / state->clock_frequency;