looping sounds

76 views
Skip to first unread message

jessica

unread,
May 7, 2008, 12:13:19 PM5/7/08
to E-Prime
Hi all,

Could someone please help me with a simple code to loop sound stimuli?
(e.g., ba, ba, ba, ba...)

I tried the 'Loop' function in the Properties section, but it doesn't
seem to be working properly - sometimes it doesn't loop at all (or
skips the sound altogether), sometimes the gap between repetitions is
way too long, or way too short... I don't know if this is because my
computer is too slow or something, but it's really frustrating! :(

Any help would be greatly appreciated!

Thanks in advance!

jessica

ben robinson

unread,
May 7, 2008, 12:50:24 PM5/7/08
to e-p...@googlegroups.com
could you simply place a label object (Label1) before the sound object, then following presentation of the sound use an inline to "Goto Label1"?

jessica

unread,
May 7, 2008, 1:07:10 PM5/7/08
to E-Prime
Thanks so much for your speedy response, Ben!

So I did what you suggested, and placed a label before SoundObject1,
and it's definitely repeating!

Now, how do I make it stop and move on to the next sound? For example,
how do I make it loop for say 10 times before SoundObject2 starts
playing?

Also, is there a way to place a small gap (e.g, 500 ms) between each
repetition?

I'm not really familiar with the whole scripting side of E-prime... so
many many thanks for your patience and help!!

:)


On May 7, 12:50 pm, "ben robinson" <baltimore....@gmail.com> wrote:
> could you simply place a label object (Label1) before the sound object, then
> following presentation of the sound use an inline to "Goto Label1"?
>

ben robinson

unread,
May 7, 2008, 1:17:48 PM5/7/08
to e-p...@googlegroups.com
in the same inline where you tell it to go to Label1, before going to Label1 you need to set up a counter.  when that counter = 10, you'll no longer Goto Label1.  to do this, in your user script tab:
Dim toneCount as Integer

in the inline after your sound object, before Goto Label1:
toneCount = toneCount +1
If toneCount <= 10 Then
   Goto Label1
Else
   toneCount = 0
End If

jessica

unread,
May 8, 2008, 10:49:09 AM5/8/08
to E-Prime
Ben, you are awesome! Thanks so much!

I have one more question for now... (sorry to take up so much of your
time!)

So now I know how to make this counter, but what if there is a
response before the counter is finished? For example, how can make
SoundObject 2 repeat for 5 times, OR until there is a response from
the participant, whichever comes first?

I hope that makes sense... I cannot tell you how much I appreciate
your help!

:)



On May 7, 1:17 pm, "ben robinson" <baltimore....@gmail.com> wrote:
> in the same inline where you tell it to go to Label1, before going to Label1
> you need to set up a counter. when that counter = 10, you'll no longer Goto
> Label1. to do this, in your user script tab:Dim toneCount as Integer
>
> in the inline after your sound object, before Goto Label1:
> toneCount = toneCount +1
> If toneCount <= 10 Then
> Goto Label1
> Else
> toneCount = 0
> End If
>

ben robinson

unread,
May 8, 2008, 11:31:44 AM5/8/08
to e-p...@googlegroups.com
how about...

> toneCount = toneCount +1
> If toneCount <= 10 Or NameOfObjectPresentingTone.RESP = "" Then

>    Goto Label1
> Else
>    toneCount = 0
> End If

jessica

unread,
May 8, 2008, 12:11:17 PM5/8/08
to E-Prime
Ben, you are a superstar... sorry, I wasn't clear before with my
previous post, so I have to ask one more last question (for now, if
that's okay!) :)

For this experiment, whenever the participant responds correctly, a
Movie Display will come on the screen. So, if there is a correct
response before the counter finishes, I need the program to jump
immediately to the Movie Display. I placed a Label before the Movie
Display, and tried to adapt your suggested code:

toneCount = toneCount +1

If toneCount <= 5 Then
Goto Label2

If TrainingSound2.RESP = "{SPACE}" Then
Goto Label3

Else
toneCount = 0

End If

***

But of course, I did something wrong... please correct me!

:)

On May 8, 11:31 am, "ben robinson" <baltimore....@gmail.com> wrote:
> how about...
>
> > toneCount = toneCount +1
> > If toneCount <= 10 Or NameOfObjectPresentingTone.RESP = "" Then
> > Goto Label1
> > Else
> > toneCount = 0
> > End If

jessica

unread,
May 8, 2008, 12:17:12 PM5/8/08
to E-Prime
If it helps, the error that comes up while trying to compile the
script is:

Encountered: EndSub
Expecting: Else, ElseIf, End If

James Keidel

unread,
May 8, 2008, 12:26:48 PM5/8/08
to e-p...@googlegroups.com
I think you just need to close the first If statement with an End If


> >
> > toneCount = toneCount +1
> >
> > If toneCount <= 5 Then
> > Goto Label2

End If

jessica

unread,
May 8, 2008, 12:47:15 PM5/8/08
to E-Prime
Thanks, James! Clearly, I've still got A LOT to learn! :)

Okay, so now the script is working, but it's not doing exactly what I
want - it still doesn't jump directly to the Movie Display once I hit
the space bar (the sound continues repeating, and actually seems to
repeat an extra time whenever I hit the space bar).

Any thoughts on how I can fix this?

James Keidel

unread,
May 9, 2008, 7:45:15 AM5/9/08
to e-p...@googlegroups.com
from looking at the code you posted earlier it appears that you are
testing the value of toneCount and if it meets some condition then you
go to label2. thus you never get to the test of the response. I
think the order you need to test things is check whether there is a
correct response, and if there is not then you check the value of the
toneCount. hope this makes sense.

JK

David McFarlane

unread,
May 9, 2008, 10:31:19 AM5/9/08
to e-p...@googlegroups.com
Jessica,

At 5/9/2008 07:45 AM Friday, James Keidel wrote:
>the order you need to test things is check whether there is a
>correct response, and if there is not then you check the value of the
>toneCount.

Just to complete James' thought, here is the script (with a bit of
rearangement, and adding comments):

toneCount = toneCount + 1
If (toneCount <= 5) And (TrainingSound2.RESP <> "{SPACE}"> Then
Goto Label2 ' repeat the training loop
Else
toneCount = 0 ' reset counter for next time
Goto Label3 ' exit the training loop
End If


BTW, if the movie object immediately follows this inline script, then
you shouldn't even need the final Goto. Also, strictly speaking,
since the first Goto jumps you out of the If ... Then, you don't even
need the Else clause (although it may improve readability if you
leave it in). Putting all those together, the script might become simply:

toneCount = toneCount + 1
If (toneCount <= 5) And (TrainingSound2.RESP <> "{SPACE}"> Then
Goto Label2 ' repeat the training loop
End If
' Training loop completed, reset counter for next time:
toneCount = 0
' And move on to the movie ...


But now I'm getting too pedantic.

-- David McFarlane, Professional Faultfinder

jessica

unread,
May 9, 2008, 12:09:00 PM5/9/08
to E-Prime
James and David - you are BRILLIANT!! Thank you soooo much for taking
the time to help me!! Thank you, thank you, THANK YOU!!!!!!! Really, I
cannot thank you enough!!

There's just ONE more thing... sorry, I keep saying that, but once one
problem is fixed, another issue inevitably pops up that I have no idea
how to fix (which I guess is the nature of research... bah).

Now, I need the movie to play ONLY after a response. If there is no
response, how do I make the program continue on to the next trial,
without going straight to the movie?

So here's the basic set up:

- Start Screen (where you press a button to proceed to the trial)
- Sound 1
- Sound 2
- Movie

So, if there is no response to Sound 2, I need it to go back to the
start screen, skipping the movie, and proceeding with the rest of the
trial list.

I tried this code, trying to adapt what you all gave me:

If (toneCount <= 5) And (TrainingSound2.RESP <> "") Then
Goto Label4 (where Label 4 was placed before the Start Screen)

Else
toneCount = 0

End If

and it seemed to work, but if there was no response, the list just
kept on cycling over and over again, instead of moving through to the
end (i.e., if I had 3 trials, and there was no response on those 3
trials, the list wouldn't end, it just kept starting over again... but
if I responded on those 3 trials, then the list would end).

Does that make sense?

Many many thanks in advance!!

:)

David McFarlane

unread,
May 9, 2008, 1:11:30 PM5/9/08
to e-p...@googlegroups.com
Jessica,

>I tried this code, trying to adapt what you all gave me:
>
>If (toneCount <= 5) And (TrainingSound2.RESP <> "") Then
> Goto Label4 (where Label 4 was placed before the Start Screen)
>Else
> toneCount = 0
>End If

Indeed, the "... And (TrainingSound2.RESP <> "")" means it will never
stop without a response. To make it stop you need to rewrite that
test as either

If (toneCount <= 5) And (TrainingSound2.RESP <> "") Then

or

If (toneCount <= 5) And (TrainingSound2.RESP = "{SPACE}") Then

Pay close attention to the differing use of = vs. <>, and "" vs.
"{SPACE}". This first example will exit the loop for *any* key
press, the second example will exit only for a *space* key.

Now, it sounds like, after the program plays five tones without a
response, you want it to skip the movie. If that is correct then ...
well, let's review the experiment structure first so we have
something to refer to (thanks for posting that). Here is how I
understand your experiment structure, with a few names changed to
suit my tastes:

- TrialList (this contains your three trials)
- TrialProc
- StartScreenLabel
- StartScreen (where you press a button to proceed to the trial)
- TrainingSound1
- TrainingSound2
- TrialResponseScript
- MovieLabel
- Movie
- NoMovieLabel

Now we have three possible outcomes: repeat the loop, play the
movie, or skip the movie and go right to the next trial. We need to
rearrange the logic of TrialResponseScript a bit, maybe something
like this (again, some renaming and commenting to suit my tastes):

toneCount = toneCount + 1

If TrainingSound2.RESP <> "" Then ' stop for any response


toneCount = 0 ' reset counter for next time

Goto MovieLabel
ElseIf toneCount <= 5 Then
Goto StartScreenLabel ' repeat the training loop
Else ' completed 5 loops with no response


toneCount = 0 ' reset counter for next time

Goto NoMovieLabel ' no response, so skip the movie
End If


There might be a better way to arrange that (makes me nervous to have
put same the counter reset in two branches), but that's enough
thinking for now.

David K McFarlane

unread,
May 10, 2008, 11:51:47 AM5/10/08
to e-p...@googlegroups.com
David McFarlane wrote:
>>I tried this code, trying to adapt what you all gave me:
>>
>>If (toneCount <= 5) And (TrainingSound2.RESP <> "") Then
>> Goto Label4 (where Label 4 was placed before the Start Screen)
>>Else
>> toneCount = 0
>>End If
>
> Indeed, the "... And (TrainingSound2.RESP <> "")" means it will never
> stop without a response.

Oops, I misread that the first time. The "... And (TrainingSound2.RESP <>
"")" really means that it will repeat the training sounds *only* if there
*is* a response *and* it has not yet done it five times. But this does not
correspond to the behavior that you report, so I suspect that the first
line of script was mis-copied. No matter, as by now you no doubt have your
program working with the help you've gotten.


Regards,
-- David McFarlane, Professional Faultfinder, trying to correct the record


jessica

unread,
May 13, 2008, 4:10:32 PM5/13/08
to E-Prime
THANK YOU, THANK YOU, THANK YOU!!!

To Ben, James, and David - I cannot even begin to express how
appreciative I am to you all for being so kind to take the time to
help me. Seriously, you have no idea...

As I told David, you're all going in my acknowledgements!! :) I know
that when I finally get to complete this project, there is absolutely
NO WAY that I could have done it without the help of you wonderful
people!!

Hopefully, this WILL be the LAST you'll hear from me (at least with
respect to this experiment) :)

Thank you again!!

All the best!! :)
Reply all
Reply to author
Forward
0 new messages