diff options
author | Chris Robinson <[email protected]> | 2023-02-18 17:16:00 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-02-18 17:16:00 -0800 |
commit | 9f49f6cab06374d6f5a4e1ab63f1532bf79d4cb2 (patch) | |
tree | af83c2f9eeb4975ff0b5dc6021c4795a98622d6c /core | |
parent | 7e00d4a00243e417ff59d3be001e1180ff55b72b (diff) |
Track the callback buffer base separately
Instead of recalculating it all the time, even for sources that don't use
callback buffers.
Diffstat (limited to 'core')
-rw-r--r-- | core/voice.cpp | 13 | ||||
-rw-r--r-- | core/voice.h | 1 |
2 files changed, 6 insertions, 8 deletions
diff --git a/core/voice.cpp b/core/voice.cpp index b390df49..40f3c6b2 100644 --- a/core/voice.cpp +++ b/core/voice.cpp @@ -779,12 +779,6 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi const al::span<float> dst) { std::copy_n(src, dst.size(), dst.begin()); }} : mResampler}; - /* For callback buffers, this is the sample offset for the start of the - * buffer data. This is needed with compressed formats to track how many - * samples into a block we're starting from. - */ - const uint callbackBase{RoundDown(static_cast<uint>(maxi(DataPosInt, 0)), mSamplesPerBlock)}; - /* UHJ2 and SuperStereo only have 2 buffer channels, but 3 mixing channels * (3rd channel is generated from decoding). */ @@ -894,6 +888,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi mFrameStep, srcSampleDelay, srcBufferSize, al::to_address(resampleBuffer)); else if(mFlags.test(VoiceIsCallback)) { + const uint callbackBase{mCallbackBlockBase * mSamplesPerBlock}; const size_t bufferOffset{uintPos - callbackBase}; const size_t needSamples{bufferOffset + srcBufferSize - srcSampleDelay}; const size_t needBlocks{(needSamples + mSamplesPerBlock-1) / mSamplesPerBlock}; @@ -1091,8 +1086,8 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi else if(mFlags.test(VoiceIsCallback)) { /* Handle callback buffer source */ - const uint samplesDone{static_cast<uint>(DataPosInt) - callbackBase}; - const uint blocksDone{samplesDone / mSamplesPerBlock}; + const uint currentBlock{static_cast<uint>(DataPosInt) / mSamplesPerBlock}; + const uint blocksDone{currentBlock - mCallbackBlockBase}; if(blocksDone < mNumCallbackBlocks) { const size_t byteOffset{blocksDone*mBytesPerBlock}; @@ -1100,11 +1095,13 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi al::byte *data{BufferListItem->mSamples}; std::copy(data+byteOffset, data+byteEnd, data); mNumCallbackBlocks -= blocksDone; + mCallbackBlockBase += blocksDone; } else { BufferListItem = nullptr; mNumCallbackBlocks = 0; + mCallbackBlockBase += blocksDone; } } else diff --git a/core/voice.h b/core/voice.h index f197e463..000174b6 100644 --- a/core/voice.h +++ b/core/voice.h @@ -238,6 +238,7 @@ struct Voice { std::bitset<VoiceFlagCount> mFlags{}; uint mNumCallbackBlocks{0}; + uint mCallbackBlockBase{0}; struct TargetData { int FilterType; |