def present(save_fn: str, duration=120, n_trials=2010, iti=0.5, soa=3.0, jitter=0.2, volume=0.8, random_state=42, eeg=None, cf1=900, amf1=45, cf2=770, amf2=40.018, sample_rate=44100):
    '\n\n    Auditory SSAEP Experiment\n    ===========================\n\n\n    Parameters:\n    -----------\n\n    duration - duration of the recording in seconds (default 10)\n\n    n_trials - number of trials (default 10)\n\n    iti - intertrial interval (default 0.3)\n\n    soa - stimulus onset asynchrony, = interval between end of stimulus\n          and next trial (default 0.2)\n\n    jitter - jitter in the intertrial intervals (default 0.2)\n\n    secs - duration of the sound in seconds (default 0.2)\n\n    volume - volume of the sounds in [0,1] (default 0.8)\n\n    random_state - random seed (default 42)\n\n\n    '
    np.random.seed(random_state)
    markernames = [1, 2]
    record_duration = np.float32(duration)
    am1 = generate_am_waveform(cf1, amf1, secs=soa, sample_rate=sample_rate)
    am2 = generate_am_waveform(cf2, amf2, secs=soa, sample_rate=sample_rate)
    aud1 = sound.Sound(am1, sampleRate=sample_rate)
    aud1.setVolume(volume)
    aud2 = sound.Sound(am2, sampleRate=sample_rate)
    aud2.setVolume(volume)
    auds = [aud1, aud2]
    stim_freq = np.random.binomial(1, 0.5, n_trials)
    itis = (iti + (np.random.rand(n_trials) * jitter))
    trials = DataFrame(dict(stim_freq=stim_freq, timestamp=np.zeros(n_trials)))
    trials['iti'] = itis
    trials['soa'] = soa
    mywin = visual.Window([1920, 1080], monitor='testMonitor', units='deg', fullscr=True)
    fixation = visual.GratingStim(win=mywin, size=0.2, pos=[0, 0], sf=0, rgb=[1, 0, 0])
    fixation.setAutoDraw(True)
    mywin.flip()
    show_instructions(10)
    if eeg:
        eeg.start(save_fn, duration=record_duration)
    start = time()
    for (ii, trial) in trials.iterrows():
        core.wait((trial['iti'] + (np.random.randn() * jitter)))
        ind = trials['stim_freq'].iloc[ii]
        auds[ind].stop()
        auds[ind].play()
        if eeg:
            timestamp = time()
            if (eeg.backend == 'muselsl'):
                marker = [markernames[ind]]
                marker = list(map(int, marker))
            else:
                marker = markernames[ind]
            eeg.push_sample(marker=marker, timestamp=timestamp)
        mywin.flip()
        core.wait(soa)
        if (len(event.getKeys()) > 0):
            break
        if ((time() - start) > record_duration):
            break
        event.clearEvents()
    if eeg:
        eeg.stop()
    mywin.close()
Auditory SSAEP Experiment
===========================


Parameters:
-----------

duration - duration of the recording in seconds (default 10)

n_trials - number of trials (default 10)

iti - intertrial interval (default 0.3)

soa - stimulus onset asynchrony, = interval between end of stimulus
      and next trial (default 0.2)

jitter - jitter in the intertrial intervals (default 0.2)

secs - duration of the sound in seconds (default 0.2)

volume - volume of the sounds in [0,1] (default 0.8)

random_state - random seed (default 42)
def present(save_fn: str, duration=120, n_trials=2010, iti=0.5, soa=3.0, jitter=0.2, volume=0.8, random_state=42, eeg=None, cf1=900, amf1=45, cf2=770, amf2=40.018, sample_rate=44100):
    '\n\n    Auditory SSAEP Experiment\n    ===========================\n\n\n    Parameters:\n    -----------\n\n    duration - duration of the recording in seconds (default 10)\n\n    n_trials - number of trials (default 10)\n\n    iti - intertrial interval (default 0.3)\n\n    soa - stimulus onset asynchrony, = interval between end of stimulus\n          and next trial (default 0.2)\n\n    jitter - jitter in the intertrial intervals (default 0.2)\n\n    secs - duration of the sound in seconds (default 0.2)\n\n    volume - volume of the sounds in [0,1] (default 0.8)\n\n    random_state - random seed (default 42)\n\n\n    '
    np.random.seed(random_state)
    markernames = [1, 2]
    record_duration = np.float32(duration)
    am1 = generate_am_waveform(cf1, amf1, secs=soa, sample_rate=sample_rate)
    am2 = generate_am_waveform(cf2, amf2, secs=soa, sample_rate=sample_rate)
    aud1 = sound.Sound(am1, sampleRate=sample_rate)
    aud1.setVolume(volume)
    aud2 = sound.Sound(am2, sampleRate=sample_rate)
    aud2.setVolume(volume)
    auds = [aud1, aud2]
    stim_freq = np.random.binomial(1, 0.5, n_trials)
    itis = (iti + (np.random.rand(n_trials) * jitter))
    trials = DataFrame(dict(stim_freq=stim_freq, timestamp=np.zeros(n_trials)))
    trials['iti'] = itis
    trials['soa'] = soa
    mywin = visual.Window([1920, 1080], monitor='testMonitor', units='deg', fullscr=True)
    fixation = visual.GratingStim(win=mywin, size=0.2, pos=[0, 0], sf=0, rgb=[1, 0, 0])
    fixation.setAutoDraw(True)
    mywin.flip()
    show_instructions(10)
    if eeg:
        eeg.start(save_fn, duration=record_duration)
    start = time()
    for (ii, trial) in trials.iterrows():
        core.wait((trial['iti'] + (np.random.randn() * jitter)))
        ind = trials['stim_freq'].iloc[ii]
        auds[ind].stop()
        auds[ind].play()
        if eeg:
            timestamp = time()
            if (eeg.backend == 'muselsl'):
                marker = [markernames[ind]]
                marker = list(map(int, marker))
            else:
                marker = markernames[ind]
            eeg.push_sample(marker=marker, timestamp=timestamp)
        mywin.flip()
        core.wait(soa)
        if (len(event.getKeys()) > 0):
            break
        if ((time() - start) > record_duration):
            break
        event.clearEvents()
    if eeg:
        eeg.stop()
    mywin.close()