aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2022-11-13 14:03:06 -0800
committerChris Robinson <[email protected]>2022-11-13 14:03:06 -0800
commit156f3b6ff5e1e686c8b8f6584a6a1625dcc5c365 (patch)
tree6ee48ca970a6c066f2123107b408ecf2e02ae0a0 /core
parent2f2d3c33aaa3014a134a29488842e0f1da5a6129 (diff)
Avoid duplicate checks and calculations
Diffstat (limited to 'core')
-rw-r--r--core/converter.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/core/converter.cpp b/core/converter.cpp
index 015046f5..69e0d8dd 100644
--- a/core/converter.cpp
+++ b/core/converter.cpp
@@ -4,6 +4,7 @@
#include "converter.h"
#include <algorithm>
+#include <cassert>
#include <cmath>
#include <cstdint>
#include <iterator>
@@ -261,6 +262,9 @@ uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint
const uint DataPosEnd{DstSize*increment + DataPosFrac};
const uint SrcDataEnd{DataPosEnd>>MixerFracBits};
+ assert(prepcount+readable >= SrcDataEnd);
+ const uint nextprep{minu(prepcount + readable - SrcDataEnd, MaxResamplerPadding)};
+
for(size_t chan{0u};chan < mChan.size();chan++)
{
const al::byte *SrcSamples{SamplesIn + mSrcTypeSize*chan};
@@ -275,17 +279,9 @@ uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint
/* Store as many prep samples for next time as possible, given the
* number of output samples being generated.
*/
- if(SrcDataEnd >= prepcount+readable)
- std::fill(std::begin(mChan[chan].PrevSamples),
- std::end(mChan[chan].PrevSamples), 0.0f);
- else
- {
- const size_t len{minz(al::size(mChan[chan].PrevSamples),
- prepcount+readable-SrcDataEnd)};
- std::copy_n(SrcData+SrcDataEnd, len, mChan[chan].PrevSamples);
- std::fill(std::begin(mChan[chan].PrevSamples)+len,
- std::end(mChan[chan].PrevSamples), 0.0f);
- }
+ std::copy_n(SrcData+SrcDataEnd, nextprep, mChan[chan].PrevSamples);
+ std::fill(std::begin(mChan[chan].PrevSamples)+nextprep,
+ std::end(mChan[chan].PrevSamples), 0.0f);
/* Now resample, and store the result in the output buffer. */
const float *ResampledData{mResample(&mState, SrcData+(MaxResamplerPadding>>1),
@@ -297,7 +293,7 @@ uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint
/* Update the number of prep samples still available, as well as the
* fractional offset.
*/
- mSrcPrepCount = minu(prepcount + readable - SrcDataEnd, MaxResamplerPadding);
+ mSrcPrepCount = nextprep;
mFracOffset = DataPosEnd & MixerFracMask;
/* Update the src and dst pointers in case there's still more to do. */