# this implements a very basic auditory oddball task using PsychoPy
# see https://en.wikipedia.org/wiki/Oddball_paradigm for more details

from psychopy import prefs, visual, core, sound
import random

prefs.hardware['audioDevice'] = 'Speaker/HP (2- Realtek High Definition Audio)'

screen = visual.Window([800, 600], color='black', units='pix')
fixation = visual.TextStim(screen, text='+', color='white', height=50)
standard = sound.Sound('A', secs=0.5)  # standard sound stimulus
deviant = sound.Sound('C', secs=0.5)   # deviant sound stimulus

# present 10 trials of the oddball task
for trial in range(10):
    stimulus = random.choice([standard, standard, standard, standard, deviant])

    fixation.draw()
    screen.flip()
    core.wait(0.5)
    screen.flip()
    stimulus.play()  # play the randomly chosen stimulus

screen.close()
core.quit()
