Skip to content

Instantly share code, notes, and snippets.

@standinga
Last active May 4, 2019 14:02
Show Gist options
  • Save standinga/c311fd324b4d9fb62d3029e7494eeb80 to your computer and use it in GitHub Desktop.
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
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