Every good programming framework needs a "Hello World" and this is AudioKit's version of Hello World! Basically, it is just the simplest and shortest amount of code that create an instrument and allow the user to start and stop that instrument from a button on the screen. The app simply plays a pair of oscillators at random frequencies, but there are plenty of more complicated examples to try out once you have this one working.
This starter example is included in AudioKit in the Examples directory with versions for iOS, macOS, and tvOS. There is also an iOS version of this example in Objective-C. When you open the project you will see that there are two primary files that drive this example. The ViewController.swift file contains all of the AudioKit code as well and the Main.storyboard contains the button that activates methods in the ViewController.swift file to control the instrument. There are many storyboard tutorials available online, so we'll just focus on the ViewController.swift's AudioKit code.
The first step is to make an instrument available to every method in this class, so we create two instances of an AKOscillator:
Then, in viewDidLoad, hook up the oscillator to the speakers and start the AudioKit engine.
Finally, we just to need to connect the button from the Main.storyboard file to an action. The only AudioKit code here is to set the frequency of the oscillator and play/stop it. The other parts are just to update the UI to reflect the state of the instrument.
And that's it!
Mac and tvOS Versions
The macOS and tvOS versions differ from the iOS version of this example only in the user interface code.