USB interface latency

Talk about your MIDI interfaces, microphones, keyboards...

Moderators: MattKingUSA, khz

paul
Established Member
Posts: 226
Joined: Wed May 07, 2014 9:50 pm
Location: UK
Has thanked: 1 time
Been thanked: 1 time

USB interface latency

Post by paul »

Hello,

I've noticed that there is an appreciable increase in latency if I use my Scarlett 2i2 for output instead of the internal soundcard (of a ThinkPad). I can't measure it, but it sounds like something of the order of 10 ms.
Is this due to my interface being cheap, is it due to USB being slow, or is it something software or computer-related?
I would like to get a better interface for playing live (so, minimal latency), but first I need to identify the problem.

Thanks!
Keep on rocking in the free world!
gimmeapill
Established Member
Posts: 564
Joined: Thu Mar 12, 2015 8:41 am
Has thanked: 44 times
Been thanked: 8 times

Re: USB interface latency

Post by gimmeapill »

The Scarlett 2i2 is probably the best price/quality ratio you can find in the prosumer market at the moment, I can't believe an integrated notebook sound card would perform better - despite the USB bus. Not even mentioning the DAC quality.
Going to a more expensive sound card will most likely not solve your latency issues: if you want to achieve real low latency (<8-10ms) you need to tune your system properly.
And the first step is to measure it - your sound server / application should give you that info - do not rely only on ear.
Please post some details about your current configuration and what you are trying to achieve exactly.
The lowest latency you'll be able to achieve is highly configuration dependent, so this is important.

To give you an idea, my2i2 runs happily at about 2ms in / 2ms out @24bit/96khz (4ms round trip) with guitarix/ardour/hydrogen. But I have another set up involving wine and Renoise using only outputs, where 17-18 ms @16bit/44.1khz is the maximum.

Cheers,

LX
paul
Established Member
Posts: 226
Joined: Wed May 07, 2014 9:50 pm
Location: UK
Has thanked: 1 time
Been thanked: 1 time

Re: USB interface latency

Post by paul »

This evening I'll try to make a more technical analysis.

Anyway, here is roughly what happens:
I connect my piano with a MIDI-USB interface to Carla, where I play a piano soundfont. Jack running with buffer at 256 samples, nominal latency 5.8 ms (according to Cadence).
Now, if I use the internal sound card, I hear the sound basically as soon as I play the note. If I use the 2i2 (which for all other purposes I really like), the sound comes later, too much later.

If I activate also the piano speakers, so that I get sound both from the piano and from the computer, and I play a note, I hear "da" using the internal soundcard, and "dla" using the 2i2 (yeah, sorry, that's as best as I can explain :| I hope it's clear enough).
Keep on rocking in the free world!
asbak
Established Member
Posts: 897
Joined: Thu Sep 11, 2014 3:04 pm
Has thanked: 71 times
Been thanked: 64 times

Re: USB interface latency

Post by asbak »

I imagine the issue is software & setup related, not the USB card. (Although it may be worth checking the firmware version and updating if necessary).

There are a zillion variables involved which have an effect on the performance you'll get out of your soundcard.

-Your base OS & Kernel version
Contrary to what a lot of users will claim about not needing low-latency or RT kernels (because they have no idea what low-latency means, don't need or use it and don't use a keyboard to play a softsynth live), it's unlikely you'll get decent performance without some kind of PREEMPT or RT Kernel installed. The "low-latency" kernel that can be installed on Ubuntu and similar may work ok'ish (don't know). Under Debian one would have to compile a PREEMPT or RT kernel or source one from somewhere else. Without that I don't think performance will be very good under jack.

-Your harddrive performance

-Whether you've done the typical tuning as per most installation guides

-The kind of videodrivers and hardware you're using (I had bad experiences with nouveau drivers but perhaps other users don't have issues... who knows)

-The particular USB port you're using on the computer, some may behave differently than others

-Ensuring that only the audio card is plugged into the USB port. (DON'T make use of USB hubs).

-What kinds of services are running in the background impacting system performance, many of which you may not be aware of

-Whether you've configured jack settings optimally for your audiocard - This in particular will lead to poor performance if sub-optimal values are used.

-Whether Pulseaudio is causing issues

-Whether jackdbus is causing issues
Some Focal / 20.04 audio packages and resources https://midistudio.groups.io/g/linuxaudio
gimmeapill
Established Member
Posts: 564
Joined: Thu Mar 12, 2015 8:41 am
Has thanked: 44 times
Been thanked: 8 times

Re: USB interface latency

Post by gimmeapill »

Agree. This sounds more like a cadence setup issue than a hardware limitation.
Make sure you use the same buffer size and period number when you switch device in Cadence.

Keeping in mind that you may always hear a small latency when comparing with the integrated piano speakers, with this config you could probably get down to a buffer size of 128 samples (this will require some tuning tough, unless you use one of the audio distributions).
One comment related to USB connectivity: according to common wisdom, the sweet spot is usually found with 3 periods - with PCI it is usually 2. ymmv...
CrocoDuck
Established Member
Posts: 1133
Joined: Sat May 05, 2012 6:12 pm
Been thanked: 17 times

Re: USB interface latency

Post by CrocoDuck »

Hi! I own a Scarlett 2i4 (pretty much the same stuff of the 2i2 a part for MIDI ports and a couple of outputs more). As part of my MSc project in Audio Acoustics I am using it for some audio equipment measurement. As such, I had to determine the sound card response at first. I see a lot of people referring to this line of interfaces as the best, but honestly I am kinda disappointed. Don't get my wrong, they are indeed good: the frequency response is pretty flat in magnitude (linear in phase a part regions at frequencies < 100 Hz and > 20000 Hz, where phase distortion starts getting more appreciable), and the high order impulse responses (responsible for distortion) are extremely little compared with the linear response (although distortion products in the high end are clearly audible). What that bothers me is the HORRIBLE cross-talk it has. Seriously, the signal in one channel leaks on the others so easily. This is NOT what you expect from a such expensive device and it has been the source of many problems.

That for the outburst... Relevant to your problem: after messing weeks with jack_iodelay the round-trip latency when using the Scarlett is higher with respect when using the internal Intel_HDA also in my case. My theory for this:

Clock jitter that produces converter inaccuracies (experienced in other Focusrite Devices) + messy delays introduced at the firmware/bus levels in my quirky laptop + software load.

I think the last two are the most important, as you have acknowledged. Have a look at this, this and this, they might be interesting for you.
asbak
Established Member
Posts: 897
Joined: Thu Sep 11, 2014 3:04 pm
Has thanked: 71 times
Been thanked: 64 times

Re: USB interface latency

Post by asbak »

Also check your USB ports, whether these are USB3 or USB2. It may be worth setting it to USB2 if it is USB3.
Some Focal / 20.04 audio packages and resources https://midistudio.groups.io/g/linuxaudio
gimmeapill
Established Member
Posts: 564
Joined: Thu Mar 12, 2015 8:41 am
Has thanked: 44 times
Been thanked: 8 times

Re: USB interface latency

Post by gimmeapill »

@CrocoDuck: this is indeed very interesting. Thanks for shedding some light.
I don't think crosstalk will be too much of an issue for 2i2 owners, but the clock jitter might be since it causes higher latencies.
Out of curiosity, what is the best roundtrip latency achievable with your config? (without any heavy DSP load - just as a reference for myself)

Cheers,

LX
CrocoDuck
Established Member
Posts: 1133
Joined: Sat May 05, 2012 6:12 pm
Been thanked: 17 times

Re: USB interface latency

Post by CrocoDuck »

gimmeapill wrote:I don't think crosstalk will be too much of an issue for 2i2 owners
It is a very annoying thing once you are aware of it but yes, I got to try to make scientific measurements to notice it. Using the device for home studio / music stuff shouldn't give much issues. Seems fair, since the device is designed for that, not as a Laboratory piece of equipment. However, this kind of cheap manufacturing makes me mad anyway considering the price :evil: .
gimmeapill wrote:Out of curiosity, what is the best roundtrip latency achievable with your config? (without any heavy DSP load - just as a reference for myself)
It is about 15 ms. My personal rule is no more than 7 ms, so its like twice of what I would like to have. With a latency lower than 20 ms it is very hard to hear a clear delay. Usually 20 ms are quoted as the threshold of audibility but I don't think there is much evidence for that. Especially, I feel the lack of experiments trying to acknowledge the small delays perception when the subjects are producing the sounds (I was thinking to do that as a MSc Project... but I then switched to other stuff). I think the 20 ms rule is based in the Haas effect in room acoustics, but I am not even so sure about that actually. I am trying to put order in my head about the stuff I have been studying/experimenting in my blog. It is new, ugly, probably full of mistakes (maybe even huge), but I wrote about latency and maybe you are interested in the references I used. However, I am not sure how much my setup can be a good reference for you, since it is possibly plagued by messy USB hubs/controllers managing too many peripherals. They are giving me headaches since 2012.
emarsk
Established Member
Posts: 96
Joined: Wed Jul 27, 2011 3:50 pm

Re: USB interface latency

Post by emarsk »

You can use jack_delay (from http://kokkinizita.linuxaudio.org/linuxaudio/) to measure the real latency.
The latency reported by jack (and its configuration tools) is only the one introduced by the buffer, it doesn't - and can't - measure all the other ones: USB driver, AD/DA conversions etc.
More info at http://apps.linuxaudio.org/wiki/jack_latency_tests
Please, avoid some common spelling errors:
http://theoatmeal.com/comics/misspelling
CrocoDuck
Established Member
Posts: 1133
Joined: Sat May 05, 2012 6:12 pm
Been thanked: 17 times

Re: USB interface latency

Post by CrocoDuck »

emarsk wrote:You can use jack_delay (from http://kokkinizita.linuxaudio.org/linuxaudio/) to measure the real latency.
The latency reported by jack (and its configuration tools) is only the one introduced by the buffer, it doesn't - and can't - measure all the other ones: USB driver, AD/DA conversions etc.
More info at http://apps.linuxaudio.org/wiki/jack_latency_tests
Alternatively, you can use jack_iodelay. It does a little of maths more and it should be included in every jack package by default.
CrocoDuck
Established Member
Posts: 1133
Joined: Sat May 05, 2012 6:12 pm
Been thanked: 17 times

Re: USB interface latency

Post by CrocoDuck »

Hay. Today I was in the University's labs and I found one of these old fashioned MAudio mobile pre. I tested it quickly with my Linux box. Seems to work well out of the box, the latency is the only thing I looked into. It was 10 bloody ms greater than the one measured with the Scarlett 2i4 (same jack setup): ~25 ms VS ~15 ms (Scarlett). Latency as given by jack_iodelay. I am starting thinking that the speed of the converters in the sound cards could be central to the issue (I was assuming them all to be pretty quick since early 2000... probably I was wrong).
gimmeapill
Established Member
Posts: 564
Joined: Thu Mar 12, 2015 8:41 am
Has thanked: 44 times
Been thanked: 8 times

Re: USB interface latency

Post by gimmeapill »

Ok, I finally ran a proper latency test on the 2i2 with a mono patch cable (tested both with with jack_delay and jack_iodelay)

- config
cpu: core i5 3317u (ivy bridge) with turbo boost disabled in the BIOS and locked at max frequency with "cpupower frequency-set -g performance"
Kernel: stock arch kernel (4.1.2-2 at the time of writing), RT prio correctly set, nothing more.
Jack: /usr/bin/jackd -P89 -p128 -t2000 -dalsa -r96000 -p64 -n3 -D -Chw:USB -Phw:USB -o2
latency reported in qjacktl: 2ms+2ms (actually 0.7 ms X 3 periods in and out - so should be ~4.2 ms)
OS: pretty slim. no DE. Just Fluxbox as window manager + some gnome apps.

- Result as reported by both utilities:
639.628 frames 6.663 ms total roundtrip latency
extra loopback latency: 511 frames

- The obligatory screenshot
https://drive.google.com/file/d/0B2beUW ... sp=sharing

- Conclusions
qjackctl is off by 2.4 ms. If I got it correctly, this means that the ad/da added latency is ~2.4 ms
secundo, the 2i2 is perfectly capable to go below 10ms @96Khz, but I wouldn't go any lower for practical use
This is actually my setting for guitarix, and I get some xruns unless I use an RT kernel - then it's solid enough (not a single buffer overrun in a 2 hour session).
Adding Ardour and hydrogen is still ok but I start to get xruns around 50% DSP load.

Last conclusion: Croco, I think there's something wrong with your 2i4, I can't believe it performs so much worse than the 2i2.

Cheers,

LX
gimmeapill
Established Member
Posts: 564
Joined: Thu Mar 12, 2015 8:41 am
Has thanked: 44 times
Been thanked: 8 times

Re: USB interface latency

Post by gimmeapill »

Actually it's quite interesting that you get better latency with the Mobile-Pre which is a USB1 interface. This really points to to the USB controller, cable or possibly the driver...

Going back to Paul question: since he's playing from a midi keyboard -> Computer -> 2i2, we should be able to deduct the a/d (input) latency of a full duplex set up (not sure though how to account for the midi latency). But I'd bet that 4ms should be achievable with a properly set HW and SW config.

As for me, I'm curious to see how that integrated Intel HDA in my average notebook compares in terms of latency...probably next week.

Cheers,

LX
CrocoDuck
Established Member
Posts: 1133
Joined: Sat May 05, 2012 6:12 pm
Been thanked: 17 times

Re: USB interface latency

Post by CrocoDuck »

gimmeapill wrote:Actually it's quite interesting that you get better latency with the Mobile-Pre which is a USB1 interface. This really points to to the USB controller, cable or possibly the driver...
:oops: Sorry for my bad English, seems I was not clear on that. Actually I get better latency with the Scarlett (~15 ms). With the Mobile-Pre I get the worst latency ever (~25 ms). However, I do think that the core if the issue is in the USB controller. I think that my Compaq Presario CQ61 has some weird USB hardware. I am about to upgrade to this. Being a laptop and being packed with features I expect it to be rather quirky as well with audio... but I need something portable and powerful for my numerical stuff. I will report if something change. If the problem is in the sound card itself I would start thinking about a malediction: I already got a faulty Scarlett 2i4 device .

Nice to see that you found a good setup :D !
Post Reply