diff base/RealTimeSV.cpp @ 1262:c4f873749ab5 3.0-integration

RealTime fixes to comply with new, more demanding tests; also run same (failing) tests on Vamp SDK version
author Chris Cannam
date Tue, 15 Nov 2016 16:12:48 +0000
parents a2091d148d7f
children b7b84ae5f0a7
line wrap: on
line diff
--- a/base/RealTimeSV.cpp	Mon Nov 14 17:54:22 2016 +0000
+++ b/base/RealTimeSV.cpp	Tue Nov 15 16:12:48 2016 +0000
@@ -449,20 +449,21 @@
 {
     if (frame < 0) return -frame2RealTime_i(-frame, iSampleRate);
 
-    RealTime rt;
-    sv_frame_t sec = frame / iSampleRate;
-    rt.sec = int(sec);
+    int sec = int(frame / iSampleRate);
     frame -= sec * iSampleRate;
-    rt.nsec = (int)(((double(frame) * 1000000.0) / double(iSampleRate)) * 1000.0);
-    return rt;
+    int nsec = int((double(frame) / double(iSampleRate)) * ONE_BILLION + 0.5);
+    // Use ctor here instead of setting data members directly to
+    // ensure nsec > ONE_BILLION is handled properly.  It's extremely
+    // unlikely, but not impossible.
+    return RealTime(sec, nsec);
 }
 
 sv_frame_t
 RealTime::realTime2Frame(const RealTime &time, sv_samplerate_t sampleRate)
 {
     if (time < zeroTime) return -realTime2Frame(-time, sampleRate);
-    double s = time.sec + double(time.nsec + 1) / 1000000000.0;
-    return sv_frame_t(s * sampleRate);
+    double s = time.sec + double(time.nsec) / 1000000000.0;
+    return sv_frame_t(s * sampleRate + 0.5);
 }
 
 RealTime