Annoying clicking sounds while using external sound file and running in Pavlovia

URL of experiment: Pavlovia

Description of the problem: I have downloaded an external sound file of a 440hz sound wave to use in my experiment in Pavlovia. the problem is that I get a lot of the click sounds in every sound playing and I guess its because the hamming function doesn’t work for external files. I’ve even included ramps at the start and end of my sound wave but I still get these click sounds.
@sotiri I think you would have some great ideas on this issue. I very much appreciate your help.

Dear @Zhaleh, sorry to hear your are having issues getting your project to run as expected. Quite right PsychoJS has no hamming features at the moment. Have you tried using synthesized tones instead of prepared audio? The project you link to is too complex for me to examine. Please, would it be possible to send me a minimal working example of what you are trying to achieve? x

@sotiri Hi, Thank you so much for your response.
Here is the link to a very sample of an audio experiment which include no code component. It’s just a sound repeating 5 times and I’ve used the sound file instead of sound routine of the psychopy in order to avoid annoying square sounds produced by pavlovia.
https://run.pavlovia.org/Zhaleh/soundfile

OK, alright, yes, I see what you mean, on it, thanks, x

Hi @sotiri

I may also be having this problem in my code, lots of the sounds are generating a kind of sawtooth/square waveform background noise so I can’t properly hear the track file as it is muffled by this sort of long beep. Is there anything I can do to smooth out the sound?

My experiment is this one (sorry the code is really ugly, I’m a beginner) https://gitlab.pavlovia.org/Sharp_lab/mist_stressonly/tree/master

Hi @Zhaleh, apologies for the late response and many thanks again for flagging. I believe the problem here can be addressed by giving the audio sample short fades in and out, which can thankfully be achieved programmatically as well.

I have added the relevant bits in a JS only code component Before Experiment tab on the support fork. I have also raised the issue on GitHub and should be able to make a permanent fix available with the next release.

Please let me know if you come across anything else, here to help, x

Hi @Leah_S, would it be possible to give me developer access so I can inspect the source code for your project? Thank you, x

Hi @sotiri. Thanks a lot for your reply. I tested the experiment but unfortunately I still have those clicking sounds there!

Hi @Zhaleh, sorry to hear that, no clicks were apparent while testing. Please, were you able to try out different fadeDuration values to potentially smoothen out playback even more? You could also try synthesizing the tones for your project dynamically, or embed fades to the audio files using a wave editor maybe? x

Hi @sotiri . Thank you for your attention. Yes, I tried different fadeDuration values but there’s still these clicking sounds.
A friend of mine also tried to help me with a different solution and strange thing about it is that on my laptop sounds are ok and on the university system it’s all packed with these clicking sounds! I’m so confused why is that! It’s getting too long and I need to start data collection but I can’t solve the problem of sounds on Pavlovia.
Could you please help me with this and what do you think is the reason for different outputs in different systems?

Hi,

1 - The clicking sounds are generally link to the sound card / headphones (if there are very bad quality) because (1) the volume is too high or (2) the attack is too short. If the volume is too high the sound card can’t handle it because it can deliver a limited voltage (for the headphones the cone can move for a limited distance). If the attack is too short it’s a problem too because the cone of the headphones needs (really short but existing) time to go from 0 to 1. I said headphones but it’s the same for speaker. The solution for (1) is too limit the signal amplitude between [-1,1] or let’s say [-0.9,0.9] to be safer. Check if it’s not the problem. The solution for (2) is to add a ramp with the fade in duration to smooth the attack.

2- the problem I encountered here and that I suspect in your case is the programs that are preinstalled on windows as the Dolby software program. It applies some filter on the sounds so you don’t hear what you send… check in the sound parameters of windows and verify you’ve checked “disable all sound effects”. Compare on the two computers, it could be the real problem… In my case I add to make a little video at the beggining of the experiment to explain to my participant how to disable it… You tried the fade in and I think psychoPy normalize the amplitude of sounds so I think the problem is here.

Sorry if I said some things you already know, I think everyone knows the first point but I wanted to be sure. I hope the solution is there!

1 Like

Thanks for weighing in @F_Elisabeth, you make good points. Sorry @Zhaleh I am unable to look at this before next week, but my approach would likely be to try and create the sounds on the fly, rather than have them play back from file, because they are just simple tones, x

Hi @zhaleh, OK I seem to be getting the same type of click with the tone generator as well, in PsychoPy, not just online. It only happens sporadically, but is a real issue no doubt. Please allow me some time to study the details a little better, very keen to have this addressed though, thanks again for flagging, x

Hey @sotiri
Many many thanks for your time and effort. That would be great to solve it in a way and as you mentioned it’s not just online but also in local running the task we have the same issue.
I’ve tried this piece of code but I still have clicking sounds sporadically.


sound.TonePlayer.prototype._initSoundLibrary = function () {
    const response = {
        origin: 'TonePlayer._initSoundLibrary',
        context: 'when initialising the sound library'
    };
    if (this._soundLibrary === sound.TonePlayer.SoundLibrary.TONE_JS) {
        if (typeof Tone === 'undefined') {
            throw Object.assign(response, {
                error: "Tone.js is not available. A different sound library must be selected. Please contact the experiment designer."
            });
        }
        if (typeof Tone !== 'undefined' && Tone.Transport.state !== 'started') {
            this.psychoJS.logger.info('[PsychoJS] start Tone Transport');
            Tone.Transport.start(Tone.now());
            Tone.context.lookAhead = 0;
        }
        console.log("Using sine wave")
        this._synthOtions = {
            oscillator: {
                type: 'sine1'
            },
            envelope: {
                attack: 0.001,
                decay: 0.001,
                sustain: 1,
                release: 0.001
            }
        };
        this._synth = new Tone.Synth(this._synthOtions);
        this._volumeNode = new Tone.Volume(-60 + this._volume * 66);
        this._synth.connect(this._volumeNode);
        if (typeof this._volumeNode.toDestination === 'function') {
            this._volumeNode.toDestination();
        }
        else {
            this._volumeNode.toMaster();
        }
    }
    else {
        if (typeof this._audioContext === 'undefined') {
            const AudioContext = window.AudioContext || window.webkitAudioContext;
            if (typeof AudioContext === 'undefined') {
                throw Object.assign(response, {
                    error: `AudioContext is not available on your browser, ${this._psychoJS.browser}, please contact the experiment designer.`
                });
            }
            this._audioContext = new AudioContext();
        }
    }
};

It would be a great achievement if we can find the solution for this problem.

Thanks again and I’m looking forward for seeing what you will come up with.

No worries @Zhaleh, on it, thanks, x

Hi dear @sotiri . Hope you’re doing well. Sorry, could you please give me a rough estimation of when this problem may be solved? It’s about a year I have challenges with this and it’s hard to wait more. I need to start data collection as soon as possible. I’m sorry but have you had any success of addressing this issue? Appreciate your help.

Do you get clicking sounds on my music player demo?

Have you tried your experiment on different Browsers and computers? Do you think it will affect all participants of just some?

Hi @wakecarter . I tried your demo and I couldn’t hear the click sounds that are in my experiment.
Yes, I’ve tried it in different browsers and computers and it doesn’t seem to make a change.
If not all participants I can say for sure that at least 70% of participants will be affected by that (based on the piloting results).
I very much appreciate it if you could find out what is the problem that makes these clicking sounds.

I’m not someone who can work out why you’re getting clicking sounds with your implementation, but if you don’t get clicks on my demo then you (or I) should be able to use the method used by my demo to solve your issue.

Hi @wakecarter
I run it again and I noticed that in your experiment Pavlovia has used square waves instead of sine waves (which sounds are kind of sharp and annoying) and this is what Pavlivia does everytime we export our experiments to it. While I’ve used sine waves in Pavlovia and I’ve included ramps at the start and end of sounds. So here is my problem of getting clicking sounds even though I’ve included ramps at the start and the end of sounds.