[Scummvm-cvs-logs] SF.net SVN: scummvm: [32258] scummvm/trunk/sound

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun May 25 00:41:15 CEST 2008


Revision: 32258
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32258&view=rev
Author:   fingolfin
Date:     2008-05-24 15:41:15 -0700 (Sat, 24 May 2008)

Log Message:
-----------
Patch #1970427: AudioStream play length querying

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

Modified: scummvm/trunk/sound/audiostream.cpp
===================================================================
--- scummvm/trunk/sound/audiostream.cpp	2008-05-24 22:11:41 UTC (rev 32257)
+++ scummvm/trunk/sound/audiostream.cpp	2008-05-24 22:41:15 UTC (rev 32258)
@@ -102,6 +102,11 @@
 #pragma mark --- LinearMemoryStream ---
 #pragma mark -
 
+inline int32 calculatePlayTime(int rate, int samples) {
+	int32 seconds = samples / rate;
+	int32 milliseconds = (1000 * (samples % rate)) / rate;
+	return seconds * 1000 + milliseconds;
+}
 
 /**
  * A simple raw audio stream, purely memory based. It operates on a single
@@ -122,10 +127,11 @@
 	const byte *_loopEnd;
 	const int _rate;
 	const byte *_origPtr;
+	const int32 _playtime;
 
 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) {
+		: _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)
@@ -147,10 +153,11 @@
 	}
 	int readBuffer(int16 *buffer, const int numSamples);
 
-	bool isStereo() const		{ return stereo; }
-	bool endOfData() const		{ return _ptr >= _end; }
+	bool isStereo() const			{ return stereo; }
+	bool endOfData() const			{ return _ptr >= _end; }
 
-	int getRate() const			{ return _rate; }
+	int getRate() const				{ return _rate; }
+	int32 getTotalPlayTime() const	{ return _playtime; }
 };
 
 template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>

Modified: scummvm/trunk/sound/audiostream.h
===================================================================
--- scummvm/trunk/sound/audiostream.h	2008-05-24 22:11:41 UTC (rev 32257)
+++ scummvm/trunk/sound/audiostream.h	2008-05-24 22:41:15 UTC (rev 32258)
@@ -93,6 +93,20 @@
 	 *			NULL in case of an error (e.g. invalid/nonexisting file)
 	 */
 	static AudioStream* openStreamFile(const Common::String &basename, uint32 startTime = 0, uint32 duration = 0, uint numLoops = 1);
+
+	enum {
+		kUnknownPlayTime = -1
+	};
+
+	/**
+	 * Returns total playtime of the AudioStream object.
+	 * Note that this does not require to return an playtime, if the
+	 * playtime of the AudioStream is unknown it returns 'kUnknownPlayTime'.
+	 * @see kUnknownPlayTime
+	 *
+	 * @return	playtime in milliseconds
+	 */
+	int32 getTotalPlayTime() const { return kUnknownPlayTime; }
 };
 
 /**


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