I am writing an audio sequencer application using Swift and Mac OS desktop. I user AVAudioMixerNode objects for generic routing and pass-through nodes (nodes where the audio just goes from point A to point B). The pass through nodes provide temporary "pit stops" in the audio chain where I can apply volume changes.
I have found that if you connect an AVAudioMixerNode to the AVAudioEngine's main mixer node, then call prepare, the mixer node gets automatically disconnected. There is no error or warning message. I have been ripping my hair out for four days trying to figure out why some nodes in my signal path were not connecting. Now I have written a simple Playground that proves definitively that this is the case.
import Cocoa
import AVFoundation
let engine = AVAudioEngine()
let mixer1 = AVAudioMixerNode()
engine.attach(mixer1)
let format = engine.mainMixerNode.outputFormat(forBus: 0)
engine.connect(mixer1, to: engine.mainMixerNode, format: format)
var connections = engine.outputConnectionPoints(for: mixer1, outputBus: 0)
print("Number of connections = \(connections.count)")
engine.prepare()
connections = engine.outputConnectionPoints(for: mixer1, outputBus: 0)
print("Number of connections = \(connections.count)")
The node is still present in the graph as evidenced by
print
but is in a pending state:I suspect this is because there is no attached input or generator node although I haven't had a chance to experiment further.