aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends
diff options
context:
space:
mode:
Diffstat (limited to 'Alc/backends')
-rw-r--r--Alc/backends/pulseaudio.cpp15
-rw-r--r--Alc/backends/wasapi.cpp15
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))