MoBI_frames_Brescia.m 1.5 KB

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