Skip to content

Instantly share code, notes, and snippets.

Embed
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
AudioKit.start()
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() {
AudioKit.stop()
}
@objc private func start() {
AudioKit.start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment