Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get latency info from Android's AudioTrack class?

Tags:

android

audio

I've noticed that the C++ classes underlying the AudioTrack and AudioRecord APIs in Android both have a latency() method that is not exposed via JNI. As far as I can see, the latency() method in AudioRecord still does not take into account the hardware latency (they have a TODO comment for that), but the latency() method in AudioTrack does add in the hardware latency.

I absolutely need to get this latency value from AudioTrack. Is there any possible way I can do this? I don't care what kind of crazy hack is needed as long as it doesn't require a rooted phone (the resulting code must still be packaged as an app on the market).

like image 719
Ryan Avatar asked Apr 08 '10 03:04

Ryan


1 Answers

There is a method on AudioTrack called getLatency() that you can invoke via reflection. For an example, look at Exoplayer or https://developer.amazon.com/docs/fire-tv/audio-video-synchronization.html#section1-2

like image 152
tmm1 Avatar answered Sep 21 '22 17:09

tmm1