4

I have some iOS Swift code (using AudioKit 4.5.3), that’s using an AKSequencer feeding an AKCallbackInstrument to play an eight beat drum loop.

I’m also quantizing some user input, so I’m accessing .currentRelativePosition, and .nearestQuantizedPosition from the AKSequencer.

I was seeing some odd quantizing results, so I checked out .currentRelativePosition and .nearestQuantizedPosition whenever the AKCallbackInstrument receives a .noteOn event from the AKSequencer:

       case .noteOn:
                self.currentBeat = self.drummer.nearestQuantizedPosition(quantizationInBeats: 1.0).beats
                self.noteOnTimeStamp = self.drummer.currentRelativePosition.beats
                print(String(format: "Current beat : %.1f\n-- MIDI noteOn at : %.4f \n", self.currentBeat, self.noteOnTimeStamp ))

The output surprised me… everything was normal, except beat seven. Even though .currentRelativePosition consistently returns beat seven correctly, .nearestQuantizedPosition just as consistently returns zero as the nearest beat for beat seven. Beat zero, and all other beats are correctly displayed by both routines. Any thoughts would be appreciated!

Current beat : 0.0 -- MIDI noteOn at : 0.0002

Current beat : 1.0 -- MIDI noteOn at : 1.0002

Current beat : 2.0 -- MIDI noteOn at : 2.0002

Current beat : 3.0 -- MIDI noteOn at : 3.0001

Current beat : 4.0 -- MIDI noteOn at : 4.0002

Current beat : 5.0 -- MIDI noteOn at : 5.0003

Current beat : 6.0 -- MIDI noteOn at : 6.0005

Current beat : 0.0 -- MIDI noteOn at : 7.0003

Current beat : 0.0 -- MIDI noteOn at : 0.0005

Current beat : 1.0 -- MIDI noteOn at : 1.0003


Edit: I just tried a different sequence, with the same results. My sequence is now twelve beats, and .nearestQuantizedPosition returns zero for beat eleven.

My test sequence is just a string of one beat notes, created with this:

    for beatPosition in 0 ... 11 {
        drummer.tracks[0].add(
            noteNumber: 27,
            velocity: 100,
            position: AKDuration(beats: Double(beatPosition)),
            duration: AKDuration(beats: 1))
    }

The length of the sequence appears to be sample-accurate. Printing drummer.length returns:

264600 samples at 44100.0 = 12.0 Beats at 120.0 BPM = 6.0s


Output from 12 beat loop:

Current beat : 9.0 -- MIDI noteOn at : 9.0005

Current beat : 10.0 -- MIDI noteOn at : 10.0003

Current beat : 0.0 -- MIDI noteOn at : 11.0005

Current beat : 0.0 -- MIDI noteOn at : 0.0002

Current beat : 1.0 -- MIDI noteOn at : 1.0005

Brian H
  • 153
  • 7

0 Answers0