Reputation: 43
Can AudioKit be setup to both record from the microphone and install a pitch tap on it at the same time?
Every attempt I make gets error 'uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: nullptr == Tap() when the recording is started. Either real device or simulator. It fails in both cases.
func startRecordingMicWithTapHandler(tapHandler:TapHandlerProtocol, recordAudio:Bool) {
///It appears that we cannot both record the mic and install a tap on it at the same time
///Error is reason: 'required condition is false: nullptr == Tap()' when the record starts.
checkMicPermission(completion: {granted in
if !granted {
Logger.shared.reportError(self, "No microphone permission")
}
})
setSession()
///Based on CookBook Tuner
self.engine = AudioEngine()
guard let engine = self.engine else {
Logger.shared.reportError(self, "No engine")
return
}
guard let input = engine.input else {
Logger.shared.reportError(self, "No input")
return
}
if recordAudio {
do {
self.recorder = try NodeRecorder(node: input)
} catch let err {
Logger.shared.reportError(self, "Recorder \(err.localizedDescription)")
}
}
else {
self.recorder = nil
}
guard let device = engine.inputDevice else {
Logger.shared.reportError(self, "No input device")
return
}
self.initialDevice = device
self.mic = input
self.tappableNodeA = Fader(mic!)
self.tappableNodeB = Fader(tappableNodeA!)
self.tappableNodeC = Fader(tappableNodeB!)
self.silence = Fader(tappableNodeC!, gain: 0)
engine.output = silence
// self.pitchTap = PitchTap(mic!) { pitch, amp in
// DispatchQueue.main.async {
// print("============>>", pitch, amp)
// }
// }
self.pitchTap = installTapHandler(node: mic!,
bufferSize: 4096,
tapHandler: tapHandler,
asynch: true)
self.tapHandler = tapHandler
if let pitchTap = self.pitchTap {
pitchTap.start()
}
do {
///As per the order in Cookbook Recorder example
try engine.start()
if recordAudio {
try recorder?.record() <=========== 😡 Error OCCURS HERE
}
}
catch {
Logger.shared.reportError(self, "Error starting engine: \(error)")
}
}
Upvotes: 1
Views: 49