Question about time in OpenVibe

Come here to discuss about OpenViBE in general!
Post Reply
toncho11
Posts: 124
Joined: Tue Apr 19, 2011 7:58 pm

Question about time in OpenVibe

Post by toncho11 »

Time in OpenVibe is represented in 32:32 64bit number, right. This is like BCD numbers I believe.

Not sure I got it right.

Suppose I want to convert variable N which contains time in ms to OpenVibe's times format.

I need to:

int N = 4500 ms

uint64 k = N / 1000; //k are integer seconds that needs to be encoded in the left 32 bits
uint64 m = N % 1000; //m is the fraction that needs to be encoded in the right 32 bits

uint64 result;

k = k << 32; //we relocate the seconds to the left and leave space for the fraction

result = k | m;//merge the two, but keep them in their own bits

so now "result" contains "N" in format that can be used for addition and subtraction with other time values in OpenVibe?
Last edited by toncho11 on Mon Apr 16, 2012 12:59 pm, edited 2 times in total.

yrenard
Site Admin
Posts: 645
Joined: Fri Sep 01, 2006 3:39 pm
Contact:

Re: Question about time in OpenVibe

Post by yrenard »

Dear Anton,

if you haven't read it already, please look at A (rather long) story about time, then read Fixed Point Arithmetic on Wikipedia :) You'll know everything about how it works and hopefully understand why it must be this way.

Hope this helps,
Regards,
Yann

toncho11
Posts: 124
Joined: Tue Apr 19, 2011 7:58 pm

Re: Question about time in OpenVibe

Post by toncho11 »

Hi,

I am doing something wrong above.

When I convert my time to OpenVibe's time and then print it like that:

logm << LogLevel_Info << "stimulation time stamp: " << time64(result) << "\n";

then I see that milliseconds are lost. That is, I encoded them, but OpenVibe does not find them. It prints "xxx.000 sec".

So the problem I suppose is that I am not encoding the seconds and milliseconds correctly?

toncho11
Posts: 124
Joined: Tue Apr 19, 2011 7:58 pm

Re: Question about time in OpenVibe

Post by toncho11 »

Ok,

I did:

uint64 time_ms = 4500;

float64 time_sec = (float64)time_ms / (float64)1000;

uint64 ov_time = (uint64)(time_sec * 1024)<<22;

Ant it seems to work, but I am not 100% sure it is OK.

I will appreciate some clarification.

Post Reply