From 0733e962bb6b84f9c3ed53b6f0fe77eeebbc1a71 Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Sun, 7 Sep 2014 12:31:23 +0100 Subject: [PATCH] rename absolute_time_in_ns to absolute_time_in_fp (more accurate name). Fix osx timing calculation. --- common.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/common.c b/common.c index a070a249..74ce7436 100644 --- a/common.c +++ b/common.c @@ -421,12 +421,12 @@ double vol2attn(double vol, long max_db, long min_db) { return vol_setting; } -uint64_t get_absolute_time_in_ns() { - uint64_t time_now_ns; +uint64_t get_absolute_time_in_fp() { + uint64_t time_now_fp; #ifdef COMPILE_FOR_LINUX struct timespec tn; clock_gettime(CLOCK_MONOTONIC,&tn); - time_now_ns=((uint64_t)tn.tv_sec<<32)+((uint64_t)tn.tv_nsec<<32)/1000000000; + time_now_fp=((uint64_t)tn.tv_sec<<32)+((uint64_t)tn.tv_nsec<<32)/1000000000; #endif #ifdef COMPILE_FOR_OSX uint64_t time_now_mach; @@ -438,7 +438,7 @@ uint64_t get_absolute_time_in_ns() { // If this is the first time we've run, get the timebase. // We can use denom == 0 to indicate that sTimebaseInfo is // uninitialised because it makes no sense to have a zero - // denominator is a fraction. + // denominator in a fraction. if ( sTimebaseInfo.denom == 0 ) { debug(1,"Mac initialise timebase info."); @@ -448,12 +448,13 @@ uint64_t get_absolute_time_in_ns() { // Do the maths. We hope that the multiplication doesn't // overflow; the price you pay for working in fixed point. - // need to turn this into NTP 64-bit fixed point format - // and change the very misleading title of this function to - // get_absolute_fp_time or something - time_now_ns = time_now_mach * sTimebaseInfo.numer / sTimebaseInfo.denom; + // this gives us nanoseconds + uint64_t time_now_ns = time_now_mach * sTimebaseInfo.numer / sTimebaseInfo.denom; + + // take the units and shift them to the upper half of the fp, and take the nanoseconds, shift them to the upper half and then divide the result to 1000000000 + time_now_fp = ((time_now_ns/1000000000)<<32) + (((time_now_ns%1000000000)<<32)/1000000000); #endif - return time_now_ns; + return time_now_fp; }