Problem with feedback: no feedback on last trial

Hi, everyone! I’m having a little trouble. My experiment shows two melodies and participants should click on a green button if they’re the same, on a red if they’re not, and there’s a “check” sound for each button. Alternatively there’s a blank button if they don’t want to answer. It’s one routine in a loop with the route of the sounds in an excel file.

Experiment works great but on the last trial there’s no feedback sound. It looks like I’m missing how to end the experiment or something. The runner shows this message: 68.7590 WARNING t of last frame was 22.76ms (=1/43)

This is the code and a picture of the builder, if it helps. Thanks a lot.

Begin experiment

x = 1
clock = core.Clock()
soundfile = ['files/check.wav', 'files/blank.wav']
resultats = open('MiniMET melodia_resultats(' + expInfo['participant'] + ').txt', 'w')

Begin Routine

clock.reset()

mouserec=mouse.getPos()
minRT = 9

Each Frame

mouseloc = mouse.getPos()
if mouseloc[0]==mouserec[0] and mouseloc[1]==mouserec[1]:
    pass
elif correct.contains(mouse) or wrong.contains(mouse) or blank.contains(mouse):
     if t>minRT:
         continueRoutine = False
     else:
          mouserec = mouse.getPos()
          
if correct.contains(mouse) or wrong.contains(mouse):
    sound = soundfile[0]
else:
    sound = soundfile[1]

End Routine

if correct.contains(mouse):
    resultats.write(str(x) + ' correct ' + str(clock.getTime() - 9) + '\n')
    x += 1
elif wrong.contains(mouse):
    resultats.write(str(x) + ' wrong ' + str(clock.getTime() - 9) + '\n')
    x += 1
else:
    resultats.write(str(x) + ' blank ' + str(clock.getTime() - 9) + '\n')
    x += 1

let me know if you need more information… It’s a bit weird that only on the last trial there’s no feedback.

How does your feedback sound play? Maybe what you are hearing is the sound set by the previous loop at the beginning of the routine. That would explain your lack of final sound

The Sound parameter in the feedback_sound component is set to $sound, then I coded a list in Begin experiment and I call the sounds from the list on Each Frame. Once the participant taps the button, it sounds the “check” sound (sort of iPhone sound when you write on the keyboard). I saw this method on a tutorial, but maybe there’s a better one?

Begin experiment

soundfile = ['files/check.wav', 'files/blank.wav']

Each Frame

if correct.contains(mouse) or wrong.contains(mouse):
    sound = soundfile[0]
else:
    sound = soundfile[1]

I’ve not come across that method before. Since the click ends the routine I would put the feedback into a new routine which is set every repeat. You could also split out the pre-response part into a different routine too though if you have sound running across pre and during response that might take a little extra coding.

Thanks, now it works! Just out of curiosity, to learn: Why do you need to set the feedback sound in another routine and not the same one where the other complements are?

Code in Each Frame takes a lot of processing power (it’s being read up to 60 times per second) so it’s best to only execute a line of code once if you only need it once.

I suspect that the only reason to set a sound component every frame would be if you were using a dynamic frequency. I’m not sure what happens if you use it for a sound file, but I guess that under the hood there might be a warning on every frame you try to set a new sound file when one is already playing.

1 Like