From 262abc1d8daf243cf295c060ff4c47f93dcdbe2f Mon Sep 17 00:00:00 2001
From: Andrew Eikum <aeikum@codeweavers.com>
Date: Tue, 4 Sep 2018 13:40:58 -0500
Subject: [PATCH 1/3] winepulse: account for PA devices that fall way behind
To: wine-devel <wine-devel@winehq.org>
Reply-To: wine-devel <wine-devel@winehq.org>,Andrew Eikum <aeikum@codeweavers.com>

---
 dlls/winepulse.drv/mmdevdrv.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c
index 1ce6cea9d6..6b994ada4e 100644
--- a/dlls/winepulse.drv/mmdevdrv.c
+++ b/dlls/winepulse.drv/mmdevdrv.c
@@ -980,6 +980,9 @@ static void pulse_underflow_callback(pa_stream *s, void *userdata)
     ACImpl *This = userdata;
     WARN("%p: Underflow\n", userdata);
     This->just_underran = TRUE;
+    /* re-sync */
+    This->pa_offs_bytes = This->lcl_offs_bytes;
+    This->pa_held_bytes = This->held_bytes;
 }
 
 static void pulse_started_callback(pa_stream *s, void *userdata)
@@ -2524,6 +2527,11 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
 
     This->held_bytes += written_bytes;
     This->pa_held_bytes += written_bytes;
+    if(This->pa_held_bytes > This->real_bufsize_bytes){
+        This->pa_offs_bytes += This->pa_held_bytes - This->real_bufsize_bytes;
+        This->pa_offs_bytes %= This->real_bufsize_bytes;
+        This->pa_held_bytes = This->real_bufsize_bytes;
+    }
     This->clock_written += written_bytes;
     This->locked = 0;
 
-- 
2.19.2

