aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
Diffstat (limited to 'alc')
-rw-r--r--alc/alc.cpp6
-rw-r--r--alc/backends/pipewire.cpp9
2 files changed, 8 insertions, 7 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index d944cf0c..e9d3aed7 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -1025,7 +1025,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
optsrate = clampu(*freqopt, MinOutputRate, MaxOutputRate);
const double scale{static_cast<double>(*optsrate) / double{DefaultOutputRate}};
- period_size = static_cast<uint>(period_size*scale + 0.5);
+ period_size = static_cast<uint>(std::lround(period_size * scale));
}
if(auto persizeopt = device->configValue<uint>({}, "period_size"))
@@ -1330,8 +1330,8 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
freqAttr = clampi(freqAttr, MinOutputRate, MaxOutputRate);
const double scale{static_cast<double>(freqAttr) / oldrate};
- period_size = static_cast<uint>(period_size*scale + 0.5);
- buffer_size = static_cast<uint>(buffer_size*scale + 0.5);
+ period_size = static_cast<uint>(std::lround(period_size * scale));
+ buffer_size = static_cast<uint>(std::lround(buffer_size * scale));
optsrate = static_cast<uint>(freqAttr);
}
}
diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp
index 2e6e20cc..c31f943e 100644
--- a/alc/backends/pipewire.cpp
+++ b/alc/backends/pipewire.cpp
@@ -1629,11 +1629,12 @@ bool PipeWirePlayback::reset()
{
/* Scale the update size if the sample rate changes. */
const double scale{static_cast<double>(match->mSampleRate) / mDevice->Frequency};
- const double numbufs{static_cast<double>(mDevice->BufferSize)/mDevice->UpdateSize};
+ const double updatesize{std::round(mDevice->UpdateSize * scale)};
+ const double buffersize{std::round(mDevice->BufferSize * scale)};
+
mDevice->Frequency = match->mSampleRate;
- mDevice->UpdateSize = static_cast<uint>(clampd(mDevice->UpdateSize*scale + 0.5,
- 64.0, 8192.0));
- mDevice->BufferSize = static_cast<uint>(numbufs*mDevice->UpdateSize + 0.5);
+ mDevice->UpdateSize = static_cast<uint>(clampd(updatesize, 64.0, 8192.0));
+ mDevice->BufferSize = static_cast<uint>(maxd(buffersize, 128.0));
}
if(!mDevice->Flags.test(ChannelsRequest) && match->mChannels != InvalidChannelConfig)
mDevice->FmtChans = match->mChannels;