2

我在使用音序器将 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。文件

如果我改变这一行:

AudioKit.output = offlineRender

AudioKit.output = piano

声音应有尽有,有 16 秒的声音,而不仅仅是前几秒。

上面的代码有问题吗?

提前致谢

4

0 回答 0