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

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Sun Nov 16 21:34:35 CET 2008


Revision: 35098
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35098&view=rev
Author:   drmccoy
Date:     2008-11-16 20:34:31 +0000 (Sun, 16 Nov 2008)

Log Message:
-----------
Implementing getTotalPlayTime() for AppendableMemoryStream

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

Modified: scummvm/trunk/sound/audiostream.cpp
===================================================================
--- scummvm/trunk/sound/audiostream.cpp	2008-11-16 20:31:07 UTC (rev 35097)
+++ scummvm/trunk/sound/audiostream.cpp	2008-11-16 20:34:31 UTC (rev 35098)
@@ -263,6 +263,10 @@
 	const int _rate;
 	byte *_pos;
 
+	// Playing time in milliseconds and rest samples
+	int _playTime;
+	int _playSamp;
+
 	inline bool eosIntern() const { return _bufferQueue.empty(); };
 public:
 	AppendableMemoryStream(int rate);
@@ -275,13 +279,15 @@
 
 	int getRate() const			{ return _rate; }
 
+	int32 getTotalPlayTime() const { return _playTime; }
+
 	void queueBuffer(byte *data, uint32 size);
 	void finish()				{ _finalized = true; }
 };
 
 template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
 AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::AppendableMemoryStream(int rate)
- : _finalized(false), _rate(rate), _pos(0) {
+ : _finalized(false), _rate(rate), _pos(0), _playTime(0), _playSamp(0) {
 
 }
 
@@ -320,7 +326,14 @@
 		} while (--len);
 	}
 
-	return numSamples-samples;
+	int written = numSamples - samples;
+
+	_playSamp += (stereo ? (written / 2) : written);
+
+	_playTime += _playSamp / (_rate / 1000);
+	_playSamp %= (_rate / 1000);
+
+	return written;
 }
 
 template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>


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