Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. //
  2. // AudioEngine.swift
  3. // TPI
  4. //
  5. // Created by Stephen Radford on 29/05/2017.
  6. // Copyright © 2017 Cocoon Development Ltd. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10. import AudioKit
  11.  
  12. class AudioEngine {
  13.  
  14. static let shared = AudioEngine()
  15.  
  16. var mic: AKMicrophone!
  17. var booster: AKBooster!
  18. var tracker: AKFrequencyTracker!
  19. var silence: AKBooster!
  20. var tap: AKFFTTap?
  21. var mixer: AKMixer
  22.  
  23. private init() {
  24. AKSettings.audioInputEnabled = true
  25.  
  26. // Shared by SPL + RTA
  27. mic = AKMicrophone()
  28. booster = AKBooster(mic)
  29. tracker = AKFrequencyTracker(booster)
  30. silence = AKBooster(tracker, gain: 0)
  31.  
  32. // Tap for RTA
  33. tap = AKFFTTap(booster)
  34. mixer = AKMixer(silence, white, pink, sineOscillator, squareOscillator)
  35.  
  36. AudioKit.output = mixer
  37. AudioKit.start()
  38.  
  39. NotificationCenter.default.addObserver(self, selector: #selector(start), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
  40. NotificationCenter.default.addObserver(self, selector: #selector(stop), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
  41. }
  42.  
  43. deinit {
  44. NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
  45. NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
  46. }
  47.  
  48. @objc private func stop() {
  49. AudioKit.stop()
  50. }
  51.  
  52. @objc private func start() {
  53. AudioKit.start()
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement