Commit 7a27cc89 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

dsound: Don't propagate writepos in the non-WRITEPRIMARY case - it's unused.

parent 3ab2482e
...@@ -487,10 +487,9 @@ static void DSOUND_MixerVol(const IDirectSoundBufferImpl *dsb, INT frames) ...@@ -487,10 +487,9 @@ static void DSOUND_MixerVol(const IDirectSoundBufferImpl *dsb, INT frames)
* (and it is not looping). * (and it is not looping).
* *
* dsb = the secondary buffer to mix from * dsb = the secondary buffer to mix from
* writepos = position (offset) in device buffer to write at
* fraglen = number of bytes to mix * fraglen = number of bytes to mix
*/ */
static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD writepos, DWORD fraglen) static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD fraglen)
{ {
INT len = fraglen; INT len = fraglen;
float *ibuf; float *ibuf;
...@@ -498,7 +497,7 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, float *mix_buffer, ...@@ -498,7 +497,7 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, float *mix_buffer,
UINT frames = fraglen / dsb->device->pwfx->nBlockAlign; UINT frames = fraglen / dsb->device->pwfx->nBlockAlign;
TRACE("sec_mixpos=%d/%d\n", dsb->sec_mixpos, dsb->buflen); TRACE("sec_mixpos=%d/%d\n", dsb->sec_mixpos, dsb->buflen);
TRACE("(%p,%d,%d)\n",dsb,writepos,fraglen); TRACE("(%p,%d)\n",dsb,fraglen);
if (len % dsb->device->pwfx->nBlockAlign) { if (len % dsb->device->pwfx->nBlockAlign) {
INT nBlockAlign = dsb->device->pwfx->nBlockAlign; INT nBlockAlign = dsb->device->pwfx->nBlockAlign;
...@@ -532,18 +531,16 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, float *mix_buffer, ...@@ -532,18 +531,16 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, float *mix_buffer,
* *
* dsb = the secondary buffer * dsb = the secondary buffer
* playpos = the current play position in the device buffer (primary buffer) * playpos = the current play position in the device buffer (primary buffer)
* writepos = the current safe-to-write position in the device buffer
* mixlen = the maximum number of bytes in the primary buffer to mix, from the * mixlen = the maximum number of bytes in the primary buffer to mix, from the
* current writepos. * current writepos.
* *
* Returns: the number of bytes beyond the writepos that were mixed. * Returns: the number of bytes beyond the writepos that were mixed.
*/ */
static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD writepos, DWORD mixlen) static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD mixlen)
{ {
DWORD primary_done = 0; DWORD primary_done = 0;
TRACE("(%p,%d,%d)\n",dsb,writepos,mixlen); TRACE("(%p,%d)\n",dsb,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 */
...@@ -552,7 +549,6 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD ...@@ -552,7 +549,6 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD
if (mixlen > 2 * dsb->device->fraglen) { if (mixlen > 2 * dsb->device->fraglen) {
primary_done = mixlen - 2 * dsb->device->fraglen; primary_done = mixlen - 2 * dsb->device->fraglen;
mixlen = 2 * dsb->device->fraglen; mixlen = 2 * dsb->device->fraglen;
writepos += primary_done;
dsb->sec_mixpos += (primary_done / dsb->device->pwfx->nBlockAlign) * dsb->sec_mixpos += (primary_done / dsb->device->pwfx->nBlockAlign) *
dsb->pwfx->nBlockAlign * dsb->freqAdjustNum / dsb->freqAdjustDen; dsb->pwfx->nBlockAlign * dsb->freqAdjustNum / dsb->freqAdjustDen;
} }
...@@ -565,7 +561,7 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD ...@@ -565,7 +561,7 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD
/* 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
*/ */
primary_done += DSOUND_MixInBuffer(dsb, mix_buffer, writepos, mixlen); primary_done += DSOUND_MixInBuffer(dsb, mix_buffer, mixlen);
TRACE("total mixed data=%d\n", primary_done); TRACE("total mixed data=%d\n", primary_done);
...@@ -577,7 +573,6 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD ...@@ -577,7 +573,6 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD
* For a DirectSoundDevice, go through all the currently playing buffers and * For a DirectSoundDevice, go through all the currently playing buffers and
* mix them in to the device buffer. * mix them in to the device buffer.
* *
* writepos = the current safe-to-write position in the primary buffer
* mixlen = the maximum amount to mix into the primary buffer * mixlen = the maximum amount to mix into the primary buffer
* (beyond the current writepos) * (beyond the current writepos)
* all_stopped = reports back if all buffers have stopped * all_stopped = reports back if all buffers have stopped
...@@ -585,7 +580,7 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD ...@@ -585,7 +580,7 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD
* Returns: the length beyond the writepos that was mixed to. * Returns: the length beyond the writepos that was mixed to.
*/ */
static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buffer, DWORD writepos, DWORD mixlen, BOOL *all_stopped) static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buffer, DWORD mixlen, BOOL *all_stopped)
{ {
INT i; INT i;
IDirectSoundBufferImpl *dsb; IDirectSoundBufferImpl *dsb;
...@@ -593,7 +588,7 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buff ...@@ -593,7 +588,7 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buff
/* unless we find a running buffer, all have stopped */ /* unless we find a running buffer, all have stopped */
*all_stopped = TRUE; *all_stopped = TRUE;
TRACE("(%d,%d)\n", writepos, mixlen); TRACE("(%d)\n", mixlen);
for (i = 0; i < device->nrofbuffers; i++) { for (i = 0; i < device->nrofbuffers; i++) {
dsb = device->buffers[i]; dsb = device->buffers[i];
...@@ -613,7 +608,7 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buff ...@@ -613,7 +608,7 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buff
dsb->state = STATE_PLAYING; dsb->state = STATE_PLAYING;
/* mix next buffer into the main buffer */ /* mix next buffer into the main buffer */
DSOUND_MixOne(dsb, mix_buffer, writepos, mixlen); DSOUND_MixOne(dsb, mix_buffer, mixlen);
*all_stopped = FALSE; *all_stopped = FALSE;
} }
...@@ -671,7 +666,7 @@ static void DSOUND_WaveQueue(DirectSoundDevice *device, LPBYTE pos, DWORD bytes) ...@@ -671,7 +666,7 @@ static void DSOUND_WaveQueue(DirectSoundDevice *device, LPBYTE pos, DWORD bytes)
*/ */
static void DSOUND_PerformMix(DirectSoundDevice *device) static void DSOUND_PerformMix(DirectSoundDevice *device)
{ {
UINT32 pad, maxq, writepos; UINT32 pad, maxq;
DWORD block; DWORD block;
HRESULT hr; HRESULT hr;
...@@ -701,8 +696,6 @@ static void DSOUND_PerformMix(DirectSoundDevice *device) ...@@ -701,8 +696,6 @@ static void DSOUND_PerformMix(DirectSoundDevice *device)
if (maxq > device->fraglen * 3) if (maxq > device->fraglen * 3)
maxq = device->fraglen * 3; maxq = device->fraglen * 3;
writepos = (device->playpos + pad) % device->buflen;
if (device->priolevel != DSSCL_WRITEPRIMARY) { if (device->priolevel != DSSCL_WRITEPRIMARY) {
BOOL all_stopped = FALSE; BOOL all_stopped = FALSE;
int nfiller; int nfiller;
...@@ -726,12 +719,12 @@ static void DSOUND_PerformMix(DirectSoundDevice *device) ...@@ -726,12 +719,12 @@ static void DSOUND_PerformMix(DirectSoundDevice *device)
memset(buffer, nfiller, maxq); memset(buffer, nfiller, maxq);
if (!device->normfunction) if (!device->normfunction)
DSOUND_MixToPrimary(device, buffer, writepos, maxq, &all_stopped); DSOUND_MixToPrimary(device, buffer, maxq, &all_stopped);
else { else {
memset(device->buffer, nfiller, device->buflen); memset(device->buffer, nfiller, device->buflen);
/* do the mixing */ /* do the mixing */
DSOUND_MixToPrimary(device, (float*)device->buffer, writepos, maxq, &all_stopped); DSOUND_MixToPrimary(device, (float*)device->buffer, maxq, &all_stopped);
device->normfunction(device->buffer, buffer, maxq); device->normfunction(device->buffer, buffer, maxq);
} }
...@@ -742,6 +735,8 @@ static void DSOUND_PerformMix(DirectSoundDevice *device) ...@@ -742,6 +735,8 @@ static void DSOUND_PerformMix(DirectSoundDevice *device)
device->pad += maxq; device->pad += maxq;
} else if (!device->stopped) { } else if (!device->stopped) {
DWORD writepos = (device->playpos + pad) % device->buflen;
if (maxq > device->buflen) if (maxq > device->buflen)
maxq = device->buflen; maxq = device->buflen;
if (writepos + maxq > device->buflen) { if (writepos + maxq > device->buflen) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment