Last active
May 4, 2019 14:02
-
-
Save standinga/c311fd324b4d9fb62d3029e7494eeb80 to your computer and use it in GitHub Desktop.
AudioUnitViewController.swift for medium post about Audio Unit V3 Extension, updated Framework's extension view controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CoreAudioKit | |
public class AudioUnitViewController: AUViewController, AUAudioUnitFactory { | |
public var audioUnit: VolumePluginAudioUnit? { | |
didSet { | |
DispatchQueue.main.async { | |
if self.isViewLoaded { | |
self.connectWithAU() | |
} | |
} | |
} | |
} | |
private var volumeParam: AUParameter? | |
public override func viewDidLoad() { | |
super.viewDidLoad() | |
if audioUnit == nil { | |
return | |
} | |
self.connectWithAU() | |
} | |
func connectWithAU() { | |
guard let paramTree = audioUnit?.parameterTree else { | |
fatalError("paramTree nil!") | |
} | |
volumeParam = paramTree.value(forKey: "param1") as? AUParameter | |
} | |
public func createAudioUnit(with componentDescription: AudioComponentDescription) throws -> AUAudioUnit { | |
audioUnit = try VolumePluginAudioUnit(componentDescription: componentDescription, options: []) | |
return audioUnit! | |
} | |
@IBAction func volumeSlider(_ sender: NSSliderCell) { | |
volumeParam?.value = AUValue(sender.doubleValue) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment