0

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.

david
  • 2,529
  • 1
  • 34
  • 50

1 Answers1

0

i found all of the examples are working if i first play audio on the host-system stopping playback before starting docker.

restarting docker without playing back audio on the host first, results in the described buffer underruns.

--EDIT

another observation: playing a soundfile in the docker-container (aplay file) prior to starting liquidsoap always results in buffer underruns.

i.n.g.o.
  • 51
  • 6
  • Thanks a lot for your reply, Ingo! I'm not sure if I understood your answer correctly: You are playing audio on the host system, then you stop playplack, and only after that you are starting Docker while playing audio? And how long did you test playing audio from your analog inputs? For me there was a setting where I got it working for like 20mins but then it ended in plenty buffer underruns again. While simple audio playback from within Docker was working fine. – david Jun 29 '21 at 17:16
  • After reading your observation regarding `aplay file` I assume you have maybe another precondition (e.g. can you ensure that no PulseAudio is running on your machine?), because for me simple playback from within Docker worked nicely with certain settings. Also no problems with `aplay`. My question is actually not so much about playback from within Docker, but more about playing live audio from the analog inputs from within Docker. Would be happy if you could provide some more clarification and possible ideas. Thanks :) – david Jun 29 '21 at 17:16
  • 1
    hi david. 1) exactly. i play audio on the host system (aplay or otherwise), then stop playback and then start docker. no playback on the host-system while docker is running. pretty sure i let it run for more than 20 minutes, but will test again. 2) sorry my edit is a bit misleading: playing a file from within docker works fine (no buffer underrun), only that running liquidsoap after aplay finished results in buffer underruns, even though i played audio on the host before starting docker. so i would expect it to work, but somehow aplay within docker makes liquidsoap result in underruns. – i.n.g.o. Jun 30 '21 at 19:42
  • you are right, after a while buffer underruns start to happen. in my case it was after 1,5 hours. – i.n.g.o. Jul 01 '21 at 05:52
  • Thanks for the clarification, Ingo. You may also try to customize the value for `frame.audio.size`. This value is specific to every audio interface. So your's might be actually different. Here I have detailed how to get the correct frame-size in the section "Detecting the correct frame-size": https://gitlab.servus.at/aura/engine-core/-/blob/master/docs/audio-device-configuration.md#b-unbuffered-audio – david Jul 02 '21 at 12:18
  • Hi David. For the fun of it i tried using latency.c (https://github.com/alsa-project/alsa-lib/blob/master/test/latency.c) in the same docker container. Also this runs into buffer underruns after a while. This may indicate that this is indeed not an issue of liquidsoap... – i.n.g.o. Jul 09 '21 at 11:08