Audio Device latencies & safety offsets on Mac


#1

Hi good people at ROLI,

juce_mac_CoreAudio.cpp doesn't include the safety offsets in the input or output latency values. Can we have these included please?

The safety offset can be queried with kAudioDevicePropertySafetyOffset. This can just be added to the latency returned when querying  kAudioDeviceLatency.

​If I do this, then the sum of the reported latencies are very close to what I measure for the round trip.

-------------

While I'm at it, I've noticed that the latency values include the current block size for the default audio device on the iMac, but if I switch to a Steinberg UR22 then the current block size is excluded (which is wrong).

Does anyone else see this happening with other audio interfaces?


#2

Thanks, we didn't know such a thing existed, but will take a look!


#3

Either did I before today!

Saw it referenced here: http://lists.apple.com/archives/coreaudio-api/2010/Jan/msg00046.html

And then found it in CoreAudio/AudioHardwareBase.h


#4


A polite bump, just in case this was forgotten :)

Plus some code to show how easy it is!
 

​//
// juce_mac_CoreAudio.cpp
//

int getLatencyFromDevice (AudioObjectPropertyScope scope) const
{
     UInt32 lat = 0;
     UInt32 size = sizeof (lat);
     AudioObjectPropertyAddress pa;
     pa.mElement = kAudioObjectPropertyElementMaster;
     pa.mSelector = kAudioDevicePropertyLatency;
     pa.mScope = scope;
     AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &size, &lat);

     // =========================================================================
     // New bit to include the safety offset (assumes lat and off are same size)
     // =========================================================================
     UInt32 off = 0;
     pa.mSelector = kAudioDevicePropertySafetyOffset;
     AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &size, &off);
     return (int) (lat + off);
}

#5

Thanks Andrew, not forgotten! Will do it imminently!


#6

FYI, done now, much appreciated!


#7

Cool.  Not seeing it in the commits yet - is it just my imagination, or are you batching these up lately?


#8

oh yes, I forgot to push it to github - should be there now.


#9

Thanks!