diff options
-rw-r--r-- | alc/alc.cpp | 6 | ||||
-rw-r--r-- | alc/backends/pipewire.cpp | 9 | ||||
-rw-r--r-- | examples/alffplay.cpp | 4 | ||||
-rw-r--r-- | utils/makemhr/loadsofa.cpp | 2 |
4 files changed, 11 insertions, 10 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; diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index 890ecedb..a7633bfa 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -1509,9 +1509,9 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer, bool re { double aspect_ratio = av_q2d(frame->sample_aspect_ratio); if(aspect_ratio >= 1.0) - frame_width = static_cast<int>(frame_width*aspect_ratio + 0.5); + frame_width = static_cast<int>(std::lround(frame_width * aspect_ratio)); else if(aspect_ratio > 0.0) - frame_height = static_cast<int>(frame_height/aspect_ratio + 0.5); + frame_height = static_cast<int>(std::lround(frame_height / aspect_ratio)); } SDL_SetWindowSize(screen, frame_width, frame_height); } diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index c29cb45c..b2038c77 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -460,7 +460,7 @@ bool LoadSofaFile(const char *filename, const uint numThreads, const uint fftSiz /* Assume a default head radius of 9cm. */ hData->mRadius = 0.09; - hData->mIrRate = static_cast<uint>(GetSampleRate(sofaHrtf.get()) + 0.5f); + hData->mIrRate = static_cast<uint>(std::lround(GetSampleRate(sofaHrtf.get()))); if(!hData->mIrRate) return false; |