dsound: Get rid of redundant primary_mixpos member.
This commit is contained in:
parent
e0ccd9e399
commit
5cce1d9da2
|
@ -186,7 +186,7 @@ struct IDirectSoundBufferImpl
|
||||||
DWORD firstep;
|
DWORD firstep;
|
||||||
float freqAcc, freqAdjust, firgain;
|
float freqAcc, freqAdjust, firgain;
|
||||||
/* used for mixing */
|
/* used for mixing */
|
||||||
DWORD primary_mixpos, sec_mixpos;
|
DWORD sec_mixpos;
|
||||||
|
|
||||||
/* IDirectSoundNotify fields */
|
/* IDirectSoundNotify fields */
|
||||||
LPDSBPOSITIONNOTIFY notifies;
|
LPDSBPOSITIONNOTIFY notifies;
|
||||||
|
|
|
@ -520,10 +520,6 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, DWORD writepos, DWO
|
||||||
DSOUND_CheckEvent(dsb, oldpos, ilen);
|
DSOUND_CheckEvent(dsb, oldpos, ilen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* increase mix position */
|
|
||||||
dsb->primary_mixpos += len;
|
|
||||||
dsb->primary_mixpos %= dsb->device->buflen;
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,55 +537,34 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, DWORD writepos, DWO
|
||||||
*/
|
*/
|
||||||
static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen)
|
static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen)
|
||||||
{
|
{
|
||||||
/* The buffer's primary_mixpos may be before or after the device
|
DWORD primary_done = 0;
|
||||||
* buffer's mixpos, but both must be ahead of writepos. */
|
|
||||||
DWORD primary_done;
|
|
||||||
|
|
||||||
TRACE("(%p,%d,%d)\n",dsb,writepos,mixlen);
|
TRACE("(%p,%d,%d)\n",dsb,writepos,mixlen);
|
||||||
TRACE("writepos=%d, primary_mixpos=%d, mixlen=%d\n", writepos, dsb->primary_mixpos, mixlen);
|
TRACE("writepos=%d, mixlen=%d\n", writepos, mixlen);
|
||||||
TRACE("looping=%d, leadin=%d\n", dsb->playflags, dsb->leadin);
|
TRACE("looping=%d, leadin=%d\n", dsb->playflags, dsb->leadin);
|
||||||
|
|
||||||
/* If leading in, only mix about 20 ms, and 'skip' mixing the rest, for more fluid pointer advancement */
|
/* If leading in, only mix about 20 ms, and 'skip' mixing the rest, for more fluid pointer advancement */
|
||||||
if (dsb->leadin && dsb->state == STATE_STARTING)
|
/* FIXME: Is this needed? */
|
||||||
{
|
if (dsb->leadin && dsb->state == STATE_STARTING) {
|
||||||
if (mixlen > 2 * dsb->device->fraglen)
|
if (mixlen > 2 * dsb->device->fraglen) {
|
||||||
{
|
primary_done = mixlen - 2 * dsb->device->fraglen;
|
||||||
dsb->primary_mixpos += mixlen - 2 * dsb->device->fraglen;
|
mixlen = 2 * dsb->device->fraglen;
|
||||||
dsb->primary_mixpos %= dsb->device->buflen;
|
writepos += primary_done;
|
||||||
|
dsb->sec_mixpos += (primary_done / dsb->device->pwfx->nBlockAlign) *
|
||||||
|
dsb->pwfx->nBlockAlign * dsb->freqAdjust;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dsb->leadin = FALSE;
|
dsb->leadin = FALSE;
|
||||||
|
|
||||||
/* calculate how much pre-buffering has already been done for this buffer */
|
TRACE("mixlen (primary) = %i\n", mixlen);
|
||||||
primary_done = DSOUND_BufPtrDiff(dsb->device->buflen, dsb->primary_mixpos, writepos);
|
|
||||||
|
|
||||||
/* sanity */
|
|
||||||
if(mixlen < primary_done)
|
|
||||||
{
|
|
||||||
/* Should *NEVER* happen */
|
|
||||||
ERR("Fatal error. Under/Overflow? primary_done=%d, mixpos=%d/%d, primary_mixpos=%d, writepos=%d, mixlen=%d\n", primary_done,dsb->sec_mixpos, dsb->buflen, dsb->primary_mixpos, writepos, mixlen);
|
|
||||||
dsb->primary_mixpos = writepos + mixlen;
|
|
||||||
dsb->primary_mixpos %= dsb->device->buflen;
|
|
||||||
return mixlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* take into account already mixed data */
|
|
||||||
mixlen -= primary_done;
|
|
||||||
|
|
||||||
TRACE("primary_done=%d, mixlen (primary) = %i\n", primary_done, mixlen);
|
|
||||||
|
|
||||||
if (!mixlen)
|
|
||||||
return primary_done;
|
|
||||||
|
|
||||||
/* First try to mix to the end of the buffer if possible
|
/* First try to mix to the end of the buffer if possible
|
||||||
* Theoretically it would allow for better optimization
|
* Theoretically it would allow for better optimization
|
||||||
*/
|
*/
|
||||||
DSOUND_MixInBuffer(dsb, dsb->primary_mixpos, mixlen);
|
primary_done += DSOUND_MixInBuffer(dsb, writepos, mixlen);
|
||||||
|
|
||||||
/* re-calculate the primary done */
|
TRACE("total mixed data=%d\n", primary_done);
|
||||||
primary_done = DSOUND_BufPtrDiff(dsb->device->buflen, dsb->primary_mixpos, writepos);
|
|
||||||
|
|
||||||
TRACE("new primary_mixpos=%d, total mixed data=%d\n", dsb->primary_mixpos, primary_done);
|
|
||||||
|
|
||||||
/* Report back the total prebuffered amount for this buffer */
|
/* Report back the total prebuffered amount for this buffer */
|
||||||
return primary_done;
|
return primary_done;
|
||||||
|
@ -632,11 +607,6 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, DWORD writepos,
|
||||||
DSOUND_CheckEvent(dsb, 0, 0);
|
DSOUND_CheckEvent(dsb, 0, 0);
|
||||||
} else if (dsb->state != STATE_STOPPED) {
|
} else if (dsb->state != STATE_STOPPED) {
|
||||||
|
|
||||||
/* if recovering, reset the mix position */
|
|
||||||
if ((dsb->state == STATE_STARTING) || recover) {
|
|
||||||
dsb->primary_mixpos = writepos;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if the buffer was starting, it must be playing now */
|
/* if the buffer was starting, it must be playing now */
|
||||||
if (dsb->state == STATE_STARTING)
|
if (dsb->state == STATE_STARTING)
|
||||||
dsb->state = STATE_PLAYING;
|
dsb->state = STATE_PLAYING;
|
||||||
|
@ -806,8 +776,6 @@ static void DSOUND_PerformMix(DirectSoundDevice *device)
|
||||||
|
|
||||||
/* calc maximum prebuff */
|
/* calc maximum prebuff */
|
||||||
prebuff_max = (device->prebuf * device->fraglen);
|
prebuff_max = (device->prebuf * device->fraglen);
|
||||||
if (playpos + prebuff_max >= device->helfrags * device->fraglen)
|
|
||||||
prebuff_max += device->buflen - device->helfrags * device->fraglen;
|
|
||||||
|
|
||||||
/* check how close we are to an underrun. It occurs when the writepos overtakes the mixpos */
|
/* check how close we are to an underrun. It occurs when the writepos overtakes the mixpos */
|
||||||
prebuff_left = DSOUND_BufPtrDiff(device->buflen, device->mixpos, playpos);
|
prebuff_left = DSOUND_BufPtrDiff(device->buflen, device->mixpos, playpos);
|
||||||
|
|
|
@ -537,7 +537,6 @@ opened:
|
||||||
|
|
||||||
(*dsb)->freqAdjust = (*dsb)->freq / (float)device->pwfx->nSamplesPerSec;
|
(*dsb)->freqAdjust = (*dsb)->freq / (float)device->pwfx->nSamplesPerSec;
|
||||||
DSOUND_RecalcFormat((*dsb));
|
DSOUND_RecalcFormat((*dsb));
|
||||||
(*dsb)->primary_mixpos = 0;
|
|
||||||
|
|
||||||
RtlReleaseResource(&(*dsb)->lock);
|
RtlReleaseResource(&(*dsb)->lock);
|
||||||
/* **** */
|
/* **** */
|
||||||
|
|
Loading…
Reference in New Issue