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:
on arch I needed yay -S realtime-privileges jack2 jack2-dbus
sudo usermod -a -G realtime mpd
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
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
}
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
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.
sudo systemctl daemon-reload
sudo systemctl enable jackd
sudo systemctl enable jackd-network
sudo systemctl start jackd
sudo systemctl restart mpd
install pulseaudio-jack
install cadence
and run it. under System -> Configure -> Driver pick Net
Pick jack output in pavucontrol.