Home audio system using MPD and RTP
This little document describes the setup I use at home for listening to music. It's a fairly over-the-top home-grown solution, there are far easier methods out there.
With this setup the music plays simultaneously in all rooms that have an audio system and I can control the playback and playlist from any computer in the household.
General picture
The core of the system is a VM that I run on my home server. On this (Debian stable) machine I run two services:
The basic idea of MPD is that the player itself and the user interface are two seperate programs. The MPD daemon is is headless, all it does is listen on a TCP port (usually 6600) and wait for commands. You can use one of the many clients out there to control it. There are standard GUI interfaces for your desktop, web interfaces, apps for smartphones (Android, iPhone, etc) and you can use as many at the same time as you like.
PulseAudio is a sound server that routes and multiplexes audio streams. In this setup it's used to both send and receive the audio stream over the network. For this I've used RTP multicasting, which means I have one transmitter and as many receivers on the local network as I like.
Setting up MPD
Install mpd using Debian package management.
The configuration file can be found at /etc/mpd.conf
.
Some relevant configuration lines are below.
Make mpd listen to more than just the loopback interface:
bind_to_address "::"
Have MPD dump its audio to PulseAudio:
audio_output { type "pulse" name "Multicast RTP" sink "rtp" }
Audio output tweaks:
audio_output_format "44100:16:2" samplerate_converter "Medium Sinc Interpolator" mixer_type "software" replaygain "album" volume_normalization "no"
Don't forget to configure the path to your music collection (see the top of mpd.conf
).
Consider skimming all of the options to see if there's anything to tweak.
Setting up PulseAudio
Create a minimalistic configuration file for the daemon itself by replacing the contents of /etc/pulse/default.pa
with this:
#! /usr/bin/pulseaudio -nF load-module module-native-protocol-unix load-module module-suspend-on-idle timeout=1 load-module module-null-sink sink_name=rtp load-module module-rtp-send source=rtp.monitor
Make sure that /etc/pulse/daemon.conf
contains these options:
exit-idle-time = -1 default-sample-format = s16le
That's it.
Run service mpd restart
.
Both processes should be running now.
In case something doesn't work, check syslog and /var/log/mpd/mpd.log
.
Setting up the clients
While it should be possible to use something like VLC to listen to the RTP multicast, I've personally had the best results with PulseAudio (in client mode).
My Debian desktop comes with PulseAudio by default, you may need to install it manually if your distro doesn't.
Uncomment the following line in /etc/pulse/default.pa
:
load-module module-rtp-recv
Restart your PulseAudio:
pulseaudio -k; pulseaudio --start
Try to play some audio!
Easier methods
Too much tinkering? Consider one of these simpler alternatives for audio streaming:
- Running MPD with a simple ogg vorbis streaming output:
audio_output { type "httpd" name "My Streaming Radio" encoder "vorbis" port "55555" quality "6" format "44100:16:2" }
- Running a different program altogether.