diff options
author | Max Horn | 2003-08-05 00:50:15 +0000 |
---|---|---|
committer | Max Horn | 2003-08-05 00:50:15 +0000 |
commit | b1d3b7ab99e2b504284109c5a0ef1c0c35914706 (patch) | |
tree | be401d789a39fa509c60a8de22013f816f9a193d /sound | |
parent | b96e5501e669dc7e781a780ac810963d08131477 (diff) | |
download | scummvm-rg350-b1d3b7ab99e2b504284109c5a0ef1c0c35914706.tar.gz scummvm-rg350-b1d3b7ab99e2b504284109c5a0ef1c0c35914706.tar.bz2 scummvm-rg350-b1d3b7ab99e2b504284109c5a0ef1c0c35914706.zip |
optimized WrappedMemoryStream::readBuffer (It's almost 3 AM, so I don't trust myself, hence I'll leave this as an #ifdef for now :-)
svn-id: r9473
Diffstat (limited to 'sound')
-rw-r--r-- | sound/audiostream.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 2c92fc7916..684673d6c1 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -72,9 +72,10 @@ public: int samples = 0; while (samples < numSamples && !eosIntern()) { const int len = MIN(numSamples, (_end - _ptr) / (is16Bit ? 2 : 1)); - for (; samples < len; samples++) { + while (samples < len) { *buffer++ = readSample<is16Bit, isUnsigned>(_ptr); _ptr += (is16Bit ? 2 : 1); + samples++; } if (_loopPtr && _ptr == _end) { _ptr = _loopPtr; @@ -143,10 +144,26 @@ inline int16 WrappedMemoryStream<stereo, is16Bit, isUnsigned>::readIntern() { template<bool stereo, bool is16Bit, bool isUnsigned> int WrappedMemoryStream<stereo, is16Bit, isUnsigned>::readBuffer(int16 *buffer, int numSamples) { - int samples; + int samples = 0; +#if 1 + for (int i = (_pos > _end) ? 0 : 1; i < 2 && samples < numSamples && !eosIntern(); i++) { + const byte *endMarker = (i == 0) ? _bufferEnd : _end; + const int len = MIN(numSamples, (endMarker - _pos) / (is16Bit ? 2 : 1)); + + while (samples < len) { + *buffer++ = readSample<is16Bit, isUnsigned>(_pos); + _pos += (is16Bit ? 2 : 1); + samples++; + } + // Wrap around? + if (_pos >= _bufferEnd) + _pos = _pos - (_bufferEnd - _bufferStart); + } +#else for (samples = 0; samples < numSamples && !eosIntern(); samples++) { *buffer++ = readIntern(); } +#endif return samples; } |