aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2011-02-09 00:12:22 +0000
committerMax Horn2011-02-09 00:12:22 +0000
commit633b8ed27784814e264edd943797e0c6d44366db (patch)
tree3c4238c9d8fca47cc0d6f14b435185e274ff7f7a /sound
parent97bfd60e61991be9ed6686d6eb70370a901d4371 (diff)
downloadscummvm-rg350-633b8ed27784814e264edd943797e0c6d44366db.tar.gz
scummvm-rg350-633b8ed27784814e264edd943797e0c6d44366db.tar.bz2
scummvm-rg350-633b8ed27784814e264edd943797e0c6d44366db.zip
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! svn-id: r55840
Diffstat (limited to 'sound')
-rw-r--r--sound/timestamp.cpp34
-rw-r--r--sound/timestamp.h12
2 files changed, 11 insertions, 35 deletions
diff --git a/sound/timestamp.cpp b/sound/timestamp.cpp
index 1eb5483fc2..1e49e1b476 100644
--- a/sound/timestamp.cpp
+++ b/sound/timestamp.cpp
@@ -148,21 +148,9 @@ Timestamp Timestamp::addMsecs(int ms) const {
}
void Timestamp::addIntern(const Timestamp &ts) {
+ assert(_framerate == ts._framerate);
_secs += ts._secs;
-
- 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;
- }
+ _numFrames += ts._numFrames;
normalize();
}
@@ -187,24 +175,6 @@ Timestamp Timestamp::operator-(const Timestamp &ts) const {
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;
diff --git a/sound/timestamp.h b/sound/timestamp.h
index 410445eccd..fef4107535 100644
--- a/sound/timestamp.h
+++ b/sound/timestamp.h
@@ -126,11 +126,17 @@ public:
// 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;
- Timestamp operator-(const Timestamp &ts) const;
-// Timestamp &operator+=(const Timestamp &ts);
-// Timestamp &operator-=(const Timestamp &ts);
+ /**
+ * Compute the difference between two timestamps. This is only
+ * allowed if they use the same framerate.
+ */
+ Timestamp operator-(const Timestamp &ts) const;
/**
* Computes the number of frames between this timestamp and ts.