From 0c501d303f64fe752b1660c192dc8dca5d0a776d Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 12 Nov 2008 12:25:26 +0000 Subject: Verify sanity of LinearMemoryStream params in the factory function instead of the constructor (which is replicated for each instantiation of the LinearMemoryStream template class) -> saves some bytes svn-id: r35014 --- sound/audiostream.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 588c49ebec..7ba7871bc0 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -133,20 +133,10 @@ public: LinearMemoryStream(int rate, const byte *ptr, uint len, uint loopOffset, uint loopLen, bool autoFreeMemory) : _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate), _playtime(calculatePlayTime(rate, len / (is16Bit ? 2 : 1) / (stereo ? 2 : 1))) { - // Verify the buffer sizes are sane - if (is16Bit && stereo) { - assert((len & 3) == 0 && (loopLen & 3) == 0); - } else if (is16Bit || stereo) { - assert((len & 1) == 0 && (loopLen & 1) == 0); - } - if (loopLen) { _loopPtr = _ptr + loopOffset; _loopEnd = _loopPtr + loopLen; } - if (stereo) { // Stereo requires even sized data - assert(len % 2 == 0); - } _origPtr = autoFreeMemory ? ptr : 0; } @@ -222,6 +212,13 @@ AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte f loopLen = loopEnd - loopStart; } + // Verify the buffer sizes are sane + if (is16Bit && isStereo) { + assert((len & 3) == 0 && (loopLen & 3) == 0); + } else if (is16Bit || isStereo) { + assert((len & 1) == 0 && (loopLen & 1) == 0); + } + if (isStereo) { if (isUnsigned) { MAKE_LINEAR(true, true); -- cgit v1.2.3