From e4f588ae4cd666588a9055066304a67821daa005 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 3 Apr 2010 15:57:04 +0000 Subject: Do not use a template parameter for stereo setting for RawStream but instead pass the constructor a boolean, this should save some binary size. svn-id: r48496 --- sound/decoders/raw.cpp | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/sound/decoders/raw.cpp b/sound/decoders/raw.cpp index a7122ee75d..3614975d57 100644 --- a/sound/decoders/raw.cpp +++ b/sound/decoders/raw.cpp @@ -49,7 +49,7 @@ namespace Audio { * This is a stream, which allows for playing raw PCM data from a stream. * It also features playback of multiple blocks from a given stream. */ -template +template class RawStream : public SeekableAudioStream { // Allow backends to override buffer size @@ -63,6 +63,7 @@ protected: byte *_buffer; ///< Streaming buffer const byte *_ptr; ///< Pointer to current position in stream buffer const int _rate; ///< Sample rate of stream + const bool _isStereo; ///< Whether this is an stereo stream Timestamp _playtime; ///< Calculated total play time Common::SeekableReadStream *_stream; ///< Stream to read data from @@ -74,8 +75,8 @@ protected: const RawStreamBlockList _blocks; ///< Audio block list RawStreamBlockList::const_iterator _curBlock; ///< Current audio block number public: - RawStream(int rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream, const RawStreamBlockList &blocks) - : _rate(rate), _playtime(0, rate), _stream(stream), _disposeAfterUse(disposeStream), _blocks(blocks), _curBlock(_blocks.begin()) { + RawStream(int rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream, const RawStreamBlockList &blocks) + : _rate(rate), _isStereo(stereo), _playtime(0, rate), _stream(stream), _disposeAfterUse(disposeStream), _blocks(blocks), _curBlock(_blocks.begin()) { assert(_blocks.size() > 0); @@ -95,11 +96,11 @@ public: // Add up length of all blocks in order to caluclate total play time int32 len = 0; for (RawStreamBlockList::const_iterator i = _blocks.begin(); i != _blocks.end(); ++i) { - assert(i->len % (stereo ? 2 : 1) == 0); + assert(i->len % (_isStereo ? 2 : 1) == 0); len += i->len; } - _playtime = Timestamp(0, len / (stereo ? 2 : 1), rate); + _playtime = Timestamp(0, len / (_isStereo ? 2 : 1), rate); } @@ -112,7 +113,7 @@ public: int readBuffer(int16 *buffer, const int numSamples); - bool isStereo() const { return stereo; } + bool isStereo() const { return _isStereo; } bool endOfData() const { return (_curBlock == _blocks.end()) && (_diskLeft == 0) && (_bufferLeft == 0); } int getRate() const { return _rate; } @@ -121,8 +122,8 @@ public: bool seek(const Timestamp &where); }; -template -int RawStream::readBuffer(int16 *buffer, const int numSamples) { +template +int RawStream::readBuffer(int16 *buffer, const int numSamples) { int oldPos = _stream->pos(); bool restoreFilePosition = false; @@ -183,8 +184,8 @@ int RawStream::readBuffer(int16 *buffer, cons return numSamples - samples; } -template -bool RawStream::seek(const Timestamp &where) { +template +bool RawStream::seek(const Timestamp &where) { _filePos = 0; _diskLeft = 0; _bufferLeft = 0; @@ -231,14 +232,14 @@ bool RawStream::seek(const Timestamp &where) * particular case it should actually help it :-) */ -#define MAKE_RAW_STREAM(STEREO, UNSIGNED) \ +#define MAKE_RAW_STREAM(UNSIGNED) \ if (is16Bit) { \ if (isLE) \ - return new RawStream(rate, disposeAfterUse, stream, blockList); \ + return new RawStream(rate, isStereo, disposeAfterUse, stream, blockList); \ else \ - return new RawStream(rate, disposeAfterUse, stream, blockList); \ + return new RawStream(rate, isStereo, disposeAfterUse, stream, blockList); \ } else \ - return new RawStream(rate, disposeAfterUse, stream, blockList) + return new RawStream(rate, isStereo, disposeAfterUse, stream, blockList) SeekableAudioStream *makeRawStream(Common::SeekableReadStream *stream, const RawStreamBlockList &blockList, @@ -257,18 +258,10 @@ SeekableAudioStream *makeRawStream(Common::SeekableReadStream *stream, return 0; } - if (isStereo) { - if (isUnsigned) { - MAKE_RAW_STREAM(true, true); - } else { - MAKE_RAW_STREAM(true, false); - } + if (isUnsigned) { + MAKE_RAW_STREAM(true); } else { - if (isUnsigned) { - MAKE_RAW_STREAM(false, true); - } else { - MAKE_RAW_STREAM(false, false); - } + MAKE_RAW_STREAM(false); } } -- cgit v1.2.3