From 997253fe6aa52795289a1d0e3c5955652212ed14 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Sun, 24 Jun 2007 17:42:36 +0000 Subject: Small tweak to the readBuffer routines of sound/audiostream.cpp; by counting a variable down we save 1 cycle per sample copied (at least) on most architectures. svn-id: r27693 --- sound/audiostream.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'sound/audiostream.cpp') diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index eba02c74f3..9fd2f046fe 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -156,21 +156,21 @@ public: template int LinearMemoryStream::readBuffer(int16 *buffer, const int numSamples) { - int samples = 0; - while (samples < numSamples && _ptr < _end) { - const int len = MIN(numSamples, samples + (int)(_end - _ptr) / (is16Bit ? 2 : 1)); - while (samples < len) { + int samples = numSamples; + while (samples > 0 && _ptr < _end) { + int len = MIN(numSamples, (int)(_end - _ptr) / (is16Bit ? 2 : 1)); + samples -= len; + do { *buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE); _ptr += (is16Bit ? 2 : 1); - samples++; - } + } while (--len); // Loop, if looping was specified if (_loopPtr && _ptr >= _end) { _ptr = _loopPtr; _end = _loopEnd; } } - return samples; + return numSamples-samples; } @@ -209,7 +209,7 @@ AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte f loopEnd = len; assert(loopStart <= loopEnd); assert(loopEnd <= len); - + loopOffset = loopStart; loopLen = loopEnd - loopStart; } @@ -250,7 +250,7 @@ protected: // the linked list) in thread aware environments. Common::Mutex _mutex; - // List of all queueud buffers + // List of all queued buffers Common::List _bufferQueue; // Position in the front buffer, if any @@ -292,8 +292,8 @@ template int AppendableMemoryStream::readBuffer(int16 *buffer, const int numSamples) { Common::StackLock lock(_mutex); - int samples = 0; - while (samples < numSamples && !eosIntern()) { + int samples = numSamples; + while (samples > 0 && !eosIntern()) { Buffer buf = *_bufferQueue.begin(); if (_pos == 0) _pos = buf.start; @@ -307,15 +307,15 @@ int AppendableMemoryStream::readBuffer(int16 continue; } - const int len = MIN(numSamples, samples + samplesLeftInCurBuffer / (is16Bit ? 2 : 1)); - while (samples < len) { + int len = MIN(samples, samplesLeftInCurBuffer / (is16Bit ? 2 : 1)); + samples -= len; + do { *buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _pos, isLE); _pos += (is16Bit ? 2 : 1); - samples++; - } + } while (--len); } - return samples; + return numSamples-samples; } template -- cgit v1.2.3