[PATCH 1/3] xaudio2: Fix mmdevapi buffer size calculation

Andrew Eikum aeikum at codeweavers.com
Thu Sep 24 14:33:05 CDT 2015


Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
---
 dlls/xaudio2_7/xaudio_dll.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/dlls/xaudio2_7/xaudio_dll.c b/dlls/xaudio2_7/xaudio_dll.c
index ccbcd21..4f8c76b 100644
--- a/dlls/xaudio2_7/xaudio_dll.c
+++ b/dlls/xaudio2_7/xaudio_dll.c
@@ -1798,7 +1798,7 @@ static HRESULT WINAPI IXAudio2Impl_CreateMasteringVoice(IXAudio2 *iface,
     HRESULT hr;
     WAVEFORMATEX *fmt;
     ALCint attrs[7];
-    REFERENCE_TIME period;
+    REFERENCE_TIME period, bufdur;
 
     TRACE("(%p)->(%p, %u, %u, 0x%x, %s, %p, 0x%x)\n", This,
             ppMasteringVoice, inputChannels, inputSampleRate, flags,
@@ -1885,15 +1885,6 @@ static HRESULT WINAPI IXAudio2Impl_CreateMasteringVoice(IXAudio2 *iface,
 
     CoTaskMemFree(fmt);
 
-    hr = IAudioClient_Initialize(This->aclient, AUDCLNT_SHAREMODE_SHARED,
-            AUDCLNT_STREAMFLAGS_EVENTCALLBACK, inputSampleRate /* 1s buffer */,
-            0, &This->fmt.Format, NULL);
-    if(FAILED(hr)){
-        WARN("Initialize failed: %08x\n", hr);
-        hr = XAUDIO2_E_DEVICE_INVALIDATED;
-        goto exit;
-    }
-
     hr = IAudioClient_GetDevicePeriod(This->aclient, &period, NULL);
     if(FAILED(hr)){
         WARN("GetDevicePeriod failed: %08x\n", hr);
@@ -1901,6 +1892,18 @@ static HRESULT WINAPI IXAudio2Impl_CreateMasteringVoice(IXAudio2 *iface,
         goto exit;
     }
 
+    /* 3 periods or 0.1 seconds */
+    bufdur = max(3 * period, 1000000);
+
+    hr = IAudioClient_Initialize(This->aclient, AUDCLNT_SHAREMODE_SHARED,
+            AUDCLNT_STREAMFLAGS_EVENTCALLBACK, bufdur,
+            0, &This->fmt.Format, NULL);
+    if(FAILED(hr)){
+        WARN("Initialize failed: %08x\n", hr);
+        hr = XAUDIO2_E_DEVICE_INVALIDATED;
+        goto exit;
+    }
+
     This->period_frames = MulDiv(period, inputSampleRate, 10000000);
 
     hr = IAudioClient_SetEventHandle(This->aclient, This->mmevt);
-- 
2.5.3





More information about the wine-patches mailing list