Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Howto get JACK audio working with a docker container #544

Open
domichel opened this issue Oct 29, 2024 · 0 comments
Open

Howto get JACK audio working with a docker container #544

domichel opened this issue Oct 29, 2024 · 0 comments

Comments

@domichel
Copy link

On linux, we have the JACK professional audio server that provide both a constant sound latency (PulseAudio doesn't provide that) and a parallel execution of all its sound processes. That howto is intended for peoples that have JACK running all the time into their system.

On https://github.com/mviereck/x11docker/wiki/Container-sound:-ALSA-or-Pulseaudio is explained how to get sound with ALSA and PulseAudio. It is also possible to get that sound into JACk audio. For that, the docker container will use its ALSA output, and a bridge between ALSA and JACK must be setup and running.

It is several ways to get such a bridge:

  1. ALSA -> Loop -> JACK
  2. ALSA -> JACK plugin
  3. ALSA -> PulseAudio -> JACK plugin

As I don't use PA, I will focus on the first 2 solutions. But it should be easy to setup 3), because for how I understand it, One will have to setup the container to use PulseAudio as already explained into the wiki, and to setup PulseAudio in the host to use the JACK plugin.

The ALSA sound of a docker container need an ALSA sound device, which imply the JACK plugin will not work. We have to use the Loop device. It's a virtual audio loop device that will appear as a supplementary sound card into the system. We also want the same sound card order between reboot.

System configuration

A typical setup is a computer with 2 built-in sound cards, a PCM device and a HDMI device, and an external sound card of better quality. The Loop device will be configured as first sound card and default ALSA device. The order of the other devices doesn't matter as long it remain consistent between reboot.

From https://wiki.gentoo.org/wiki/ALSA :
We fix the sound card order:

# /etc/modprobe.d/alsa.conf
options snd slots=snd-aloop,snd-hda-intel,snd-hda-intel,snd-usb-audio
options snd-hda-intel index=1,2 model=1002:1637,1022:15e3

To get the model strings, use lspci:

root #lspci
04:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Renoir Radeon High Definition Audio Controller
04:00.6 Audio device: Advanced Micro Devices, Inc. [AMD] Family 17h/19h HD Audio Controller
root #lspci -s 04:00.1 -n
04:00.1 0403: 1002:1637
root #lspci -s 04:00.6 -n
04:00.6 0403: 1022:15e3

We instruct the kernel to load the virtual sound cards:

# /etc/modules-load.d/alsa.conf
snd-aloop

User ALSA configuration
This configure the ALSA JACK plugin as default ALSA sound device. Yes we need to configure it for the other ALSA only software. Using Cadence, we can skip that step because it will manage that file for You when the ALSA -> JACK (plugin) is set in its System tab.

# ~/.asoundrc
pcm.!default {
    type plug
    slave { pcm "jack" }
}

pcm.jack {
    type jack
    playback_ports {
        0 system:playback_1
        1 system:playback_2
    }
    capture_ports {
        0 system:capture_1
        1 system:capture_2
    }
}

ctl.mixer0 {
    type hw
    card 0
}

Running a Docker container

After a reboot, we will get the following sound devices:

  1. the aloop virtual card
  2. the hda-intel pcm device
  3. the hda-intel hdmi device
  4. the usb card

I use Cadence to setup and control JACK. On its System tab, we must set Bridge Type: ALSA -> Loop -> JACK before running the docker container, as example:
x11docker --home --group-add=audio --alsa=/dev/snd --desktop "x11docker-fvwm-tuxguitar"

The good news with that setup is that, when you are done with the docker, you can use Cadence to switch back on the fly to the more modern bridge solution: Bridge Type: ALSA -> JACK (Plugin).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant