Change audio clip through code

I’m currently creating a flight game and today I decided to implement simple engine sounds. Changing the pitch worked fine, but when I decided to implement a different sound for when the thrust is high and low.
The code’s simple:

	if (thrust > 1000) {
			Source.pitch = (thrust / 80000);
			audio.clip = EngineSoundMain;

		}
		if (thrust < 1000) {
			Source.pitch = 1;
			audio.clip = EngineSoundIdle;
		}

However, when I press play, the game plays… no sound at all. The error log says the following:

NullReferenceException: Object reference not set to an instance of an object
PlanePhysics.Update () (at Assets/Scripts/PlanePhysics.cs:78)

Which I find quite baffling. What object am I supposed to refer to? And how?

this is hard to correct cause we can’t see the rest of your code and your lookups. but I cant see why you are trying to change the pitch and the clip differently.

actually even if you are not getting errors, if you keep calling it like you are showing you will find you cant keep updating the component, but you do need to keep checking the value. so you need another varible to check if the statis has changed.

this should work:

    public AudioClip somemp3; //<---drag mp3 into the inspector here
         public AudioClip nextmp3; //<---drag  mp3#2 into the inspector here
                  AudioSource audio;
 
 int current;
               
           void Start() { 
         // you need a reference to your component
          audio=gameObject.GetComponent<AudioSource>();
      }
      
      // now you should be able to say this anywhere else in your code
       void Update(){
      if(whatever){
 
           if(current!=0){current=0;
           audio.clip=somemp3;
           audio.pitch=.5f;
  audio.Play();
 }
  
           }else{
 if(current!=1){current=1;
   audio.clip=nextmp3;
           audio.pitch=.8f;
  audio.Play();
 }
  }