"""
=============
A-V sync test
=============

This example tests synchronization between the screen and the audio playback.

NOTE: On Linux (w/NVIDIA), XFCE has been observed to give consistent timings,
whereas Compiz WMs did not (doubled timings).
"""
# Author: Dan McCloy <drmccloy@uw.edu>
#
# License: BSD (3-clause)

import numpy as np
import matplotlib.pyplot as plt

from expyfun import ExperimentController
import expyfun.analyze as ea

print(__doc__)


# Fullscreen MUST be used to guarantee flip accuracy!
with ExperimentController('SyncTest', full_screen=True, noise_db=-np.inf,
                          participant='s', session='0', output_dir=None,
                          suppress_resamp=True, check_rms=None) as ec:
    ec.load_buffer(np.r_[0.1, np.zeros(99)])  # RMS == 0.01
    pressed = None
    screenshot = None
    while pressed != '8':  # enable a clean quit if required
        ec.set_background_color('white')
        t1 = ec.start_stimulus(start_of_trial=False)  # skip checks
        ec.set_background_color('black')
        t2 = ec.flip()
        diff = round(1000 * (t2 - t1), 2)
        ec.screen_text('IFI (ms): {}'.format(diff), wrap=False)
        screenshot = ec.screenshot() if screenshot is None else screenshot
        ec.flip()
        pressed = ec.wait_one_press(0.5)[0]
        ec.stop()

plt.ion()
ea.plot_screen(screenshot)

@@ -39,17 +39,16 @@
 =======%0A
-%0A
 This exa
@@ -117,17 +117,16 @@
 ayback.%0A
-%0A
 NOTE: On
@@ -406,16 +406,50 @@
 troller%0A
+from expyfun.visual import Circle%0A
 import e
@@ -856,24 +856,169 @@
 shot = None%0A
+    # Make a circle so that the photodiode can be centered on the screen%0A    circle = Circle(ec, 1, units='deg', fill_color='k', line_color='w')%0A
     while pr
@@ -1338,21 +1338,42 @@
 ), wrap=
-False
+True)%0A        circle.draw(
 )%0A      

add circle