aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-02-15 10:53:04 -0800
committerChris Robinson <[email protected]>2023-02-15 10:57:49 -0800
commit67415a2686279871822d0e5971155a0fd20092b2 (patch)
tree7984ee0a7dca0327c7e1268eac44edc06a26f1e6 /core
parent6381fc1ab08d8b626c88231276dfe575c7745f4c (diff)
Combine and simplify some loops
Diffstat (limited to 'core')
-rw-r--r--core/voice.cpp38
1 files changed, 14 insertions, 24 deletions
diff --git a/core/voice.cpp b/core/voice.cpp
index c02210ef..9e349d8e 100644
--- a/core/voice.cpp
+++ b/core/voice.cpp
@@ -361,7 +361,7 @@ inline void LoadSamples<FmtIMA4>(float *RESTRICT dstSamples, const al::byte *src
}
src += blockBytes;
- } while(1);
+ } while(true);
}
template<>
@@ -435,7 +435,7 @@ inline void LoadSamples<FmtMSADPCM>(float *RESTRICT dstSamples, const al::byte *
/* The rest of the block is a series of nibbles, interleaved per-
* channel. Decode the number of samples that we need to skip in the
- * block.
+ * block (will always be less than the block size).
*/
const size_t startOffset{skip + 2};
size_t nibbleOffset{srcChan};
@@ -447,31 +447,21 @@ inline void LoadSamples<FmtMSADPCM>(float *RESTRICT dstSamples, const al::byte *
nibbleOffset += srcStep;
}
- int samples[8]{};
- for(size_t i{startOffset};i < samplesPerBlock;)
+ /* Now decode the rest of the block, until the end of the block or the
+ * dst buffer is full.
+ */
+ const size_t todo{minz(samplesPerBlock-startOffset, samplesToLoad-wrote)};
+ for(size_t j{0};j < todo;++j)
{
- /* Here we decode a set of (up to) 8 samples at a time to write out
- * together. This is more efficient than decoding each sample
- * individually and checking for the end each time.
- */
- const size_t todo{minz(samplesPerBlock-i, 8)};
-
- for(size_t j{0};j < todo;++j)
- {
- const size_t byteOffset{nibbleOffset>>1};
- const size_t byteShift{((nibbleOffset&1)^1) * 4};
- samples[j] = decode_sample((input[byteOffset]>>byteShift) & 15);
- nibbleOffset += srcStep;
- }
-
- const size_t towrite{minz(todo, samplesToLoad-wrote)};
- for(size_t j{0};j < towrite;++j)
- dstSamples[wrote++] = static_cast<float>(samples[j]) / 32768.0f;
- if(wrote == samplesToLoad)
- return;
+ const size_t byteOffset{nibbleOffset>>1};
+ const size_t byteShift{((nibbleOffset&1)^1) * 4};
+ nibbleOffset += srcStep;
- i += todo;
+ const int sample{decode_sample((input[byteOffset]>>byteShift) & 15)};
+ dstSamples[wrote++] = static_cast<float>(sample) / 32768.0f;
}
+ if(wrote == samplesToLoad)
+ return;
src += blockBytes;
} while(true);