ndk-samples icon indicating copy to clipboard operation
ndk-samples copied to clipboard

Best effort to get the exact timestamp of audio stream

Open sunwell1994 opened this issue 3 years ago • 5 comments

Is it possible to get the exact timestamp on starting the audio stream? There are some APIs such as media.AudioTimeStamp and AAudioStream_getTimestamp(), but I am not sure if they can guarantee the high accuracy(microseconds level).

sunwell1994 avatar Jan 01 '22 02:01 sunwell1994

You can back calculate the time of frame zero. But the accuracy is not great. The CDD requests an accuracy of <2 msec. But many devices are more like 5 msec. We are trying to make the timestamp work for AV Sync. Anything under 10 msec is usually not noticeable, particularly if the audio comes after the video. If you move your chair five feet then it will change the AV sync by about 5 msec.

What use case requires microsecond accuracy?

philburk avatar Jan 01 '22 19:01 philburk

You can back calculate the time of frame zero. But the accuracy is not great. The CDD requests an accuracy of <2 msec. But many devices are more like 5 msec. We are trying to make the timestamp work for AV Sync. Anything under 10 msec is usually not noticeable, particularly if the audio comes after the video. If you move your chair five feet then it will change the AV sync by about 5 msec.

What use case requires microsecond accuracy?

Thanks for your great response. I try to compute the distance based on the AV arrival time difference for the AV event. To achieve high resolution of distance measurement, accurate AV sync is required. How about the variance of the AV sync error? If the variance is small, it is also acceptable.

sunwell1994 avatar Jan 01 '22 21:01 sunwell1994

CDD

I am more interested in minimizing input latency.

sunwell1994 avatar Jan 03 '22 16:01 sunwell1994

You can back calculate the time of frame zero. But the accuracy is not great. The CDD requests an accuracy of <2 msec. But many devices are more like 5 msec. We are trying to make the timestamp work for AV Sync. Anything under 10 msec is usually not noticeable, particularly if the audio comes after the video. If you move your chair five feet then it will change the AV sync by about 5 msec.

What use case requires microsecond accuracy?

Hi Phil, could you share more experience on the input latency such as mean value and variance value, and how to keep input latency stable? Thanks!

sunwell1994 avatar Jan 03 '22 20:01 sunwell1994

AAudioStream_getTimestamp()

Hi Phil, for AAudioStream_getTimestamp(), how are errors of timestamp distributed?

sunwell1994 avatar Jan 11 '22 05:01 sunwell1994

Not really a samples problem, so closing.

If you feel there's a missing API (and Phil's comment makes me believe that what you're asking for is not useful with the laws of physics that I live by), file a request against the framework at http://b.android.com

DanAlbert avatar May 03 '24 22:05 DanAlbert