diff options
-rw-r--r-- | sound/timestamp.cpp | 9 | ||||
-rw-r--r-- | sound/timestamp.h | 8 | ||||
-rw-r--r-- | test/sound/timestamp.h | 2 |
3 files changed, 19 insertions, 0 deletions
diff --git a/sound/timestamp.cpp b/sound/timestamp.cpp index f6ac56bfad..6cf0c8fa9f 100644 --- a/sound/timestamp.cpp +++ b/sound/timestamp.cpp @@ -46,6 +46,15 @@ Timestamp::Timestamp(uint32 ms, int fr) { _numberOfFrames = (ms % 1000) * _framerate / 1000; } +Timestamp::Timestamp(uint s, int frames, int fr) { + assert(fr > 0); + + _secs = s; + _framerateFactor = 1000 / gcd(1000, fr); + _framerate = fr * _framerateFactor; + _numberOfFrames = 0; + *this = addFrames(frames); +} Timestamp Timestamp::convertToFramerate(int newFramerate) const { Timestamp ts(*this); diff --git a/sound/timestamp.h b/sound/timestamp.h index fcfa8cf5fc..cf149a65d0 100644 --- a/sound/timestamp.h +++ b/sound/timestamp.h @@ -78,6 +78,14 @@ public: Timestamp(uint32 msecs, int framerate); /** + * Set up a timestamp with a given time, frames and framerate. + * @param secs starting time in seconds + * @param frames starting frames + * @param framerate number of frames per second (must be > 0) + */ + Timestamp(uint secs, int frames, int framerate); + + /** * Return a timestamp which represents as closely as possible * the point in time describes by this timestamp, but with * a different framerate. diff --git a/test/sound/timestamp.h b/test/sound/timestamp.h index 6fc83480b4..0df459dc64 100644 --- a/test/sound/timestamp.h +++ b/test/sound/timestamp.h @@ -89,6 +89,8 @@ class TimestampTestSuite : public CxxTest::TestSuite const Audio::Timestamp a = Audio::Timestamp(500, 1000); Audio::Timestamp b = Audio::Timestamp(0, 1000); Audio::Timestamp c = Audio::Timestamp(0, 100); + + TS_ASSERT_EQUALS(a, Audio::Timestamp(0, 500, 1000)); TS_ASSERT(a != b); TS_ASSERT(a != c); |