Playing a continuous tone which varies every few seconds - warbling

OS (Win10):
PsychoPy version (2023.2.3):
**Standard Standalone? (y)

Hi. I’m trying to play a pure continuous tone that changes in pitch approximately every 3 seconds (I intend to vary this at a later stage).

I have got the sound playing (and changing) as needed but the sound itself begins to “warble” (like it is playing multiple sounds over the top of itself) as the notes progress.

I am using builder for the most part but I have the code snippet below.

I’m not sure which of the parameters might be causing this because if I stop the sound for a few seconds between each instigation, the notes appear to play pure again. If someone could shed some light on what I’m not understanding (which could be legion) I’d much appreciate any help.

Justin.

#in begin experiment
tonearray=["A","B","C","D","E","F","G"]
iframecount=0
itonecount=0

#in each frame
iframecount=iframecount+1
if iframecount>180:
    iframecount=0
    tone = sound.Sound(value=tonearray[itonecount],octave=4, volume=1,secs=50,sampleRate=None, blockSize=128, preBuffer=-1, hamming=False)
    tone.play()
    core.wait(1)
    itonecount=itonecount+1

If I was doing this I would set up 7 sound objects in a previous routine so they could be played on top of each other (i.e. play one before stopping the previous one). You can set them with 0 volumen and then change all the volumes to 1 at the start of the trial routine.

I do not recommend using core.wait() in Builder experiments.

Ah ok, thanks for the quick response. I’ll give that a go. I thought the core.wait was necessary for playing sounds for some reason so am happy to jettison that.

Thanks Carter. Whilst I didn’t implement your solution it did get me thinking and I changed where I created the sound object. I also removed the core.wait code.

This now works as expected.

#In the begin Experiment tab

tonearray=["A","B","C","D","E","F","G"]

iframecount=0
itonecount=0

tone = sound.Sound(value=tonearray[itonecount],octave=4, secs=50,sampleRate=None, blockSize=128, preBuffer=-1, hamming=False)

#in the Each Frame tab
iframecount=iframecount+1
if iframecount>180:
    iframecount=0
    tone.setSound(tonearray[itonecount],octave=4, secs=50)
    tone.play()
    itonecount=itonecount+1