/usr/share/psychtoolbox-3/PsychJava/JavaTimeToGetSecs.m is in psychtoolbox-3-common 3.0.9+svn2579.dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | function timeSecs=JavaTimeToGetSecs(javaTime, updateInterval)
% timeSecs=JavaTimeToGetSecs(javaTime, [updateInterval])
%
% Convert time as reported by "java.lang.System.currentTimeMillis()" to
% GetSecs units.
%
% The Java timebase and JavaTimeToGetSecs are used internally by GetChar
% because Java calls underlying GetChar timestamp keyboard events in those
% units.
%
% updateInterval is the number of seconds before this function updates its
% internal timing cache measuring the difference between GetSecs and
% java.lang.System.currentTimeMillis(). If set to -1, the cache is only
% made the first time this function funs. When ommitted, it defaults to 0,
% i.e., it recaches at every call.
%
%
% see also:
% HISTORY
%
% 6/7/06 awi Wrote it.
% 6/13/06 awi Do not cache difference between Java and GetSecs clocks;
% their clocks run at different rates.
% 6/14/06 awi Commented out Priority calls surrounding the loop which
% samples GetSecs and java.lang.System.currentTimeMillis()
% for purpose of finding their difference. Those calls would
% make JavaTimeToGetSecs impractically slow for use by
% GetSecs, JavaTimeToGetSecs' raison d'?tre. This is not
% really so bad; if you want better timing, raise Priority
% before calling GetChar.
persistent JAVA_CURRENTTIMEMILIS_GETSECS_CLOCKS_DIFF;
if nargin == 2
updateIntervalSecs = updateInterval;
else
updateIntervalSecs = 0;
end
updateLoops = 10;
if isempty(JAVA_CURRENTTIMEMILIS_GETSECS_CLOCKS_DIFF)
doRecache = true;
elseif updateIntervalSecs < 0
doRecache = false;
else
doRecache = (GetSecs - JAVA_CURRENTTIMEMILIS_GETSECS_CLOCKS_DIFF.lastSampleTimeSecs) >= updateIntervalSecs;
end
% Periodically re-estimate and cache the difference between the
% java.lang.System.currentTimeMillis() and GetSecs clocks.
if doRecache
JAVA_CURRENTTIMEMILIS_GETSECS_CLOCKS_DIFF.lastSampleTimeSecs = GetSecs;
timeASecs=zeros(1,updateLoops);
timeBMillisecs=zeros(1,updateLoops);
timeCSecs=zeros(1,updateLoops);
for i = 1:updateLoops
timeASecs(i)=GetSecs;
timeBMilliSecs(i)=java.lang.System.currentTimeMillis();
timeCSecs(i)=GetSecs;
end
timeBSecs= timeBMilliSecs/1000;
passIntervals= timeCSecs-timeASecs;
[shortPassTime, shortPassIndex]=min(passIntervals);
getSecsAtJavaCall= (timeCSecs(shortPassIndex) - timeASecs(shortPassIndex)) / 2 + timeASecs(shortPassIndex);
JAVA_CURRENTTIMEMILIS_GETSECS_CLOCKS_DIFF.diffSecs = timeBSecs(shortPassIndex) - getSecsAtJavaCall;
end
% Using estimated difference between clocks, calculate GetSecs time for given Java currentTimeMillis() value.
timeSecs= javaTime / 1000.0 - JAVA_CURRENTTIMEMILIS_GETSECS_CLOCKS_DIFF.diffSecs;
|