Mac OS
PsychoPy v.2021.2.3
I am trying to have sound stimuli play every 2.25 seconds while randomized visual stimuli are displayed every 3 seconds followed by a question and key response over a number of trials.
The visual stimuli use a .xlsx spread sheet within a randomized loop. Each trial, a new set of visual stimuli are presented with a corresponding question and answer. Each trial lasts 3.9 seconds so that the visual stimuli is presented at 1.4 seconds from t=0 and last .9 seconds. This means that by the next trial it will have been 3 seconds since the visual stimuli were presented.
Incorporating the sound stimuli is where I am having trouble. I have determined a list of exact onset times for the sound. Within the same routine as the visual stimuli I have included two sound stimuli which I would like to follow predetermined onset times in their exact order from a list (so that they play every 2.25 seconds, and independently from the visual stimuli -I don’t want them lining up all the time).
This is the list of onset times for the two stimuli:
sound_1Onset sound_2Onset
0 2.25
0.6 2.85
1.2 3.45
1.8 I don’t want the sound to play this trial
0.15 2.4
0.75 3
1.35 3.6
1.95 I don’t want the sound to play this trial
0.3 2.55
0.9 3.15
1.5 3.75
2.1 I don’t want the sound to play this trial
0.45 2.7
1.05 3.3
1.65 I don’t want the sound to play this trial
As you can see, if the 2 sound stimuli are played at the above times, in the specified order, from trial 1 to n, then the sound onset will be every 2.25 seconds.
Normally, I could have the sound’s onsets be played in the specified order each loop by setting the loop type to sequential. However, since the visual stimuli must be randomized, the loop type must also be random. My first thought was to create a nested loop, however if I simply put the random loop inside the sequential loop, then the full list of random variables is gone through for each condition in the sequential loop, which is not what I am looking for (I believe this is the same if the sequential loop is nested in the random loop). My next thought was to add the sound stimuli to the spreadsheet with the visual stimuli and have only the visual stimuli randomized from the sheet, while the sound onset is sequential. This does not work because the randomized stimuli correspond to the other randomized stimuli in the row, and I get an error since the script expects an integer from the sheet… to make a long story short, I don’t know if that’s the way to go about this either, unless I am approaching it completely wrong. For the same reason I don’t think I can randomize the visual stimuli using the method described here in the forum post I mention later, since the visual variables correspond to other variables in the row such as the display of other visual stimuli at the same time and questions. I am not sure if there is a way around this?
My idea now is to specify the sound onset variable in a code component (in builder view, I find it easier than working with builder generated code), and then each trial have the onset be drawn from that list in the given order. (Originally I thought another way to do this would be to adjust the next onset time by 2.25 seconds, but then realized that some of the onsets would exceed the bounds of the trial time and make things messy).
My primary question is, how do I use the code component to do what I mentioned above (in builder view, although if easier in an IDE, please advise), and how do I then record the onset times in the data sheet from the variable I created (with the question responses and onset times of the visual stimuli)? Would I then just input “$nameOfVariable” into the onset for the sound stimulus block I have in the routine?
This comes close to what I want:
but instead of randomization I need the list played in the order specified, and don’t want to pop out numbers incase I cycle through the list more than once in its given order. Are there any more efficient ways to have the sequential presentation occur independently from the randomized presentation of the visual stimuli?
One final note: you may notice that there are certain trials that I don’t want sound played. Is there an efficient way to do this?
Any help would be appreciated.