Commit 1cc9ecb5 authored by Andrew Eikum's avatar Andrew Eikum Committed by Alexandre Julliard

dsound: Don't use IAudioClock::GetPosition to determine buffer fullness.

parent d2ddd200
...@@ -83,7 +83,6 @@ struct DirectSoundDevice ...@@ -83,7 +83,6 @@ struct DirectSoundDevice
DWORD priolevel; DWORD priolevel;
PWAVEFORMATEX pwfx; PWAVEFORMATEX pwfx;
UINT timerID, playing_offs_bytes, in_mmdev_bytes, prebuf, helfrags; UINT timerID, playing_offs_bytes, in_mmdev_bytes, prebuf, helfrags;
UINT64 last_pos_bytes;
DWORD fraglen; DWORD fraglen;
LPBYTE buffer; LPBYTE buffer;
DWORD writelead, buflen, state, playpos, mixpos; DWORD writelead, buflen, state, playpos, mixpos;
......
...@@ -667,8 +667,7 @@ static void DSOUND_WaveQueue(DirectSoundDevice *device, BOOL force) ...@@ -667,8 +667,7 @@ static void DSOUND_WaveQueue(DirectSoundDevice *device, BOOL force)
*/ */
static void DSOUND_PerformMix(DirectSoundDevice *device) static void DSOUND_PerformMix(DirectSoundDevice *device)
{ {
UINT64 clock_pos, clock_freq, pos_bytes; UINT32 pad, to_mix_frags, to_mix_bytes;
UINT delta_frags;
HRESULT hr; HRESULT hr;
TRACE("(%p)\n", device); TRACE("(%p)\n", device);
...@@ -676,28 +675,28 @@ static void DSOUND_PerformMix(DirectSoundDevice *device) ...@@ -676,28 +675,28 @@ static void DSOUND_PerformMix(DirectSoundDevice *device)
/* **** */ /* **** */
EnterCriticalSection(&device->mixlock); EnterCriticalSection(&device->mixlock);
hr = IAudioClock_GetFrequency(device->clock, &clock_freq); hr = IAudioClient_GetCurrentPadding(device->client, &pad);
if(FAILED(hr)){ if(FAILED(hr)){
WARN("GetFrequency failed: %08x\n", hr); WARN("GetCurrentPadding failed: %08x\n", hr);
LeaveCriticalSection(&device->mixlock); LeaveCriticalSection(&device->mixlock);
return; return;
} }
hr = IAudioClock_GetPosition(device->clock, &clock_pos, NULL); to_mix_frags = device->prebuf - (pad * device->pwfx->nBlockAlign + device->fraglen - 1) / device->fraglen;
if(FAILED(hr)){
WARN("GetCurrentPadding failed: %08x\n", hr); if(to_mix_frags == 0){
LeaveCriticalSection(&device->mixlock); /* nothing to do! */
LeaveCriticalSection(&device->mixlock);
return; return;
} }
pos_bytes = (clock_pos * device->pwfx->nSamplesPerSec * device->pwfx->nBlockAlign) / clock_freq; to_mix_bytes = to_mix_frags * device->fraglen;
delta_frags = (pos_bytes - device->last_pos_bytes) / device->fraglen; if(device->in_mmdev_bytes > 0){
if(delta_frags > 0){ DWORD delta_bytes = min(to_mix_bytes, device->in_mmdev_bytes);
device->playing_offs_bytes += delta_frags * device->fraglen; device->in_mmdev_bytes -= delta_bytes;
device->playing_offs_bytes += delta_bytes;
device->playing_offs_bytes %= device->buflen; device->playing_offs_bytes %= device->buflen;
device->in_mmdev_bytes -= delta_frags * device->fraglen;
device->last_pos_bytes = pos_bytes - (pos_bytes % device->fraglen);
} }
if (device->priolevel != DSSCL_WRITEPRIMARY) { if (device->priolevel != DSSCL_WRITEPRIMARY) {
......
...@@ -196,7 +196,7 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) ...@@ -196,7 +196,7 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device)
FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0); FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0);
FillMemory(device->mix_buffer, device->mix_buffer_len, 0); FillMemory(device->mix_buffer, device->mix_buffer_len, 0);
device->last_pos_bytes = device->playing_offs_bytes = device->in_mmdev_bytes = device->playpos = device->mixpos = 0; device->playing_offs_bytes = device->in_mmdev_bytes = device->playpos = device->mixpos = 0;
return DS_OK; return DS_OK;
} }
......
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