Millisecond Forums

control when to stop a sound stimulus

https://forums.millisecond.com/Topic17417.aspx

By Nakayama Yao - 10/18/2015

Hi, Inquisit community,
Suppose I want to present a sound which lasts 3s, and I want it to stop at any point before the 3s . Which syntax should I use?
Best,
Nakayama
By Nakayama Yao - 10/18/2015

(*instead of using Timeout)
By Dave - 10/18/2015

You should use either /timeout or /trialduration, set to a random value below 3 seconds.

<values>
/ randomduration = 0
</values>

<sound mysound>
/ items = ("threeseconds.wav")
/ playthrough = false
</sound>

<trial sometrial>
/ ontrialbegin = [values.randomduration = round(rand(10,2999))]
/ stimulusframes = [1=mysound]
/ validresponse = (0)
/ timeout = values.randomduration
</trial>

There is no other way to "stop" a sound once it's started playing.
By Nakayama Yao - 10/18/2015

Thank you for your advice, Dave.
Best,
nakayama 
By nakayama - 10/25/2015

Hi, Dave.
It is possible to let this random value drawn following a normal distribution with a certain fixed mean and standard deviation, say, 2000 and 40? So the timeout stop approximately 68% times within 2000+_40.
ontrialbegin = [values.randomduration = round(rand(10,2999))]
Best,
Nakayama
By nakayama - 10/25/2015

stimulustimes property

I am trying to randomize the onset (stimulustimes) of the stimulus using this syntax, but it seems not working.

<trial time>
/ ontrialbegin = [clear(trial.time.stimulustimes]
/ ontrialbegin = [setitem(trial.time.stimulustimes,shape.targetdot,list.targetduration.nextvalue)]
/ stimulustimes = [1=fixation;2000=targetdot]
/ timeout = 2900
</trial>
Is there a way to fix this?
Thank you.
By Dave - 10/25/2015

Regarding your first question (sampling values from a normal distribution), see https://www.millisecond.com/forums/Topic8431.aspx

Regarding randomizing the onset of the stimulus, your syntax is invalid. You need to use the trial elements setstimulustime() function. See e.g. https://www.millisecond.com/forums/Topic11671.aspx as well as the language reference for setstimulustime(), resetstimulusframes(), etc.
By nakayama - 10/25/2015

Thank you Dave. Very appreciated for your advice.
The one for normal distribution generation appears complicated to comprehend so I decide to use discrete stimuli to approximate Gaussian.
Looking forward Inquisit to have some functions like norm().
Best,
nakayama


By nakayama - 10/25/2015

Hi, Dave.
Sorry for asking again.
Following your advice, I made this:
However, onset of items appears synchronous, is there a way to varying them using the values from list?

<list targetduration>
/ items = (2100,2200,2300,2400,2500)
/ selectionmode=random
</list>

<trial timepresent1>
/ ontrialbegin = [trial.timepresent1.setstimulustime(shape.dot2,list.targetduration.nextvalue);
trial.timepresent1.insertstimulustime(shape.dot3,list.targetduration.nextvalue);
trial.timepresent1.insertstimulustime(shape.dot4,list.targetduration.nextvalue)]
/ stimulustimes = [0=fixation;2000=erase]
/ timeout = 2900
/ ontrialend = [trial.timepresent1.resetstimulusframes()]
</trial>
By Dave - 10/25/2015

If you need to sample more than one value from a <list> in a given <trial>, you need to set its /selectionrate to always. The default is trial. Details can be found in the documentation for the /selectionrate attribute.

<list targetduration>
/ items = (2100,2200,2300,2400,2500)
/ selectionmode=random
/ selectionrate = always
</list>

You'll also have to think about resetting the list before it runs out of items (you are sampling without replacement). You'll want to do

<trial timepresent1>
...
/ ontrialend = [trial.timepresent1.resetstimulusframes(); list.targetduration.reset(); ]
</trial>                               
By nakayama - 10/25/2015

As always, thank you, Dave.
Best,
nakayama
By Nakayama Yao - 11/1/2015

Hi, Dave. 
I am wondering whether it is possible to track the position of the target, and erase it at random stimulustime, given that its position and onset varies randomly?  
So that they can appear and be erased randomly.
I guess should I use ontrialbegin? Thank you.

<list erase>
/ items = (2500,2600,2700,2800,2900)
/ selectionmode=random
/ selectionrate = always
</list>

<list targetduration>
/ items = (2100,2200,2300,2400,2500)
/ selectionmode=random
/ selectionrate = always
</list>
<trial timepresent1>
...
/ ontrialend = [trial.timepresent1.resetstimulusframes(); list.targetduration.reset(); ]
</trial>  

             
By Dave - 11/1/2015

Yes, and it works exactly like what you've already done. You've used the insertstimulustime() function to display your target(s) at a random onsets. You only need to do the exact same thing for the stimuli that erase the respective target(s).
By nakayama - 11/1/2015

Thank you for your reply. It works when the position of stimulus was set fixed. However, when the position was set according to a list:

...
/hposition=list.hpos1.nextvalue
/vposition=list.vpos1.nextvalue

How should I set the position of
if I want to erase shape 1?
It didn't erase shape1 if I input:

/hposition=shape.1.hposition
/vposition=shape.1.vposition
And input insertstimulus(shape.erase,list.eraseduration.nextvalue) under the same ontrislbegin with shape1

By Dave - 11/1/2015

Store positions etc. in global variables (<values> entries), reference those as needed:

<values>
/ s1h = 0
/ s1v = 0
/ s1onset = 0
/ s1duration = 0
/ s2h = 0
/ s2v = 0
/ s2onset = 0
/ s2duration = 0
</values>

<list onsets>
/ items = (2000,2500,3000,3500,4000,4500)
/ selectionrate = always
</list>

<list duration>
/ items = (100,200,300,400,500,600)
/ selectionrate = always
</list>

<list h>
/ items = (20%, 40%, 60%, 80%)
/ selectionrate = always
</list>

<list v>
/ items = (20%, 30%, 40%, 50%, 60%, 70%, 80%)
/ selectionrate = always
</list>

<block someblock>
/ trials = [1-10=sometrial]
</block>

<trial sometrial>
/ ontrialbegin = [values.s1h=list.h.nextvalue; values.s1v=list.v.nextvalue;
    values.s1onset=list.onsets.nextvalue; values.s1duration=list.duration.nextvalue;

    values.s2h=list.h.nextvalue; values.s2v=list.v.nextvalue;
    values.s2onset=list.onsets.nextvalue; values.s2duration=list.duration.nextvalue; ]
/ ontrialbegin = [trial.sometrial.insertstimulustime(shape.s1, values.s1onset);
    trial.sometrial.insertstimulustime(shape.e1, values.s1onset+values.s1duration);

    trial.sometrial.insertstimulustime(shape.s2, values.s2onset);
    trial.sometrial.insertstimulustime(shape.e2, values.s2onset+values.s2duration); ]

/ ontrialend = [trial.sometrial.resetstimulusframes(); list.h.reset(); list.v.reset(); list.duration.reset(); list.onsets.reset(); ]

/ stimulusframes = [1=info]
/ validresponse = (57)

</trial>

<shape s1>
/ shape = rectangle
/ color = red
/ size = (100px, 100px)
/ hposition = values.s1h
/ vposition = values.s1v
</shape>

<shape e1>
/ shape = rectangle
/ color = white
/ size = (100px, 100px)
/ hposition = values.s1h
/ vposition = values.s1v
</shape>

<shape s2>
/ shape = circle
/ color = green
/ size = (100px, 100px)
/ hposition = values.s2h
/ vposition = values.s2v
</shape>

<shape e2>
/ shape = circle
/ color = white
/ size = (100px, 100px)
/ hposition = values.s2h
/ vposition = values.s2v
</shape>

<text info>
/ items = ("S1: Onset = <%values.s1onset%> | Duration = <%values.s1duration%> | X = <%values.s1h%> | Y = <%values.s1v%>
~nS2: Onset = <%values.s2onset%> | Duration = <%values.s2duration%> | X = <%values.s2h%> | Y = <%values.s2v%>")
/ position = (50%, 5%)
/ erase = false
/ size = (90%, 5%)
</text>

By nakayama - 11/2/2015

Thank you Dave! this scrip helped a lot!