[Scummvm-cvs-logs] SF.net SVN: scummvm:[43479] scummvm/trunk/sound/audiostream.cpp

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Mon Aug 17 15:16:40 CEST 2009


Revision: 43479
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43479&view=rev
Author:   thebluegr
Date:     2009-08-17 13:16:40 +0000 (Mon, 17 Aug 2009)

Log Message:
-----------
Added looping support to LinearDiskStream, needed by SAGA and perhaps other engines. Note that the loop end parameter is still not implemented

Modified Paths:
--------------
    scummvm/trunk/sound/audiostream.cpp

Modified: scummvm/trunk/sound/audiostream.cpp
===================================================================
--- scummvm/trunk/sound/audiostream.cpp	2009-08-17 12:58:53 UTC (rev 43478)
+++ scummvm/trunk/sound/audiostream.cpp	2009-08-17 13:16:40 UTC (rev 43479)
@@ -211,14 +211,14 @@
 	int _audioBlockCount;		///< Number of blocks in _audioBlock
 	int _currentBlock;		///< Current audio block number
 
-	int _beginLoop;			///< Loop parameter, currently not implemented
-	int _endLoop;			///< Loop parameter, currently not implemented
+	int _beginLoop;			///< Loop start parameter
+	int _endLoop;			///< Loop end parameter, currently not implemented
+	bool _loop;				///< Determines if the stream should be looped when it finishes
 
-
 public:
-	LinearDiskStream(int rate, uint beginLoop, uint endLoop, bool disposeStream, Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, uint numBlocks)
+	LinearDiskStream(int rate, uint beginLoop, uint endLoop, bool disposeStream, Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, uint numBlocks, bool loop)
 		: _rate(rate), _stream(stream), _beginLoop(beginLoop), _endLoop(endLoop), _disposeAfterUse(disposeStream),
-		  _audioBlockCount(numBlocks) {
+		  _audioBlockCount(numBlocks), _loop(loop) {
 
 		// Allocate streaming buffer
 		if (is16Bit) {
@@ -296,7 +296,6 @@
 			_diskLeft = _audioBlock[_currentBlock].len;
 		}
 			
-
 		// Now read more data from disk if there is more to be read
 		if ((_bufferLeft == 0) && (_diskLeft > 0)) {
 			int32 readAmount = MIN(_diskLeft, BUFFER_SIZE);
@@ -315,6 +314,14 @@
 			// original position.
 			restoreFilePosition = true;
 		}
+
+		// Looping
+		if (_diskLeft == 0 && _loop) {
+			// Reset the stream
+			_currentBlock = 0;
+			_filePos = _audioBlock[_currentBlock].pos + _beginLoop;
+			_diskLeft = _audioBlock[_currentBlock].len;
+		}
 	}
 
 	// In case calling code relies on the position of this stream staying 
@@ -399,11 +406,11 @@
 #define MAKE_LINEAR_DISK(STEREO, UNSIGNED) \
 		if (is16Bit) { \
 			if (isLE) \
-				return new LinearDiskStream<STEREO, true, UNSIGNED, true>(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks); \
+				return new LinearDiskStream<STEREO, true, UNSIGNED, true>(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks, loop); \
 			else  \
-				return new LinearDiskStream<STEREO, true, UNSIGNED, false>(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks); \
+				return new LinearDiskStream<STEREO, true, UNSIGNED, false>(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks, loop); \
 		} else \
-			return new LinearDiskStream<STEREO, false, UNSIGNED, false>(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks)
+			return new LinearDiskStream<STEREO, false, UNSIGNED, false>(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks, loop)
 
 
 AudioStream *makeLinearDiskStream(Common::SeekableReadStream& stream, LinearDiskStreamAudioBlock* block, int numBlocks, int rate, byte flags, bool takeOwnership, uint loopStart, uint loopEnd) {
@@ -411,8 +418,8 @@
 	const bool is16Bit    = (flags & Audio::Mixer::FLAG_16BITS) != 0;
 	const bool isUnsigned = (flags & Audio::Mixer::FLAG_UNSIGNED) != 0;
 	const bool isLE       = (flags & Audio::Mixer::FLAG_LITTLE_ENDIAN) != 0;
+	const bool loop       = (flags & Audio::Mixer::FLAG_LOOP) != 0;
 
-
 	if (isStereo) {
 		if (isUnsigned) {
 			MAKE_LINEAR_DISK(true, true);


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