Fix roundoff error to prevent negative length.
This commit is contained in:
parent
9251b2c6b5
commit
e5208ca7a3
|
@ -380,11 +380,16 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, DWORD writepos, DWO
|
||||||
|
|
||||||
len = fraglen;
|
len = fraglen;
|
||||||
if (!(dsb->playflags & DSBPLAY_LOOPING)) {
|
if (!(dsb->playflags & DSBPLAY_LOOPING)) {
|
||||||
INT temp = MulDiv(dsb->dsound->device->pwfx->nAvgBytesPerSec, dsb->buflen,
|
int secondary_remainder = dsb->buflen - dsb->buf_mixpos;
|
||||||
dsb->nAvgBytesPerSec) -
|
int adjusted_remainder = MulDiv(dsb->dsound->device->pwfx->nAvgBytesPerSec, secondary_remainder, dsb->nAvgBytesPerSec);
|
||||||
MulDiv(dsb->dsound->device->pwfx->nAvgBytesPerSec, dsb->buf_mixpos,
|
assert(remainder >= 0);
|
||||||
dsb->nAvgBytesPerSec);
|
TRACE("secondary_remainder = %d, adjusted_remainder = %d, len = %d\n", secondary_remainder, adjusted_remainder, len);
|
||||||
len = min(len, temp);
|
if (adjusted_remainder < len) {
|
||||||
|
TRACE("clipping len to remainder of secondary buffer\n");
|
||||||
|
len = adjusted_remainder;
|
||||||
|
}
|
||||||
|
if (len == 0)
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len % dsb->dsound->device->pwfx->nBlockAlign) {
|
if (len % dsb->dsound->device->pwfx->nBlockAlign) {
|
||||||
|
@ -393,11 +398,6 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, DWORD writepos, DWO
|
||||||
len = (len / nBlockAlign) * nBlockAlign; /* data alignment */
|
len = (len / nBlockAlign) * nBlockAlign; /* data alignment */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 0) {
|
|
||||||
/* This should only happen if we aren't looping and temp < nBlockAlign */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((buf = ibuf = DSOUND_tmpbuffer(dsb->dsound->device, len)) == NULL)
|
if ((buf = ibuf = DSOUND_tmpbuffer(dsb->dsound->device, len)) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue