继上一期之后,我停止使用AKSampler
,转而使用AKMIDISampler
. 让我的循环再次工作(在此Google Groups 帖子的帮助下),但我正在播放正弦波(当 MIDISampler 找不到它的源文件时会发生这种情况)。
这不是我定位的源文件的问题,因为它们都可以正常播放。正弦波来自过程中的其他地方,但我看不出在哪里......
请帮忙 8•)
(经过简化和编辑的代码仅显示相关详细信息 - 请联系以获取任何说明)
var MIDISamplePlayer = AKMIDISampler()
var sequencer: AKSequencer?
var mixer: AKMixer!
// initialise the mixer
mixer = AKMixer()
do {
audiofile = try AKAudioFile(readFileName: SoundFilename as! String,
baseDir: .resources)
} catch let error as NSError {
print("There's an error: \(error)")
}
do {
try sprite.MIDISamplePlayer.loadAudioFile(audiofile)
} catch let error as NSError {
print("There's an error: \(error)")
}
sprite.tracker = AKAmplitudeTracker(sprite.MIDISamplePlayer)
mixer.connect(to:sprite.tracker, bus: mixer.nextInput.bus)
sequencer = AKSequencer(filename: POPmidi)
sequencer?.enableLooping()
let midi = AKMIDI()
for i in 0..<popCount {
gPOPs[i].MIDISamplePlayer.enableMIDI(midi.client, name: "MIDISample_\(i)")
mixer.connect(gPOPs[i].MIDISamplePlayer)
sequencer!.tracks[i].setMIDIOutput(gPOPs[i].MIDISamplePlayer.midiIn)
}
AudioKit.start()
sequencer!.play()