function [actual_frames, actual_seconds, nominal_frames, nominal_seconds] = MoBI_frames_Brescia(secs, ifi) % first output = number of frames output shortened by a 0.5 frames to be inserted into % the (Screen('Flip'), VBL) as waiting. This strategy allows to have % exactly the delay that is the closest one to the delay requested % second output = actual seconds to wait for the next flip to happen % example: the set delay is 0.21 secs, with a inter frame interval of % 0.0167 s (60 Hz refresh rate) % 0.21 s is not a multiple of the frame interval % so 0.21 is going to be rounded to the closer multple --> 13 frames (which corresponds to 0.2171s) % in order to avoid that Psuchtoolbox flips randomly at 13 or at 14 frames % the strategy is to reduce the delay to be inserted in the function by a % half frame. --> 12.5 % then the function transforms back the 12.5 frames into seconds % thus the flipping will happen always and exactly at (13 frames * ifi) which is 0.2171s % [actual_frames actual_seconds, nominal_frames nominal_seconds] = MoBI_frames_Brescia(0.21, 0.0167) % actual_frames = 12.5000 % actual_seconds = 0.2087 % nominal_frames = 13 % nominal_seconds = 0.2100 % rounds the indicated time to an exact number of frames nominal_frames = round(secs/ifi); % subtract half frames in order not to risk an overshoot (longer duration than required) actual_frames = nominal_frames - 0.5; % true waiting actual_seconds = actual_frames*ifi; nominal_seconds = secs; end