From: Andrew Eikum <aeikum@codeweavers.com>
Subject: [PATCH] dsound: Request a more exact buffer size from MMDevAPI
Message-Id: <20111012201004.GI409@foghorn.codeweavers.com>
Date: Wed, 12 Oct 2011 15:10:04 -0500

---
 dlls/dsound/primary.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c
index 7243cc6..9155634 100644
--- a/dlls/dsound/primary.c
+++ b/dlls/dsound/primary.c
@@ -84,6 +84,8 @@ static void DSOUND_RecalcPrimary(DirectSoundDevice *device)
 
 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
 {
+    UINT prebuf_frames;
+    REFERENCE_TIME prebuf_rt;
     HRESULT hres;
 
     TRACE("(%p, %d)\n", device, forcewave);
@@ -112,10 +114,11 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
         return hres;
     }
 
-    /* buffer size = 200 * 100000 (100 ns) = 2.0 seconds */
+    prebuf_frames = device->prebuf * DSOUND_fraglen(device->pwfx->nSamplesPerSec, device->pwfx->nBlockAlign) / device->pwfx->nBlockAlign;
+    prebuf_rt = (prebuf_frames / (double)device->pwfx->nSamplesPerSec) * 10000000;
     hres = IAudioClient_Initialize(device->client,
             AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST,
-            200 * 100000, 50000, device->pwfx, NULL);
+            prebuf_rt, 50000, device->pwfx, NULL);
     if(FAILED(hres)){
         IAudioClient_Release(device->client);
         device->client = NULL;