Ardour's Midi/Audio latency compensation confuses me

Recently I was recording some Piano for a song, using Pianoteq controlled from a Midi keyboard, and recording it into a track in Ardour. Listening back, I noticed that the Piano played slightly (but yet very obviously) too early compared to the rest of the tracks that I had played along with. This led me to look into it and do some tests of latency in Ardour, but the results of these have if anything left me more confused and unsure of what to trust and how to set it up correctly.

I use Ubuntu Studio 24.04, and the Ardour version is 8.4.0ds1-2ubuntu8. My usual setup is to use Ardour for recording audio and Renoise handling sequencing of software and hardware synthesizers. Both synced through Jack transport. I also record some regular miked instruments and some synths played from midi keyboard rather than sequenced. I have used this setup for a long time, for several years on an older computer and now on a new computer I recently bought. I cannot swear the issues I’ll describe weren’t also present on the older computer, but if they were I never noticed them and I think I would have. I’m also unsure if these issues were present right from the start on the new computer or if it’s an even more recent development. I haven’t had the new computer for that long, so it’s possible it’s had problems all along that I failed to spot until now. On the older computer I used the old jack and pulse combination despite pipewire being recommended when I upgraded to Ubuntu 24.04. There were some annoying issues which made me stick to the more tried and true jack/pulse. Initially when I installed the new computer I continued using jack and pulse, but during the troubleshooting process here I temporarily switched to pipewire. Unfortunately, this particular problem remained with pipewire.

I ran a series of tests where I set up a Midi track in Ardour to trigger notes in Pianoteq which I recorded in Ardour. I did this test with different settings for Pipewire buffersize and checked the delay for each. I had the possibility to output the midi track directly into the Pianoteq port, but also to output to the a2jmidi bridge representation of the Pianoteq port, so I made measurements of both. I also ran tests with Renoise triggering Pianoteq and recording into Ardour (synced with Jack transport). At this point I experienced transport sometimes locked up and had to restart Ardour and Renoise to get it running. These are problems I haven’t seen (at least not much) before switching to Pipewire. Below is a table of the different buffersizes and Midi sources and the approximate delay in frames (quite inexact, I just tried to find onset of note in audio and compared with where the Midi triggered, but they will give a good idea of the magnitude of error). I will note that for some points I restarted all applications and did a new measurement and got different results. For buffersize 1024 and Midi through bridge I redid the measurement after restart, and the got pretty much the same delay as renoise then, rather than double. I did a few more tests with restarting and redoing a certain measurement and got other differences, but the differences were then much smaller. Negative values mean audio in recording occurs before Midi triggering.

	128	256	512	1024
midi	-40	-180	-420	-850
bridge	200	330	1000	2100
renoise	100	330	600	1060

During this I found that pipewire still didn’t seem very stable so I went back to jack + pulse again, and could verify the problem was still there. I also downgraded Ardour to version 6.9 to check if the problem was still there, and it seems to be. With jack running at 256 frames/period and 3 periods/buffer, here a miditrack in ardour triggering pianoteq and then recording the audio from pianoteq results in the audio recorded being about 550 frames early. Sending midi via the a2j bridge instead results in the audio delayed by 780 frames. Looking at these numbers I feel I see a pattern, but I don’t know at all if I’m just rambling here: I run jack at 256 frames/period, 3 periods/buffer, with qjackctl reporting a Latency of 17.4 ms. If I go into Ardour, Window menu, Audio/MIDI setup it reports it’s connected to Jack, and says buffer size 256 samples (5.8 ms). To me it coincides with the the audio recording difference when using direct midi, allowing for some jitter that could actually be that it’s 512 frames (ie 2 periods) too early. And on the other hand with the bridge connection, keeping jitter in mind that might as well be 768 frames late, ie the whole jack buffer. I don’t know, I’m just trying to make sense of this.

As an aside, I notice one difference between Ardour 8.4 and 6.9. In version 8.4 if I enable jack transport and start recording, the resulting region from recording will always start a bit later than the playhead location before starting, while in 6.9 the resulting region always start directly from the playhead was. I don’t know if this is how it’s supposed to work?

tldr
This became a long post, but what I’m really wondering is what I am doing wrong, and how I should set Ardour and Jack up to avoid sync/latency problems and keep everything (external and software synths sequenced in Renoise, external and software synths played with midi, and miked/lined in instruments) in sync with each other? I’ve tried to provide as much information as I could think of and test as best I could, but I’ll be happy to provide more information if needed.

tl;dr: you’re using JACK.

jackd has no means to configure systemic latency for MIDI, and it assumes MIDI port latency is the same as Audio (which is not true).

This is one of the main reasons why we recommend using Ardour/ALSA; but that requires exclusive access to the soundcard, so you cannot use Renoise alongside Ardour…

Thank you for your answer. I wondered if it would be something in that direction with regard to Jack but I wasn’t sure so it’s good to know. Thinking about it more, I wouldn’t ever have noticed this before since my habit is to always record all sequenced synths as tracks in Ardour, usually beginning with drums. So when I recorded live instruments later they would be played along to the recorded audio in Ardour, and so all the instruments would be aligned with each other, but not completely to the bars/beats timeline. It was only because I started doing measurements that I noticed that issue.

But I’m still unsure about the situation when using ALSA midi ports, and Ardour seemingly overcompensating latency proportional to the Jack buffer settings. This is something I do think I would have noticed if it had happened before so I’m still wondering if I have misconfigured something when I switched computer.
And also the issue of recording start being delayed, which occurs in Ardour 8 but not in 6, is there some change in recent Ardour which causes it to behave differently?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.