Skip to content

Instantly share code, notes, and snippets.

@zoe1337
Last active June 1, 2022 06:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zoe1337/0bce14fb366e9373a0f837c40164d00b to your computer and use it in GitHub Desktop.
Save zoe1337/0bce14fb366e9373a0f837c40164d00b to your computer and use it in GitHub Desktop.
How I got our mpd to use JACK2 in Arch

Problem Description

We have a smol server at home which is among others responsible for music. This is accomplished by mpd.

I wanted to change the output from pulseaudio, because it was making pops every time the playlist was finished and it released the sound card. Also I wanted to have networked audio, so we can watch/listen occasionally on the speakers from our desktop PCs.

Without further explanation:

install packages

on arch I needed yay -S realtime-privileges jack2 jack2-dbus

give the mpd user realtime privileges

sudo usermod -a -G realtime mpd

create jackd service file

create /etc/systemd/system/jackd.service with

[Unit]
Description=JACK
After=sound.target

[Service]
LimitRTPRIO=99
LimitMEMLOCK=infinity
User=mpd
Environment="JACK_NO_AUDIO_RESERVATION=1"
ExecStart=/usr/bin/jackd -R -P89 -dalsa -dhw:0 -r48000 -p256 -n3

[Install]
WantedBy=multi-user.target

a bit tricky is to figure out the hardware identifier and I don't know what's The Solution for this. linux audio is pretty alright these days but audio hardware discoverability kinda sucks, especially without GUI tools like qjackctl you could use on a non-headless / desktop setup

you can try cat /proc/asound/cards and cat /proc/asound/devices but I don't exactly know how to interpret the fields. hw:0 did the job in my case.

you can tweak the sample rate if you have a fancy card. if you ran into glitches due to buffer underruns, increase -p256 to a larger power of 2 (like 1024) this increases latency tho

tweak mpd config

in your /etc/mpd.conf change the output from pulse (or alsa) to:

audio_output {
        name            "jack output"
        type            "jack"
        client_name     "mpd"
        autostart       "no"
        mixer_type      "software"              # needed for volume control
}

create ALSA config if you don't have one already

into /etc/asound.conf

defaults.pcm.!card "PCH"
defaults.ctl.!card "PCH"

the identifier (in our case PCH) is the string coming from /proc/asound/cards

enable network transport

I created a second service which configures jackd to use the network input. Into /etc/systemd/system/jackd-network.service

[Unit]
Description=JACK Network Input
Requires=jackd.service

[Service]
Type=oneshot
User=mpd
ExecStart=jack_load netmanager -i -c

[Install]
WantedBy=multi-user.target

You can experiment by running sudo -u mpd 'jack_load netmanager -i -c' it should confirm that the network module is loaded.

restart everything

sudo systemctl daemon-reload
sudo systemctl enable jackd
sudo systemctl enable jackd-network
sudo systemctl start jackd
sudo systemctl restart mpd

on the desktop PC:

install pulseaudio-jack
install cadence and run it. under System -> Configure -> Driver pick Net

Pick jack output in pavucontrol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment