Search Unity

Audio Microphone delay in windows 10

Discussion in 'Audio & Video' started by LabMatti, Sep 5, 2019.

  1. LabMatti

    LabMatti

    Joined:
    Jan 19, 2018
    Posts:
    57
    Hi all!
    My project needs to analyze the microphone inpute and to draw the spectrum graph.
    Everything works fine in the editor, but in the build there is at least 0.3s of delay(sometimes even a second).

    Is some windows setting? or is a unity problem?

    the mic script is this:


    Code (CSharp):
    1.    
    2.  
    3. public float[] spectrum = new float[512];
    4. AudioSource audioSource;
    5.  
    6.  
    7. void Start()
    8. {
    9.  
    10.         audioSource = GetComponent<AudioSource>();
    11.         int index = 0;
    12.         foreach (var device in Microphone.devices)
    13.         {
    14.             print("MIC device "+ index+" "+device);
    15.         }
    16.  
    17.  
    18.        
    19.         audioSource.clip = Microphone.Start(Microphone.devices[0], true, 1, 22050);
    20.         audioSource.loop = true;
    21.  
    22.         while (!(Microphone.GetPosition(Microphone.devices[0]) > 0))
    23.         {
    24.         }
    25.         audioSource.Play();
    26.        
    27. }
    28.  
    29. void LateUpdate()
    30. {
    31.      AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Rectangular);
    32. }
    33.  
    34.  

    I'm using Unity 2018 on windows 10