Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // 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()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement