Module: wine Branch: master Commit: d65ae3ffe9533fbadd7a4ea92240840f6b7e045f URL: http://source.winehq.org/git/wine.git/?a=commit;h=d65ae3ffe9533fbadd7a4ea922...
Author: Maarten Lankhorst m.b.lankhorst@gmail.com Date: Thu Sep 6 17:35:58 2007 +0200
dsound: Support arbitrarily sized buffers for waveout.
---
dlls/dsound/mixer.c | 28 +++++++++++++++++----------- dlls/dsound/primary.c | 14 +++++--------- 2 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index fcbf678..2486e72 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -802,18 +802,24 @@ static void DSOUND_WaveQueue(DirectSoundDevice *device, BOOL force) TRACE("wave_fragpos = %i, wave_writepos = %i, pwqueue = %i, prebuf = %i\n", wave_fragpos, wave_writepos, device->pwqueue, device->prebuf);
- if(force == FALSE){ + if (!force) + { /* check remaining prebuffered frags */ - prebuf_frags = DSOUND_BufPtrDiff(device->buflen, device->mixpos, wave_writepos); - prebuf_frags = prebuf_frags / device->fraglen; + prebuf_frags = device->mixpos / device->fraglen; + if (prebuf_frags == device->helfrags) + --prebuf_frags; + TRACE("wave_fragpos = %d, mixpos_frags = %d\n", wave_fragpos, prebuf_frags); + if (prebuf_frags < wave_fragpos) + prebuf_frags += device->helfrags; + prebuf_frags -= wave_fragpos; + TRACE("wanted prebuf_frags = %d\n", prebuf_frags); } - else{ + else /* buffer the maximum amount of frags */ prebuf_frags = device->prebuf; - }
/* limit to the queue we have left */ - if((prebuf_frags + device->pwqueue) > device->prebuf) + if ((prebuf_frags + device->pwqueue) > device->prebuf) prebuf_frags = device->prebuf - device->pwqueue;
TRACE("prebuf_frags = %i\n", prebuf_frags); @@ -846,7 +852,6 @@ static void DSOUND_WaveQueue(DirectSoundDevice *device, BOOL force) */ static void DSOUND_PerformMix(DirectSoundDevice *device) { - TRACE("(%p)\n", device);
/* **** */ @@ -907,6 +912,8 @@ static void DSOUND_PerformMix(DirectSoundDevice *device)
/* calc maximum prebuff */ prebuff_max = (device->prebuf * device->fraglen); + if (!device->hwbuf && 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 */ prebuff_left = DSOUND_BufPtrDiff(device->buflen, device->mixpos, playpos); @@ -964,9 +971,8 @@ static void DSOUND_PerformMix(DirectSoundDevice *device) if (prebuff_left >= device->fraglen){
/* update the wave queue if using wave system */ - if(device->hwbuf == NULL){ - DSOUND_WaveQueue(device,TRUE); - } + if (!device->hwbuf) + DSOUND_WaveQueue(device, FALSE);
/* buffers are full. start playing if applicable */ if(device->state == STATE_STARTING){ @@ -1005,7 +1011,7 @@ static void DSOUND_PerformMix(DirectSoundDevice *device) } else {
/* update the wave queue if using wave system */ - if(device->hwbuf == NULL) + if (!device->hwbuf) DSOUND_WaveQueue(device, TRUE); else /* Keep alsa happy, which needs GetPosition called once every 10 ms */ diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index ce2f943..a27ee14 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -381,23 +381,19 @@ HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LP return err; } } else { + TRACE("pwplay=%i, pwqueue=%i\n", device->pwplay, device->pwqueue);
/* check if playpos was requested */ - if (playpos) { + if (playpos) /* use the cached play position */ *playpos = device->pwplay * device->fraglen; - }
/* check if writepos was requested */ - if (writepos) { - TRACE("pwplay=%i, pwqueue=%i\n", device->pwplay, device->pwqueue); - + if (writepos) /* the writepos is the first non-queued position */ - *writepos = (device->pwplay + device->pwqueue) * device->fraglen; - *writepos %= device->buflen; - } + *writepos = ((device->pwplay + device->pwqueue) % device->helfrags) * device->fraglen; } - TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:0, writepos?*writepos:0, device, GetTickCount()); + TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:-1, writepos?*writepos:-1, device, GetTickCount()); return DS_OK; }