使用音序器将midi保存到本地文件时遇到问题。 正在创建和保存音频,但音频输出完全不同。
以下是我正在使用的代码:
var sequencer : AKSequencer?
let piano = AKMIDISampler()
var offlineRender = AKOfflineRenderNode()
do {
try piano.loadWav("mixloop")
piano >>> offlineRender
AudioKit.output = offlineRender
sequencer = AKSequencer(filename: "melody")
sequencer?.setGlobalMIDIOutput(piano.midiIn)
AudioKit.start()
let docs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let destAudioFile = docs.appendingPathComponent("rendered11.caf")
offlineRender.internalRenderEnabled = false
self.sequencer?.play()
let seconds = sequencer?.length.seconds
try self.offlineRender.renderToURL(destAudioFile, seconds: seconds ?? 4)
self.sequencer!.stop()
self.offlineRender.internalRenderEnabled = true
print("Done! Rendered to " + destAudioFile.path)
// test the local song using just AVAudioPlayer
playLocalSong(url: destAudioFile)
} catch {
print(error)
return
}
我正在附加mixloop.wav,melody.mid和输出render11.caf。 files
如果我改变这一行:
AudioKit.output = offlineRender
到
AudioKit.output = piano
声音是应该的,声音是16秒而不是前几秒。
上面的代码有问题吗?
提前致谢