Search code examples
iosswiftaudiokit

Quantized Sequence using AudioKit


I've been working with AudioKit to create a sequencer that I would like to play a perfectly quantized sequence (i.e. all subdivisions metrically perfect). However, when I add notes to a sequence I hear fluctuations/imperfections in the time; the subdivisions aren't lining up in a metrically perfect way. When I print the current position of the sequencer in beats to the console during note on events, the fluctuations are shown: the notes are only consistent to two decimal places or so, and then they show variations in the placement. In the callback, I would expect perhaps, with a slight delay: 1.001, 2.001, 3.001. But the output displays seemingly random numbers after two decimals places.

I've created a project to demonstrate the issue here

What am I doing wrong here?

Note that in the project I've made use of AKCallbackInstrument, but the issue persists even if I plug the sampler that will play the sound directly into the sequencer. Also, in the project I've added notes to the sequencer "manually," but the issue persists even if I load a .mid file directly to the sequencer. The sampler in the demo project uses a sound font (.sf2), but the issue exists when I load a .wav or .mp3 sample as well.


Solution

  • I don't think you're doing anything wrong. The AKSequencer is based off of Apple's own MIDI Sequencer, so we provide AKSequencer as a wrapper to that functionality. However, there are known timing accuracies in Apple's sequencer that we can't address because it is closed source. We are working on a replacement to AKSequencer (which will be called AKSequencer, moving the current sequencer to AKAppleSequencer). This should be done in July. In the meantime, you can use AKTimeline to build your own sequencer as was done in the MetronomeSampleSync examples in AudioKit.