Recorder Demo

Recorder Demo

This demo is based off of the work by Laurent Veliscek.

Before reading this, we highly recommend you to read a great tutorial on the Hello World example first. This example is included in AudioKit in the Examples directory with versions for iOS and macOS.

First, set session settings:

AKSettings.bufferLength = .medium

do {
    try AKSettings.setSession(category: .playAndRecord, with: .allowBluetoothA2DP)
} catch {
    AKLog("Could not set session category.")

AKSettings.defaultToSpeaker = true

Then, create an instance of input node, and then 2 mixing nodes (a node that mixes its inputs to a single output).

inputPlot.node = mic
micMixer = AKMixer(mic)
micBooster = AKBooster(micMixer)

And then set amplification factor for a mixing node to zero, create an instance of audio recorder class, return the AKAudioFile for reading and set the properties for the playback node. So we're able to create a filter node using the playback one and this gives us an opportunity to playback recorded sounds with the effects like a cutoff frequency and a resonance.

micBooster.gain = 0
recorder = try? AKNodeRecorder(node: micMixer)
if let file = recorder.audioFile {
    player = try? AKAudioPlayer(file: file)
player.looping = true
player.completionHandler = playingEnded

moogLadder = AKMoogLadder(player)

Finally, create a main mixer node and start the AudioKit engine.

mainMixer = AKMixer(moogLadder, micBooster)

AudioKit.output = mainMixer