psychopy.org | Reference | Downloads | Github

Presenting two different stimuli but that are time independent

Hello everyone,

I’ve had a search in the forum, however I am struggling to find guidance on this topic and it may prove useful for some others.

I’m building a visual search task that will alter between two conditions, easy and hard. So far I’ve managed to get the visual search task performing well and I’ve written the majority of the task in code, mainly due to allowing ease of creating the number of distractors. Participants can take as long as needed to respond.

Additionally I’d like to create two additional conditions where participants complete both a visual search task and a tone detection task in the same trial, however, the visual search task generally lasts a 1-2 seconds, where I’d like the tone to play for say 5-6 seconds, and do this say maybe 10-15 times during the overall number of trials, and the participant has to respond whether the tone changes and only when it changes.

I’ve had a go at inserting sound via the builder, however once the visual search task is completed, the sound stops and the next trial starts. Is there a way for the tone to play independent of the visual search task in relation to time? My other alternative idea was to play just a singular tone for the dual task constantly, then every so often the tone changes.

Kind regards,

Rob

You should start and stop the tones in code so they don’t automatically stop at the end of your visual search trials.

Hi Rob,

I came across this thread when I was searching for how to do something similar. I was wondering whether you managed to solve your problem? I currently have a visual task in Builder and a tone stream written in code and am trying to see if there is a way to let the tones play in the background as the visual task unfolds. It would be good to talk about this if you’re still around.

Hi Ana,

I definitely think that is possible! My problem is I have very little in the builder, so I don’t have a list of conditions which would make my life easier. I came across this thread which I think will be very helpful for you.

Whilst I haven’t got my tones to play perfectly, I did manage to get them to play in the background. The problem I have is whilst it’s sort of independent. When my visual search task trial is complete, the sound loop starts again, so it isn’t truly independent of my visual task, which is what I am currently trying to improve!

I have used this thread as my starting point

I can play just one tone perfectly and it responds how I want it, but my task involves participants responding to high and low Hz tones and getting them to play independently of how my visual task is running is proving rather tricky.

Let me know how you get on! I am no expert on this matter by any means.

Kind regards,

Rob

Hi Rob, thanks for replying.

I’ve read all the links in your reply and I’m still stumped. :thinking:

I’m not loading a sound file but playing a series of tones that I create using code, but I don’t think that should be an important difference.

I created a simple series of visual events in Builder - text that flashes in the middle of the screen on each trial - and I’ve put code in the ‘begin routine’ tab to start the sound loop. But all I get is the sound loop being played once, and then the visual trials running. Would you mind taking a look? It might be something really trivial that I’m missing.

You can ignore the code called make_tones, it’s more complicated than it needs to be for this example but it makes a small series of tones that can then be called with my_tones().

[background_tones_example.psyexp (17.8 KB)]

I’ve written a more elaborate post about my issue here.

Hi Ana,

Not at all, what you want to do sounds pretty much identical to what I want to do, so maybe between us (and some help from the lovely people in the forums) we can figure it out. My auditory task has changed somewhat to a Auditory Oddball Task which I imagine you’re familiar with a background in M/ EEG! I am not familiar with threading so I will have a read up on it over the next few days.

One possibility is that you need some code to say when it will stop. I think currently without it, it maybe stopping at the end of the visual task, so it could be starting independently, but not stopping? it may work. So if you write a function for stopping it, and place that at the end of the routine. However I am not sure this will help as I have tested it on some of my code and whilst it works for me, the ISI only works during the trials, between trials there is a delay. However I am using trial numbers so for example:

if trials_loop.thisN == 0:
    background_sound.play()

if trials_loop.thisN == 5:
    background_sound.stop()

I can play just a singular tone over the course of 5 visual search trials no problem because I just set the duration to a very long value, but this is not what we want!, Looking at your code I can see you have 3 different tones at .01 duration. So rather than going off duration, it’s a case of going off the start/stop times? I wonder then if you need to add code snippets at the beginning/end of the routine for the start/stop times for the tones themselves which could help. Is your visual task a set length? Mine is not due to responding to a visual search.

Another possibility is some sort of code snippet to play it by frame. I’ve attached a file I have been trying to integrate into my own study that gives a nice example! ToneRandomLoop-Becca.psyexp (9.3 KB) which hopefully can offer some more guidance!

Thanks again! I will really need to have a think about this.

I thought Becca’s approach would be exactly what I need but when I change the text component in her example experiment to look like mine (text flashing over trials), the sounds stopped working. Or rather, one tone played, then the text flashes for as many trials as I tell it, then it closes. So it looks like there is something deeper about how psychopy works that I don’t understand.

Hi Ana,

If you’d like to send me your file, I can have a look! From your prior file, it looks like it should work, but the start stop times were not behaving how you wanted! There is an experiment handler/trial handler you may find useful. psychopy.data - functions for storing/saving/analysing data — PsychoPy v2021.3. I really wish I could run two builder routines at once because then I’d understand how they interact with each other, and make coding it a little easier!

I have been thinking about your paradigm. Is your visual task a set time? so for example all participants will complete it for 5 minutes and that can never change?

Kind regards,

Rob

Hi Rob, sure, here is the file:

ToneRandomLoop-Ana.psyexp (10.8 KB)

My visual task is not fixed in time. Do you know cyberball? It’s a game where players toss a ball to each other, and the study participant is one of the players. I have a cyberball setup with three players, two of which are digital. Obviously, how long it lasts depends on how much the participant hesitates who to throw to. The idea is that tones play in the background, and that I record neural activity from the tones.

I will be away for a week, so if I don’t reply soon please don’t take it as a sign that I lost interest! Once I return I will have to crack this once and for all :slight_smile: