Audio Track Latency Measurement

406 views
Skip to first unread message

Sambhav

unread,
Nov 30, 2010, 2:54:11 AM11/30/10
to android-porting
Hi,
 
Audio Track has a API to query the latency AudioTrack::latency()
 
This latency is calculated with the equation  
 
mLatency = afLatency + (1000*mFrameCount) / sampleRate;
 
where mFrameCount and sampleRate  are parameters given in AudioTrack initilzation.
afLatency is the latency obtained from the alsa driver. 
The second part of the equation is significantly a big number. 
 
Does anyone know how AudioFlinger/AudioTrack is adding to the latency ?
How buffering is done at the framework level before giving it to the drivers ?
 
Regards,
Sambhav
 
 
 
 

RockNCode

unread,
Nov 30, 2010, 12:12:21 PM11/30/10
to android-porting
I Sambhav.

I have this same question regarding the buffering. What I can say is
that I think the reason that the second term is bigger than the first
is because the mFrameCount can be 4 times the size of the driver's
output buffer (or a little bit more). mFrameCount is calculated in
MediaPlayerService.cpp in status_t
MediaPlayerService::AudioOutput::open() this way:

frameCount = (sampleRate*afFrameCount*bufferCount)/afSampleRate;

Where bufferCount is a constant on the media player side (with a value
of 4). I'm also clueless what the buffercount value means or how was
it calculated. So the only variable in the equation seems to be the
clip's sampling rate (as afSampleRate, afFrameCount and afLatency seem
to be constants obtained from the driver).

I hope we can get this doubts resolved.

- Regards.

On Nov 30, 1:54 am, Sambhav <isamb...@gmail.com> wrote:
> Hi,
>
> Audio Track has a API to query the latency *AudioTrack::latency()*
>
> This latency is calculated with the equation
>
> mLatency = afLatency + (1000*mFrameCount) / sampleRate;
>
> where mFrameCount and sampleRate  are parameters given in AudioTrack
> initilzation.
> *afLatency* is the latency obtained from the alsa driver.

Sambhav

unread,
Dec 1, 2010, 12:46:25 PM12/1/10
to alexga...@gmail.com, android-porting
I guess the bufferCount is the sizeof integer which is 4. 
The second term is something audioFlinger and audioTrack is introducing. Needs to be figured out. 
The latency introduced is not acceptable for real time applications.  

kevin

unread,
Apr 17, 2014, 3:46:50 AM4/17/14
to android...@googlegroups.com
This latency is a fixed value, not a real latency for audio data path.
In fact, it's a total buffer size.

在 2010年11月30日星期二UTC+8下午3时54分11秒,Sambhav写道:
Reply all
Reply to author
Forward
0 new messages