dsound: Use an inline for ring buffer pointer difference calculation.
This commit is contained in:
parent
0036298a14
commit
c38bcb96d7
|
@ -723,6 +723,19 @@ void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb)
|
||||||
LeaveCriticalSection(&dsb->lock);
|
LeaveCriticalSection(&dsb->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the distance between two buffer offsets, taking wraparound
|
||||||
|
* into account.
|
||||||
|
*/
|
||||||
|
static inline DWORD DSOUND_BufPtrDiff(DWORD buflen, DWORD ptr1, DWORD ptr2)
|
||||||
|
{
|
||||||
|
if (ptr1 >= ptr2) {
|
||||||
|
return ptr1 - ptr2;
|
||||||
|
} else {
|
||||||
|
return buflen + ptr1 - ptr2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mix some frames from the given secondary buffer "dsb" into the device
|
* Mix some frames from the given secondary buffer "dsb" into the device
|
||||||
* primary buffer.
|
* primary buffer.
|
||||||
|
@ -744,18 +757,10 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, DWORD playpos, DWORD wri
|
||||||
/* determine this buffer's write position */
|
/* determine this buffer's write position */
|
||||||
DWORD buf_writepos = DSOUND_CalcPlayPosition(dsb, writepos, writepos);
|
DWORD buf_writepos = DSOUND_CalcPlayPosition(dsb, writepos, writepos);
|
||||||
/* determine how much already-mixed data exists */
|
/* determine how much already-mixed data exists */
|
||||||
DWORD buf_done =
|
DWORD buf_done = DSOUND_BufPtrDiff(dsb->buflen, dsb->buf_mixpos, buf_writepos);
|
||||||
((dsb->buf_mixpos < buf_writepos) ? dsb->buflen : 0) +
|
DWORD primary_done = DSOUND_BufPtrDiff(dsb->device->buflen, dsb->primary_mixpos, writepos);
|
||||||
dsb->buf_mixpos - buf_writepos;
|
DWORD adv_done = DSOUND_BufPtrDiff(dsb->device->buflen, dsb->device->mixpos, writepos);
|
||||||
DWORD primary_done =
|
DWORD played = DSOUND_BufPtrDiff(dsb->buflen, buf_writepos, dsb->playpos);
|
||||||
((dsb->primary_mixpos < writepos) ? dsb->device->buflen : 0) +
|
|
||||||
dsb->primary_mixpos - writepos;
|
|
||||||
DWORD adv_done =
|
|
||||||
((dsb->device->mixpos < writepos) ? dsb->device->buflen : 0) +
|
|
||||||
dsb->device->mixpos - writepos;
|
|
||||||
DWORD played =
|
|
||||||
((buf_writepos < dsb->playpos) ? dsb->buflen : 0) +
|
|
||||||
buf_writepos - dsb->playpos;
|
|
||||||
DWORD buf_left = dsb->buflen - buf_writepos;
|
DWORD buf_left = dsb->buflen - buf_writepos;
|
||||||
int still_behind;
|
int still_behind;
|
||||||
|
|
||||||
|
@ -883,9 +888,7 @@ post_mix:
|
||||||
* advance its underrun detector...*/
|
* advance its underrun detector...*/
|
||||||
if (still_behind) return 0;
|
if (still_behind) return 0;
|
||||||
if ((mixlen - len) < primary_done) return 0;
|
if ((mixlen - len) < primary_done) return 0;
|
||||||
slen = ((dsb->primary_mixpos < dsb->device->mixpos) ?
|
slen = DSOUND_BufPtrDiff(dsb->device->buflen, dsb->primary_mixpos, dsb->device->mixpos);
|
||||||
dsb->device->buflen : 0) + dsb->primary_mixpos -
|
|
||||||
dsb->device->mixpos;
|
|
||||||
if (slen > mixlen) {
|
if (slen > mixlen) {
|
||||||
/* the primary_done and still_behind checks above should have worked */
|
/* the primary_done and still_behind checks above should have worked */
|
||||||
FIXME("problem with advancement calculation (advlen=%d > mixlen=%d)\n", slen, mixlen);
|
FIXME("problem with advancement calculation (advlen=%d > mixlen=%d)\n", slen, mixlen);
|
||||||
|
@ -1087,22 +1090,19 @@ static void DSOUND_PerformMix(DirectSoundDevice *device)
|
||||||
DSOUND_CheckReset(device, writepos);
|
DSOUND_CheckReset(device, writepos);
|
||||||
|
|
||||||
/* check how much prebuffering is left */
|
/* check how much prebuffering is left */
|
||||||
inq = device->mixpos;
|
inq = DSOUND_BufPtrDiff(device->buflen, device->mixpos, writepos);
|
||||||
if (inq < writepos)
|
|
||||||
inq += device->buflen;
|
|
||||||
inq -= writepos;
|
|
||||||
|
|
||||||
/* find the maximum we can prebuffer */
|
/* find the maximum we can prebuffer */
|
||||||
if (!paused) {
|
if (!paused)
|
||||||
maxq = playpos;
|
maxq = DSOUND_BufPtrDiff(device->buflen, playpos, writepos);
|
||||||
if (maxq < writepos)
|
/* If we get the whole buffer, difference is 0, so we need to set whole buffer then */
|
||||||
maxq += device->buflen;
|
if (paused || !maxq)
|
||||||
maxq -= writepos;
|
maxq = device->buflen;
|
||||||
} else maxq = device->buflen;
|
|
||||||
|
|
||||||
/* clip maxq to device->prebuf */
|
/* clip maxq to device->prebuf */
|
||||||
frag = device->prebuf * device->fraglen;
|
frag = device->prebuf * device->fraglen;
|
||||||
if (maxq > frag) maxq = frag;
|
if (maxq > frag)
|
||||||
|
maxq = frag;
|
||||||
|
|
||||||
/* check for consistency */
|
/* check for consistency */
|
||||||
if (inq > maxq) {
|
if (inq > maxq) {
|
||||||
|
@ -1248,7 +1248,7 @@ void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, D
|
||||||
playpos = pwplay * fraglen;
|
playpos = pwplay * fraglen;
|
||||||
mixpos = device->mixpos;
|
mixpos = device->mixpos;
|
||||||
/* check remaining mixed data */
|
/* check remaining mixed data */
|
||||||
inq = ((mixpos < playpos) ? buflen : 0) + mixpos - playpos;
|
inq = DSOUND_BufPtrDiff(buflen, mixpos, playpos);
|
||||||
mixq = inq / fraglen;
|
mixq = inq / fraglen;
|
||||||
if ((inq - (mixq * fraglen)) > 0) mixq++;
|
if ((inq - (mixq * fraglen)) > 0) mixq++;
|
||||||
/* complete the playing buffer */
|
/* complete the playing buffer */
|
||||||
|
|
Loading…
Reference in New Issue