I'd like to connect my electric guitar to my app. I have hardware (the Line6 Sonic Port) that passes the audio from my guitar into my iPhone. I've figured out how to get audio playing out to my headphones, but it's audio coming from my headphone mic, not the Lightning Port input. How do I programmatically find the Lightning Port audio input, instead of getting audio via the headphone mic?
Here's what I've tried so far:
self.audioEngine = AVAudioEngine()
let input = self.audioEngine.inputNode
let mixer = self.audioEngine.mainMixerNode
let output = self.audioEngine.outputNode
self.audioEngine.inputNode.installTapOnBus(0, bufferSize: 128, format: input.inputFormatForBus(0)) { (buffer, time) -> Void in
//
}
self.audioEngine.connect(input, to: mixer, format: input.inputFormatForBus(0))
self.audioEngine.connect(mixer, to: output, format: mixer.inputFormatForBus(0))
self.audioEngine.prepare()
self.audioEngine.startAndReturnError(nil)
When I run this, I hear audio - but it's coming from my headphone mic, not the guitar. How can I connect to audio coming from the lightning port?
For a quick illustration, here is the hardware that I'm using:
AVAudioSession.availableInputs
? – Curly