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?
Question about time in OpenVibe
Question about time in OpenVibe
Last edited by toncho11 on Mon Apr 16, 2012 12:59 pm, edited 2 times in total.
Re: Question about time in OpenVibe
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
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
Re: Question about time in OpenVibe
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?
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?
Re: Question about time in OpenVibe
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.
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.