diff options
author | Chris Robinson <[email protected]> | 2019-04-26 18:04:22 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-04-26 18:04:22 -0700 |
commit | 9e4ee500b61462c205ed588c31a045bd95215cdc (patch) | |
tree | 6ecded32c953d11aec4b5196f9f76f52b570e47c /Alc/backends | |
parent | b29be3b39ea2d128f9b380fb8d079815ed707c7c (diff) |
Scale the update size with sample rate changes
Diffstat (limited to 'Alc/backends')
-rw-r--r-- | Alc/backends/pulseaudio.cpp | 15 | ||||
-rw-r--r-- | Alc/backends/wasapi.cpp | 15 |
2 files changed, 15 insertions, 15 deletions
diff --git a/Alc/backends/pulseaudio.cpp b/Alc/backends/pulseaudio.cpp index 29fd5ae9..9561407c 100644 --- a/Alc/backends/pulseaudio.cpp +++ b/Alc/backends/pulseaudio.cpp @@ -1026,15 +1026,18 @@ ALCboolean PulsePlayback::reset() if(mDevice->Frequency != mSpec.rate) { /* Server updated our playback rate, so modify the buffer attribs - * accordingly. */ - double newlen{clampd( - static_cast<double>(mSpec.rate)/mDevice->Frequency*mDevice->BufferSize + 0.5, - mDevice->UpdateSize*2, std::numeric_limits<int>::max()/mFrameSize)}; + * accordingly. + */ + const auto scale = static_cast<double>(mSpec.rate) / mDevice->Frequency; + const ALuint perlen{static_cast<ALuint>(clampd(scale*mDevice->UpdateSize + 0.5, 64.0, + 8192.0))}; + const ALuint buflen{static_cast<ALuint>(clampd(scale*mDevice->BufferSize + 0.5, perlen*2, + std::numeric_limits<int>::max()/mFrameSize))}; mAttr.maxlength = -1; - mAttr.tlength = static_cast<ALuint>(newlen) * mFrameSize; + mAttr.tlength = buflen * mFrameSize; mAttr.prebuf = 0; - mAttr.minreq = mDevice->UpdateSize * mFrameSize; + mAttr.minreq = perlen * mFrameSize; op = pa_stream_set_buffer_attr(mStream, &mAttr, stream_success_callback, mLoop); wait_for_operation(op, mLoop); diff --git a/Alc/backends/wasapi.cpp b/Alc/backends/wasapi.cpp index e1a5b278..e361b7bc 100644 --- a/Alc/backends/wasapi.cpp +++ b/Alc/backends/wasapi.cpp @@ -789,7 +789,8 @@ HRESULT WasapiPlayback::resetProxy() CoTaskMemFree(wfx); wfx = nullptr; - REFERENCE_TIME buf_time{mDevice->BufferSize * REFTIME_PER_SEC / mDevice->Frequency}; + const REFERENCE_TIME per_time{mDevice->UpdateSize * REFTIME_PER_SEC / mDevice->Frequency}; + const REFERENCE_TIME buf_time{mDevice->BufferSize * REFTIME_PER_SEC / mDevice->Frequency}; if(!(mDevice->Flags&DEVICE_FREQUENCY_REQUEST)) mDevice->Frequency = OutputType.Format.nSamplesPerSec; @@ -986,18 +987,14 @@ HRESULT WasapiPlayback::resetProxy() return hr; } - min_len = (UINT32)ScaleCeil(min_per, mDevice->Frequency, REFTIME_PER_SEC); /* Find the nearest multiple of the period size to the update size */ - if(min_len < mDevice->UpdateSize) - min_len *= maxu((mDevice->UpdateSize + min_len/2) / min_len, 1u); + if(min_per < per_time) + min_per *= maxu((per_time + min_per/2) / min_per, 1u); + min_len = (UINT32)ScaleCeil(min_per, mDevice->Frequency, REFTIME_PER_SEC); + min_len = minu(min_len, buffer_len/2); mDevice->UpdateSize = min_len; mDevice->BufferSize = buffer_len; - if(mDevice->BufferSize <= mDevice->UpdateSize) - { - ERR("Audio client returned buffer_len < period*2; expect break up\n"); - mDevice->UpdateSize = buffer_len / 2; - } hr = mClient->SetEventHandle(mNotifyEvent); if(FAILED(hr)) |