From b05f8113fc20bfd28478fd43d9208a6b3d0e81b3 Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Sun, 15 Jul 2007 18:00:20 +0000 Subject: Should compile on MSW now... svn path=/trunk/externals/mrpeach/; revision=8082 --- osc/packOSC.c | 19 +++++++++++++++++-- osc/unpackOSC.c | 56 +++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/osc/packOSC.c b/osc/packOSC.c index ce73277..1a604a4 100755 --- a/osc/packOSC.c +++ b/osc/packOSC.c @@ -37,12 +37,13 @@ The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl #include #include #include -#include #ifdef MSW #include +#include #else #include +#include #endif #ifdef unix @@ -1268,9 +1269,22 @@ static OSCTimeTag OSCTT_Infinite(void) static OSCTimeTag OSCTT_CurrentTimePlusOffset(uint4 offset) { /* offset is in microseconds */ OSCTimeTag tt; + static unsigned int onemillion = 1000000; + static unsigned int onethousand = 1000; +#ifdef MSW + struct _timeb tb; + + _ftime(&tb); + + /* First get the seconds right */ + tt.seconds = (unsigned)SECONDS_FROM_1900_to_1970 + + (unsigned)tb.time+ + (unsigned)offset/onemillion; + /* Now get the fractional part. */ + tt.fraction = (unsigned)tb.millitm*onethousand + (unsigned)(offset%onemillion); /* in usec */ +#else struct timeval tv; struct timezone tz; - static unsigned int onemillion = 1000000; gettimeofday(&tv, &tz); @@ -1282,6 +1296,7 @@ static OSCTimeTag OSCTT_CurrentTimePlusOffset(uint4 offset) (unsigned) offset/onemillion; /* Now get the fractional part. */ tt.fraction = (unsigned) tv.tv_usec + (unsigned)(offset%onemillion); /* in usec */ +#endif if (tt.fraction > onemillion) { tt.fraction -= onemillion; diff --git a/osc/unpackOSC.c b/osc/unpackOSC.c index c4b39d1..c1ca36a 100755 --- a/osc/unpackOSC.c +++ b/osc/unpackOSC.c @@ -77,13 +77,14 @@ The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl #include #include #include - #include #ifdef _WIN32 #include + #include #else #include #include #include + #include #endif /* _WIN32 */ /* Declarations */ @@ -604,26 +605,43 @@ static int unpackOSC_IsNiceString(char *string, char *boundary) /* return the time difference in milliseconds between an OSC timetag and now */ static t_float unpackOSC_DeltaTime(OSCTimeTag tt) { - OSCTimeTag ttnow; - struct timeval tv; - struct timezone tz; static double onemillion = 1000000.0f; - double ttusec, nowusec, delta; + static double onethousand = 1000.0f; if (tt.fraction == 1 && tt.seconds == 0) return 0.0; /* immediate */ - gettimeofday(&tv, &tz); /* find now */ - /* First get the seconds right */ - ttnow.seconds = (unsigned) SECONDS_FROM_1900_to_1970 + - (unsigned) tv.tv_sec - - (unsigned) 60 * tz.tz_minuteswest + - (unsigned) (tz.tz_dsttime ? 3600 : 0); - /* find usec in tt */ - ttusec = tt.seconds*onemillion + ONE_MILLION_OVER_TWO_TO_THE_32*tt.fraction; - nowusec = ttnow.seconds*onemillion + tv.tv_usec; - /* subtract now from tt to get delta time */ - /* if (ttusec < nowusec) return 0.0; */ - /*negative delays are all right */ - delta = ttusec - nowusec; - return (float)(delta*0.001f); + else + { + OSCTimeTag ttnow; + double ttusec, nowusec, delta; +#ifdef MSW + struct _timeb tb; + + _ftime(&tb); /* find now */ + /* First get the seconds right */ + ttnow.seconds = (unsigned) SECONDS_FROM_1900_to_1970 + + (unsigned) tb.time; + /* find usec in tt */ + ttusec = tt.seconds*onemillion + ONE_MILLION_OVER_TWO_TO_THE_32*tt.fraction; + nowusec = ttnow.seconds*onemillion + tb.millitm*onethousand; +#else + struct timeval tv; + struct timezone tz; + + gettimeofday(&tv, &tz); /* find now */ + /* First get the seconds right */ + ttnow.seconds = (unsigned) SECONDS_FROM_1900_to_1970 + + (unsigned) tv.tv_sec - + (unsigned) 60 * tz.tz_minuteswest + + (unsigned) (tz.tz_dsttime ? 3600 : 0); + /* find usec in tt */ + ttusec = tt.seconds*onemillion + ONE_MILLION_OVER_TWO_TO_THE_32*tt.fraction; + nowusec = ttnow.seconds*onemillion + tv.tv_usec; +#endif /* ifdef MSW */ + /* subtract now from tt to get delta time */ + /* if (ttusec < nowusec) return 0.0; */ + /*negative delays are all right */ + delta = ttusec - nowusec; + return (float)(delta*0.001f); + } } /* end of unpackOSC.c */ -- cgit v1.2.1