diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2007-07-15 18:00:20 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2007-07-15 18:00:20 +0000 |
commit | b05f8113fc20bfd28478fd43d9208a6b3d0e81b3 (patch) | |
tree | 0cd0bfcc7d378dfecc2912d93bcb880e7267b73c /osc | |
parent | 9d4dbf04277754f2a120719bf41b17d40dcc6736 (diff) |
Should compile on MSW now...
svn path=/trunk/externals/mrpeach/; revision=8082
Diffstat (limited to 'osc')
-rwxr-xr-x | osc/packOSC.c | 19 | ||||
-rwxr-xr-x | 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 <stdio.h> #include <string.h> #include <stdlib.h> -#include <sys/time.h> #ifdef MSW #include <winsock2.h> +#include <sys/timeb.h> #else #include <ctype.h> +#include <sys/time.h> #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 <stdio.h> #include <string.h> #include <stdlib.h> - #include <sys/time.h> #ifdef _WIN32 #include <winsock2.h> + #include <sys/timeb.h> #else #include <sys/types.h> #include <netinet/in.h> #include <ctype.h> + #include <sys/time.h> #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 */ |