What causes the audio clicking & how do I get a clean sound?

I have two sounds that I’m triggering about twice a second, one for each player, for an old-arcade-style movement noise (wakka wakka wakka bloit bloit bloit…) using PlayClipAtPoint. They’re just uncompressed AIFFs and there’s no other sound going on yet.

I get this intermittent “thwip…thwip” glitch at random times every few seconds that sounds like a loose speaker connection. I’m getting over 100fps so the CPU can’t be struggling.

I thought it could be a problem trying to play the sound before the last one had finished so I made two AudioSources for each player and alternated which one played sound each time; that didn’t seem to make any difference.

Any other ideas?

I had the same issue with PCM compression format. When I changed Load Type to Streaming, problem was solved. Compressed in memory or Decompress on load was causing the clicking sounds.

Also Compression format ADPCM or Vorbis worked for me,

This can be set directly in Inspector in Unity when clicking on audio file.

1 Like

I realize this is an old thread but I wanted to share how I solved this issue. I had a similar problem with some audio clips I had and the fixes listed here did not work for me. I solved my issue by exporting at a higher bitrate. Originally they were 44100 (Hz) but changing to 48000 (Hz) and exporting as a .wav file solved the clicking noise issue.

Go to Project SettingsAudio and set the DSP buffer size to best performance. it works.

1 Like

The clicking comes from not starting or ending at a zero sample… and when shutting off a looping sound or any sound anywhere before the end, you could do the fade out your self like this

AudioSource oASEngine;
bool bEngineFadeOut = false;
...
  
void Start()
{
	...
	foreach (AudioSource aSource in GetComponents<AudioSource>()) {
		if (aSource.clip!=null && aSource.clip.name.Equals("engine"))
			oASEngine = aSource;
		else ...
	}
}
  
void FixedUpdate()
{
	...
	if (startEngine) {
		bEngineFadeOut = false;
		oASEngine.volume = 1.0f;
		oASEngine.Play();
	} else if(stopEngine) {
		//oASEngine.Pause(); //don't, this may cause clicking noise
		bEngineFadeOut = true;
	}
	if(bEngineFadeOut)
		oASEngine.volume *= 0.8f; //fade out over ~100-200 ms
}

I just had this problem. I switched up some audio to use 3D (It’s a 2D shooter) and I wanted more spatial awareness in my clips. I drop recyclable objects for explosions and audio, and after switching to 3D, I got clicks. This mostly happened on recycling the pooled object… for my situation, it ended up being a timing issue… delaying the playback until into the second Update call solved the issue nicely. Since the 3D call depends on the placement of the gameobject, and a rapid change in that position can skew the playback, I suspect that was resulting in the click.
TL;DR version… Delay playing the clip back on 3D audio until position has been established.

I was also having this clicking and popping sound, and I seem to have found a solution.

My problem only occurred when recycling items from a pool, so if you don’t use a sound pool this may not work for you. In my case it was an impact particle effect which played a hit sound effect on awake, so it would often be recycled when I needed to display a hit effect, which would very often be in different places around the game.

I would only get the clicks and pops when the item which was being recycled was moving a large distance from where it was when it was released from the pool, to where it moved to when it was re-enabled. This seemed to be down to the doppler effect.

What was happening was that the item was being enabled, which called OnAwake, and the audio was set to play on awake, so it started playing, then immediately afterwards it was moved from its original position to the new position, this seemed to cause unity to try to calculate the doppler pitch between the two positions, and this would massively skew the sound effect. I found two solutions

  1. Disable the Doppler Level in the 3D Sound Settings of the audio source playing the sound. Just set the value to 0
  2. Disable Play On Awake, and use code to play the audio once it has moved position

When it goes to audio, always do a double check in a DAW before exporting to an Engine. It’s very important to find out where the problem is. Sometimes it’s a problem with the sound wave.

First of all, try looping one of the sounds all alone. Since you are using an uncompressed AIFF sound there won’t be a looping problem. Them do the same with the second one.

Second, try adding some silence to the end of the clip. Since you are using two Audio Sources it won’t cause gaps between sounds

Third, you can try getting the sound exported in other formats, like .mp3 and .wav.

I hope one of this solutions solves your problem.

I had this problem. It maybe that the way you start your sound.
Check your script logic to make sure that your script is not starting to play the sound every frame.
e.g. add logging to see how many times your audioSource.Play() is getting hit.

First off, all your sounds should be gone over with an audio editor to have fade in and fade out startings and endings with a little bit of silence before and after the sound.

Anything that is going to loop needs to start and end on the zero line.
forget the fade in and fade outs for looping sounds and the silence before and after.

That should solve most your problems. However with sounds you’re going to cut off on purpose mid run there is a simple trick to that.

Add the sound to be used in the AudioClip of the Audio Source on the object.
From a script on the same object you now can call the sound off the Audio Source.

In the variables section of that script add in: AudioSource audioSource;
Than in the void Start() add in: audioSource = GetComponent();

Now, you can call the sound like this: (jamming it on and off at will without any pops) :slight_smile:

if (Input.GetButton (MyKey)) {
    GetComponent<AudioSource> ().mute = false;
	if (!audioSource.isPlaying) {
	     audioSource.Play ();
	}
       // do your stuff
} else if (Input.GetButtonUp (MyKey)) {
GetComponent<AudioSource> ().mute = true;
}

It can also be caused if you change the AudioSource .time property while it’s playing. This generates a discontinuity in the samples you’re trying to output to the speaker and will make a click.

I had the same issue when playing sounds on top of each other with the same AudioSource.

It makes sense, because the first sound hasn’t stopped, then suddenly you’re starting the next one (whether it’s the same sound or a different one) and there’s a big amplitude jump.

Use AudioSource.PlayOneShot, this will allow the same AudioSource to play multiple files and have them overlap instead of cut each other off.

As @rh_galaxy wrote, the clicking is caused by stopping a sound when its amplitude is at a non zero position, most likely in looped sounds. I solved this using this Couroutine that decreases the volume over multiple frames:

public void StopAudioWithoutClicking(AudioSource audioSource)
{
	StartCoroutine(FadeOutAudioSource(audioSource, 0.2f));
}
  
private IEnumerator FadeOutAudioSource(AudioSource audioSource, float decreasePerFrame)
{
	float originalVolume = audioSource.volume;
	while (audioSource.volume > 0)
	{
		audioSource.volume -= decreasePerFrame;
		yield return null;
	}
	audioSource.Stop();
	audioSource.volume = originalVolume;
}

Old thread but, I had waaay better results without playing with custom fading, by just putting the AudioSource through a AudioMixer, and adding a Compressor effect, as this is how audio engineers do!

Just play with the Threshold, Attenuation volume, and the rest for fine-tuning.

The thread is outdated but if for someone the problem is still actual.

In my case crackling was randomly appear during 3 minute long mp3 audio playing in 2D UI.
Configuration audio asset didn’t help. After some time of investigation I figured out that the root cause in particles (it was used as background for canvas) .

By the way the issue is still wasn’t fixed even in Unity-2023-2 :

Thanks! Disabling doppler worked for me. The issue was exactly what you mentioned. The doppler effect being affected by the large position change in a quick time from the recycling point and target position

Disabling doppler resolved my issue. It was indeed as you described—the doppler effect was impacted by the rapid position change between the recycling point and target position.