diff --git a/include/SFML/Audio/InputSoundFile.hpp b/include/SFML/Audio/InputSoundFile.hpp index c389ac3b..250a9b16 100644 --- a/include/SFML/Audio/InputSoundFile.hpp +++ b/include/SFML/Audio/InputSoundFile.hpp @@ -153,6 +153,9 @@ public: /// precision. If you need to jump to a given time, use the /// other overload. /// + /// The sample offset takes the channels into account. + /// Offsets can be calculated like this: + /// `sampleNumber * sampleRate * channelCount` /// If the given offset exceeds to total number of samples, /// this function jumps to the end of the sound file. /// diff --git a/include/SFML/Audio/SoundFileReader.hpp b/include/SFML/Audio/SoundFileReader.hpp index 549f50b6..0bf83550 100644 --- a/include/SFML/Audio/SoundFileReader.hpp +++ b/include/SFML/Audio/SoundFileReader.hpp @@ -79,6 +79,9 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the current read position to the given sample offset /// + /// The sample offset takes the channels into account. + /// Offsets can be calculated like this: + /// `sampleNumber * sampleRate * channelCount` /// If the given offset exceeds to total number of samples, /// this function must jump to the end of the file. /// diff --git a/src/SFML/Audio/SoundFileReaderFlac.cpp b/src/SFML/Audio/SoundFileReaderFlac.cpp index ba91b412..bba45360 100644 --- a/src/SFML/Audio/SoundFileReaderFlac.cpp +++ b/src/SFML/Audio/SoundFileReaderFlac.cpp @@ -210,7 +210,8 @@ bool SoundFileReaderFlac::check(InputStream& stream) //////////////////////////////////////////////////////////// SoundFileReaderFlac::SoundFileReaderFlac() : m_decoder(NULL), -m_clientData() +m_clientData(), +m_channelCount(0) { } @@ -248,6 +249,9 @@ bool SoundFileReaderFlac::open(InputStream& stream, Info& info) // Retrieve the sound properties info = m_clientData.info; // was filled in the "metadata" callback + // We must keep the channel count for the seek function + m_channelCount = info.channelCount; + return true; } @@ -262,7 +266,8 @@ void SoundFileReaderFlac::seek(Uint64 sampleOffset) m_clientData.remaining = 0; m_clientData.leftovers.clear(); - FLAC__stream_decoder_seek_absolute(m_decoder, sampleOffset); + // FLAC decoder expects absolute sample offset, so we take the channel count out + FLAC__stream_decoder_seek_absolute(m_decoder, sampleOffset / m_channelCount); } diff --git a/src/SFML/Audio/SoundFileReaderFlac.hpp b/src/SFML/Audio/SoundFileReaderFlac.hpp index ee9079a3..f1dec1fb 100644 --- a/src/SFML/Audio/SoundFileReaderFlac.hpp +++ b/src/SFML/Audio/SoundFileReaderFlac.hpp @@ -82,6 +82,9 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the current read position to the given sample offset /// + /// The sample offset takes the channels into account. + /// Offsets can be calculated like this: + /// `sampleNumber * sampleRate * channelCount` /// If the given offset exceeds to total number of samples, /// this function must jump to the end of the file. /// @@ -128,8 +131,9 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - FLAC__StreamDecoder* m_decoder; ///< FLAC decoder - ClientData m_clientData; ///< Structure passed to the decoder callbacks + FLAC__StreamDecoder* m_decoder; ///< FLAC decoder + ClientData m_clientData; ///< Structure passed to the decoder callbacks + unsigned int m_channelCount; ///< number of channels of the sound file }; } // namespace priv diff --git a/src/SFML/Audio/SoundFileReaderOgg.hpp b/src/SFML/Audio/SoundFileReaderOgg.hpp index 2b9917b8..087f9811 100644 --- a/src/SFML/Audio/SoundFileReaderOgg.hpp +++ b/src/SFML/Audio/SoundFileReaderOgg.hpp @@ -82,6 +82,9 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the current read position to the given sample offset /// + /// The sample offset takes the channels into account. + /// Offsets can be calculated like this: + /// `sampleNumber * sampleRate * channelCount` /// If the given offset exceeds to total number of samples, /// this function must jump to the end of the file. /// diff --git a/src/SFML/Audio/SoundFileReaderWav.hpp b/src/SFML/Audio/SoundFileReaderWav.hpp index 015518dd..16c7611c 100644 --- a/src/SFML/Audio/SoundFileReaderWav.hpp +++ b/src/SFML/Audio/SoundFileReaderWav.hpp @@ -74,6 +74,9 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the current read position to the given sample offset /// + /// The sample offset takes the channels into account. + /// Offsets can be calculated like this: + /// `sampleNumber * sampleRate * channelCount` /// If the given offset exceeds to total number of samples, /// this function must jump to the end of the file. ///