# precise control of audiovisual SOA

**URL:** <https://psychtoolbox.discourse.group/t/precise-control-of-audiovisual-soa/127>\
**Category:** Uncategorized\
**Created:** [March 29, 2017, 12:40pm UTC](https://psychtoolbox.discourse.group/t/precise-control-of-audiovisual-soa/127 "2017-03-29T12:40:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [March 29, 2017, 12:40pm UTC](https://psychtoolbox.discourse.group/t/precise-control-of-audiovisual-soa/127/1 "2017-03-29T12:40:19Z")

</div>

Dear all,

  

I need precise control of audiovisual SOA, with sound onset leading visual onset. &nbsp;I figured out a way of doing that (see code below) but I’m not sure it’s the best, so I need advice.

  

VBLref = Screen('Flip', window);&nbsp;% get a reference VBL! Everything else will depend on it!

Screen('FillRect', window, 255, rect);&nbsp;% draw visual stimulus!

Screen('DrawingFinished', window);&nbsp;% useful for better timing if visual stimulus is complex!

PsychPortAudio('RescheduleStart', pahandle, VBLref + audDelay, 0);&nbsp;% delay audio by audDelay Re: VBLref!!

[VBL, trueVisualOnset] = Screen('Flip', window, VBLref + (3 - 0.5)\*ifi);&nbsp;% delay visual by 3 frames Re: VBLref!!

Screen('Flip', window, VBL + (nFrames - 0.5)\*ifi);&nbsp;% remove visual stimulus, so that stimulus duration is nFrames

  

As a result, the AV asynchrony would be precisely = 3\*ifi - audDelay

  

If you use pause() or WaitSecs(), please ignore this…

  

Thanks!

Best,

Yinan
