aboutsummaryrefslogtreecommitdiff
path: root/sound/timestamp.h
diff options
context:
space:
mode:
authorMax Horn2010-01-06 12:09:14 +0000
committerMax Horn2010-01-06 12:09:14 +0000
commit5b635fd610a2d1f895adadbb43af3a76a36f1fd0 (patch)
tree8f0100d3eac84d0669bb37faf92b5c0955519507 /sound/timestamp.h
parent69566f6bf127af0ebdca73d2f33e30b6a0321094 (diff)
downloadscummvm-rg350-5b635fd610a2d1f895adadbb43af3a76a36f1fd0.tar.gz
scummvm-rg350-5b635fd610a2d1f895adadbb43af3a76a36f1fd0.tar.bz2
scummvm-rg350-5b635fd610a2d1f895adadbb43af3a76a36f1fd0.zip
Change the way Timestamp stores its data.
Instead of storing milliseconds and frames (which causes rounding errors, and causes ambiguity in how a given time is stored), we now do things differently: We store a number of seconds, and frames. To make sure that we can still handle milliseconds accurately, though, we change the framerate to the least common multiple of the original framerate and 1000. So 60 becomes 6000, and 44100 becomes 441000. There are no visible changes for client code, except for the increased accuracy. svn-id: r47070
Diffstat (limited to 'sound/timestamp.h')
-rw-r--r--sound/timestamp.h38
1 files changed, 29 insertions, 9 deletions
diff --git a/sound/timestamp.h b/sound/timestamp.h
index 218198dcf7..2e8689a81d 100644
--- a/sound/timestamp.h
+++ b/sound/timestamp.h
@@ -39,24 +39,36 @@ namespace Audio {
class Timestamp {
protected:
/**
- * The millisecond part of this timestamp.
- * The total time represented by this timestamp is
+ * The seconds part of this timestamp.
+ * The total time in seconds represented by this timestamp can be
* computed as follows:
- * _msecs + 1000 * _numberOfFrames / _framerate
+ * _secs + (double)_numberOfFrames / _framerate
*/
- uint _msecs;
+ uint _secs;
/**
- * The number of frames which together with _msecs encodes
+ * The number of frames which together with _secs encodes
* the timestamp. The total number of frames represented
* by this timestamp is computed as follows:
- * _numberOfFrames + _msecs * _framerate / 1000
+ * _numberOfFrames + _secs * _framerate
*/
int _numberOfFrames;
- /** The framerate, i.e. the number of frames per second. */
+ /**
+ * The internal framerate, i.e. the number of frames per second.
+ * This is computed as the least common multiple of the framerate
+ * specified by the client code, and 1000.
+ * This way, we ensure that we can store both frames and
+ * milliseconds without any rounding losses.
+ */
int _framerate;
+ /**
+ * Factor by which the original framerate specified by the client
+ * code was multipled to obtain the internal _framerate value.
+ */
+ int _framerateFactor;
+
public:
/**
* Set up a timestamp with a given time and framerate.
@@ -72,7 +84,13 @@ public:
*/
Timestamp convertToFramerate(int newFramerate) const;
+ /**
+ * Check whether to timestamps describe the exact same moment
+ * in time. This means that two timestamps can compare
+ * as equal even if they use different framerates.
+ */
bool operator==(const Timestamp &ts) const;
+
bool operator!=(const Timestamp &ts) const;
// bool operator<(const Timestamp &ts) const;
// bool operator<=(const Timestamp &ts) const;
@@ -82,14 +100,16 @@ public:
/**
* Returns a new timestamp, which corresponds to the time encoded
* by this timestamp with the given number of frames added.
+ * @param frames number of frames to add
*/
Timestamp addFrames(int frames) const;
/**
* Returns a new timestamp, which corresponds to the time encoded
* by this timestamp with the given number of milliseconds added.
+ * @param msecs number of milliseconds to add
*/
- Timestamp addMsecs(int ms) const;
+ Timestamp addMsecs(int msecs) const;
/**
* Computes the number of frames between this timestamp and ts.
@@ -108,7 +128,7 @@ public:
uint32 msecs() const;
/** Return the framerate used by this timestamp. */
- int getFramerate() const { return _framerate; }
+ int getFramerate() const { return _framerate / _framerateFactor; }
};