From afe1199b6922da5db79dd0a461292e04ab3e5e4d Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 9 Jul 2017 13:28:16 +0300 Subject: [PATCH] Fixed sound looping when stream length is a multiply of buffer size https://forum.zdoom.org/viewtopic.php?t=57164 --- src/sound/musicformats/music_libsndfile.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/sound/musicformats/music_libsndfile.cpp b/src/sound/musicformats/music_libsndfile.cpp index 85b670a6b..fed79dcf0 100644 --- a/src/sound/musicformats/music_libsndfile.cpp +++ b/src/sound/musicformats/music_libsndfile.cpp @@ -339,18 +339,12 @@ bool SndFileSong::Read(SoundStream *stream, void *vbuff, int ilen, void *userdat if (currentpos + framestoread > song->Loop_End) { size_t endblock = (song->Loop_End - currentpos) * song->Channels * 2; - size_t endlen = song->Decoder->read(buff, 0 == endblock ? len : endblock); - if (endlen != 0) - { - buff = buff + endlen; - len -= endlen; - song->Decoder->seek(song->Loop_Start, false, true); - } - else - { - song->CritSec.Leave(); - return false; - } + size_t endlen = song->Decoder->read(buff, endblock); + + // Even if zero bytes was read give it a chance to start from the beginning + buff = buff + endlen; + len -= endlen; + song->Decoder->seek(song->Loop_Start, false, true); } while (len > 0) {