From c11ea7792fbcff95a7a9107d9ff2d4565be4efe9 Mon Sep 17 00:00:00 2001 From: Marukyu <434348-Marukyu@users.noreply.gitlab.com> Date: Thu, 1 Oct 2020 13:07:00 +0200 Subject: [PATCH] Round sample offset when seeking InputSoundFile This fixes a bug that caused `sf::Music` to cease looping after certain seeks due to the sample offset misaligning with the sound file's channel count. --- src/SFML/Audio/InputSoundFile.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SFML/Audio/InputSoundFile.cpp b/src/SFML/Audio/InputSoundFile.cpp index cb8bed048..e835abd72 100644 --- a/src/SFML/Audio/InputSoundFile.cpp +++ b/src/SFML/Audio/InputSoundFile.cpp @@ -225,11 +225,11 @@ Uint64 InputSoundFile::getSampleOffset() const //////////////////////////////////////////////////////////// void InputSoundFile::seek(Uint64 sampleOffset) { - if (m_reader) + if (m_reader && m_channelCount != 0) { // The reader handles an overrun gracefully, but we // pre-check to keep our known position consistent - m_sampleOffset = std::min(sampleOffset, m_sampleCount); + m_sampleOffset = std::min(sampleOffset / m_channelCount * m_channelCount, m_sampleCount); m_reader->seek(m_sampleOffset); } } @@ -238,7 +238,7 @@ void InputSoundFile::seek(Uint64 sampleOffset) //////////////////////////////////////////////////////////// void InputSoundFile::seek(Time timeOffset) { - seek(static_cast(timeOffset.asSeconds() * m_sampleRate * m_channelCount)); + seek(static_cast(timeOffset.asSeconds() * m_sampleRate) * m_channelCount); }