Last active
May 13, 2022 09:47
-
-
Save Norod/18286ec54c1f15a05c61 to your computer and use it in GitHub Desktop.
A Dalek-like audio effect
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
#!/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