While simple audio playback in Docker using Liquidsoap's output.alsa(..)
is working fine, I cannot get live audio to work. Basically I want to route the analog audio input to the analog audio output, like output.alsa(input.alsa())
. Following three example work fine natively:
Example 1: Buffered I/O
# Successfully tested with Liquidsoap 1.4.4 & ALSA 1.1.3 (native)
# Low latency, no buffer underruns
set("frame.audio.size", 2048)
set("alsa.alsa_buffer", 8192)
set("alsa.buffer_length", 10)
input_analog = input.alsa(device="default", bufferize=true)
output.alsa(device="default", input_analog, bufferize=true)
Example 2: Extra Buffered I/O
# Successfully tested with Liquidsoap 1.4.4 + 1.1.3 (native)
# High latency, no buffer underruns
set("frame.audio.size", 2048)
set("alsa.alsa_buffer", 8192)
set("alsa.buffer_length", 10)
input_analog = input.alsa(device="default", bufferize=true)
input_analog = mksafe(buffer(input_analog))
output.alsa(device="default", input_analog, bufferize=true)
Example 3: Unbuffered I/O
# Successfully tested with Liquidsoap 2 & ALSA 1.2.4 (native)
# Almost no latency, no buffer underruns
# Doesn't work in Liquidsoap 1.4 because of some calculation bug
set("frame.audio.size", 7526)
set("frame.video.framerate", 0)
input_analog = input.alsa(device="default", bufferize=false)
output.alsa(device="default", input_analog, bufferize=false)
With these examples in Docker I get plenty of audio hickups and buffer underruns, no matter which buffer or frame settings I try. The CPU usage of the Docker Container is usually < 1%, sometimes spikes to 5%. With the current Liquidsoap 2 branch things got much better when setting some extra high buffer & frame-size, but still underruns are happening.
I'm starting the container like this (had also tried specific settings with extra CPU and memory provided to the container before):
docker run -it \
--network="host" \
--mount type=tmpfs,destination=/tmp \
-v /dev/snd:/dev/snd \
-v "/etc/asound.conf":"/etc/asound.conf" \
--group-add audio \
--privileged \
savonet/liquidsoap:main \
...
The default
ALSA device is defined as simple as that:
#/etc/asound.conf
defaults.pcm.card 2
defaults.ctl.card 2
Is there any secret sauce required? Do you have an example how you got it working?
Maybe it's not a Liquidsoap problem at all. Hopefully it's enough to do some special ALSA device configurations in combination with some hidden Docker flags.