My ultimate guide to the Raspberry Pi audio server I wanted — Introduction

Mathieu Réquillart
3 min readApr 19, 2020

--

Introduction

A few years ago I bought a Raspberry Pi model B+ and a cheap mini bluetooth adaptor with the idea in mind to create a network audio server out of it and make any audio player available on IP and bluetooth. I quickly realized the Pi native jack output was crap and added a Hifiberry DAC+ Pro, a high-resolution digital-to-analog converter which connects directly on top of the Pi. I put everything in a nice wooden case and began my long journey to make the best of it.

My Pi in its natural state

Over the years, I tried many solutions like Volumio (3x times), RuneAudio, Mopidy, Pi MusicBox… unfortunately, none of them matched all my needs (except maybe Volumio paid subscriptions), and all my attempts to add what I needed by tweaking them ended up badly with weird audio cracks, concurrency issues, audio-video sync problems, or media database issues, and still no user friendly bluetooth connection.

My requirements were the following:

  1. Bluetooth audio sink, with PIN authentication
  2. Pulseaudio server available on the network for my other computers : Desktop (Fedora/Windows), Laptop (ArchLinux) and HTPC (Debian)
  3. Playing audio files from the library on my NAS
  4. Creating an UPNP audio renderer
  5. Automatically playing audio files from usb sticks
  6. Autoplay CDs
  7. Add Spotify support

During Covid19 confinement, I finally got everything I wanted to work (almost) exactly as I wanted. I had a hard time finding all ressources I needed and setting it up so I thought I would share what I did online.

Whole setup is pretty long and it took me a lot of work to write it all so I think it’ll be better to split it in several part and use this one as an introduction to begin to explain why I came to this particular setup.

From what I understood trying to tweak them, most out-of-the-box solutions rely directly on ALSA (Advanced Linux Sound Architecture) on the lower side to access the sound card, and MPD (Music Player Daemon) a free and open music player server to play music. So ALSA plays sound, and MPD plays music with ALSA.

Today, most Linux distributions use Pulseaudio, a sound server, that sits on-top of ALSA and provides a layer of abstraction that allows for more advanced functionality than ALSA can provide alone, like per-application control, bluetooth, dlna, zeroconf…

Accessing ALSA directly when also using Pulseaudio isn’t a good idea. It makes Pulseaudio and the program using alsa fight for sound control, creating lag, glitches and cracks. So when you choose to use Pulseaudio for one thing on your system, you have to commit to use it and stop using directly ALSA, and I never managed to tweak out-of-the box solutions to this point. I think because they want to keep alsa for high quality playback, but it seems also doable with Pulseaudio according to this repo.

MPD works on an even higher level, and can use ALSA directly, Pulseaudio, and many other audio outputs. It can also act as a Media Library, where files are stored on my NAS, but can’t be indexed properly by the Pi for various reasons we’ll see later. MPD itself can be accessed by various clients, command line, web, smartphone app, which will also come in handy.

So my goal was to install and use Pulseaudio for bluetooth, network, MPD, and work around those for the rest, without installing too many more dependencies on the Pi.

When it comes to server, Debian is my favorite distribution, so I started with its Raspberry version Rasbian, enabled ssh for headless setup, enabled the DAC+ output instead of the crappy jack, disabled SWAP (memory usage will be low since it’s a headleass setup and SWAP reduces SD cards life time), and installed ntp

$ sudo apt install ntp
$ sudo systemctl enable ntp

When it comes to audio, it’s important for your systems clock to be in sync and syncing their time through the network is exactly what NTP does.

Part 1 : Bluetooth

--

--