[Scummvm-cvs-logs] SF.net SVN: scummvm:[48505] scummvm/branches/branch-1-1-0/sound/decoders/ raw.cpp

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sun Apr 4 12:09:49 CEST 2010


Revision: 48505
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48505&view=rev
Author:   lordhoto
Date:     2010-04-04 10:09:49 +0000 (Sun, 04 Apr 2010)

Log Message:
-----------
Backport of r48495+r48496: "RawStream cleanup".

Modified Paths:
--------------
    scummvm/branches/branch-1-1-0/sound/decoders/raw.cpp

Modified: scummvm/branches/branch-1-1-0/sound/decoders/raw.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/sound/decoders/raw.cpp	2010-04-04 10:00:48 UTC (rev 48504)
+++ scummvm/branches/branch-1-1-0/sound/decoders/raw.cpp	2010-04-04 10:09:49 UTC (rev 48505)
@@ -49,7 +49,7 @@
  * 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<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+template<bool is16Bit, bool isUnsigned, bool isLE>
 class RawStream : public SeekableAudioStream {
 
 // Allow backends to override buffer size
@@ -63,6 +63,7 @@
 	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 @@
 	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 @@
 		// 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 @@
 
 	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 @@
 	bool seek(const Timestamp &where);
 };
 
-template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
-int RawStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) {
+template<bool is16Bit, bool isUnsigned, bool isLE>
+int RawStream<is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) {
 	int oldPos = _stream->pos();
 	bool restoreFilePosition = false;
 
@@ -159,7 +160,7 @@
 			// If that is not the case, we should probably stop the
 			// stream playback.
 			_stream->seek(_filePos, SEEK_SET);
-			_stream->read(_buffer, readAmount * (is16Bit? 2: 1));
+			_stream->read(_buffer, readAmount * (is16Bit ? 2 : 1));
 
 			// Amount of data in buffer is now the amount read in, and
 			// the amount left to read on disk is decreased by the same amount
@@ -183,8 +184,8 @@
 	return numSamples - samples;
 }
 
-template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
-bool RawStream<stereo, is16Bit, isUnsigned, isLE>::seek(const Timestamp &where) {
+template<bool is16Bit, bool isUnsigned, bool isLE>
+bool RawStream<is16Bit, isUnsigned, isLE>::seek(const Timestamp &where) {
 	_filePos = 0;
 	_diskLeft = 0;
 	_bufferLeft = 0;
@@ -231,14 +232,14 @@
  * particular case it should actually help it :-)
  */
 
-#define MAKE_LINEAR_DISK(STEREO, UNSIGNED) \
+#define MAKE_RAW_STREAM(UNSIGNED) \
 		if (is16Bit) { \
 			if (isLE) \
-				return new RawStream<STEREO, true, UNSIGNED, true>(rate, disposeAfterUse, stream, blockList); \
+				return new RawStream<true, UNSIGNED, true>(rate, isStereo, disposeAfterUse, stream, blockList); \
 			else  \
-				return new RawStream<STEREO, true, UNSIGNED, false>(rate, disposeAfterUse, stream, blockList); \
+				return new RawStream<true, UNSIGNED, false>(rate, isStereo, disposeAfterUse, stream, blockList); \
 		} else \
-			return new RawStream<STEREO, false, UNSIGNED, false>(rate, disposeAfterUse, stream, blockList)
+			return new RawStream<false, UNSIGNED, false>(rate, isStereo, disposeAfterUse, stream, blockList)
 
 SeekableAudioStream *makeRawStream(Common::SeekableReadStream *stream,
                                    const RawStreamBlockList &blockList,
@@ -257,18 +258,10 @@
 		return 0;
 	}
 
-	if (isStereo) {
-		if (isUnsigned) {
-			MAKE_LINEAR_DISK(true, true);
-		} else {
-			MAKE_LINEAR_DISK(true, false);
-		}
+	if (isUnsigned) {
+		MAKE_RAW_STREAM(true);
 	} else {
-		if (isUnsigned) {
-			MAKE_LINEAR_DISK(false, true);
-		} else {
-			MAKE_LINEAR_DISK(false, false);
-		}
+		MAKE_RAW_STREAM(false);
 	}
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list