Playgrounds

Playback Speed

This playground uses the AKVariSpeed node to change the playback speed of a file (which also affects the pitch)

import AudioKitPlaygrounds
import AudioKit

let file = try AKAudioFile(readFileName: playgroundAudioFiles[0])
let player = AKPlayer(audioFile: file)
player.isLooping = true

var variSpeed = AKVariSpeed(player)
variSpeed.rate = 2.0

AudioKit.output = variSpeed
try AudioKit.start()
player.play()

User Interface Set up

import AudioKitUI

class LiveView: AKLiveViewController {

    override func viewDidLoad() {
        addTitle("Playback Speed")

        addView(AKResourcesAudioFileLoaderView(player: player, filenames: playgroundAudioFiles))

        addView(AKButton(title: "Stop Effect") { button in
            let node = variSpeed
            node.isStarted ? node.stop() : node.play()
            button.title = node.isStarted ? "Stop Effect" : "Start Effect"
        })

        addView(AKSlider(property: "Rate", value: variSpeed.rate, range: 0.312_5 ... 5) { sliderValue in
            variSpeed.rate = sliderValue
        })
    }
}

import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
PlaygroundPage.current.liveView = LiveView()