Mercurial > hg > vamp-plugin-sdk
diff src/vamp-sdk/RealTime.cpp @ 419:55de53d7c777
Merge
author | Chris Cannam |
---|---|
date | Tue, 01 Mar 2016 12:21:23 +0000 |
parents | 6f88563ea26f |
children | 35fa4733bc5d |
line wrap: on
line diff
--- a/src/vamp-sdk/RealTime.cpp Tue Mar 01 12:10:29 2016 +0000 +++ b/src/vamp-sdk/RealTime.cpp Tue Mar 01 12:21:23 2016 +0000 @@ -92,7 +92,14 @@ RealTime RealTime::fromSeconds(double sec) { - return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION + 0.5)); + if (sec != sec) { // NaN + cerr << "ERROR: NaN/Inf passed to Vamp::RealTime::fromSeconds" << endl; + return RealTime::zeroTime; + } else if (sec >= 0) { + return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION + 0.5)); + } else { + return -fromSeconds(-sec); + } } RealTime @@ -139,10 +146,6 @@ std::stringstream out; out << *this; -#if (__GNUC__ < 3) - out << std::ends; -#endif - std::string s = out.str(); // remove trailing R @@ -157,17 +160,19 @@ std::stringstream out; if (sec >= 3600) { - out << (sec / 3600) << ":"; + out << (sec / 3600) << ":"; } - + if (sec >= 60) { - out << (sec % 3600) / 60 << ":"; + int minutes = (sec % 3600) / 60; + if (sec >= 3600 && minutes < 10) out << "0"; + out << minutes << ":"; } - + if (sec >= 10) { - out << ((sec % 60) / 10); + out << ((sec % 60) / 10); } - + out << (sec % 10); int ms = msec(); @@ -191,16 +196,11 @@ out << ".000"; } -#if (__GNUC__ < 3) - out << std::ends; -#endif - std::string s = out.str(); return s; } - RealTime RealTime::operator/(int d) const {