quartz: Don't fill the dsound buffer with small amounts

Chris Robinson chris.kcat at gmail.com
Fri Mar 30 06:03:04 CDT 2007


A discussion on IRC brought up the point that filling the buffer by really 
small amounts is less CPU efficient than needed, especially where the 
critical sections are concerned. This also helps clean up the loop.
-------------- next part --------------
From 1f23648350d642fe1f63868509578795b2cd507b Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat at gmail.com>
Date: Fri, 30 Mar 2007 03:13:54 -0700
Subject: [PATCH] quartz: Don't fill the dsound buffer with small amounts

---
 dlls/quartz/dsoundrender.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/dlls/quartz/dsoundrender.c b/dlls/quartz/dsoundrender.c
index 259a25b..23c522d 100644
--- a/dlls/quartz/dsoundrender.c
+++ b/dlls/quartz/dsoundrender.c
@@ -203,13 +203,13 @@ static HRESULT DSoundRender_SendSampleData(DSoundRenderImpl* This, LPBYTE data,
             ERR("Error GetCurrentPosition: %x\n", hr);
             break;
         }
-        if (This->write_pos < play_pos)
+        if (This->write_pos <= play_pos)
              buf_free = play_pos-This->write_pos;
         else
              buf_free = DSBUFFERSIZE - This->write_pos + play_pos;
 
-        /* This situation is ambiguous; Assume full when playing */
-        if(buf_free == DSBUFFERSIZE)
+        /* Wait for enough of the buffer to empty before filling it */
+        if(buf_free < DSBUFFERSIZE/4)
         {
             Sleep(10);
             continue;
@@ -234,11 +234,7 @@ static HRESULT DSoundRender_SendSampleData(DSoundRenderImpl* This, LPBYTE data,
         size -= dwsize1 + dwsize2;
         data += dwsize1 + dwsize2;
         This->write_pos = (This->write_pos + dwsize1 + dwsize2) % DSBUFFERSIZE;
-
-        if (!size)
-            break;
-        Sleep(10);
-    } while (This->state == State_Running);
+    } while (size && This->state == State_Running);
 
     return hr;
 }
-- 
1.4.4.4



More information about the wine-patches mailing list