From b1d3b7ab99e2b504284109c5a0ef1c0c35914706 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 5 Aug 2003 00:50:15 +0000 Subject: 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 --- sound/audiostream.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'sound/audiostream.cpp') 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(_ptr); _ptr += (is16Bit ? 2 : 1); + samples++; } if (_loopPtr && _ptr == _end) { _ptr = _loopPtr; @@ -143,10 +144,26 @@ inline int16 WrappedMemoryStream::readIntern() { template int WrappedMemoryStream::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(_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; } -- cgit v1.2.3