Following on from a previous issue, I stopped using AKSampler
to move to the functionality used in AKMIDISampler
. Got my loops working again (with help from this Google Groups post), but I have a sinewave playing (which happens when the MIDISampler can't find it's source file).
It's not an issue with the source files I'm targeting because they all play OK. The sinewave is coming from somewhere else in the process, but I can't see where...
Please help 8•)
(Simplified and edited code to show only relevant details - please get in touch for any clarification)
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()