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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Feb 9 01:12:22 CET 2011


Revision: 55840
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55840&view=rev
Author:   fingolfin
Date:     2011-02-09 00:12:22 +0000 (Wed, 09 Feb 2011)

Log Message:
-----------
AUDIO: Forbid adding timestamps with differing framerate

We used to allow this, but the result is a timestamp with a framerate
potentially different from that of both original timestamps, which can
lead to completely unexpected behavior. For example, consider this code
snippet:
  a = a + b;
  a = a.addFrames(1);  // frame rate changed!

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

Modified: scummvm/trunk/sound/timestamp.cpp
===================================================================
--- scummvm/trunk/sound/timestamp.cpp	2011-02-09 00:12:02 UTC (rev 55839)
+++ scummvm/trunk/sound/timestamp.cpp	2011-02-09 00:12:22 UTC (rev 55840)
@@ -148,22 +148,10 @@
 }
 
 void Timestamp::addIntern(const Timestamp &ts) {
+	assert(_framerate == ts._framerate);
 	_secs += ts._secs;
+	_numFrames += ts._numFrames;
 
-	if (_framerate == ts._framerate) {
-		_numFrames += ts._numFrames;
-	} else {
-		// We need to multiply by the quotient of the two framerates.
-		// We cancel the GCD in this fraction to reduce the risk of
-		// overflows.
-		const uint g = Common::gcd(_framerate, ts._framerate);
-		const uint p = _framerate / g;
-		const uint q = ts._framerate / g;
-
-		_framerate *= q;
-		_numFrames = _numFrames * q + ts._numFrames * p;
-	}
-
 	normalize();
 }
 
@@ -187,26 +175,8 @@
 	return result;
 }
 
-/*
-Timestamp &Timestamp::operator+=(const Timestamp &ts) {
-	addIntern(ts);
-	return *this;
-}
-
-Timestamp &Timestamp::operator-=(const Timestamp &ts) {
-	addIntern(-ts);
-	return *this;
-}
-*/
-
-/*
 int Timestamp::frameDiff(const Timestamp &ts) const {
-	return (*this - ts).totalNumberOfFrames();
-}
-*/
 
-int Timestamp::frameDiff(const Timestamp &ts) const {
-
 	int delta = 0;
 	if (_secs != ts._secs)
 		delta = (_secs - ts._secs) * _framerate;

Modified: scummvm/trunk/sound/timestamp.h
===================================================================
--- scummvm/trunk/sound/timestamp.h	2011-02-09 00:12:02 UTC (rev 55839)
+++ scummvm/trunk/sound/timestamp.h	2011-02-09 00:12:22 UTC (rev 55840)
@@ -126,12 +126,18 @@
 	// unary minus
 	Timestamp operator-() const;
 
+	/**
+	 * Compute the sum of two timestamps. This is only
+	 * allowed if they use the same framerate.
+	 */
 	Timestamp operator+(const Timestamp &ts) const;
+
+	/**
+	 * Compute the difference between two timestamps. This is only
+	 * allowed if they use the same framerate.
+	 */
 	Timestamp operator-(const Timestamp &ts) const;
 
-//	Timestamp &operator+=(const Timestamp &ts);
-//	Timestamp &operator-=(const Timestamp &ts);
-
 	/**
 	 * Computes the number of frames between this timestamp and ts.
 	 * The frames are with respect to the framerate used by this


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