Fixed performance issue with reading WAV files

Calling tell() and thus std::ftell() for every reading iteration ate up
80-90% of the whole read call. By manually tracking the current position
the calls to tell() can be safely removed.
This commit is contained in:
Lukas Dürrenberger 2018-06-09 11:45:16 +02:00 committed by Lukas Dürrenberger
parent 4a41f37d5d
commit 33c26dd6e6

View File

@ -155,7 +155,11 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount)
assert(m_stream); assert(m_stream);
Uint64 count = 0; Uint64 count = 0;
while ((count < maxCount) && (static_cast<Uint64>(m_stream->tell()) < m_dataEnd)) Uint64 startPos = m_stream->tell();
// Tracking of m_dataEnd is important to prevent sf::Music from reading
// data until EOF, as WAV files may have metadata at the end.
while ((count < maxCount) && (startPos + count * m_bytesPerSample < m_dataEnd))
{ {
switch (m_bytesPerSample) switch (m_bytesPerSample)
{ {