Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] "Cancel" sampler playback on keypress?

edited April 2012 in OpenSesame

Hi there!

I am just trying to build up an experiment in which subjects have to respond to an audio stimulus as quickly as they can, with a maximum of 1000ms after the audio playback is finished to respond. However, I'd like them to be able to respond even while the file is still playing. Now I've managed to do that on the surface in a sequence of sketchpad->sampler->keyboard_response->logger, but I have to either live with having the sampler play out and then waiting for the keyboard_response to collect a response that was given while playing, which makes me unsure of how to deal with the response time, or I manage to skip from sampler with finish on keypress and timeout set to the files duration for the sampler, but then the sampler keeps playing into the next stimulus. So, I guess my question essentially is whether it is possible to somehow "stop" or "cancel" all samplers that are currently playing audio at the end of my sequence?

Thanks, Florian.

Comments

  • edited 3:26PM

    Hi Florian,

    Yes, sure. You can achieve this with (something like) the following sequence.

    • a sampler with the duration set to 0 ms, so that it advances immediately to the keyboard_response
    • a keyboard_response to collect the response
    • an inline_script with the following code:
    import pygame
    pygame.mixer.stop()

    This directly accesses the PyGame mixer. You can find out more about this here: http://www.pygame.org/docs/ref/mixer.html

    Does this work for you and/ or answer your question?

    Cheers and happy Easter!
    Sebastiaan

  • edited 3:26PM

    Thank you Sebastian, that works a treat!

    I've also added an inline script to the beginning of the loop, setting the variable response_timeout to the duration of my cue (which I have extracted before and inserted into the loop's table) + 1000, and then set the timeout in the keyboard_response to [response_timeout] to give the 1s timeout after playback is finished.
    cue_duration = self.get("cue_duration")
    self.experiment.set("response_timeout", cue_duration+1000)

    Just in case anybody diggs this up in the future :-)

    And a happy Easter to you too! Florian

  • edited February 2020

    Hi All,

    I am building a Stroop experiment (words) where during the trial the participant has to listen to some music (to test its effects on Stroop performance), I have built the experiment and all is working as expected, except one thing:

    I have the following

    • Loop
    • sequence
    • sampler (sound file .ogg)
    • fixation point
    • sketchpad
    • keyboard response
    • logger
    • inline script (which stops the music once all trials are complete).

    The problem is, because the 'sampler' is in a 'sequence', after every stimulus (word + keyboard press) the music is repeating itself and gets all scrambled.

    I just want the music to play once continuously during the trials, and then end, (the end section works fine), I just cant figure out to stop the music repeating itself during the loop of trials.


    Help, I am so close to finishing this experiment, just need to nail this final bit.

    Thanks


    Paul

  • Hi Paul,

    If I understand correctly, the only thing you need to do is to put the sampler with the music at the start of the experiment sequence, rather than in the trial sequence. That way it will start once, and keep playing in the background while the experiment continues.

    Cheers!

    Sebastiaan

Sign In or Register to comment.