Skip to content

Instantly share code, notes, and snippets.

@Ilesh
Forked from genedelisa/MIDISamplerSetup
Created May 24, 2019 11:38
Show Gist options
  • Save Ilesh/b0af0b27a8ba8e9ac27c5b922f6883ae to your computer and use it in GitHub Desktop.
Save Ilesh/b0af0b27a8ba8e9ac27c5b922f6883ae to your computer and use it in GitHub Desktop.
Swift MIDI Sampler setup
class MIDISampler : NSObject {
var engine:AVAudioEngine!
var playerNode:AVAudioPlayerNode!
var mixer:AVAudioMixerNode!
var sampler:AVAudioUnitSampler!
override init() {
super.init()
initAudioEngine()
}
func initAudioEngine () {
engine = AVAudioEngine()
playerNode = AVAudioPlayerNode()
engine.attachNode(playerNode)
mixer = engine.mainMixerNode
engine.connect(playerNode, to: mixer, format: mixer.outputFormatForBus(0))
// MIDI
sampler = AVAudioUnitSampler()
engine.attachNode(sampler)
engine.connect(sampler, to: engine.outputNode, format: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment