问题
I'm trying to play a midi file as a wav audio is being played.
I've tried with
let akSequencer = AKSequencer(filename: "melody")
akSequencer.enableLooping()
akSequencer.play()
But it only plays the first note and nothing else. Also, I'm not being able to use a mixer to mix it with the wav file that it's being loaded like:
let akMidiSampler = AKMIDISampler()
let akSampler = AKSampler()
let wavFile = try AKAudioFile(forReading: wavUrl!)
try akSampler.loadAudioFile(wavFile)
let mixer = AKMixer(akSampler, akMidiSampler)
mixer.volume = 1
AudioKit.output = mixer
AudioKit.start()
akSampler.play()
The wav audio is being played, but the midi just the first note.
Any help is very welcome!
回答1:
I believe you don't have properly hooked up your sequencer to your MIDI Sampler. If you look at some of the AudioKit example playgrounds here:
http://audiokit.io/playgrounds/Playback/Sequencer/
or
http://audiokit.io/playgrounds/Playback/Drum%20Sequencer/
You'll notice there's a line that connects the sequencers to the samplers like:
sequencer.setGlobalMIDIOutput(piano.midiIn)
or
sequencer.setGlobalMIDIOutput(drums.midiIn)
Eventually you could have different samplers for different tracks of the sequencer, but I think this global method is what will work best for you now. Remember that you may have to enable audio background modes on your iOS for MIDI to work. HTH!
来源:https://stackoverflow.com/questions/46574351/play-midi-file-together-with-wav-audiokit