Questions about AVAudioEngine node tap

Hi,


I have a couple of doubts about the API for installing a tap on an AVAudioEngine node.


1) Does the timestamp on the callback refer to the time at which the buffer starts? And is it right that I should compensate for input lag if I want to calculate the host time corresponding to these samples as accurately as possible? At the moment I'm doing this calcuation to calculate the host time corresponding to the first sample in the buffer:


let inputLatency = AVAudioSession.sharedInstance().inputLatency
input.installTap(onBus: 0, bufferSize: sampleRate / 10, format: nil) { buffer, timestamp in
     let bufferStart = AVAudioTime.seconds(forHostTime: timestamp.hostTime) - inputLatency
}


2) The documentation states that the callback may happen off the main thread — in practice this always seems to be the case. Could there be any negative consequences to performing signal processing on the thread on which the callback occurs? Or is it essentially a serial queue set up just for this tap? Obviously the safest thing would be to dispatch straight away to my own context, but is that actually necessary in practice?


Thanks!


~Milo