[DSOUND] DSOUND_CalcPlayPosition cleanup

Robert Reif reif at earthlink.net
Sat May 7 13:42:24 CDT 2005


Remove dead code and redundant variables from
DSOUND_CalcPlayPosition and callers.
-------------- next part --------------
Index: dlls/dsound/buffer.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/buffer.c,v
retrieving revision 1.48
diff -u -p -r1.48 buffer.c
--- dlls/dsound/buffer.c	6 May 2005 15:44:32 -0000	1.48
+++ dlls/dsound/buffer.c	7 May 2005 18:38:34 -0000
@@ -394,27 +394,15 @@ static ULONG WINAPI IDirectSoundBufferIm
     return ref;
 }
 
-DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
-			      DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix)
+DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This, DWORD pplay, DWORD pwrite)
 {
-	DWORD bplay;
-
-	TRACE("primary playpos=%ld, mixpos=%ld\n", pplay, pmix);
-	TRACE("this mixpos=%ld, time=%ld\n", bmix, GetTickCount());
+	DWORD bplay = This->buf_mixpos;
+	DWORD pmix = This->primary_mixpos;
+	TRACE("(%p, pplay=%lu, pwrite=%lu)\n", This, pplay, pwrite);
 
 	/* the actual primary play position (pplay) is always behind last mixed (pmix),
 	 * unless the computer is too slow or something */
 	/* we need to know how far away we are from there */
-#if 0 /* we'll never fill the primary entirely */
-	if (pmix == pplay) {
-		if ((state == STATE_PLAYING) || (state == STATE_STOPPING)) {
-			/* wow, the software mixer is really doing well,
-			 * seems the entire primary buffer is filled! */
-			pmix += This->dsound->buflen;
-		}
-		/* else: the primary buffer is not playing, so probably empty */
-	}
-#endif
 	if (pmix < pplay) pmix += This->dsound->buflen; /* wraparound */
 	pmix -= pplay;
 	/* detect buffer underrun */
@@ -433,10 +421,9 @@ DWORD DSOUND_CalcPlayPosition(IDirectSou
 	pmix *= This->pwfx->nBlockAlign;
 	TRACE("this back-offset=%ld\n", pmix);
 	/* subtract from our last mixed position */
-	bplay = bmix;
 	while (bplay < pmix) bplay += This->buflen; /* wraparound */
 	bplay -= pmix;
-	if (This->leadin && ((bplay < This->startpos) || (bplay > bmix))) {
+	if (This->leadin && ((bplay < This->startpos) || (bplay > This->buf_mixpos))) {
 		/* seems we haven't started playing yet */
 		TRACE("this still in lead-in phase\n");
 		bplay = This->startpos;
@@ -462,28 +449,17 @@ static HRESULT WINAPI IDirectSoundBuffer
 			/* we haven't been merged into the primary buffer (yet) */
 			*playpos = This->buf_mixpos;
 		} else if (playpos) {
-			DWORD pplay, pwrite, lplay, splay, pstate;
+			DWORD pplay, pwrite;
 			/* let's get this exact; first, recursively call GetPosition on the primary */
 			EnterCriticalSection(&(This->dsound->mixlock));
 			if (DSOUND_PrimaryGetPosition(This->dsound, &pplay, &pwrite) != DS_OK)
 				WARN("DSOUND_PrimaryGetPosition failed\n");
 			/* detect HEL mode underrun */
-			pstate = This->dsound->state;
-			if (!(This->dsound->hwbuf || This->dsound->pwqueue)) {
+			if (!(This->dsound->hwbuf || This->dsound->pwqueue))
 				TRACE("detected an underrun\n");
-				/* pplay = ? */
-				if (pstate == STATE_PLAYING)
-					pstate = STATE_STARTING;
-				else if (pstate == STATE_STOPPING)
-					pstate = STATE_STOPPED;
-			}
-			/* get data for ourselves while we still have the lock */
-			pstate &= This->state;
-			lplay = This->primary_mixpos;
-			splay = This->buf_mixpos;
 			if ((This->dsbd.dwFlags & DSBCAPS_GETCURRENTPOSITION2) || This->dsound->hwbuf) {
 				/* calculate play position using this */
-				*playpos = DSOUND_CalcPlayPosition(This, pstate, pplay, pwrite, lplay, splay);
+				*playpos = DSOUND_CalcPlayPosition(This, pplay, pwrite);
 			} else {
 				/* (unless the app isn't using GETCURRENTPOSITION2) */
 				/* don't know exactly how this should be handled...
@@ -493,7 +469,7 @@ static HRESULT WINAPI IDirectSoundBuffer
 				DWORD wp;
 				wp = (This->dsound->pwplay + ds_hel_margin) * This->dsound->fraglen;
 				wp %= This->dsound->buflen;
-				*playpos = DSOUND_CalcPlayPosition(This, pstate, wp, pwrite, lplay, splay);
+				*playpos = DSOUND_CalcPlayPosition(This, wp, pwrite);
 			}
 			LeaveCriticalSection(&(This->dsound->mixlock));
 		}
Index: dlls/dsound/dsound_private.h
===================================================================
RCS file: /home/wine/wine/dlls/dsound/dsound_private.h,v
retrieving revision 1.26
diff -u -p -r1.26 dsound_private.h
--- dlls/dsound/dsound_private.h	15 Mar 2005 15:40:36 -0000	1.26
+++ dlls/dsound/dsound_private.h	7 May 2005 18:38:34 -0000
@@ -469,8 +469,7 @@ HRESULT DSOUND_PrimaryGetPosition(IDirec
 
 /* buffer.c */
 
-DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
-			      DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
+DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This, DWORD pplay, DWORD pwrite);
 
 /* mixer.c */
 
Index: dlls/dsound/mixer.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/mixer.c,v
retrieving revision 1.34
diff -u -p -r1.34 mixer.c
--- dlls/dsound/mixer.c	19 Mar 2005 17:09:33 -0000	1.34
+++ dlls/dsound/mixer.c	7 May 2005 18:38:35 -0000
@@ -657,13 +657,8 @@ void DSOUND_ForceRemix(IDirectSoundBuffe
 {
 	TRACE("(%p)\n",dsb);
 	EnterCriticalSection(&dsb->lock);
-	if (dsb->state == STATE_PLAYING) {
-#if 0 /* this may not be quite reliable yet */
-		dsb->need_remix = TRUE;
-#else
+	if (dsb->state == STATE_PLAYING)
 		dsb->dsound->need_remix = TRUE;
-#endif
-	}
 	LeaveCriticalSection(&dsb->lock);
 }
 
@@ -671,8 +666,7 @@ static DWORD DSOUND_MixOne(IDirectSoundB
 {
 	DWORD len, slen;
 	/* determine this buffer's write position */
-	DWORD buf_writepos = DSOUND_CalcPlayPosition(dsb, dsb->state & dsb->dsound->state, writepos,
-						     writepos, dsb->primary_mixpos, dsb->buf_mixpos);
+	DWORD buf_writepos = DSOUND_CalcPlayPosition(dsb, writepos, writepos);
 	/* determine how much already-mixed data exists */
 	DWORD buf_done =
 		((dsb->buf_mixpos < buf_writepos) ? dsb->buflen : 0) +
@@ -805,6 +799,7 @@ post_mix:
 		dsb->last_playpos = 0;
 		dsb->buf_mixpos = 0;
 		dsb->leadin = FALSE;
+		dsb->need_remix = FALSE;
 		DSOUND_CheckEvent(dsb, buf_left);
 	}
 


More information about the wine-patches mailing list