Play MIDI file together with wav AudioKit

眉间皱痕 提交于 2021-02-07 21:53:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!