From: Andrew Eikum Subject: [PATCH 1/3] xaudio2: Fix mmdevapi buffer size calculation Message-Id: <20150924193305.GH7912@foghorn.codeweavers.com> Date: Thu, 24 Sep 2015 14:33:05 -0500 Signed-off-by: Andrew Eikum --- 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