Skip to content

Instantly share code, notes, and snippets.

@Norod
Last active May 13, 2022 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Norod/18286ec54c1f15a05c61 to your computer and use it in GitHub Desktop.
Save Norod/18286ec54c1f15a05c61 to your computer and use it in GitHub Desktop.
A Dalek-like audio effect
#!/usr/bin/env xcrun swift
// $ chmod +x dalekTalk.swift
// $ ./dalekTalk.swift
// Based upon https://gist.github.com/okket/e461e85ea8b414863648
import Cocoa
import AVFoundation
import Foundation
if #available(iOS 9, OSX 10.10, *) {
// Setup engine and node instances
var engine = AVAudioEngine()
var mixer = engine.mainMixerNode
var input = engine.inputNode
var format = input!.inputFormat(forBus: 0)
// Attach FX nodes to engine
var reverb = AVAudioUnitReverb()
reverb.loadFactoryPreset(AVAudioUnitReverbPreset.plate)
reverb.wetDryMix = 50
engine.attach(reverb)
var distortion = AVAudioUnitDistortion()
distortion.loadFactoryPreset(AVAudioUnitDistortionPreset.speechCosmicInterference)
distortion.wetDryMix = 85
engine.attach(distortion)
// Connect nodes
engine.connect(input!, to: reverb, format: format)
engine.connect(reverb, to: distortion, format: format)
engine.connect(distortion, to: mixer, format: format)
// Start engine
do {
try engine.start()
print("\nShout like a Dalek")
print("Make sure to use Headphones")
print("\nHit <ENTER> when you get bored")
var output: CInt = 0
var c = getchar()
print("Exterminated!")
}
catch {
print("oh no!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment