aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alc.cpp8
-rw-r--r--Alc/backends/pulseaudio.cpp15
-rw-r--r--Alc/backends/wasapi.cpp15
3 files changed, 18 insertions, 20 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index edea3846..7c218785 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -1754,6 +1754,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
{
freq = maxi(freq, MIN_OUTPUT_RATE);
+ device->UpdateSize = (device->UpdateSize*freq + device->Frequency/2) /
+ device->Frequency;
device->BufferSize = (device->BufferSize*freq + device->Frequency/2) /
device->Frequency;
@@ -1763,9 +1765,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
ConfigValueUInt(devname, nullptr, "period_size", &device->UpdateSize);
device->UpdateSize = clampu(device->UpdateSize, 64, 8192);
- /* SSE and Neon do best with the update size being a multiple of 4. */
- if((CPUCapFlags&(CPU_CAP_SSE|CPU_CAP_NEON)) != 0)
- device->UpdateSize = (device->UpdateSize+3u)&~3u;
ALuint periods{};
if(ConfigValueUInt(devname, nullptr, "periods", &periods))
@@ -3765,6 +3764,7 @@ START_API_FUNC
ERR("%uhz request clamped to %uhz minimum\n", freq, MIN_OUTPUT_RATE);
freq = MIN_OUTPUT_RATE;
}
+ device->UpdateSize = (device->UpdateSize*freq + device->Frequency/2) / device->Frequency;
device->BufferSize = (device->BufferSize*freq + device->Frequency/2) / device->Frequency;
device->Frequency = freq;
device->Flags |= DEVICE_FREQUENCY_REQUEST;
@@ -3772,8 +3772,6 @@ START_API_FUNC
ConfigValueUInt(deviceName, nullptr, "period_size", &device->UpdateSize);
device->UpdateSize = clampu(device->UpdateSize, 64, 8192);
- if((CPUCapFlags&(CPU_CAP_SSE|CPU_CAP_NEON)) != 0)
- device->UpdateSize = (device->UpdateSize+3u)&~3u;
ALuint periods{};
if(ConfigValueUInt(deviceName, nullptr, "periods", &periods))
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))