Lowest possible latency

Moderator: flatmax

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Lowest possible latency

Post by flatmax » Tue Jul 18, 2017 12:51 pm

It busy writes... i.e. it loops on the write till all is written.

One idea is to increase the thread priority in a similar way to jackd :
https://github.com/jackaudio/jack2/blob ... d.cpp#L113

There they up the thread priority and enable FIFO scheduling :
#define JACK_SCHED_POLICY SCHED_FIFO

The latency you see is most likely two periods totaling 667 us (about half a millisecond).

Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

robiwan
Posts: 59
Joined: Wed Jul 05, 2017 1:18 am

Re: Lowest possible latency

Post by robiwan » Tue Jul 18, 2017 6:22 pm

Well, if 64 is the latency, then it is pretty good. I'd definitely settle for < 1ms throughput latency.

Anyway, I tried to setup an asymmetric alsa device, like so:

Code: Select all

/etc/asound.conf:

pcm.ladspa {
        type ladspa
        slave.pcm "plughw:0"
        path "/usr/lib/ladspa"
        plugins [{
        	# Reverb plugin from the CAPS LADSPA plugin collection
        	# (http://quitte.de/dsp/caps.html)
                label PlateX2
                input {
                        controls [0.75 0.5 0.25 0.5]
                }
        }]
}

and in ~/.asoundrc:

pcm.!default {
    type asym
    playback.pcm "plug:ladspa"
    capture.pcm  "plughw:0"
}
and tried to use "default" as device name, but the full duplex test fails to open the device, however the patest_wire app does manage to open it though. This is pretty much the last "ground work" I need for my application.

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Lowest possible latency

Post by flatmax » Fri Jul 21, 2017 9:02 pm

Sweet ... let us know how it goes ... perhaps if you can take a picture, video or sound or something ?!?!
Also a block diagram would be nice :) But no sweat, I am sure that you are very busy with your projects and may not have time to do that.
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

robiwan
Posts: 59
Joined: Wed Jul 05, 2017 1:18 am

Re: Lowest possible latency

Post by robiwan » Fri Jul 21, 2017 9:11 pm

Actually, I now been able to run alsaloop with a latency of 48 frames @ 48 kHz, which means a total of 1ms SW latency. Awesome! I had to use chrt to heighten process to realtime status though. But now it works without a glitch, running the LADSPA reverb :)

True, I might not have the time to write that up, but it actually was pretty easy:
1. Setup a LADSPA plugin within ALSA:

Code: Select all

pcm.ladspa {
        type ladspa
        slave.pcm "plughw:0"
        path "/usr/lib/ladspa"
        plugins [{
        	# Reverb plugin from the CAPS LADSPA plugin collection
        	# (http://quitte.de/dsp/caps.html)
                label PlateX2
                input {
                        controls [0.75 0.5 0.25 0.5]
                }
        }]
}
2. Use alsaloop to pipe from capture to playback (optionally with chrt to heighten priority of process):

Code: Select all

>[chrt -rr 70] alsaloop -C plughw:0 -P plug:ladspa --latency <latency in frames>
Now, of course, is the job to fix the actual filtering plugin :)

robiwan
Posts: 59
Joined: Wed Jul 05, 2017 1:18 am

Re: Lowest possible latency

Post by robiwan » Wed Jul 26, 2017 5:38 pm

Matt, I've measured the latency in/out to about 2.5 ms, so a part of that must be the analog <-> I2S latencies. I've tried to find info about that in the Wolfson datasheets but could not find anything. Do you have the possibility to short circuit I2S so that you can measure the ADC -> I2S -> DAC path (i.e. eliminating ALSA) ?

unipiguy
Posts: 5
Joined: Tue Jan 24, 2017 2:48 am

Re: Lowest possible latency

Post by unipiguy » Sat Aug 26, 2017 7:46 am

I'd be very interested in any progress in this venue.
I've got a third party input device (USB) that ALSA allows us to set a buffer (at 48k) of as low as 8frames (less than 200 microseconds), so I know it's really not ALSA per se..
I'm more interested in the input (not using the output portion as this is a streaming engine for me).
has anybody been able to get sub 32 frame length?

robiwan
Posts: 59
Joined: Wed Jul 05, 2017 1:18 am

Re: Lowest possible latency

Post by robiwan » Sat Aug 26, 2017 5:23 pm

I have not anyway. Looking at the I2S spec of the RPi, it should be possible to get really low latency by lowering the FIFO IRQ threshold of the I2S subsystem, but I have no idea if it is possible to config the current I2S driver for this.

Btw, which USB unit are you using for the 8 frame setup ?

unipiguy
Posts: 5
Joined: Tue Jan 24, 2017 2:48 am

Re: Lowest possible latency

Post by unipiguy » Sun Aug 27, 2017 6:31 am

thx.

i've tried several different preamps - Tascam, Focusrite,and Presonus...
they vary, but all could get well below 24 frames without issue.

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Lowest possible latency

Post by flatmax » Sun Aug 27, 2017 3:51 pm

USB can't have a latency which is low because of the UAC2 or UAC protocol which is used over USB. Typically packets of audio are transmitted over USB which doesn't allow for much less then 3 ms (from memory) of latency. The concept of getting true latency of 8 frames (167 us @48kHz) over USB would be incredible !

The latencies we are talking about here are typically within the DMA process in ALSA. Typically Codecs have 1 sample of latency. I imagine that the incoming audio bits get fed directly to the sigma delta converters in some way.

You can set the number of periods and the size of the period in am audio buffer with ALSA. That is the means to tuning the latency. With zero computational load and only memory copies and heightened scheduling priority, you can probably get reliable latencies down to 0.5 ms.

Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

robiwan
Posts: 59
Joined: Wed Jul 05, 2017 1:18 am

Re: Lowest possible latency

Post by robiwan » Sun Aug 27, 2017 6:45 pm

flatmax wrote:
Sun Aug 27, 2017 3:51 pm
The latencies we are talking about here are typically within the DMA process in ALSA. Typically Codecs have 1 sample of latency. I imagine that the incoming audio bits get fed directly to the sigma delta converters in some way.
Yes, I've tried to query Cirrus for the analog<->digital latency of the WM8731 codec, haven't got any response so far. ADI has a "low-latency" codec which they say have about 150us analog<->digital latency (@48KHz), so I imagine the WM8731 will have the same or more than that. So just the HW of the codec will add at least 0.3 ms of latency. Then there's the FIFO in the RPi I2S subsystem, which will have at maximum 32 frames (stereo) in/out latency (the FIFOs are 64 samples long).

So, because the FIFOs are fixed in length, I suspect the Octocard to have a lot less latency since 8 channels will fill up the FIFOs much faster.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests