When using a HiFiBerry sound card for music production or jamming, latency in recording, transmission and playback of the audio can become a problem.
What is latency?
Latency is the delay from an audio transmitter to the audio receiver. Even without any electronics, there will always be some latency as the speed of sound is relatively low. The latency of two musicians standing 5m away from each other would be already 5m / 343 m/s = 0.0145s = 14.5ms.
The same happens with electronics in between. The good thing is that electric current travels much faster then sound (with the speed of light) making it possible to have low latancy even if there’s a long distance between sender and receiver.
Why is it important?
When musicians want to jam together it’s important that they can synchronise their play. You might have noticed already on some internet phone calls that it is very irritating if there is a long delay on the transmission. As a rule of thumb, the latency between different musicians who want to play together should be <25-30ms. Higher latency will make it hard to impossible to play together.
30ms seems quite a lot, but think about the whole process of record/transmit/playback. When musicians want to play together at different locations there will be a major impact of the “transmit” part of this process. Audio has to be encoded, transmitted and decoded. While you might find some situations where network round-trip-delays are <10ms, this isn’t always the case. Therefore bringing latency of the record/playback part down helps to deal with higher latency in the transport network.
How high is the latency?
Unfortunately there isn’t a simple answer for this. While we could tell you the latency on the hardware, that doesn’t really help. The data must be transmitted to the Pi which will always include some buffering. Therefore, even if the hardware has a latency of just 5 samples, it will take a lot longer until your application really receives the data.
Symonics, a company specialised in audio transmissions over the Internet, did some measurements comparing the latency of different solutions for the Raspberry Pi. You see that the HiFiBerry sound cards perform much better compared to USB solutions. The reason for this is simple: HiFiBerry sound cards use a direct connection to Raspberry Pi’s CPU, while USB solutions will need to pack audio data into USB frames and unpack it on the other side again. While these look already quite impressive, there is potential for even lower latency. Elk tested the DAC+ ADC Pro with their highly optimized Elk Audio OS at <2ms minimal latency.
Another user also did some tests. (We’re not sure why the DAC+ ADC Pro had lower latency here, might be the filter configuration for input and outputs filters that had been set differently).
What can I do to get the lowest latency?
- Reduce buffer size. Note that dealing with buffers of <64 samples can be quite challenging.
- Set “DSP Program” to a low-latency filter in the ALSA mixer controls
- Use a higher sample rate. This might help a bit if your application works stable
In general, these things aren’t easy to do. If you’re not doing audio programming on Linux for a longer time, it’s probably best to use software that’s already optimized like Elk Audio OS.
June 10, 2020