Buzzing Audio

Hello i am having problems with unity audio-source, For some reason my audio is buzzing.

There are 2 audio-sources on a tank, The Engine and Tracks. The engine plays on awake then loops then the pitch of the engine is changed in script, The tracks i want to play when (speed > 1) But for some reason the tracks still play when stationary “not intended” but the tracks audio plays and sounds normal, When i start to drive forward the tracks audio clip starts to buzz violently until my speed is at 0 again. I cannot make sense of it but i hope someone can help me. Here is the code.

EDIT: Here is a webplayer so you can see / hear the problem i am facing. Thanks.WebPlayer

public class TransformSpeed : MonoBehaviour
{
	//Define the Variables
	Vector3 lastPosition = Vector3.zero;
	public float Speed = 0;
	float maxSpeed = 25;

	AudioSource tankEngine;
	AudioSource tankTracks;

	void Start() {
		AudioSource[] audios = GetComponents<AudioSource>();
		tankEngine = audios[0];
		tankTracks = audios[1];
	}

	void FixedUpdate()
	{

		
		Speed = (transform.position - lastPosition).magnitude / Time.deltaTime * 3.6f;
		
		//don't forget to update your lastposition after the calculation
		lastPosition = transform.position;
	}
	
	void OnGUI()
	{
		// a simple way to display the speed in km/h of the Transform Object
		GUI.Label(new Rect(10, 10, 100, 50), Speed.ToString("##0 km/h"));
		

		if (Speed > 0){
			tankEngine.audio.pitch = 0.5f + (Speed / maxSpeed);
		}
		if (Speed > 1){
			tankTracks.Play();
		}
	}
}

It sounds like you are starting the clip from the start every time you call AudioSource.Play(). This would explain a buzzing when Speed is greater than 1.

You can use AudioSource.isPlaying to correct this behavior. There is a nice example on that manual page.

On a side note I would recommend moving your audio logic out of OnGUI() and into Update(). I believe that ``OnGUI()` is called multiple times per frame, and you probably don’t need to execute this logic so often.