aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends/pulseaudio.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-04-26 15:58:25 -0700
committerChris Robinson <[email protected]>2019-04-26 15:58:25 -0700
commitf23ff0394d8ae58dc12f8d1076fe5cd9dfde383d (patch)
tree6ab98ccc85c76eb77bf8c533cdaae179fb0b6bd4 /Alc/backends/pulseaudio.cpp
parent348e01dc4bc16ac4543d54b722fb46dbdebcb1e3 (diff)
Specify the buffer size as itself instead of the period count
Certain backends don't need a buffer size to be a strict multiple of the period count, which allows a little more flexibility. The period/update size simply acts as the minimum request, which helps control CPU load by determining how often parameter and other pre-mixing updates are processed.
Diffstat (limited to 'Alc/backends/pulseaudio.cpp')
-rw-r--r--Alc/backends/pulseaudio.cpp33
1 files changed, 13 insertions, 20 deletions
diff --git a/Alc/backends/pulseaudio.cpp b/Alc/backends/pulseaudio.cpp
index fad6e8b4..29fd5ae9 100644
--- a/Alc/backends/pulseaudio.cpp
+++ b/Alc/backends/pulseaudio.cpp
@@ -691,7 +691,7 @@ void PulsePlayback::bufferAttrCallbackC(pa_stream *stream, void *pdata)
void PulsePlayback::bufferAttrCallback(pa_stream *stream)
{
- /* FIXME: Update the device's UpdateSize (and/or NumUpdates) using the new
+ /* FIXME: Update the device's UpdateSize (and/or BufferSize) using the new
* buffer attributes? Changing UpdateSize will change the ALC_REFRESH
* property, which probably shouldn't change between device resets. But
* leaving it alone means ALC_REFRESH will be off.
@@ -1007,11 +1007,10 @@ ALCboolean PulsePlayback::reset()
}
SetDefaultWFXChannelOrder(mDevice);
- size_t period_size{mDevice->UpdateSize * pa_frame_size(&mSpec)};
mAttr.maxlength = -1;
- mAttr.tlength = period_size * maxu(mDevice->NumUpdates, 2);
+ mAttr.tlength = mDevice->BufferSize * pa_frame_size(&mSpec);
mAttr.prebuf = 0;
- mAttr.minreq = period_size;
+ mAttr.minreq = mDevice->UpdateSize * pa_frame_size(&mSpec);
mAttr.fragsize = -1;
mStream = pulse_connect_stream(mDeviceName.c_str(), mLoop, mContext, flags, &mAttr, &mSpec,
@@ -1028,14 +1027,14 @@ ALCboolean PulsePlayback::reset()
{
/* Server updated our playback rate, so modify the buffer attribs
* accordingly. */
- mDevice->NumUpdates = static_cast<ALuint>(clampd(
- static_cast<ALdouble>(mSpec.rate)/mDevice->Frequency*mDevice->NumUpdates + 0.5, 2.0, 16.0));
+ double newlen{clampd(
+ static_cast<double>(mSpec.rate)/mDevice->Frequency*mDevice->BufferSize + 0.5,
+ mDevice->UpdateSize*2, std::numeric_limits<int>::max()/mFrameSize)};
- period_size = mDevice->UpdateSize * mFrameSize;
mAttr.maxlength = -1;
- mAttr.tlength = period_size * maxu(mDevice->NumUpdates, 2);
+ mAttr.tlength = static_cast<ALuint>(newlen) * mFrameSize;
mAttr.prebuf = 0;
- mAttr.minreq = period_size;
+ mAttr.minreq = mDevice->UpdateSize * mFrameSize;
op = pa_stream_set_buffer_attr(mStream, &mAttr, stream_success_callback, mLoop);
wait_for_operation(op, mLoop);
@@ -1046,7 +1045,7 @@ ALCboolean PulsePlayback::reset()
pa_stream_set_buffer_attr_callback(mStream, &PulsePlayback::bufferAttrCallbackC, this);
bufferAttrCallback(mStream);
- mDevice->NumUpdates = clampu((mAttr.tlength + mAttr.minreq/2u) / mAttr.minreq, 2u, 16u);
+ mDevice->BufferSize = mAttr.tlength / mFrameSize;
mDevice->UpdateSize = mAttr.minreq / mFrameSize;
/* HACK: prebuf should be 0 as that's what we set it to. However on some
@@ -1058,15 +1057,9 @@ ALCboolean PulsePlayback::reset()
if(mAttr.prebuf != 0)
{
ALuint len{mAttr.prebuf / mFrameSize};
- if(len <= mDevice->UpdateSize*mDevice->NumUpdates)
+ if(len <= mDevice->BufferSize)
ERR("Non-0 prebuf, %u samples (%u bytes), device has %u samples\n",
- len, mAttr.prebuf, mDevice->UpdateSize*mDevice->NumUpdates);
- else
- {
- ERR("Large prebuf, %u samples (%u bytes), increasing device from %u samples",
- len, mAttr.prebuf, mDevice->UpdateSize*mDevice->NumUpdates);
- mDevice->NumUpdates = (len+mDevice->UpdateSize-1) / mDevice->UpdateSize;
- }
+ len, mAttr.prebuf, mDevice->BufferSize);
}
return ALC_TRUE;
@@ -1328,7 +1321,7 @@ ALCenum PulseCapture::open(const ALCchar *name)
return ALC_INVALID_VALUE;
}
- ALuint samples{mDevice->UpdateSize * mDevice->NumUpdates};
+ ALuint samples{mDevice->BufferSize};
samples = maxu(samples, 100 * mDevice->Frequency / 1000);
mAttr.minreq = -1;
@@ -1337,7 +1330,7 @@ ALCenum PulseCapture::open(const ALCchar *name)
mAttr.tlength = -1;
mAttr.fragsize = minu(samples, 50*mDevice->Frequency/1000) * pa_frame_size(&mSpec);
- pa_stream_flags_t flags{PA_STREAM_START_CORKED|PA_STREAM_ADJUST_LATENCY};
+ pa_stream_flags_t flags{PA_STREAM_START_CORKED | PA_STREAM_ADJUST_LATENCY};
if(!GetConfigValueBool(nullptr, "pulse", "allow-moves", 0))
flags |= PA_STREAM_DONT_MOVE;