 
 public class PitchEngine {
 
+  public enum Error: ErrorType {
+    case RecordPermissionDenied
+  }
+
+  public enum Mode {
+    case Record, Play
+  }
+
+  public let mode: Mode
+  public let bufferSize: AVAudioFrameCount
+  public var active = false
   public weak var delegate: PitchEngineDelegate?
-  public var active = false
-
-  private let bufferSize: AVAudioFrameCount
-  private var frequencies = [Float]()
-  public var pitches = [Pitch]()
-  public var currentPitch: Pitch!
 
   private lazy var signalTracker: SignalTrackingAware = { [unowned self] in
     let inputMonitor = InputSignalTracker(


  // MARK: - Initialization

  public init(bufferSize: AVAudioFrameCount = 4096, delegate: PitchEngineDelegate?) {
    self.bufferSize = bufferSize
    self.delegate = delegate
  }

  // MARK: - Processing

  public func start() {
    guard mode == .Play else {
      activate()
      return
    }

    AVAudioSession.sharedInstance().requestRecordPermission { [weak self] granted  in
      guard let weakSelf = self else { return }

      guard granted else {
        weakSelf.delegate?.pitchEngineDidRecieveError(weakSelf,
          error: Error.RecordPermissionDenied)
        return
      }

      dispatch_async(dispatch_get_main_queue()) {
        weakSelf.activate()
      }
    }
  }

  public func stop() {
    signalTracker.stop()
    active = false
  }

  private func activate() {
    do {
      try signalTracker.start()
      active = true
    } catch {
      delegate?.pitchEngineDidRecieveError(self, error: error)
    }
  }
}

