Lag noticed when playing audio

Hello,

First time using audio in unity, the sound is playing constantly, i want the frequency to change when i hit the button “change frequency”. This works fine but there is a 0.4seconds lag. Any idea why ?

I use this function audio.create (doc here Unity - Scripting API: AudioClip.Create)
and pcmreadercallback :

here is the code :

void Start()
{
      audio = GetComponent<AudioSource>();
      audio.loop = true;
      audio.clip = AudioClip.Create("Stream", 120, 1, audioSamplingFreq, true, onReaderCallback);
      audio.Play();
}

private bool  low_f=false;

void onReaderCallback(float[] data)
   {
       for (var i = 0; i < data.Length; i++, t++)
       {
           float f;

           if (low_f)
               f = 600;
           else
               f = 800;

           data[i] = 0.2f * (float)Math.Sin(2.0f * (float)Math.PI * f * (float)t / audioSamplingFreq);
       }
     
   }
   
    void OnGUI()
    {
        if (GUI.Button(new Rect(Screen.width - 135, 40, 100, 25), "change frequency"))
        {
            low_f = !low_f;
        }
    }

Looks like a natural consequence of the fact that the reader reads the data in chunks. onReaderCallback is called every time a new block of data is needed so your frequency is not changed until the next block read. The bigger the size of the block, the longer it is, therefore the bigger the latency.