Skip to content

Commit

Permalink
Merge pull request #33 from vadymmarkov/fix/input-signal-tracker
Browse files Browse the repository at this point in the history
Make audio engine optional
  • Loading branch information
vadymmarkov authored Sep 4, 2016
2 parents 80e8172 + 04fc145 commit c970fa5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Source/SignalTracking/Units/InputSignalTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class InputSignalTracker: SignalTracker {

var audioChannel: AVCaptureAudioChannel?
let captureSession = AVCaptureSession()
private var audioEngine: AVAudioEngine!
private var audioEngine: AVAudioEngine?
private let session = AVAudioSession.sharedInstance()
private let bus = 0

Expand Down Expand Up @@ -45,7 +45,7 @@ public class InputSignalTracker: SignalTracker {

audioEngine = AVAudioEngine()

guard let inputNode = audioEngine.inputNode else {
guard let inputNode = audioEngine?.inputNode else {
throw Error.InputNodeMissing
}

Expand All @@ -63,17 +63,19 @@ public class InputSignalTracker: SignalTracker {
}

captureSession.startRunning()
audioEngine.prepare()
try audioEngine.start()
audioEngine?.prepare()
try audioEngine?.start()
}

public func stop() {
if audioEngine != nil {
audioEngine.stop()
audioEngine.reset()
audioEngine = nil
captureSession.stopRunning()
guard audioEngine != nil else {
return
}

audioEngine?.stop()
audioEngine?.reset()
audioEngine = nil
captureSession.stopRunning()
}

func setupAudio() {
Expand Down

0 comments on commit c970fa5

Please sign in to comment.