Inconsistent systemic latency measurements - without usb device restart

Dear Ardour community!

I have been racking my brain for several days about an issue of inconsistent systemic latency measurements - without usb device restart, that I am having using Ardour and/or Mixbus in Linux (Debian 12, Liquorix 6.4, Amd 5900x, Presonus 1818vsl and Audient EVO 8).

If I understand it well, the issue is likely related with Alsa (and not related directly with Ardour / Mixbus).
And have tried to read all I could find about the the issue, and have come to conclusion, that asking in Ardour forum might bring some light to it, and possibly find some solution, as there are clearly highly knowledgeable creators here. My motivation is to improve Linux audio experience with Ardour/Mixbus.

I am aware of this post: Audio delay inconsistent
And have read this recent post Trouble with latency (compensation) and pipewire which I believe might be related.

It behaves the following way:
The latency measurement tool first measures some systemic latency, but later the latency changes (typically rises) again and again, up until a point of relative stability. This happens without stopping the audio device (ALSA connected). Unfortunately sometimes the measured latency also drops back to lower levels from the observed maximum.

I noticed this on recording a click via microphone that I could not sync it with bars. Followup measurements with the tool usually add a some samples, eg for 128*3 periods goes gradually eg from 64+64 samples sometimes up to 200+200, within several minutes, and without stopping audio device. The recorded click gets out of sync if I don’t remeasure the systemic latency. Tested on a single track with just the click recorded / and also on a multitrack project.

It seems, that when on dsp heavier project there seems to be more of this behavior. It also seems, that setting up larger buffer makes this less frequent. It seems to me, that with 3 periods it is less frequent, but also present.

It doesn’t depend on cpu vendor (tried on older intel 6th gen with newer kernel). It basically behaved the same. Also tried other usb sound card Audient EVO 8, same situation. On AV Linux MX-21.3 same. Another circumstance - there are no xruns.

Then I tried older AV Linux on intel PC, Debian 9 based, Kernel 4.19 (stock and 4.16 avl-rt), and it did not behave like this. The latency measurement was consistent, albeit it was on the higher side, but stable. (on device restart there were just small changes).

I started googling what has changed, and found out, that there has been a new low latency patch included in recent kernels (5.15). This post Corrupt audio using jackd after upgrade to kernel 5.15.7+ / Kernel & Hardware / Arch Linux Forums stated, that with kernel boot parameter in grub “snd_usb_audio.lowlatency=0” it disables the patch. I tested it, and the Liquorix 6.4 had stable latency - but on the high side…

Then I found out that the patch is probably originating from Post #16 from this thread ALSA Underrun Recovery - Cockos Incorporated Forums - where there was a module patch, that allowed for significantly lower usb card latencies in Linux.

The original patch allowing for lower latencies is probably this: parameters.patch - aur.git - AUR Package Repositories - and it exposes various parameters to tweak. It is for me rather difficult to understand, what is going on there with all the URBs, max_packs, queues, but at least it would be possible to try tweaking those. I however tried using the module parameters in grub, but in dmesg there was a message, that they are not recognized (at least on recent kernels).

Than I found this mainline patch, that introduced the possibility to switch of the low latency option (I suppose it is the one from the above Arch dkms patch, but I am really not sure. However what the remains of my coding understaning from ages before tell me - there are conditions (in the code) under which low latency behaviour is switched on. And although I don’t really understand, whats is going on there, it possibly allows for inconsitent behaviour. Some details for the record are here: [PATCH 5.15 003/207] ALSA: usb-audio: Disable low-latency playback for free-wheel mode - Greg Kroah-Hartman

Now, can anyone confirm this behavior on their systems? as my knowledge is limited, I am not sure whether I am not doing wrong something else…

It seems to me, that the snd_usb_audio module somehow changes the parameters of its buffers on the fly, based on something i don’t know how to control. The desired solution would be the possibility, to fine tune it, so that I can record midi instrument with minimal possible latency, while keeping the systemic latency stable for the time the audio device is started.

Any Ideas welcome. Possibly I am not the only one, who is baffled by this. I was wondering, how great it would be to have more parameters of the snd_usb_audio exposed, so we could try to tweak it for multitrack recording purposes… Or possible someone has another ideas?

Thanks and take care,