diff options
author | Robin Watts | 2007-06-24 17:42:36 +0000 |
---|---|---|
committer | Robin Watts | 2007-06-24 17:42:36 +0000 |
commit | 997253fe6aa52795289a1d0e3c5955652212ed14 (patch) | |
tree | 265967218318273a4a1b035f018f0b53cf0fb3b9 /sound | |
parent | a106f01d2f1b1c7cef36f8bd90d502add1f9235e (diff) | |
download | scummvm-rg350-997253fe6aa52795289a1d0e3c5955652212ed14.tar.gz scummvm-rg350-997253fe6aa52795289a1d0e3c5955652212ed14.tar.bz2 scummvm-rg350-997253fe6aa52795289a1d0e3c5955652212ed14.zip |
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
Diffstat (limited to 'sound')
-rw-r--r-- | sound/audiostream.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
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<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> int LinearMemoryStream<stereo, is16Bit, isUnsigned, isLE>::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<Buffer> _bufferQueue; // Position in the front buffer, if any @@ -292,8 +292,8 @@ template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> int AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::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<stereo, is16Bit, isUnsigned, isLE>::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<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> |