aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-01-04 01:44:40 -0800
committerChris Robinson <[email protected]>2023-01-04 01:57:11 -0800
commite38413a4fbb0b4f85950c929141856a767993f4f (patch)
tree65dc89c4043ddf8caf7f1969dddea4b961b7820a
parent8054ccd8f91fee5aacb35e01decbecb67a8da8ce (diff)
Handle negative offset starts for callback buffers
-rw-r--r--core/voice.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/core/voice.cpp b/core/voice.cpp
index 0199d948..fc3a38cc 100644
--- a/core/voice.cpp
+++ b/core/voice.cpp
@@ -297,14 +297,15 @@ void LoadBufferStatic(VoiceBufferItem *buffer, VoiceBufferItem *&bufferLoopItem,
void LoadBufferCallback(VoiceBufferItem *buffer, const size_t numCallbackSamples,
const FmtType sampleType, const FmtChannels sampleChannels, const size_t srcStep,
- const size_t samplesToLoad, const al::span<float*> voiceSamples)
+ size_t samplesLoaded, const size_t samplesToLoad, const al::span<float*> voiceSamples)
{
/* Load what's left to play from the buffer */
- const size_t remaining{minz(samplesToLoad, numCallbackSamples)};
- LoadSamples(voiceSamples, 0, buffer->mSamples, 0, sampleType, sampleChannels, srcStep,
- remaining);
+ const size_t remaining{minz(samplesToLoad-samplesLoaded, numCallbackSamples)};
+ LoadSamples(voiceSamples, samplesLoaded, buffer->mSamples, 0, sampleType, sampleChannels,
+ srcStep, remaining);
+ samplesLoaded += remaining;
- if(const size_t toFill{samplesToLoad - remaining})
+ if(const size_t toFill{samplesToLoad - samplesLoaded})
{
for(auto *chanbuffer : voiceSamples)
{
@@ -649,10 +650,11 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi
mFmtChannels, mFrameStep, samplesLoaded, SrcBufferSize, MixingSamples);
else if(mFlags.test(VoiceIsCallback))
{
- if(!mFlags.test(VoiceCallbackStopped) && SrcBufferSize > mNumCallbackSamples)
+ const size_t remaining{SrcBufferSize - samplesLoaded};
+ if(!mFlags.test(VoiceCallbackStopped) && remaining > mNumCallbackSamples)
{
const size_t byteOffset{mNumCallbackSamples*mFrameSize};
- const size_t needBytes{SrcBufferSize*mFrameSize - byteOffset};
+ const size_t needBytes{remaining*mFrameSize - byteOffset};
const int gotBytes{BufferListItem->mCallback(BufferListItem->mUserData,
&BufferListItem->mSamples[byteOffset], static_cast<int>(needBytes))};
@@ -664,10 +666,10 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi
mNumCallbackSamples += static_cast<uint>(gotBytes) / mFrameSize;
}
else
- mNumCallbackSamples = SrcBufferSize;
+ mNumCallbackSamples = static_cast<uint>(remaining);
}
LoadBufferCallback(BufferListItem, mNumCallbackSamples, mFmtType, mFmtChannels,
- mFrameStep, SrcBufferSize, MixingSamples);
+ mFrameStep, samplesLoaded, SrcBufferSize, MixingSamples);
}
else
LoadBufferQueue(BufferListItem, BufferLoopItem, DataPosUInt, mFmtType, mFmtChannels,