diff options
| author | Matthew Hoops | 2010-05-17 20:53:04 +0000 |
|---|---|---|
| committer | Matthew Hoops | 2010-05-17 20:53:04 +0000 |
| commit | 811fc0e7ec04950d0a4454d1780e49a4d87af9ae (patch) | |
| tree | 7436667ee81f126b0a95015fe06f17b0409d7a38 /sound | |
| parent | dd0c1fd6f0b0cca6fba9c189b69debe28fe8a078 (diff) | |
| download | scummvm-rg350-811fc0e7ec04950d0a4454d1780e49a4d87af9ae.tar.gz scummvm-rg350-811fc0e7ec04950d0a4454d1780e49a4d87af9ae.tar.bz2 scummvm-rg350-811fc0e7ec04950d0a4454d1780e49a4d87af9ae.zip | |
Add the Common::Rational class from patch #2963496 (VideoDecoder Rewrite)
svn-id: r49061
Diffstat (limited to 'sound')
| -rw-r--r-- | sound/timestamp.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/sound/timestamp.cpp b/sound/timestamp.cpp index f705ff4521..1eb5483fc2 100644 --- a/sound/timestamp.cpp +++ b/sound/timestamp.cpp @@ -24,23 +24,15 @@ */ #include "sound/timestamp.h" +#include "common/algorithm.h" namespace Audio { -static uint gcd(uint a, uint b) { - while (a > 0) { - int tmp = a; - a = b % a; - b = tmp; - } - return b; -} - Timestamp::Timestamp(uint ms, uint fr) { assert(fr > 0); _secs = ms / 1000; - _framerateFactor = 1000 / gcd(1000, fr); + _framerateFactor = 1000 / Common::gcd<uint>(1000, fr); _framerate = fr * _framerateFactor; // Note that _framerate is always divisible by 1000. @@ -51,7 +43,7 @@ Timestamp::Timestamp(uint s, uint frames, uint fr) { assert(fr > 0); _secs = s; - _framerateFactor = 1000 / gcd(1000, fr); + _framerateFactor = 1000 / Common::gcd<uint>(1000, fr); _framerate = fr * _framerateFactor; _numFrames = frames * _framerateFactor; @@ -62,10 +54,10 @@ Timestamp Timestamp::convertToFramerate(uint newFramerate) const { Timestamp ts(*this); if (ts.framerate() != newFramerate) { - ts._framerateFactor = 1000 / gcd(1000, newFramerate); + ts._framerateFactor = 1000 / Common::gcd<uint>(1000, newFramerate); ts._framerate = newFramerate * ts._framerateFactor; - const uint g = gcd(_framerate, ts._framerate); + const uint g = Common::gcd(_framerate, ts._framerate); const uint p = _framerate / g; const uint q = ts._framerate / g; @@ -122,7 +114,7 @@ bool Timestamp::operator>=(const Timestamp &ts) const { int Timestamp::cmp(const Timestamp &ts) const { int delta = _secs - ts._secs; if (!delta) { - const uint g = gcd(_framerate, ts._framerate); + const uint g = Common::gcd(_framerate, ts._framerate); const uint p = _framerate / g; const uint q = ts._framerate / g; @@ -164,7 +156,7 @@ void Timestamp::addIntern(const Timestamp &ts) { // 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 = gcd(_framerate, ts._framerate); + const uint g = Common::gcd(_framerate, ts._framerate); const uint p = _framerate / g; const uint q = ts._framerate / g; @@ -227,7 +219,7 @@ int Timestamp::frameDiff(const Timestamp &ts) const { // 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 = gcd(_framerate, ts._framerate); + const uint g = Common::gcd(_framerate, ts._framerate); const uint p = _framerate / g; const uint q = ts._framerate / g; |
