From 0a87828b4134e7bde65a8f2e2e2b98519ca891d3 Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Sat, 18 Dec 2021 03:59:32 -0800
Subject: Don't swallow up buffer callback samples when pausing

---
 core/voice.cpp | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

(limited to 'core/voice.cpp')

diff --git a/core/voice.cpp b/core/voice.cpp
index 12df996a..1eb804ac 100644
--- a/core/voice.cpp
+++ b/core/voice.cpp
@@ -733,18 +733,24 @@ void Voice::mix(const State vstate, ContextBase *Context, const uint SamplesToDo
         }
         else if((mFlags&VoiceIsCallback))
         {
-            if(SrcSamplesDone < mNumCallbackSamples)
-            {
-                const size_t byteOffset{SrcSamplesDone*mFrameSize};
-                const size_t byteEnd{mNumCallbackSamples*mFrameSize};
-                al::byte *data{BufferListItem->mSamples};
-                std::copy(data+byteOffset, data+byteEnd, data);
-                mNumCallbackSamples -= SrcSamplesDone;
-            }
-            else
+            /* Don't use up the stored callback samples when stopping (pausing)
+             * since they'll be replayed when resuming.
+             */
+            if(likely(vstate == Playing))
             {
-                BufferListItem = nullptr;
-                mNumCallbackSamples = 0;
+                if(SrcSamplesDone < mNumCallbackSamples)
+                {
+                    const size_t byteOffset{SrcSamplesDone*mFrameSize};
+                    const size_t byteEnd{mNumCallbackSamples*mFrameSize};
+                    al::byte *data{BufferListItem->mSamples};
+                    std::copy(data+byteOffset, data+byteEnd, data);
+                    mNumCallbackSamples -= SrcSamplesDone;
+                }
+                else
+                {
+                    BufferListItem = nullptr;
+                    mNumCallbackSamples = 0;
+                }
             }
         }
         else
-- 
cgit v1.2.3