Search Unity

Audio Latency on recording

Discussion in 'Editor & General Support' started by sonicviz, Feb 25, 2013.

  1. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Hi,
    I'm testing recording audio alongside some other audio playing in the background (like a music mixer).
    When I play the recorded track back alongside the backing tracks it's delayed by around 200 ms or so.
    (I'm pretty certain I'm playing in time with the backing).

    By saving the recorded audio to wav I can compare in Audacity against the backing to determine the lag.

    Any tips/ideas/suggestions on what could be causing this or workarounds or ideas to try?

    ty!
     
    Last edited: Feb 26, 2013
  2. janm_unity3d

    janm_unity3d

    Unity Technologies

    Joined:
    Jun 12, 2012
    Posts:
    36
    You should be able to reduce that considerably either by waiting for the Microphone.GetPosition() to get close to the AudioSource.timeSamples right after Microphone.Start() has been called, or by having the script adaptively and very slightly increasing/decreasing the playback speed depending on the difference between the two.
     
  3. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Hi Janm,
    Thanks for the ideas.
    I'm already doing #1:
    //Start recording and store the audio captured from the microphone at the AudioClip in the AudioSource
    goAudioSource.clip = Microphone.Start (null, false, length, maxFreq);
    while (!(Microphone.GetPosition(null) > 0)) {
    }
    By "get close to the AudioSource.timeSamples right after Microphone.Start()" do you mean while (!(Microphone.GetPosition(null) >[the backing track].AudioSource.timeSamples ? What timeSamples if so?

    For #2 I've been experimenting with delaying the captured mic clip on playback by delaying it a small amount, but it's tricky. My other concern with this method is it may vary considerably depending on the platform which makes it a little dodgy for production. Unless this is a consistent engine/fmod delay I can factor in?

    ty