Created
June 19, 2014 07:45
-
-
Save jamiebullock/674033b7d4032f1651f7 to your computer and use it in GitHub Desktop.
Live coding audio with Swift Playgrounds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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