Skip to content

Instantly share code, notes, and snippets.

Created July 20, 2017 15:55
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
AudioEngine used for TPI
// AudioEngine.swift
// TPI
// Created by Stephen Radford on 29/05/2017.
// Copyright © 2017 Cocoon Development Ltd. All rights reserved.
import Foundation
import AudioKit
class AudioEngine {
static let shared = AudioEngine()
var mic: AKMicrophone!
var booster: AKBooster!
var tracker: AKFrequencyTracker!
var silence: AKBooster!
var tap: AKFFTTap?
var mixer: AKMixer
private init() {
AKSettings.audioInputEnabled = true
// Shared by SPL + RTA
mic = AKMicrophone()
booster = AKBooster(mic)
tracker = AKFrequencyTracker(booster)
silence = AKBooster(tracker, gain: 0)
// Tap for RTA
tap = AKFFTTap(booster)
mixer = AKMixer(silence, white, pink, sineOscillator, squareOscillator)
AudioKit.output = mixer
NotificationCenter.default.addObserver(self, selector: #selector(start), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(stop), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
deinit {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
@objc private func stop() {
@objc private func start() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment