eol's blog

A few years ago, I bought my first home server. I couldn’t bear the aging fans on my workstation, running 24/7 near my bed. I moved my MPD server to the NAS, plugged in my sound system (an old amp - not really modern tech with networking and bluetooth). There was no sound on my workstation, I couldn’t watch video, or play video games whith sound anymore.

I’m a lazy fuck, I did not want to plug / unplug the cable, or need to press some button on my amp to switch. But I found out that you could setup pulseaudio to play sound streams from the network And on a cabled lan, I have sub millisecond latency.

Here is the setup :

On the sound server:

/etc/systemd/system/pulseaudio.service

[Unit]
Description=PulseAudio system server

[Service]
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --log-target=journal --realtime
#ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading --log-target=journal
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

Most of the subtilities of making that work is in this file. Pulseaudio does not want to run system mode, and need to have some flags for security reasons (notably the –disallow-module-loading, see the freedesktop page) to accept running in system mode.

/etc/pulse/system.pa

\[...\]

\# allow tcp streaming from localhost and 192.0.2.0/24 network
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.0.2.0/24
load-module module-zeroconf-publish

\# Automatically restore the volume of streams and devices
load-module module-device-restore
load-module module-stream-restore
load-module module-card-restore

\[...\]

As you might notice, it also work with bluetooth and announce itself through zeroconf/avahi. A simple USB bluetooth dongle does the job, and having it annouce itself simplify the switching on mobile plateforme (eg: laptop).

on the client :

/etc/pulse/client.pa

default-server = [sound system host]

I’m not going into detail with the zeroconf part. That broke some time ago when playing with local DNS. I’ve also moved the sound server from the NAS a low power raspberry pi 1 lying around (beware that the analogic sound card on all the raspberries pi are shit).

Anyway, there you go, a “smart sound system” using FOSS and some old hardware !

I could improve it by setting up UDP transport. TCP isn’t really the best transport for audio streams. Especially on wireless network.

#Sysadmin