我有一个AKSequencer,它的内部带有AKMusicTrack,并带有AKMIDISampler的输出。我还用声音字体文件加载了AKMIDISampler。
AudioKit的renderToFile面临的问题是,当它确实创建文件时,声音为空/无声,或者它将播放单个音符,该音符将位于文件的开头以及仅演奏单个音符会在整个长度上播放奇怪的声音。
这是初始化代码
let midiSampler = AKMIDISampler()
let sequencer = AKSequencer()
let midi = AKMIDI()
do {
try midiSampler.loadSoundFont("soundFontFile", preset: 0, bank: 0)
} catch {
AKLog("Error - Couldn't load Sample!!!")
}
AudioKit.output = midiSampler
do {
try AudioKit.start()
} catch {
AKLog("AudioKit didn't begin")
}
let drumTrack = sequencer.newTrack("Drum Track")
midi.openInput()
midiSampler.enableMIDI(midi.client, name: "MIDI Sampler MIDI In")
drumTrack.setMIDIOutput(midiSampler.midiIn)
sequencer.setLength(AKDuration(beats: 8))
sequencer.setTempo(136)
sequencer.setRate(40)
midi = AudioKit.midi
这是我尝试renderToFile的方法:
let path = "recordedMIDIAudio.caf"
let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent(path)
let format = AVAudioFormat(commonFormat: .pcmFormatFloat64, sampleRate: 44100, channels: 1, interleaved: true)!
do {
let audioFile = try AKAudioFile(forWriting: url, settings: format.settings, commonFormat: format.commonFormat, interleaved: format.isInterleaved)
try AudioKit.renderToFile(audioFile, duration: 3.55, prerender: {
self.sequencer.play()
})
} catch {
AKLog("Error when converting")
}
我已经在这个特定问题上进行了大量研究,但是我没有运气。在此先感谢您的帮助或指点!
答案 0 :(得分:1)
不幸的是,这是一个众所周知的事实,但可能记录得不够充分,离线渲染不适用于基于MIDI的信号生成。 midi系统使用的时钟不会随着渲染到文件时发生的样本生成速度而加快。