Search Unity

Feature Request Microphone.Start() needs to be improved to deliver a correct timestamped clip, devs@unity

Discussion in 'Audio & Video' started by Kobald-Klaus, Apr 19, 2022.

  1. Kobald-Klaus

    Kobald-Klaus

    Joined:
    Jun 20, 2014
    Posts:
    127
    Starting a audiosource with PlayScheduled(dspTime) works great - clips can be started in sync.
    However, I want to record audio in sync with playing audiosources.
    So I am running a 1 second recording buffer in a loop with Microphone.Start() and every half second I am extracting samples from the other half buffer into a prepared audioclip.

    Now the problem is, that I have no idea what timestamp the samples of the recorded clip have, because the recording starts, whenever the system is ready. Might be now, might be 50ms later. So I am measuring the time to calculate an offset, but that does not bring consistent results.

    It would be easy for Unity developers to just put the AudioSettings.dspTime into the audioclip or into a struct somewhere, as soon as the first sample gets written into the audioclip.

    Or are there any other solutions without external libraries?
    I need to be compatible on all platforms! (at least iOS, Android, Mac, Windows)