Trouble playing next audio tone when previous tone is finished - different durations

Hi, (psychopy version v2021.2.3; windows 10) I am trying to play consecutive audio tones one after each other with no gap in between (I used core.wait(0) to have no gap). Every 7-15 audio tones, one target tone will be presented for longer than the standard tones (1120ms vs 800ms). I have successfully created the task to do this with the following code:

#Code for playing sound stimuli - this works for one tone only
snd = sound.backend_ptb.SoundPTB(value=new_pitch_list[cur_new],
secs=durlist[cur_dur], stereo=-1,
volume=1.0, loops=0, sampleRate=48000,
blockSize=4800, preBuffer=-1,
hamming=True, stopTime=-1, name=’’,
autoLog=True, syncToWin=None)

snd.play()
core.wait(0)

#Counter plus 1
cur_dur = cur_dur + 1
cur_new = cur_new + 1

The durlist contains the length of the tones in milliseconds. The problem is that when the durlist reaches the target duration (i.e., 1120), the subsequent tone that is occurs after the target tone starts to play before the target tone is finished.

So, I need to find a way for the task to only begin playing the next audio tone when the previous tone has finished, otherwise when the target tones are played they will always be overlapped with the subsequent standard tone.

Can anyone help me with this?

Hi There,

May I ask why you are using code rather than builder? In builder this should be very simple with a single tone component in a loop.

Thanks!
Becca