Issue when using two samplers
Hi all,
I am currently designing a study and I'm stuck when trying to use multiple samplers. The general idea is that people can look at two regions of interest, a left square or right square. If they look at the left one, they hear audio stream 1 and if they look at the right square they hear audio stream 2. If they look at none of them they hear nothing.
I tried to implement this (see code below) by creating two samplers, each with a different audio file. Whenever people switch their gaze to a different region of interest, the currently playing sampler is paused and the correct one is resumed.
However, when I'm trying to resume one of the samplers after it has been paused, both samplers start playing simultaneously. If i change the "sampler.resume()" code to "sampler.play()" it does play the correct sampler but it starts again from the start of the audio file, which is not what I want.
*Here's a link to a simple experiment with this code (couldn't add it as attachment): https://drive.google.com/file/d/18UAdcclJXKdjaekdLp3XkVVkL-7NgrGF/view?usp=sharing. The mouse cursor can be used to emulate eye movement (also make sure to change the folder path). This was written in OpenSesame 3.3.12 but I have the same problem with the latest version (4.0.5).
Any help is welcome :).
Best,
Christophe
import time # draw simple canvas with regions of interest represented as a rectangle (ROIs) my_canvas = Canvas() my_canvas["left_rect"] = Rect(-650,-200,400,400) my_canvas["right_rect"] = Rect(250,-200,400,400) my_canvas.show() # load ".wav" files and load them in seperate samplers folder_path = "fill_in_path_to_wav_files" random_sampler = Sampler(folder_path + "random_stream.wav") random_sampler.block = False random_sampler.play() # the idea is to play and pause the sampler quickly, so it can be resumed later (otherwise extra flags are needed) random_sampler.pause() structured_sampler = Sampler(folder_path + "structured_stream.wav") structured_sampler.block = False structured_sampler.play() # the idea is to play and pause the sampler quickly, so it can be resumed later structured_sampler.pause() # flag that stores what is currently being looked at/ what stream is playing currently_playing = None # timer for while loop duration = 10 duration_end = time.time() + duration # loop until duration is over while time.time() < duration_end: x, y = eyetracker.sample() # Get the fixation location if x > 310 and x < 710 and y > 340 and y < 740: # if in left ROI, play structured stream # pause random stream if it is playing, then resume the structured stream if currently_playing == "random": random_sampler.pause() if currently_playing != "structured": structured_sampler.resume() currently_playing = "structured" elif x > 1210 and x < 1610 and y > 340 and y < 740: # if in right ROI, play random stream # Pause structured stream if it is playing, then resume the random stream if currently_playing == "structured": structured_sampler.pause() if currently_playing != "random": random_sampler.resume() currently_playing = "random" else: # if outside of ROIs, pause stream that is currently playing if currently_playing == "structured": structured_sampler.pause() elif currently_playing == "random": random_sampler.pause() currently_playing = None
Comments
Hi @chvhouwe ,
Thanks for reporting this. Indeed, when using the legacy backend (and in OpenSesame 3.3, also the psycho with legacy sound backend), the pause/resume functions operate on all channels, rather than on individual samplers. Now that this is on the radar, it will be fixed in an upcoming maintenance release. For now, you can use the psycho backend (if that is suitable for your experiment), which does not suffer from this issue.
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
I see, I'm glad that it's such an easy fix. It does indeed work as intended when using the psycho backend. Thanks a lot!
Christophe