Permalink
Browse files

fixed a bug

should fix a bug with OSC timetags
  • Loading branch information...
1 parent 923f9fa commit 9963270382f82ff40ecb47e45af90f2bf431d459 @mrRay committed Oct 12, 2016
Showing with 11 additions and 7 deletions.
  1. +2 −2 VVOSC/FrameworkSrc/OSCBundle.m
  2. +9 −5 VVOSC/FrameworkSrc/OSCValue.m
@@ -28,7 +28,7 @@ + (void) parseRawBuffer:(unsigned char *)b ofMaxLength:(int)l toInPort:(id)p inh
if (time_s==0 && (time_us==0 || time_us==1))
localTimeTag = d;
else {
- double timeSinceRefDate = ((double)(time_s)) + ((double)time_us)/((double)1000000.0);
+ double timeSinceRefDate = ((double)(time_s)) + ((double)time_us)/((double)4294967296.0);
// ...the "reference date" in OSC is 1/1/1900, so we have to account for one century plus one year's worth of seconds to this...
timeSinceRefDate -= 3187296000.;
localTimeTag = [NSDate dateWithTimeIntervalSinceReferenceDate:timeSinceRefDate];
@@ -217,7 +217,7 @@ - (void) writeToBuffer:(unsigned char *)b {
// ...the "reference date" in OSC is 1/1/1900, so we have to account for one century plus one year's worth of seconds to this...
interval += 3187296000.;
uint32_t time_s = CFSwapInt32HostToBig((uint32_t)floor(interval));
- uint32_t time_us = CFSwapInt32HostToBig((uint32_t)(floor((double)1000000.0 * ((double)(interval - floor(interval))))));
+ uint32_t time_us = CFSwapInt32HostToBig((uint32_t)(floor((double)4294967296.0 * ((double)(interval - floor(interval))))));
writeOffset = 8;
*((long *)(b+writeOffset)) = time_s;
writeOffset = 12;
@@ -18,7 +18,12 @@ - (NSString *) description {
case OSCValTimeTag:
//return [NSString stringWithFormat:@"<OSCVal t: %ld-%ld>",*(long *)(value),*(long *)(value+1)];
//return [NSString stringWithFormat:@"<OSCVal t: %ld-%ld>",(unsigned long)(*((uint64_t *)value)>>32),(unsigned long)((*(uint64_t *)value) & 0x00000000FFFFFFFF)];
- return [NSString stringWithFormat:@"<OSCVal t: %@>",[self dateValue]];
+ //return [NSString stringWithFormat:@"<OSCVal t: %@>",[self dateValue]];
+ {
+ NSDateFormatter *fmt = [[[NSDateFormatter alloc] init] autorelease];
+ [fmt setDateFormat:@"dd/MM, HH:mm:ss.SSSSS"];
+ return [fmt stringFromDate:[self dateValue]];
+ }
case OSCVal64Int:
return [NSString stringWithFormat:@"<OSCVal h: %qi>",*(long long *)value];
case OSCValDouble:
@@ -265,9 +270,8 @@ - (id) initTimeWithDate:(NSDate *)n {
// ...the "reference date" in OSC is 1/1/1900, so we have to account for one century plus one year's worth of seconds to this...
double tmpVal = [n timeIntervalSinceReferenceDate];
tmpVal += 3187296000.;
- //NSLog(@"\t\ttime since ref date is %f",tmpVal);
uint64_t time_s = floor(tmpVal);
- uint64_t time_us = floor((double)1000000.0 * (tmpVal - (double)time_s));
+ uint64_t time_us = (tmpVal - (double)time_s) * 4294967296.0;
value = malloc(sizeof(uint64_t));
*(uint64_t *)value = time_s<<32 | time_us;
//NSLog(@"\t\tvalue is %qu",*(uint64_t *)value);
@@ -559,7 +563,7 @@ - (struct timeval) timeValue {
- (NSDate *) dateValue {
double tmpTime = 0.;
tmpTime = (double)(*((uint64_t *)value)>>32);
- tmpTime += (double)((*(uint64_t *)value) & 0xFFFFFFFF) / 1000000.0;
+ tmpTime += (double)((*(uint64_t *)value) & 0xFFFFFFFF) / 4294967296.0;
// ...the "reference date" in OSC is 1/1/1900, so we have to account for one century plus one year's worth of seconds to this...
tmpTime -= 3187296000.;
NSDate *returnMe = [NSDate dateWithTimeIntervalSinceReferenceDate:tmpTime];
@@ -672,7 +676,7 @@ - (double) calculateDoubleValue {
break;
case OSCValTimeTag:
returnMe = (double)(*((uint64_t *)value)>>32);
- returnMe += (double)((*(uint64_t *)value) & 0xFFFFFFFF) / 1000000.0;
+ returnMe += (double)((*(uint64_t *)value) & 0xFFFFFFFF) / 4294967296.0;
/*
returnMe = *((long *)(value));
returnMe += *((long *)(value+1));

0 comments on commit 9963270

Please sign in to comment.