From the course: Code Clinic: Swift
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Make sounds
- [Narrator] Now let's look at actually using AudioKit to produce sound. I'm in ViewController.swift and I'm going to scroll down into viewDidLoad and the first thing I'm going to do is set the volume of our oscillator to be low. So, oscillator.amplitude. We'll set that to 0.1 and we only want sounds to be playing while the user's finger is on the screen, so we'll need to stop the oscillator when the touches end. Instead of touchesEnded, call oscillator.stop. Now, let's go inside of updateSound. We're receiving the touch position from touchesBegan and touchesMoved and we have that as a CGPoint in this parameter. The first thing that we're going to do is check to see if AudioKit doesn't have any output set up yet. If it doesn't have any output, we're going to say that it's output is our oscillator. If AudioKit.output is equal to nil, then AudioKit.output equals oscillator and then we need to start AudioKit. We'll have to put that inside of a do-catch statement. So do, some curly…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.