[PATCH 09/13] dsound: New resampler--removed some old conflicting code and added a bit of new one (renamed vars etc.) (resend)

Krzysztof Nikiel knik00 at gmail.com
Fri Feb 11 05:47:42 CST 2011


---
 dlls/dsound/buffer.c |   74 +++++++++++--------------------------------------
 1 files changed, 17 insertions(+), 57 deletions(-)

diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c
index 0e9096a..e1e5428 100644
--- a/dlls/dsound/buffer.c
+++ b/dlls/dsound/buffer.c
@@ -292,10 +292,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
 	oldFreq = This->freq;
 	This->freq = freq;
 	if (freq != oldFreq) {
-		This->freqAdjust = ((DWORD64)This->freq << DSOUND_FREQSHIFT) /
This->device->pwfx->nSamplesPerSec;
-		This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;
 		DSOUND_RecalcFormat(This);
-		DSOUND_MixToTemporary(This, 0, This->buflen, FALSE);
 	}

 	RtlReleaseResource(&This->lock);
@@ -316,7 +313,6 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Play(

 	This->playflags = flags;
 	if (This->state == STATE_STOPPED && !This->hwbuf) {
-		This->leadin = TRUE;
 		This->state = STATE_STARTING;
 	} else if (This->state == STATE_STOPPING)
 		This->state = STATE_PLAYING;
@@ -393,7 +389,6 @@ static ULONG WINAPI
IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
 		}
 	}

-	HeapFree(GetProcessHeap(), 0, This->tmp_buffer);
 	HeapFree(GetProcessHeap(), 0, This->notifies);
 	HeapFree(GetProcessHeap(), 0, This->pwfx);
 	HeapFree(GetProcessHeap(), 0, This);
@@ -418,7 +413,7 @@ static HRESULT WINAPI
IDirectSoundBufferImpl_GetCurrentPosition(
 		    return hres;
 		}
 	} else {
-		DWORD pos = This->sec_mixpos;
+		DWORD pos = This->inpos;

 		/* sanity */
 		if (pos >= This->buflen){
@@ -427,15 +422,15 @@ static HRESULT WINAPI
IDirectSoundBufferImpl_GetCurrentPosition(
 		}

 		if (playpos)
-			*playpos = pos;
+		{
+			*playpos = pos - This->firdelay;
+			if ((INT)*playpos < 0)
+				*playpos += This->buflen;
+		}
+
 		if (writepos)
 			*writepos = pos;
 	}
-	if (writepos && This->state != STATE_STOPPED && (!This->hwbuf ||
!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDWRITELEAD))) {
-		/* apply the documented 10ms lead to writepos */
-		*writepos += This->writelead;
-		*writepos %= This->buflen;
-	}
 	RtlReleaseResource(&This->lock);

 	TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n",
@@ -569,7 +564,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
 	} else {
 		if (writecursor+writebytes <= This->buflen) {
 			*(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
-			if (This->sec_mixpos >= writecursor && This->sec_mixpos <
writecursor + writebytes && This->state == STATE_PLAYING)
+			if (This->inpos >= writecursor && This->inpos < writecursor +
writebytes && This->state == STATE_PLAYING)
 				WARN("Overwriting mixing position, case 1\n");
 			*audiobytes1 = writebytes;
 			if (lplpaudioptr2)
@@ -583,13 +578,13 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
 			DWORD remainder = writebytes + writecursor - This->buflen;
 			*(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
 			*audiobytes1 = This->buflen-writecursor;
-			if (This->sec_mixpos >= writecursor && This->sec_mixpos <
writecursor + writebytes && This->state == STATE_PLAYING)
+			if (This->inpos >= writecursor && This->inpos < writecursor +
writebytes && This->state == STATE_PLAYING)
 				WARN("Overwriting mixing position, case 2\n");
 			if (lplpaudioptr2)
 				*(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
 			if (audiobytes2)
 				*audiobytes2 = writebytes-(This->buflen-writecursor);
-			if (audiobytes2 && This->sec_mixpos < remainder && This->state ==
STATE_PLAYING)
+			if (audiobytes2 && This->inpos < remainder && This->state == STATE_PLAYING)
 				WARN("Overwriting mixing position, case 3\n");
 			TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n",
*(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ?
*(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0,
writecursor);
 		}
@@ -612,25 +607,23 @@ static HRESULT WINAPI
IDirectSoundBufferImpl_SetCurrentPosition(
 	/* **** */
 	RtlAcquireResourceExclusive(&This->lock, TRUE);

-	oldpos = This->sec_mixpos;
+	oldpos = This->inpos;

 	/* start mixing from this new location instead */
 	newpos %= This->buflen;
 	newpos -= newpos%This->pwfx->nBlockAlign;
-	This->sec_mixpos = newpos;
+	This->inpos = newpos;
+	This->infrac = 0;

 	/* at this point, do not attempt to reset buffers, mess with primary
mix position,
            or anything like that to reduce latancy. The data already
prebuffered cannot be changed */

 	/* position HW buffer if applicable, else just start mixing from new
location instead */
 	if (This->hwbuf) {
-		hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
+		hres = IDsDriverBuffer_SetPosition(This->hwbuf,
DSOUND_secpos_to_bufpos(This, newpos));
 		if (hres != DS_OK)
 			WARN("IDsDriverBuffer_SetPosition failed\n");
 	}
-	else if (oldpos != newpos)
-		/* FIXME: Perhaps add a call to DSOUND_MixToTemporary here? Not
sure it's needed */
-		This->buf_mixpos = DSOUND_secpos_to_bufpos(This, newpos, 0, NULL);

 	RtlReleaseResource(&This->lock);
 	/* **** */
@@ -702,7 +695,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
 	LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
 ) {
-	IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface, *iter;
+	IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
 	HRESULT hres = DS_OK;

 	TRACE("(%p,%p,%d,%p,%d)\n", This,p1,x1,p2,x2);
@@ -719,29 +712,6 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
 	RtlReleaseResource(&This->lock);
 	/* **** */

-	if (!p2)
-		x2 = 0;
-
-	if (!This->hwbuf && (x1 || x2))
-	{
-		RtlAcquireResourceShared(&This->device->buffer_list_lock, TRUE);
-		LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers,
IDirectSoundBufferImpl, entry )
-		{
-			RtlAcquireResourceShared(&iter->lock, TRUE);
-			if (x1)
-                        {
-			    if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen)
-			      hres = DSERR_INVALIDPARAM;
-			    else
-			      DSOUND_MixToTemporary(iter, (DWORD_PTR)p1 -
(DWORD_PTR)iter->buffer->memory, x1, FALSE);
-                        }
-			if (x2)
-				DSOUND_MixToTemporary(iter, 0, x2, FALSE);
-			RtlReleaseResource(&iter->lock);
-		}
-		RtlReleaseResource(&This->device->buffer_list_lock);
-	}
-
 	return hres;
 }

@@ -1078,16 +1048,9 @@ HRESULT IDirectSoundBufferImpl_Create(
 	list_add_head(&dsb->buffer->buffers, &dsb->entry);
 	FillMemory(dsb->buffer->memory, dsb->buflen,
dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);

-	/* It's not necessary to initialize values to zero since */
-	/* we allocated this structure with HEAP_ZERO_MEMORY... */
-	dsb->buf_mixpos = dsb->sec_mixpos = 0;
 	dsb->state = STATE_STOPPED;

-	dsb->freqAdjust = ((DWORD64)dsb->freq << DSOUND_FREQSHIFT) /
device->pwfx->nSamplesPerSec;
-	dsb->nAvgBytesPerSec = dsb->freq *
-		dsbd->lpwfxFormat->nBlockAlign;
-
-	/* calculate fragment size and write lead */
+	/* calculate new format values */
 	DSOUND_RecalcFormat(dsb);

 	if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
@@ -1212,14 +1175,12 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
     list_add_head(&dsb->buffer->buffers, &dsb->entry);
     dsb->ref = 0;
     dsb->state = STATE_STOPPED;
-    dsb->buf_mixpos = dsb->sec_mixpos = 0;
+    dsb->inpos = dsb->infrac = 0;
     dsb->device = device;
     dsb->ds3db = NULL;
     dsb->iks = NULL; /* FIXME? */
     dsb->secondary = NULL;
-    dsb->tmp_buffer = NULL;
     DSOUND_RecalcFormat(dsb);
-    DSOUND_MixToTemporary(dsb, 0, dsb->buflen, FALSE);

     RtlInitializeResource(&dsb->lock);

@@ -1227,7 +1188,6 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
     hres = DirectSoundDevice_AddBuffer(device, dsb);
     if (hres != DS_OK) {
         RtlDeleteResource(&dsb->lock);
-        HeapFree(GetProcessHeap(),0,dsb->tmp_buffer);
         list_remove(&dsb->entry);
         dsb->buffer->ref--;
         HeapFree(GetProcessHeap(),0,dsb->pwfx);
-- 
1.7.2.3



More information about the wine-patches mailing list