From 6a3a0ddc86eb44ee7c8c1bee5093a902a0f22cec Mon Sep 17 00:00:00 2001 From: Splendide Imaginarius <119545140+Splendide-Imaginarius@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:59:47 +0000 Subject: [PATCH] Audio: convert seconds to samples by rounding rather than flooring --- src/audio/sdlsoundsource.cpp | 5 ++--- src/audio/vorbissource.cpp | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/audio/sdlsoundsource.cpp b/src/audio/sdlsoundsource.cpp index afea5c158..77104addb 100644 --- a/src/audio/sdlsoundsource.cpp +++ b/src/audio/sdlsoundsource.cpp @@ -153,9 +153,8 @@ struct SDLSoundSource : ALDataSource else { // Unfortunately there is no easy API in SDL_sound for seeking with better precision than 1ms. - // TODO: Work around this by manually consuming the remaining samples. - // TODO: Also we're flooring here when we probably should be rounding. - Sound_Seek(sample, static_cast(seconds * 1000)); + // TODO: Work around this by flooring instead of rounding, and then manually consuming the remaining samples. + Sound_Seek(sample, static_cast(lround(seconds * 1000))); } } diff --git a/src/audio/vorbissource.cpp b/src/audio/vorbissource.cpp index 9c49837ad..053797650 100644 --- a/src/audio/vorbissource.cpp +++ b/src/audio/vorbissource.cpp @@ -164,8 +164,7 @@ struct VorbisSource : ALDataSource currentFrame = 0; } - // TODO: We're flooring here when we probably should be rounding. - currentFrame = seconds * info.rate; + currentFrame = lround(seconds * info.rate); if (loop.valid && currentFrame > loop.end) currentFrame = loop.start;