I posted some time ago regarding this topic, but it still stumps me. I’m experiencing what I deem unpredictable latencies when using Ardour in conjunction with MIDI. Since recording while playing along with things already tracked in Ardour works very well, I wouldn’t really care much about latencies for MIDI if they were predictable and consistent, but I find that’s not the case.
I run Ardour 8.4.0~ds1 on Ubuntu Studio 24.04. Audio system is Pipewire, but I also experienced this earlier on Jack. I noticed this problem a while after getting a new computer, on the old computer I never noticed these problems (but I can not swear it wasn’t there). The audio interface is a Focusrite Scarlett 18i8.I use Ardour for recording audio, and Renoise for sequencing hardware and software synthesizers.
Below is a screenshot that illustrates misaligned audio from recordning various MIDI sequenced sources. This was done with tempo set to 120 and various sources triggered with quarter notes from Renoise. The first 3 tracks are in order TAL drum software synthesizer on a track in Ardour, and then recordning output of the track. Second is Pianoteq, a jack capable software synthesizer. Recorded by selecting it from the external tab in the input selection. The third track is an external software synthesizer where I just selected the physical MIDI port it’s on in Renoise, and recorded directly from an input on the audio interface.
The next three tracks are exactly the same sources, but I tried activating “Use ALSA sequencer for MIDI event scheduling” in Renoise, as it was hinted it usually works better. However, looking at the recordnings it doesn’t seem to make any difference.
At this point I tried changing the period size in pipewire to 256 (it was 1024 to begin with, and reported buffer size was 32768 (set by pipewire, not me) for both period settings). The next three tracks in the screenshot are the same sources with new period settings. I’ll note that the delay is smaller throughout. TAL Drum in the Ardour track is still the latest, but Pianoteq and the hardware synth are now pretty much aligned, albeit still delayed compared to the bar/beat boundaries. I then decided to do some more testing. The third track from the bottom is also TAL drum, but this time hosted in Carla with Ardour recording from external. Second from bottom is QSynth. Seems like TAL/Carla and Qsynth are pretty aligned here, and almost on the beat. The last track is Pianoteq, with another preset. Since this software is physically modeling piano-like instruments, I wondered if there might be some unavoidable delays in the modeling. It seems earlier now, but still later than the other jack connected sources. Maybe this is something inherent to Pianoteq?
I was earlier given the advice to run Ardour directly on ALSA (difficult, due to the need for sequencing MIDI) but does everyone really run it this way, is there no one that has the need for sequencers and software synthesizers? Or should I run a dedicated computer for MIDI? I really feel there must be something I’m missing, surely this can’t be this inconsistent for everyone? Is there something I can do to get better alignment? I’m not that bothered if it doesn’t line up with the bar/beat grid, but I feel I need to be able to trust that a synth I record will be aligned with the synth I recorded yesterday, and this is not a feeling I have now.
USB devices are notorious for having different systemic latencies every time they’re started, which is why Ardour’s ALSA backend allows to calibrate systemic latency while the device is running not requiring a restart.
Check Ardour > Menu > Audio/MIDI Setup … and calibrate latency (both audio and MIDI).
–
I regularly test Ardour alignment by looping back MIDI signals, tapping them off mid-stream and feeding them as audio:
I read something somewhere else (possibly by you?) about USB having different latencies every start. This may be something I need to look into at some point ahead, but right now it seems completely irrelevant. If this was down to USB latency I would expect the tracks going through a USB connected MIDI port to have the same latency as the others + some random number. But in the tests I did the external hardware synth is earlier than almost all internal connections. And in fact, the most delayed instrument recorded is the one closest to Ardour, the TAL drum that was on an Ardour track and routed internally for recording. So I still don’t really understand the differences at play here? Are Renoise and/or Jack MIDI that inprecise? But MIDI still shouldn’t be sent at different times to Ardour and Pianoteq, and differences (if any) in timing I intuitively think should be that everything is later than the Ardour track. Or put it like this, the track Ardour should have the most control over here is the track with Tal Drum. Ardour knows when the MIDI comes in, and the Jack latency setting, and should therefore be able to figure out when the note should happen. Yet, the track that is closest to Ardour is the one most catastrophically affected. The other tracks, which are potentially subject to more added latency beyond the control of Ardour, have more precise timing.
Well, Ardour itself plays very little role here. This is all done by the OS. Specifically the Linux kernel ALSA driver (which adds buffering up to half of the buffesize for audio) that can shift MIDI around.
Since you get different alignments, could it be that there were dropouts (x-runs) which will reset the USB later and MIDI alignment shifts every time an x-run occurs.
Other OS have similar issues, systemic latency often dominates.
Start by not using pipewire. It is too new to be used reliably for music production, certainly the version that shipped with Ubuntu last year is.
If you use pipewire or JACK you will have to use for both Audio and MIDI. bypassing MIDI around pipewire will never align and it will indeed randomly shift…
Thank you. I did a run where I shutdown all Pipewire and Jack, and attempted to only use ALSA stuff. I couldn’t find any option to sync Renoise with MTC so I tried Midiclock, and it seems to work OKish. The other way around, Renoise as master, did not work as well when I tried briefly. It made the playhead and tempo in Ardour very jittery. It’s possible there was some setting to finetune it, but I thought it was better for Ardour to be master anyway. The image below show these results. It seems TAL is a bit late to the beat, but at least some of it is some frames of silence at the start of the sample. I checked later beats also and there is some variation in onset I think, but only in the magnitude of a couple of tens of frames.
The external synth which is on the second track is still earlier. I’ll note that it’s earlier by what seems as 512 frames, coincidentally I set Ardour to 512 samples, 2 periods. Would this reflect that Ardour compensates for this entire time when recording the track, but that not being the correct thing to do in this case? Since normally a track would be played in Ardour and the audio would go through the buffer before being played through speakers, then someone playing along would play and the new audio would go through buffer again, vs the sequencer going in lockstep with Ardour and sending MIDI immediately to the external synth, resulting in the audio effectively only having passed half the buffer timewise? Should I work under the assumption that MIDI to external synths therefore always will be this early, and compensate accordingly? I guess I could solder up a MIDI loopback device such as you demonstrated earlier, but that might feel a bit too above and beyond for me. I feel I’ve already been sitting doing more measurements of things rather than getting any music done.