From 15da5c1f6d909082e012469392353f9b1e084cf7 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 1 Dec 2017 13:51:22 -0800 Subject: [PATCH] Improve source stream looping behavior It now acts more like non-streaming, where if a read ends on the loop end it'll jump back to the loop start right away, rather than after the next (0-length) read. It also better handles seek failures, now breaking the loop and trying to continue playing to the end. --- src/source.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/source.cpp b/src/source.cpp index c2abf27..c42be7e 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -111,14 +111,14 @@ public: return false; ALsizei len = mUpdateLen; - if(loop && mSamplePos <= mLoopPts.second) + if(loop && mSamplePos < mLoopPts.second) len = static_cast(std::min(len, mLoopPts.second - mSamplePos)); else loop = false; ALsizei frames = mDecoder->read(mData.data(), len); mSamplePos += frames; - if(frames < mUpdateLen && loop && mSamplePos > 0) + if(loop && ((frames < mUpdateLen && mSamplePos > 0) || (mSamplePos == mLoopPts.second))) { if(mSamplePos < mLoopPts.second) { @@ -129,13 +129,23 @@ public: do { if(!mDecoder->seek(mLoopPts.first)) + { + len = mUpdateLen-frames; + if(len > 0) + { + ALuint got = mDecoder->read(&mData[frames*mFrameSize], len); + mSamplePos += got; + frames += got; + } break; + } mSamplePos = mLoopPts.first; mHasLooped = true; len = static_cast( std::min(mUpdateLen-frames, mLoopPts.second-mLoopPts.first) ); + if(len == 0) break; ALuint got = mDecoder->read(&mData[frames*mFrameSize], len); if(got == 0) break; mSamplePos += got; -- 2.11.4.GIT