---<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->freq;<br> This->freq = freq;<br> if (freq != oldFreq) {<br>
- This->freqAdjust = ((DWORD64)This->freq << DSOUND_FREQSHIFT) / This->device->pwfx->nSamplesPerSec;<br>- This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;<br> DSOUND_RecalcFormat(This);<br>
- DSOUND_MixToTemporary(This, 0, This->buflen, FALSE);<br> }<br> <br> RtlReleaseResource(&This->lock);<br>@@ -316,7 +313,6 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Play(<br> <br> This->playflags = flags;<br>
if (This->state == STATE_STOPPED && !This->hwbuf) {<br>- This->leadin = TRUE;<br> This->state = STATE_STARTING;<br> } else if (This->state == STATE_STOPPING)<br> This->state = STATE_PLAYING;<br>
@@ -393,7 +389,6 @@ static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)<br> }<br> }<br> <br>- HeapFree(GetProcessHeap(), 0, This->tmp_buffer);<br> HeapFree(GetProcessHeap(), 0, This->notifies);<br>
HeapFree(GetProcessHeap(), 0, This->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->sec_mixpos;<br>+ DWORD pos = This->inpos;<br> <br> /* sanity */<br> if (pos >= This->buflen){<br>@@ -427,15 +422,15 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(<br>
}<br> <br> if (playpos)<br>- *playpos = pos;<br>+ {<br>+ *playpos = pos - This->firdelay;<br>+ if ((INT)*playpos < 0)<br>+ *playpos += This->buflen;<br>
+ }<br>+<br> if (writepos)<br> *writepos = pos;<br> }<br>- if (writepos && This->state != STATE_STOPPED && (!This->hwbuf || !(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDWRITELEAD))) {<br>
- /* apply the documented 10ms lead to writepos */<br>- *writepos += This->writelead;<br>- *writepos %= This->buflen;<br>- }<br> RtlReleaseResource(&This->lock);<br> <br> TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n",<br>
@@ -569,7 +564,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(<br> } else {<br> if (writecursor+writebytes <= This->buflen) {<br> *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;<br>
- if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)<br>+ if (This->inpos >= writecursor && This->inpos < writecursor + writebytes && This->state == STATE_PLAYING)<br>
WARN("Overwriting mixing position, case 1\n");<br> *audiobytes1 = writebytes;<br> if (lplpaudioptr2)<br>@@ -583,13 +578,13 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(<br>
DWORD remainder = writebytes + writecursor - This->buflen;<br> *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;<br> *audiobytes1 = This->buflen-writecursor;<br>- if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)<br>
+ if (This->inpos >= writecursor && This->inpos < writecursor + writebytes && This->state == STATE_PLAYING)<br> WARN("Overwriting mixing position, case 2\n");<br>
if (lplpaudioptr2)<br> *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;<br> if (audiobytes2)<br> *audiobytes2 = writebytes-(This->buflen-writecursor);<br>- if (audiobytes2 && This->sec_mixpos < remainder && This->state == STATE_PLAYING)<br>
+ if (audiobytes2 && This->inpos < remainder && This->state == STATE_PLAYING)<br> WARN("Overwriting mixing position, case 3\n");<br> TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(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(&This->lock, TRUE);<br> <br>- oldpos = This->sec_mixpos;<br>
+ oldpos = This->inpos;<br> <br> /* start mixing from this new location instead */<br> newpos %= This->buflen;<br> newpos -= newpos%This->pwfx->nBlockAlign;<br>- This->sec_mixpos = newpos;<br>
+ This->inpos = newpos;<br>+ This->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->hwbuf) {<br>- hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);<br>+ hres = IDsDriverBuffer_SetPosition(This->hwbuf, DSOUND_secpos_to_bufpos(This, newpos));<br>
if (hres != DS_OK)<br> WARN("IDsDriverBuffer_SetPosition failed\n");<br> }<br>- else if (oldpos != newpos)<br>- /* FIXME: Perhaps add a call to DSOUND_MixToTemporary here? Not sure it's needed */<br>
- This->buf_mixpos = DSOUND_secpos_to_bufpos(This, newpos, 0, NULL);<br> <br> RtlReleaseResource(&This->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("(%p,%p,%d,%p,%d)\n", This,p1,x1,p2,x2);<br>@@ -719,29 +712,6 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(<br> RtlReleaseResource(&This->lock);<br>
/* **** */<br> <br>- if (!p2)<br>- x2 = 0;<br>-<br>- if (!This->hwbuf && (x1 || x2))<br>- {<br>- RtlAcquireResourceShared(&This->device->buffer_list_lock, TRUE);<br>- LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers, IDirectSoundBufferImpl, entry )<br>
- {<br>- RtlAcquireResourceShared(&iter->lock, TRUE);<br>- if (x1)<br>- {<br>- if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen)<br>
- hres = DSERR_INVALIDPARAM;<br>- else<br>- DSOUND_MixToTemporary(iter, (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory, x1, FALSE);<br>- }<br>
- if (x2)<br>- DSOUND_MixToTemporary(iter, 0, x2, FALSE);<br>- RtlReleaseResource(&iter->lock);<br>- }<br>- RtlReleaseResource(&This->device->buffer_list_lock);<br>
- }<br>-<br> return hres;<br> }<br> <br>@@ -1078,16 +1048,9 @@ HRESULT IDirectSoundBufferImpl_Create(<br> list_add_head(&dsb->buffer->buffers, &dsb->entry);<br> FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);<br>
<br>- /* It's not necessary to initialize values to zero since */<br>- /* we allocated this structure with HEAP_ZERO_MEMORY... */<br>- dsb->buf_mixpos = dsb->sec_mixpos = 0;<br> dsb->state = STATE_STOPPED;<br>
<br>- dsb->freqAdjust = ((DWORD64)dsb->freq << DSOUND_FREQSHIFT) / device->pwfx->nSamplesPerSec;<br>- dsb->nAvgBytesPerSec = dsb->freq *<br>- dsbd->lpwfxFormat->nBlockAlign;<br>
-<br>- /* calculate fragment size and write lead */<br>+ /* calculate new format values */<br> DSOUND_RecalcFormat(dsb);<br> <br> if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {<br>@@ -1212,14 +1175,12 @@ HRESULT IDirectSoundBufferImpl_Duplicate(<br>
list_add_head(&dsb->buffer->buffers, &dsb->entry);<br> dsb->ref = 0;<br> dsb->state = STATE_STOPPED;<br>- dsb->buf_mixpos = dsb->sec_mixpos = 0;<br>+ dsb->inpos = dsb->infrac = 0;<br>
dsb->device = device;<br> dsb->ds3db = NULL;<br> dsb->iks = NULL; /* FIXME? */<br> dsb->secondary = NULL;<br>- dsb->tmp_buffer = NULL;<br> DSOUND_RecalcFormat(dsb);<br>- DSOUND_MixToTemporary(dsb, 0, dsb->buflen, FALSE);<br>
<br> RtlInitializeResource(&dsb->lock);<br> <br>@@ -1227,7 +1188,6 @@ HRESULT IDirectSoundBufferImpl_Duplicate(<br> hres = DirectSoundDevice_AddBuffer(device, dsb);<br> if (hres != DS_OK) {<br> RtlDeleteResource(&dsb->lock);<br>
- HeapFree(GetProcessHeap(),0,dsb->tmp_buffer);<br> list_remove(&dsb->entry);<br> dsb->buffer->ref--;<br> HeapFree(GetProcessHeap(),0,dsb->pwfx);<br>-- <br>1.7.2.3<br><br>
<br>