# HG changeset patch # User cannam # Date 1213618936 0 # Node ID dbab8c3a6571238171812d77f8f240b3d954bcc9 # Parent 1b1ebb0f10ac93802e37cb2b47e1c84c0b6240b3 * Improve resilience of frame - real-time - frame round-trip conversions diff -r 1b1ebb0f10ac -r dbab8c3a6571 vamp-sdk/RealTime.cpp --- a/vamp-sdk/RealTime.cpp Wed Jun 11 09:14:27 2008 +0000 +++ b/vamp-sdk/RealTime.cpp Mon Jun 16 12:22:16 2008 +0000 @@ -224,17 +224,8 @@ RealTime::realTime2Frame(const RealTime &time, unsigned int sampleRate) { if (time < zeroTime) return -realTime2Frame(-time, sampleRate); - - // We like integers. The last term is always zero unless the - // sample rate is greater than 1MHz, but hell, you never know... - - long frame = - time.sec * sampleRate + - (time.msec() * sampleRate) / 1000 + - ((time.usec() - 1000 * time.msec()) * sampleRate) / 1000000 + - ((time.nsec - 1000 * time.usec()) * sampleRate) / 1000000000; - - return frame; + double s = time.sec + double(time.nsec + 1) / 1000000000.0; + return long(s * sampleRate); } RealTime @@ -245,7 +236,7 @@ RealTime rt; rt.sec = frame / long(sampleRate); frame -= rt.sec * long(sampleRate); - rt.nsec = (int)(((float(frame) * 1000000) / long(sampleRate)) * 1000); + rt.nsec = (int)(((double(frame) * 1000000.0) / sampleRate) * 1000.0); return rt; }