dsound: Make sure secondary_remainder and buflen are aligned to primary buffer in mixer

Maarten Lankhorst m.b.lankhorst at gmail.com
Thu Jul 26 17:57:17 CDT 2007


-------------- next part --------------
>From 8ae3936d7ddba21d0c250a32f0f0ff6a9553bc08 Mon Sep 17 00:00:00 2001
From: Maarten Lankhorst <m.b.lankhorst at gmail.com>
Date: Thu, 12 Jul 2007 12:26:19 +0200
Subject: [PATCH] dsound: Make sure secondary_remainder and buflen are aligned to primary buffer in mixer

This should fix 2 causes of err:dsound:DSOUND_MixInBuffer length not a multiple of block size

I'm not aware of any other causes
---
 dlls/dsound/mixer.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c
index 7b4864e..64ac3c9 100644
--- a/dlls/dsound/mixer.c
+++ b/dlls/dsound/mixer.c
@@ -432,6 +432,7 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, DWORD writepos, DWO
 		int secondary_remainder = dsb->buflen - dsb->buf_mixpos;
 		int adjusted_remainder = MulDiv(dsb->device->pwfx->nAvgBytesPerSec, secondary_remainder, dsb->nAvgBytesPerSec);
 		assert(adjusted_remainder >= 0);
+		adjusted_remainder -= adjusted_remainder % dsb->device->pwfx->nBlockAlign; /* data alignment */
 			/* The adjusted remainder must be at least one sample,
 			 * otherwise we will never reach the end of the
 			 * secondary buffer, as there will perpetually be a
@@ -588,7 +589,7 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, DWORD playpos, DWORD wri
 {
 	/* The buffer's primary_mixpos may be before or after the the device
 	 * buffer's mixpos, but both must be ahead of writepos. */
-	DWORD primary_done;
+	DWORD primary_done, buflen = dsb->buflen / dsb->pwfx->nBlockAlign * dsb->device->pwfx->nBlockAlign;
 
 	TRACE("(%p,%d,%d,%d)\n",dsb,playpos,writepos,mixlen);
 	TRACE("writepos=%d, buf_mixpos=%d, primary_mixpos=%d, mixlen=%d\n", writepos, dsb->buf_mixpos, dsb->primary_mixpos, mixlen);
@@ -611,7 +612,7 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, DWORD playpos, DWORD wri
 	TRACE("mixlen (primary) = %i\n", mixlen);
 
 	/* clip to valid length */
-	mixlen = (dsb->buflen < mixlen) ? dsb->buflen : mixlen;
+	mixlen = (buflen < mixlen) ? buflen : mixlen;
 
 	TRACE("primary_done=%d, mixlen (buffer)=%d\n", primary_done, mixlen);
 
-- 
1.4.4.2



More information about the wine-patches mailing list