Re: how to calculate latency?
Re: how to calculate latency?
- Subject: Re: how to calculate latency?
- From: Jeff Moore <email@hidden>
- Date: Wed, 6 Jan 2010 17:12:16 -0800
The minimum latency of an AudioStream on an AudioDevice is the sum of:
- the Device's presentation latency, kAudioDevicePropertyLatency
- the Stream's presentation latency, kAudioStreamPropertyLatency
- the Device's safety offset, kAudioDevicePropertySafetyOffset
The latency between roughly when the IOProc is called and when the first sample hits the wire is the sum of:
- the minimum latency for the Stream in question (as calculated above)
- the IO buffer frame size, kAudioDevicePropertyBufferFrameSize
A few notes:
- You probably ought to familiarize yourself with the entirety of the HAL's API. Understanding that an AudioDevice contains possibly many input and output AudioStreams is a fairly important to understanding how things work and how that relates to what you see in your IOProc. Also, you need this basic bit of information to navigate the HAL's object hierarchy to find all the bits of information you need for this calculation. BTW, there are some helpful C++ wrappers for the HAL in /Developer/Extras/CoreAudio/PublicUtility. You might also find the app, HALLab (found in /Developer/Applications/Audio), useful for exploring what various AudioDevices look like in terms of their properties.
- All the HAL properties I mentioned above are counting in sample frames at the Device's nominal sample rate.
- The input side and the output side of a Device are allowed to have different latencies and safety offsets. This makes it imperative that you pass the proper scope value in the property address when querying the properties.
- I say "roughly" above when talking about the latency from the IOProc because an IOProc is not called immediately at the beginning of a cycle. There is thread scheduling latency and a very small amount of HAL overhead to get through before the IOProc is called. This takes a small amount of time away from the IOProc. Note that this is somewhat reflected in the "now" time stamp passed to the IOProc. That said, you still want to do any synchronization using the fully summed value.
- It is fairly common for a Stream to have a value of 0 for kAudioStreamPropertyLatency. This just means that all the presentation latency is accounted for in the Device's presentation latency figure. Note that it is also common for Streams to not implement this property at all, so be sure to check return codes and use AudioObjectHasProperty where appropriate.
On Jan 6, 2010, at 3:55 PM, Peter Stuart wrote:
> Hi, there. I'm a little confused on the exact process to calculate the
> latency between my application and audio output. I read a document
> somewhere explaining to query the kAudioDevicePropertyLatency device
> property and add this to the latency of the AudioStream. Unfortunately
> I can't find the document now, otherwise I'd post a link. I also
> noticed in the CAPlayThrough sample that the safety offset and buffer
> frame size device properties are used. Do all of these things need to
> be included to calculate the total latency? Is the
> kAudioDevicePropertyLatency related to the latency of the underlying
> hardware? What is an audio stream? When I query the latency of the one
> audio stream in my device it returns 0. When would there be more than
> one audio stream? Thanks for any information!
--
Jeff Moore
Core Audio
Apple
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden