OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 3.2.4
**Standard Standalone? yes, win 64bit
What are you trying to achieve?:
I’m helping program an experiment that consists of 54 images that are divided into 3 conditions - neutral, negative, and positive. They have to be divided into 3 blocks - one block with 18 images (6 of each) and a melody playing in the left ear, one block where there is no melody, and another block with the melody in the right ear. The images have to appear in a random order, but not repeat throughout the experiment in the different block melody conditions. The melody has to run throughout the block continuously in the background. The blocks are also randomised. In addition, the fixation cross/ITI is variable - 6,8, or 10 seconds.
What did you try to make it work?:
I’ve looked through the forum and used this code to randomise the blocks and the images and make sure nothing repeats - it works:
Code component begin experiment:
pos_files = [str(i) +'_pos.png' for i in range(18)]
neg_files = [str(i) +'_neg.png' for i in range(18)]
neu_files = [str(i) +'_neu.png' for i in range(18)]
# randomise their order:
shuffle(pos_files)
shuffle(neg_files)
shuffle(neu_files)
# get now-randomised selections of each for each block:
left = pos_files[0:6] + neg_files[0:6] + neu_files[0:6]
right = pos_files[6:12] + neg_files[6:12] + neu_files[6:12]
none = pos_files[12:18] + neg_files[12:18] + neu_files[12:18]
# randomly intersperse the sound trials:
shuffle(left)
shuffle(right)
shuffle(none)
In the begin routine:
current_file = none.pop()
thisExp.addData('current_file', current_file)
In order to have the music playing in the background, I’ve tried lots of things, main solution I tried was this added as a code component (before the fixation and the stimuli condition, within the main experiment loop):
Begin experiment:
background_sound = sound.Sound('tuneleft.wav')
Begin routine:
if trials_4.thisN == 0:
background_sound.play()
End routine:
if trials_4.thisN == 17:
background_sound.stop()
For randomised fixation duration, I created an excel file with the timings and added it as a conditions file on a loop.
What specifically went wrong when you tried that?:
If there is no sound, the experiment runs fine. If I add the sound, it will run with the melody in the background if the whole presentation is sequential, but as soon as I randomise the experiment, the melody distorts. I know it might be related to an issue of the melody being in a While loop. But I don’t have enough advanced programming knowledge to understand what that means exactly.
(Also, as soon as I add the melody code, I get another error - it doesn’t go to the next block and says that stimuli are from an empty list, error like one.pop() - can’t draw from empty list (without sound it’s all fine).)
If I add a full melody as a sound component, it continues running without showing the next fixation or image (alternatively, says I’ve run out of memory).
I’m really pressed for time and at a loss.I have uploaded my psyexp file (at the moment without added sound stimuli), conditions files.
I haven’t even started to try and add breaks between blocks and making sure that doesn’t give me some error.
Maybe I don’t need blocks? One conditions file? Define the melodies in code and then randomise?
I’d appreciate any help and let me know if I need to clarify something - I thought it will be rather straightforward, but this background continuous music just messed things up. Thank you!
conds.xlsx (8.2 KB) Eli_Experiment.psyexp (33.1 KB)