Fixed seeking in multi channel FLAC files.

Updated seek() documentation.
This commit is contained in:
Maximilian Wagenbach 2016-01-17 13:24:22 +01:00 committed by Lukas Dürrenberger
parent 698bbccd6a
commit c78c8106da
6 changed files with 25 additions and 4 deletions

View File

@ -153,6 +153,9 @@ public:
/// precision. If you need to jump to a given time, use the /// precision. If you need to jump to a given time, use the
/// other overload. /// 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, /// If the given offset exceeds to total number of samples,
/// this function jumps to the end of the sound file. /// this function jumps to the end of the sound file.
/// ///

View File

@ -79,6 +79,9 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the current read position to the given sample offset /// \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, /// If the given offset exceeds to total number of samples,
/// this function must jump to the end of the file. /// this function must jump to the end of the file.
/// ///

View File

@ -210,7 +210,8 @@ bool SoundFileReaderFlac::check(InputStream& stream)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundFileReaderFlac::SoundFileReaderFlac() : SoundFileReaderFlac::SoundFileReaderFlac() :
m_decoder(NULL), 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 // Retrieve the sound properties
info = m_clientData.info; // was filled in the "metadata" callback 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; return true;
} }
@ -262,7 +266,8 @@ void SoundFileReaderFlac::seek(Uint64 sampleOffset)
m_clientData.remaining = 0; m_clientData.remaining = 0;
m_clientData.leftovers.clear(); 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);
} }

View File

@ -82,6 +82,9 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the current read position to the given sample offset /// \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, /// If the given offset exceeds to total number of samples,
/// this function must jump to the end of the file. /// this function must jump to the end of the file.
/// ///
@ -128,8 +131,9 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FLAC__StreamDecoder* m_decoder; ///< FLAC decoder FLAC__StreamDecoder* m_decoder; ///< FLAC decoder
ClientData m_clientData; ///< Structure passed to the decoder callbacks ClientData m_clientData; ///< Structure passed to the decoder callbacks
unsigned int m_channelCount; ///< number of channels of the sound file
}; };
} // namespace priv } // namespace priv

View File

@ -82,6 +82,9 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the current read position to the given sample offset /// \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, /// If the given offset exceeds to total number of samples,
/// this function must jump to the end of the file. /// this function must jump to the end of the file.
/// ///

View File

@ -74,6 +74,9 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the current read position to the given sample offset /// \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, /// If the given offset exceeds to total number of samples,
/// this function must jump to the end of the file. /// this function must jump to the end of the file.
/// ///