Measure audio latency in linux

To find out the delay introduced by the sound card, jack has a nice tool installed by default: jack_iodelay
Start it and jack_connect the in to hw-out and vice versa, and read every second the frames and ms on the command line.
Needs a cable from the output to the input of the sound card!
For starting and connection jack a gui like qjackctl works nicely.

aplay -L # find your correct hw:xxx sound card name for -dXXX below. plughw introduces bad sample rate conversion, find something with hw:CARD= and USB.
jackd -t 2000 -R -P 95 -d alsa -d hw:pisound -r 48000 -p 64 -n 2 -X seq -s
jack_iodelay
jack_connect jack_iodelay:out system:playback_1
jack_connect jack_iodelay:in system:capture_1

The async mode uses one extra buffer to conceal glitches, but is only needed under heavy load or many plugins.

Some cheap dongles have only mic and speaker out on mini TRS that cannot be shortcut-looped together without external circutry. That is thankfully very easy, see jack_latency_tests

PiSound = 4,924 (236.371frames)
It can only run with 64 Samples, 32 is not usable in jack.

1 „Gefällt mir“

ESI U24XL = 64 frames, 1.333ms
(64 extra loopback latency)

1 „Gefällt mir“

Scarlett 2i2

48kHz Samplingrate

@32Frames = 4.455ms
@64Frames = 7.456ms

96kHz Samplingrate

@32Frames = 2.178ms
@64Frames = 3.813ms

1 „Gefällt mir“

Presonus AudioBox VSL22

48kHz

32Samples = 5.419ms
64Samples = 9.064ms

96kHz

32Samples = 2.297ms
64Samples = 4.422ms

1 „Gefällt mir“

LogiLink UA0298

only miniTRS! Very small dongle! 10Eur - not pro audio quality!
48kHz Samplingrate
Framesize 64 = 10.411ms

1 „Gefällt mir“

Focusrite Scarlett 4i4

MUST HAVE external power supply via USB Hub. Raspi USB port is NOT powerful enough for this 4i4.

Focusrite Scarlett 18i8

DOE NOT WORK!!
DO NOT USE under Linux and ds-box. It is NOT CLASS COMPLIENT USB audio 2.0!!

7Eur USB-Dongle Unitec Y-247A

Manufacturer website

[ 45.199157] usb 1-1: new full-speed USB device number 5 using xhci_hcd
[ 45.349650] usb 1-1: New USB device found, idVendor=0d8c, idProduct=0014, bcdDevice= 1.00
[ 45.349655] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 45.349659] usb 1-1: Product: USB Audio Device
[ 45.349662] usb 1-1: Manufacturer: C-Media Electronics Inc.
[ 45.352410] input: C-Media Electronics Inc. USB Audio Device as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.3/0003:0D8C:0014.0003/input/input32
[ 45.411462] hid-generic 0003:0D8C:0014.0003: input,hidraw2: USB HID v1.00 Device [C-Media Electronics Inc. USB Audio Device] on usb-0000:00:14.0-1/input3
[ 45.456775] usbcore: registered new interface driver snd-usb-audio

1 „Gefällt mir“

Dell XPS15 built-in ALC3266

card 0: PCH [HDA Intel PCH], device 0: ALC3266 Analog [ALC3266 Analog]

only works >256 blocksize, 128 has many dropouts :frowning:

1 „Gefällt mir“

Wo hast Du den für 7€ her - ich finde nur das: Unitek Y-247A USB-Stereo-Soundkarte Schwarz: Amazon.de: Computer & Zubehör fast 24€, das Amazon Headset gibt für 26€… hm

Unitec Y-247A

Hab 5 Stück im Dauereinsatz, von
amazon.de (externe Soundkarten #1)
gelistet auch bei anderen Raspberry audio-Projekten. Leider sieht man oft erst was drin ist wenn man unter Linux auf der Kommandozeile nachschaut;-)

Der kann Klanglich bei perfekten Kopfhörern nicht mit >100Eur AudioInterfaces mithalten, und sie haben letztes Jahr die Mikrofonspannung von 5V auf 3V reduziert so dass laut Bewertungen nicht mehr alle Mic gehen. Die Headphones die ich Zuhause hab sind alle OK, mehrere Stunden getestet.

Vorsicht beim Kauf, gut Testen - Den USB von CreativeLabs kann ich z.B. nicht empfehlen, der verzerrt sehr schmerzhaft.

Compatibility Matrix audio devices / sound cards

Hi…Regardless of whether there were a genuine detour this wouldn’t be important for the sound preparing impacts, since they need to go through the sound chain. Consequently the ‚delicate‘ sidestep is the significant one. I concur that the 5ms seem as though the buffering delay. Presumably the 128 examples ping pong at 48kHz. Anyway 3ms for ADC and DAC appears a lot to me and would mean the mystical number of 2ms would never be accomplished.

@DellyRosen thanks for you thoughts!
I do DSP and low-level real time since 2003 and you’re right, the pure conversion does not take several milisecs - its less than one. I don’t want to go into the single steps from sigma-delta to Jack but state that there is time buffering involved wherever something is copied, and between ADC and USB, DMA and linux kernelspace and userspace alsa, and then to jack, you can’t make it without copy.
Since a regular OS scheduler might take a lot of time, worst case 100ms is happening, you must tune a real time OS scheduler to e.g 1ms, that is about the best you can get. That is precisely the reason digital-stage-box uses a RT Linux on Raspi, and the CPU does nothing but audio.

Once your OS is nicely tuned, it might be worth using a Thunderbolt or I2S audio interface to cut down another ms of USB latency and jitter.

I always have <10ms acoustic latency in LAN with all my USB sound cards, and need to increase the buffers a little for real Internet.

But if you’re experiencing >40ms ping, it’s all for nothing.

Ubuntu 21.04 + RT, Focusrite 212, Headphones->Mic:

nice -20 qjackctl
nice -20 ./digitalStagePC

Start jack with

  • Sample Rate 48
  • Frames/Period=16
  • Period/Buffer=1
  • nice -n20 jack_iodelay
  • verify niceness with htop
  • connect jack_iodelay in graph

Hardware local:
122.664 frames 2.555 ms total roundtrip latency
extra loopback latency: 90 frames
use 45 for the backend arguments -I and -O ??

Cable Internet:
1855.999 frames 38.667 ms total roundtrip latency
extra loopback latency: 1823 frames
use 911 for the backend arguments -I and -O

Becomming Realtime in Ubuntu

vim /etc/security/limits.d/audio.conf
add those lines:

@audio   -  rtprio     95
@audio   -  memlock    unlimited
groupadd audio
usermod -a -G audio `echo ${USER}`

Now log out and in again!