From 2f16fc190f2d71d7a5a3557fa61bb7a47f8fd701 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 14 Jun 2021 01:51:04 -0700 Subject: Combine some checks --- core/voice.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'core') diff --git a/core/voice.cpp b/core/voice.cpp index c764a277..e580ef05 100644 --- a/core/voice.cpp +++ b/core/voice.cpp @@ -557,28 +557,6 @@ void Voice::mix(const State vstate, ContextBase *Context, const uint SamplesToDo } } - if((mFlags&(VoiceIsCallback|VoiceCallbackStopped)) == VoiceIsCallback && BufferListItem) - { - if(SrcBufferSize > mNumCallbackSamples) - { - const size_t byteOffset{mNumCallbackSamples*mFrameSize}; - const size_t needBytes{SrcBufferSize*mFrameSize - byteOffset}; - - const int gotBytes{BufferListItem->mCallback(BufferListItem->mUserData, - &BufferListItem->mSamples[byteOffset], static_cast(needBytes))}; - if(gotBytes < 0) - mFlags |= VoiceCallbackStopped; - else if(static_cast(gotBytes) < needBytes) - { - mFlags |= VoiceCallbackStopped; - mNumCallbackSamples += static_cast(static_cast(gotBytes) / - mFrameSize); - } - else - mNumCallbackSamples = SrcBufferSize; - } - } - if UNLIKELY(!BufferListItem) { for(auto &chanbuffer : mVoiceSamples) @@ -604,8 +582,31 @@ void Voice::mix(const State vstate, ContextBase *Context, const uint SamplesToDo LoadBufferStatic(BufferListItem, BufferLoopItem, DataPosInt, mFmtType, mFmtChannels, SrcBufferSize, mVoiceSamples); else if((mFlags&VoiceIsCallback)) + { + if(!(mFlags&VoiceCallbackStopped)) + { + if(SrcBufferSize > mNumCallbackSamples) + { + const size_t byteOffset{mNumCallbackSamples*mFrameSize}; + const size_t needBytes{SrcBufferSize*mFrameSize - byteOffset}; + + const int gotBytes{BufferListItem->mCallback(BufferListItem->mUserData, + &BufferListItem->mSamples[byteOffset], static_cast(needBytes))}; + if(gotBytes < 0) + mFlags |= VoiceCallbackStopped; + else if(static_cast(gotBytes) < needBytes) + { + mFlags |= VoiceCallbackStopped; + mNumCallbackSamples += static_cast(static_cast(gotBytes) / + mFrameSize); + } + else + mNumCallbackSamples = SrcBufferSize; + } + } LoadBufferCallback(BufferListItem, mNumCallbackSamples, mFmtType, mFmtChannels, SrcBufferSize, mVoiceSamples); + } else LoadBufferQueue(BufferListItem, BufferLoopItem, DataPosInt, mFmtType, mFmtChannels, SrcBufferSize, mVoiceSamples); -- cgit v1.2.3