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