libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmTime.c 565B

1234567891011121314151617181920212223
  1. #include "cmPrefix.h"
  2. #include "cmGlobal.h"
  3. #include "cmTime.h"
  4. void cmTimeGet( cmTimeSpec_t* t )
  5. { clock_gettime(CLOCK_REALTIME,t); }
  6. // this assumes that the seconds have been normalized to a recent start time
  7. // so as to avoid overflow
  8. unsigned cmTimeElapsedMicros( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
  9. {
  10. // convert seconds to usecs
  11. long u0 = t0->tv_sec * 1000000;
  12. long u1 = t1->tv_sec * 1000000;
  13. // convert nanoseconds to usec
  14. u0 += t0->tv_nsec / 1000;
  15. u1 += t1->tv_nsec / 1000;
  16. // take diff between t1 and t0
  17. return u1 - u0;
  18. }