MIDI Quantization during Recording?

Is it possible that C3 is aligning recorded MIDI Notes on 1msec boundaries?

I am recording two streams of MIDI over USB into a single .MID file. The streams are related, in that they arrive from the same source over different paths (I am doing latency tests). One stream is always behind the other (as expected), but the latency is always an exact multiple of 1.00 msec.

I am measuring the time difference by opening the MIDI file in Reaper.

When I record the same setup directly in Reaper, I get no such “quantization” effect. Latency varies from test to test at the sample level.

Here is a diagram of my test setup:

My two signal paths are a direct USB link and a Radio link to a receiver. You can see that the latency between the two - in Samples at 44.1 kHz - is always a multiple of 44.1. All of my latency numbers are (in samples) 44, 88, 132, etc.

Has anyone experienced this in Cantabile??

Here’s another example of what I am calling MIDI “quantization” …

The text on the graphic (in case it is not readable) reads:

11 tests of MIDI RTL (Round Trip Latency) on 18Dec2021 with a physical DIN5
loopback cable on a M-Audio MidiSport 2x2 Anniversary Edition MIDI interface
showed RTL times of:
265, 309, 309, 309, 309,
265, 265, 309, 309, 309,
and 309 samples @ 44.1 kHz,
when measured in Reaper. These results demonstrate a “quantization” of the recorded
MIDI notes on 1.000 msec boundaries:
265 samples @ 44.1 kHz = 6.009 msec
309 samples @ 44.1 kHz = 7.007 msec

I am hoping that maybe @brad or someone else experienced in this area can shed some light on this phenomenon … I am hesitant to do more testing using Cantabile with this suspect behavior.

Hi Clint,

I found this explanation of why MIDI works in mS and possibly it can explain your delay findings.

Dave

1 Like

I’m not surprised that you get quantisation of MIDI notes using classic DIN cables - remember, MIDI is a serial protocol - and a relatively slow one. So there is an exact time it takes to transmit a MIDI note, and to reconstitute it from its individual bits. The time to send 3 bytes along this serial connection is 960 microseconds - almost a millisecond. So that should explain the quantisation with the DIN connection. So nothing funky involved at the Cantabile end of things - just the nature of the connection, I suspect…

I don’t think that this would happen over an all-USB connection, though. Transporting bits along a USB connection happens a lot faster. But of course your Sylpho wireless link will also have some serial comms involved in its transmission mechanism that may have similar speeds to “wired” MIDI, so it may actually have similar characteristics.

I would suspect that the “later” stream is the wireless one - correct? In that case, that would lead me to suspect that the wireless communication mechanism has a similar data rate to “classic” MIDI

Hope this helps!

Cheers,

Torsten

1 Like

Thank you to both @Torsten and @dave_dore for the info!

One thing that may confound timing is the “running status byte” optimization in MIDI (good explanation Here).

However, I did a direct comparison (same hardware config) between Reaper and Cantabile, and get very different results. Reaper results are quantized, but at a smaller granularity than Cantabile (0.522 vs. 1.000 msec or 23 vs. 44 samples) and Round Trip Latency (RTL) is lower in Reaper than Cantabile (4.59 vs. 7.70 msec).

The host, MIDI driver, MIDI files, and analysis method are the same for both tests. I can only think that there is some significant difference in the way Cantabile handles MIDI that produces these different results.

Here are the diagrams (and info) for these two tests, first using Reaper as the DAW:

… and then using Cantabile as the DAW:

Any thoughts are welcome! (I’m runnin out of ideas …)

[EDIT: Corrected the two diagrams]

It looks like the setting of the Buffer Size on the Audio interface affects the MIDI RTL
(Round Trip Latency). I did tests using the Null Audio driver. When I changed the Buffer Size from 64 to 4096, the MIDI RTL shot up from 4.2 msec to over 85 msec.

I’m not sure how the Audio Buffer comes into play for MIDI operations. However, Reaper seems to have the same behavior: when using the Dummy Audio driver in Reaper, the setting of the Buffer Size had a similar effect on MIDI RTL.

As an aside, I’m curious why Cantabile does not allow a Buffer Size of 0 on the Null Audio driver. Reaper does. The minimum Null Audio buffer size is 64 in Cantabile.

This addresses the issue that MIDI RTL times were higher in Cantabile than Reaper, but does not address the primary issue of this thread: Quantization of MIDI events recorded by Cantabile on 1 msec boundaries.

Here is the diagram with specifics of the test:

I just ran similar tests on two other MIDI interfaces - the MIDI ports on an RME UCX II and the MIDI ports on an Aodyo Link Receiver. Both had similar results to the M-Audio MidiSport 2x2 interface: the MIDI Round Trip Latency is dependent on the Buffer Size setting of whatever audio driver is in use (including Null Audio).

I am randomly wondering if the half-duplex nature of USB 2.0 is causing the 1 msec “quantization” of MIDI that I am seeing. In doing an RTL (Round-Trip Latency) test, I am sending a MIDI command down the wire and then listening for how long it takes to come back.

Is there a cost of change-in-direction in USB 2.0? … and might that explain my results being aligned on 1msec boundaries?

1 millisecond? That’s faster than a speeding bullet and that never slowed Superman! :wink:

… is the quantization of the MIDI that I am seeing … i.e. MIDI commands are aligned on exactly 1 msec boundaries … sometimes I get MIDI returned at 1.000 msec and at other times I get MIDI returned in as late as 12.000 msec, with no discernable. So, this basically gives me 11.000 msec of jitter.

A bit disconcerting to see (and it also feels that way when I’m playing …)

Also, I was doing this with “cleaned up” MIDI - only Note On/Note Off events. When I add the CC commands - which my Sylphyo wind synth can generate up to 1000 x per second for Breath Pressure - things can get bad fast for latency. In practice, I reduce CC#2 to 125x or 250x per second, to allow for pitch bends and all the other CC’s (pitch, yaw, and roll) that the Sylphyo generates …

Ah, yes, to be young again! I’m 72 yo and have slowed WAY down. That’s why my EWI5000 and Cantabile 3 are fast enough for my needs. :notes::+1:

1 Like

I’ve done some more work on these quantization issues, and now I have some big concerns about the way Cantabile records MIDI events. Specifically, I have found more evidence for quantization on 1ms boundaries, and I am thinking that if these recorded MIDI files are played back, this amounts to 1ms of jitter that could materially alter the sound of the recorded MIDI stream.

I wired up several “MIDI-Audio Tap Cables” described in an old Sound-on-Sound article on latency. Here’s the wiring diagram:

This cable nicely reports a MIDI event on an unbalanced Audio channel with a clear pulse. Using this [M+A] cable, I set up this test:

Results were interesting!

Here’s a side-by-side of the three recorded channels (analyzed in Reaper). Track 8 shows Cantabile’s recording of the outbound MIDI events. Track 9 shows the audio input from the unbalanced branch of the [M+A] cable and track 10 shows Cantabile’s recording of the input MIDI event that has been looped back.

MIDI events, as recorded to files by Cantabile, seem to always be aligned / quantized on 1ms boundaries. At 44.1 kHz and a buffer size of 48 samples, the MIDI return event on Track 10 is always 88 or 132 samples later than the MIDI send event on Track 8.

Furthermore, there are cases where the M+A cable reports the MIDI event arriving at the loopback cable before the event recorded by Cantabile is logged in the MIDI recording file:

Cantabile delays the recording of outbound MIDI port events played from the Media player and inbound MIDI port events so they sit on 1ms boundaries. The outbound notes themselves do not appear to be delayed, as demonstrated by this second screenshot.

This means that, at the least, MIDI files recorded by Cantabile have a substantial jitter - possibly as high as just under 1msec (specifically: 1ms less one sample’s duration, or 0.977ms @ 44.1 kHz).

One explanation is that MIDI and Audio files recorded at the same time are not synchronized. This would explain the Audio events occasionally (4 times out of 20 tests) appearing before the MIDI event counterparts. However, it would not explain the quantization of MIDI events on 1ms boundaries.

For my part, it means that recording of MIDI events in Cantabile cannot be used for latency testing, or for anything where a 1ms jitter is problematic. The M+A cable approach would be needed.

1 Like