Skip to content

Commit

Permalink
Merge pull request Ancurio#223 from Splendide-Imaginarius/mkxp-z-seek…
Browse files Browse the repository at this point in the history
…-round

Audio: convert seconds to samples by rounding rather than flooring
  • Loading branch information
Splendide-Imaginarius authored Sep 29, 2024
2 parents 1a6e5c9 + 6a3a0dd commit ef90a2f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/audio/sdlsoundsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(seconds * 1000));
// TODO: Work around this by flooring instead of rounding, and then manually consuming the remaining samples.
Sound_Seek(sample, static_cast<uint32_t>(lround(seconds * 1000)));
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/audio/vorbissource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ef90a2f

Please sign in to comment.