---<br> dlls/dsound/buffer.c |   74 +++++++++++--------------------------------------<br> 1 files changed, 17 insertions(+), 57 deletions(-)<br><br>diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c<br>index 0e9096a..e1e5428 100644<br>
--- a/dlls/dsound/buffer.c<br>+++ b/dlls/dsound/buffer.c<br>@@ -292,10 +292,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(<br>     oldFreq = This-&gt;freq;<br>     This-&gt;freq = freq;<br>     if (freq != oldFreq) {<br>
-        This-&gt;freqAdjust = ((DWORD64)This-&gt;freq &lt;&lt; DSOUND_FREQSHIFT) / This-&gt;device-&gt;pwfx-&gt;nSamplesPerSec;<br>-        This-&gt;nAvgBytesPerSec = freq * This-&gt;pwfx-&gt;nBlockAlign;<br>         DSOUND_RecalcFormat(This);<br>
-        DSOUND_MixToTemporary(This, 0, This-&gt;buflen, FALSE);<br>     }<br> <br>     RtlReleaseResource(&amp;This-&gt;lock);<br>@@ -316,7 +313,6 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Play(<br> <br>     This-&gt;playflags = flags;<br>
     if (This-&gt;state == STATE_STOPPED &amp;&amp; !This-&gt;hwbuf) {<br>-        This-&gt;leadin = TRUE;<br>         This-&gt;state = STATE_STARTING;<br>     } else if (This-&gt;state == STATE_STOPPING)<br>         This-&gt;state = STATE_PLAYING;<br>
@@ -393,7 +389,6 @@ static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)<br>         }<br>     }<br> <br>-    HeapFree(GetProcessHeap(), 0, This-&gt;tmp_buffer);<br>     HeapFree(GetProcessHeap(), 0, This-&gt;notifies);<br>
     HeapFree(GetProcessHeap(), 0, This-&gt;pwfx);<br>     HeapFree(GetProcessHeap(), 0, This);<br>@@ -418,7 +413,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(<br>             return hres;<br>         }<br>
     } else {<br>-        DWORD pos = This-&gt;sec_mixpos;<br>+        DWORD pos = This-&gt;inpos;<br> <br>         /* sanity */<br>         if (pos &gt;= This-&gt;buflen){<br>@@ -427,15 +422,15 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(<br>
         }<br> <br>         if (playpos)<br>-            *playpos = pos;<br>+        {<br>+            *playpos = pos - This-&gt;firdelay;<br>+            if ((INT)*playpos &lt; 0)<br>+                *playpos += This-&gt;buflen;<br>
+        }<br>+<br>         if (writepos)<br>             *writepos = pos;<br>     }<br>-    if (writepos &amp;&amp; This-&gt;state != STATE_STOPPED &amp;&amp; (!This-&gt;hwbuf || !(This-&gt;device-&gt;drvdesc.dwFlags &amp; DSDDESC_DONTNEEDWRITELEAD))) {<br>
-        /* apply the documented 10ms lead to writepos */<br>-        *writepos += This-&gt;writelead;<br>-        *writepos %= This-&gt;buflen;<br>-    }<br>     RtlReleaseResource(&amp;This-&gt;lock);<br> <br>     TRACE(&quot;playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n&quot;,<br>
@@ -569,7 +564,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(<br>     } else {<br>         if (writecursor+writebytes &lt;= This-&gt;buflen) {<br>             *(LPBYTE*)lplpaudioptr1 = This-&gt;buffer-&gt;memory+writecursor;<br>
-            if (This-&gt;sec_mixpos &gt;= writecursor &amp;&amp; This-&gt;sec_mixpos &lt; writecursor + writebytes &amp;&amp; This-&gt;state == STATE_PLAYING)<br>+            if (This-&gt;inpos &gt;= writecursor &amp;&amp; This-&gt;inpos &lt; writecursor + writebytes &amp;&amp; This-&gt;state == STATE_PLAYING)<br>
                 WARN(&quot;Overwriting mixing position, case 1\n&quot;);<br>             *audiobytes1 = writebytes;<br>             if (lplpaudioptr2)<br>@@ -583,13 +578,13 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(<br>
             DWORD remainder = writebytes + writecursor - This-&gt;buflen;<br>             *(LPBYTE*)lplpaudioptr1 = This-&gt;buffer-&gt;memory+writecursor;<br>             *audiobytes1 = This-&gt;buflen-writecursor;<br>-            if (This-&gt;sec_mixpos &gt;= writecursor &amp;&amp; This-&gt;sec_mixpos &lt; writecursor + writebytes &amp;&amp; This-&gt;state == STATE_PLAYING)<br>
+            if (This-&gt;inpos &gt;= writecursor &amp;&amp; This-&gt;inpos &lt; writecursor + writebytes &amp;&amp; This-&gt;state == STATE_PLAYING)<br>                 WARN(&quot;Overwriting mixing position, case 2\n&quot;);<br>
             if (lplpaudioptr2)<br>                 *(LPBYTE*)lplpaudioptr2 = This-&gt;buffer-&gt;memory;<br>             if (audiobytes2)<br>                 *audiobytes2 = writebytes-(This-&gt;buflen-writecursor);<br>-            if (audiobytes2 &amp;&amp; This-&gt;sec_mixpos &lt; remainder &amp;&amp; This-&gt;state == STATE_PLAYING)<br>
+            if (audiobytes2 &amp;&amp; This-&gt;inpos &lt; remainder &amp;&amp; This-&gt;state == STATE_PLAYING)<br>                 WARN(&quot;Overwriting mixing position, case 3\n&quot;);<br>             TRACE(&quot;Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n&quot;, *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);<br>
         }<br>@@ -612,25 +607,23 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(<br>     /* **** */<br>     RtlAcquireResourceExclusive(&amp;This-&gt;lock, TRUE);<br> <br>-    oldpos = This-&gt;sec_mixpos;<br>
+    oldpos = This-&gt;inpos;<br> <br>     /* start mixing from this new location instead */<br>     newpos %= This-&gt;buflen;<br>     newpos -= newpos%This-&gt;pwfx-&gt;nBlockAlign;<br>-    This-&gt;sec_mixpos = newpos;<br>
+    This-&gt;inpos = newpos;<br>+    This-&gt;infrac = 0;<br> <br>     /* at this point, do not attempt to reset buffers, mess with primary mix position,<br>            or anything like that to reduce latancy. The data already prebuffered cannot be changed */<br>
 <br>     /* position HW buffer if applicable, else just start mixing from new location instead */<br>     if (This-&gt;hwbuf) {<br>-        hres = IDsDriverBuffer_SetPosition(This-&gt;hwbuf, This-&gt;buf_mixpos);<br>+        hres = IDsDriverBuffer_SetPosition(This-&gt;hwbuf, DSOUND_secpos_to_bufpos(This, newpos));<br>
         if (hres != DS_OK)<br>             WARN(&quot;IDsDriverBuffer_SetPosition failed\n&quot;);<br>     }<br>-    else if (oldpos != newpos)<br>-        /* FIXME: Perhaps add a call to DSOUND_MixToTemporary here? Not sure it&#39;s needed */<br>
-        This-&gt;buf_mixpos = DSOUND_secpos_to_bufpos(This, newpos, 0, NULL);<br> <br>     RtlReleaseResource(&amp;This-&gt;lock);<br>     /* **** */<br>@@ -702,7 +695,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(<br>
 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(<br>     LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2<br> ) {<br>-    IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface, *iter;<br>+    IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;<br>
     HRESULT hres = DS_OK;<br> <br>     TRACE(&quot;(%p,%p,%d,%p,%d)\n&quot;, This,p1,x1,p2,x2);<br>@@ -719,29 +712,6 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(<br>     RtlReleaseResource(&amp;This-&gt;lock);<br>
     /* **** */<br> <br>-    if (!p2)<br>-        x2 = 0;<br>-<br>-    if (!This-&gt;hwbuf &amp;&amp; (x1 || x2))<br>-    {<br>-        RtlAcquireResourceShared(&amp;This-&gt;device-&gt;buffer_list_lock, TRUE);<br>-        LIST_FOR_EACH_ENTRY(iter, &amp;This-&gt;buffer-&gt;buffers, IDirectSoundBufferImpl, entry )<br>
-        {<br>-            RtlAcquireResourceShared(&amp;iter-&gt;lock, TRUE);<br>-            if (x1)<br>-                        {<br>-                if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter-&gt;buffer-&gt;memory &gt; iter-&gt;buflen)<br>
-                  hres = DSERR_INVALIDPARAM;<br>-                else<br>-                  DSOUND_MixToTemporary(iter, (DWORD_PTR)p1 - (DWORD_PTR)iter-&gt;buffer-&gt;memory, x1, FALSE);<br>-                        }<br>
-            if (x2)<br>-                DSOUND_MixToTemporary(iter, 0, x2, FALSE);<br>-            RtlReleaseResource(&amp;iter-&gt;lock);<br>-        }<br>-        RtlReleaseResource(&amp;This-&gt;device-&gt;buffer_list_lock);<br>
-    }<br>-<br>     return hres;<br> }<br> <br>@@ -1078,16 +1048,9 @@ HRESULT IDirectSoundBufferImpl_Create(<br>     list_add_head(&amp;dsb-&gt;buffer-&gt;buffers, &amp;dsb-&gt;entry);<br>     FillMemory(dsb-&gt;buffer-&gt;memory, dsb-&gt;buflen, dsbd-&gt;lpwfxFormat-&gt;wBitsPerSample == 8 ? 128 : 0);<br>
 <br>-    /* It&#39;s not necessary to initialize values to zero since */<br>-    /* we allocated this structure with HEAP_ZERO_MEMORY... */<br>-    dsb-&gt;buf_mixpos = dsb-&gt;sec_mixpos = 0;<br>     dsb-&gt;state = STATE_STOPPED;<br>
 <br>-    dsb-&gt;freqAdjust = ((DWORD64)dsb-&gt;freq &lt;&lt; DSOUND_FREQSHIFT) / device-&gt;pwfx-&gt;nSamplesPerSec;<br>-    dsb-&gt;nAvgBytesPerSec = dsb-&gt;freq *<br>-        dsbd-&gt;lpwfxFormat-&gt;nBlockAlign;<br>
-<br>-    /* calculate fragment size and write lead */<br>+    /* calculate new format values */<br>     DSOUND_RecalcFormat(dsb);<br> <br>     if (dsb-&gt;dsbd.dwFlags &amp; DSBCAPS_CTRL3D) {<br>@@ -1212,14 +1175,12 @@ HRESULT IDirectSoundBufferImpl_Duplicate(<br>
     list_add_head(&amp;dsb-&gt;buffer-&gt;buffers, &amp;dsb-&gt;entry);<br>     dsb-&gt;ref = 0;<br>     dsb-&gt;state = STATE_STOPPED;<br>-    dsb-&gt;buf_mixpos = dsb-&gt;sec_mixpos = 0;<br>+    dsb-&gt;inpos = dsb-&gt;infrac = 0;<br>
     dsb-&gt;device = device;<br>     dsb-&gt;ds3db = NULL;<br>     dsb-&gt;iks = NULL; /* FIXME? */<br>     dsb-&gt;secondary = NULL;<br>-    dsb-&gt;tmp_buffer = NULL;<br>     DSOUND_RecalcFormat(dsb);<br>-    DSOUND_MixToTemporary(dsb, 0, dsb-&gt;buflen, FALSE);<br>
 <br>     RtlInitializeResource(&amp;dsb-&gt;lock);<br> <br>@@ -1227,7 +1188,6 @@ HRESULT IDirectSoundBufferImpl_Duplicate(<br>     hres = DirectSoundDevice_AddBuffer(device, dsb);<br>     if (hres != DS_OK) {<br>         RtlDeleteResource(&amp;dsb-&gt;lock);<br>
-        HeapFree(GetProcessHeap(),0,dsb-&gt;tmp_buffer);<br>         list_remove(&amp;dsb-&gt;entry);<br>         dsb-&gt;buffer-&gt;ref--;<br>         HeapFree(GetProcessHeap(),0,dsb-&gt;pwfx);<br>-- <br>1.7.2.3<br><br>
<br>