Psychopy generated pure tones have a click despite Hamming window

OS (e.g. Win10): Mac Ventura 13.5
PsychoPy version (e.g. 1.84.x): 2022.1.4
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: Attempting to play pure tones in Psychopy at different volumes that participants will need to compare. However, because of “clicking” noises, it’s very difficult to distinguish volume differences.

What did you try to make it work?: I am playing two pure tones using the PTB sound library. The two tones are both 800 Hz but differ in volume. The tones are .1s in duration. Clicking the “Hanning” (“Hamming”) window option doesn’t seem to do anything and there is still very obvious clicking. I also still get clicking if I make the duration of the sounds longer or if I modify the latency in settings.

What specifically went wrong when you tried that?:
Clicking noises continue for all tones.

1 Like

Thank you for reporting this issue. I experience the same problem in a new task where we want to play a sequence of pure tones generated in PsychoPy. Our tones are also .1s in duration but differ in frequency, ranging from C4 (261.63 Hz) to A4 (440 Hz), with no inter stimulus intervals.

Neither changing stimulus length (I tried up to 1s), nor ISI duration (I tried to create breaks between 0.01s to 1s) help. With the long stimuli and ISIs, at least I discovered that the cracking appears at the end of each tone.

Changing the Hamming window and Stop with Routine? settings under Playback of the sound properties do not affect the problem.

This issue exists on both macOS 12.5, Windows 10 and in PsychoPy V2024.1.3 and V2023.2.3

Does anyone know a fix for this?

Hi There,

Just to follow up on this with some questions to try and pin point the issue.

  1. Does the issue occur with externally generated wav files of tones or only tones generated in PsychoPy.
  2. Does the issue occur for all frequencies or only specific frequencies.

Thanks!
Becca

I isolated specific frequencies to test if the issue is limited to certain frequencies but the issue persists throughout. I then exchanged all tones for pure tone sine waves generated in audacity as .wav files and the issue persists as well.

Hi Becca, thanks for looking into this issue! It seems to only be happening to me on a Macbook (vs. a PC) and it is with psychopy-generated pure tones. I am using psychopy version 2022.1.4. on both computers and all of the internal psychopy sound settings are the same.

Having dug deeper into the issue, we believe there’s a problem with how the Hamming window function in PsychoPy is set up, at least it appears to us that it uses a static window resulting in some frequencies not being handled sufficiently?

Here’s a fix we tried out, which arguably is somewhat of a bodge. We had a go at defining a function that finds the point closest to the end of the pure tone sine wave where sine is zero, effectively truncating the stimulus so as to avoid clicks. We then stop the sound there. This takes into account the specific frequency played.

import math
 
def generate(freq, dur):
    n_cycles=math.floor(freq*dur)
    dur2=n_cycles/freq
    return dur2

We call this function for all frequencies that appear in the experiment, and then the start and end times of the sound stimuli get updated with each repeat of the routines in the task.

This works somewhat but not perfectly, some clicks remain on a fairly random basis, possibly due to slippage or glitches. But we are not sure.