From 71d0ae8cf108a7d7de8a7ea82525c6fc060b3187 Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Mon, 13 Aug 2012 21:11:28 +0200 Subject: [PATCH] dsound: Hack in low latency --- dlls/dsound/dsound_private.h | 4 ++-- dlls/dsound/primary.c | 35 +++++++++-------------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index be4079766dd..f838b87caaf 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -20,8 +20,8 @@ */ /* Linux does not support better timing than 10ms */ -#define DS_TIME_RES 2 /* Resolution of multimedia timer */ -#define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */ +#define DS_TIME_RES 1 /* Resolution of multimedia timer */ +#define DS_TIME_DEL 1 /* Delay of multimedia timer callback, and duration of HEL fragment */ #include "wingdi.h" #include "mmdeviceapi.h" diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index 8da12e2b561..5a2b0e736a8 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -40,29 +40,11 @@ WINE_DEFAULT_DEBUG_CHANNEL(dsound); -static DWORD DSOUND_fraglen(DirectSoundDevice *device) -{ - REFERENCE_TIME period; - HRESULT hr; - DWORD ret; - - hr = IAudioClient_GetDevicePeriod(device->client, &period, NULL); - if(FAILED(hr)){ - /* just guess at 10ms */ - WARN("GetDevicePeriod failed: %08x\n", hr); - ret = MulDiv(device->pwfx->nBlockAlign, device->pwfx->nSamplesPerSec, 100); - }else - ret = MulDiv(device->pwfx->nSamplesPerSec * device->pwfx->nBlockAlign, period, 10000000); - - ret -= ret % device->pwfx->nBlockAlign; - return ret; -} - HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) { - UINT prebuf_frames; - REFERENCE_TIME prebuf_rt; HRESULT hres; + REFERENCE_TIME period; + UINT32 frames; TRACE("(%p, %d)\n", device, forcewave); @@ -90,12 +72,9 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) return hres; } - prebuf_frames = device->prebuf * DSOUND_fraglen(device) / device->pwfx->nBlockAlign; - prebuf_rt = (10000000 * (UINT64)prebuf_frames) / device->pwfx->nSamplesPerSec; - hres = IAudioClient_Initialize(device->client, AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST, - prebuf_rt, 0, device->pwfx, NULL); + 200000, 0, device->pwfx, NULL); if(FAILED(hres)){ IAudioClient_Release(device->client); device->client = NULL; @@ -136,6 +115,12 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) return hres; } + IAudioClient_GetStreamLatency(device->client, &period); + IAudioClient_GetBufferSize(device->client, &frames); + device->fraglen = MulDiv(device->pwfx->nSamplesPerSec, period, 10000000) * device->pwfx->nBlockAlign; + device->prebuf = frames * device->pwfx->nBlockAlign / device->fraglen; + TRACE("period %Lu fraglen %u prebuf %u\n", period, device->fraglen, device->prebuf); + return S_OK; } @@ -145,8 +130,6 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) TRACE("(%p)\n", device); - device->fraglen = DSOUND_fraglen(device); - /* on original windows, the buffer it set to a fixed size, no matter what the settings are. on windows this size is always fixed (tested on win-xp) */ if (!device->buflen) -- 2.11.4.GIT