Skip to content

Instantly share code, notes, and snippets.

@jamiebullock
Created June 19, 2014 07:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiebullock/674033b7d4032f1651f7 to your computer and use it in GitHub Desktop.
Save jamiebullock/674033b7d4032f1651f7 to your computer and use it in GitHub Desktop.
Live coding audio with Swift Playgrounds
import Cocoa
import AVFoundation
// Setup engine and node instances
var engine = AVAudioEngine()
var delay = AVAudioUnitDelay()
var reverb = AVAudioUnitReverb()
var mixer = engine.mainMixerNode
var input = engine.inputNode
var output = engine.outputNode
var format = input.inputFormatForBus(0)
var error:NSError?
// Attach FX nodes to engine
engine.attachNode(delay)
engine.attachNode(reverb)
// Connect nodes
engine.connect(input, to: delay, format: format)
engine.connect(delay, to: reverb, format: format)
engine.connect(reverb, to: output, format: format)
// Start engine
engine.startAndReturnError(&error)
// Change FX parameters
delay.delayTime = 1.0
delay.feedback = 80
// Keep playground running
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
@kirlen
Copy link

kirlen commented Jun 27, 2014

Hi. I get the console output below when I enter your example into a new Playground.

Playground execution failed: error: error: Couldn't lookup symbols:

OBJC_CLASS$_AVAudioMixerNode
OBJC_CLASS$_AVAudioUnitDelay
OBJC_CLASS$_AVAudioNode
OBJC_CLASS$_AVAudioFormat
OBJC_CLASS$_AVAudioUnitReverb
OBJC_CLASS$_AVAudioEngine
OBJC_CLASS$_AVAudioOutputNode
OBJC_CLASS$_AVAudioInputNode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment