[macOS] Use AudioHardwareCreateAggregateDevice

On macOS, when selecting different audio devices for input and output, JUCE uses its juce::AudioIODeviceCombiner mechanism, which according to our testing for Pajam doesn’t seem to work well (has inconsistent latency which may be different than the one reported).

I checked to see if Apple’s Logic has a similar mechanism and whether it also reports additional latency with mixed devices as juce::AudioIODeviceCombiner does, and looks like Logic doesn’t. Digging further, I found that since macOS 10.9 Core Audio can solve the problem for us with the AudioHardwareCreateAggregateDevice call (btw JUCE’s mechanism predates 10.9 by a lot).

Would you consider using AudioHardwareCreateAggregateDevice on macOS >= 10.9 for a better experience, that doesn’t have additional latency and most importantly always has the same latency that it reports?

In addition to this, the latency reported by even single devices AudioIODevices on macOS isn’t correct. It’s not enough to simply get the input and output latency and add them together. I’m doing some investigations but it’s looking like you actually need to query the AudioTimeStamps passed to audioIOProc to find the difference in input and output device times and use this as the latency.

Otherwise you have to run loopback tests and manually adjust for latency which isn’t really acceptable for users these days.

Do you have instructions on how to repro this? From our testing (with the hardwares that we have here) it seemed like the non-combiner device worked fine

The easiest thing to do is run the loopback test in the JUCE demo, with an output fed directly in to an input. The most you would expect from this would be a single buffer size but in my tests it varies massively but usually at least twice the buffer size.

I’m trying to collect more data on this but it’s a common reported problem in Waveform that users have to run the loopback test in order to get what they’re playing in sync with any already recorded tracks.

This issue has already been reported, but never been taken in consideration AFAICS. In case it helps here is old code/old CoreAudio API (more than 10 years ago probably) part of JACK: https://github.com/jackaudio/jack2/blob/develop/macosx/coreaudio/JackCoreAudioDriver.mm and in Ardour https://github.com/Ardour/ardour/blob/master/libs/backends/coreaudio/coreaudio_pcmio_aggregate.cc which is probably more or less the same.

1 Like

Do you have a link to where the issue was already reported?

No more link, probably on SOUL Slack
channel :sweat_smile: