Monthly Archives: July 2013

Raspberry Pi for Audiophiles

raspi

Here’s how to use a high-end DAC and a Raspberry Pi to make an audiophile-quality music player. With this project, you can play high-resolution music files through your stereo from the Raspberry Pi’s local disk or from a network share. You could drop multi-kilobucks on a device to do this, but we’ll put together a great sounding rig for less than $150. I’ll present a “minimum-steps, basic implementation” to get you up and running in less than an hour. From there, you can tweak yourself silly if you want to.

The Hardware: Raspberry Pi

I confess I have a soft spot for things British: Chuchill, Doctor Who, Elite, Jaffa Cakes, and now Raspberry Pi. The Raspberry Pi is a credit card sized computer developed for education. It is available in the US for around $35. Buying one is good Karma.

First you’ll need a Raspberry Pi that’s already set up and running with the latest Raspian “Wheezy” disk image. I recommend you have your keyboard and time zone correctly configured, your root file system expanded to allow you to use all the space on your SD card (if you plan to store your music there), and you’ll need to have wi-fi setup if you’re connecting to your network wirelessly.

If you’re new to Raspberry Pi, here’s a great tutorial on getting started:

The Software: MPD

MPD is a music player daemon for Linux. You can install it on your Pi like this:

$ sudo apt-get install mpd

You may get some errors like these:

Setting up mpd (0.16.7-2) ...
[....] Starting Music Player Daemon: mpd
listen: bind to '[::1]:6600' failed: Failed to create socket: Address family not supported
by protocol (continuing anyway, because binding to '127.0.0.1:6600' succeeded)
Failed to load database: Failed to open database file "/var/lib/mpd/tag_cache":
No such file or directory

Not to worry, everything will be fine momentarily.

If you plan to copy music to your SD card, the default location for music files is /var/lib/mpd/music/. You’ll need to fix permissions so members of the audio group (which includes the pi user) can copy files into that directory.

$ sudo chmod g+w /var/lib/mpd/music/
$ sudo chgrp audio /var/lib/mpd/music/

Once you’ve done that, you may want to copy some music over for testing. You can use a utility like WinSCP or CyberDuck for this.

Now, modify your mpd.conf file:

$ sudo nano /etc/mpd.conf

And change the string:

bind_to_address “localhost”

to

bind_to_address “any”

Reboot

$ sudo reboot

MPD is now running and you can connect to it from a client application and play music, but we’re not finished yet.

The DAC: HiFimeDIY Sabre USB DAC

As currently, configured, music will play through the Raspberry Pi’s analog output, which is not audiophile-approved. We want to connect a spiffy USB DAC. Feel free to spend thousands of dollars here, but since you’re reading this, I’m guessing you love a bargain. If you’re the thrifty sort, you may want to try the HifimeDIY USB Sabre DAC. At a mere $42 this is a real gem.

Plug in the DAC, then edit MPD config file.

$ sudo nano /etc/mpd.conf

Find this section:

# An example of an ALSA output:
#
audio_output {
type "alsa"
name "My ALSA Device"
device "hw:0,0" # optional
format "44100:16:2" # optional
mixer_device "default" # optional
mixer_control "PCM" # optional
mixer_index "0" # optional
}

Comment out all of those lines (enter a # symbol at the start of each line). Now, we’ll add two audio_output entries:

audio_output {
type "alsa"
name "HiFimeDIY DAC"
device "hw:1,0"
format "44100:16:2"
}

audio_output {
type “alsa”
name “HiFimeDIY DAC Direct”
device “hw:1,0”
}

Okay, we’re almost there.

The Clients: MPC, MPoD

MPC is a command line client for MPD, you don’t strictly need to install it, but it’s handy to have available. Here’s how you install it:

$ sudo apt-get install mpc

A Remote Control Client For Your iPhone Or iPad

I installed an mpd client called MPod on my iPhone. It makes navigating my music library and playing files super easy.

screen1

To configure the client, open settings and tap “Add player manually”.

screen2

Enter a name and the IP address of your Raspberry Pi:

screen3

Tap “Update database”

Tap “Refresh local cache”

You’ll see two outputs:

screen4

Here’s why we created two outputs:

Most of my music has been ripped from CD’s with Exact Audio Copy, but I do have a few 96khz/24bit flac albums. All my CD quality files play just fine, but the high-resolution flacs have some occasional pops and clicks. This isn’t the DAC’s fault, it’s a software issue. The general consensus is that the current Debian build for Raspberry Pi has a bug either in the ALSA, or USB device drivers. Some very brainy boffins are working hard at fixing this for the next release, but in the meantime, I’m working around it using two audio inputs, one which streams bit-perfect audio directly to the DAC and another which downsamples the audio prior to sending it to the DAC. I just select the correct one depending on what material I’m listening to.

Playing Music From a Network Share

First, on my NAS, I created a user called music, assigned a password to the account, and gave it permissions for a folder called audiophile.

Creating mount directory:

mkdir /mnt/nasmusic
chmod 777 /mnt/nas
$ sudo mount –t cifs –o username=music,password=musicpassword //192.168.1.2/audiophile /mnt/nasmusic

Now, we’ll make it so that our drive gets mounted everytime we boot up:

$sudo nano /etc/fstab

Append the following to the /etc/fstab file

For Password Protected Login:

//WindowsPC/Share1 /mnt/mountfoldername cifs username=yourusername,password=yourpassword 0

Now, we need to tell MPD to look for music on the network share
$sudo nano /etc/mpd.conf

Change:
music_directory “/var/lib/mpd/music”
To:
music_directory “/mnt/nas”
Reboot.

Don’t forget to spend at least several hundred dollars on a fancy Mini-to-RCA cable for hooking it all up to your preamp. Actually, I bought a spiffy one from Blue Jeans Cable for around $30.

Have fun.

P.S. If fiddling with all this isn’t your cup of tea, there is a terrific distribution out there called The Raspyfi Project which is already configured and ready to go. Just go to www.raspyfi.com, download the image, and follow the configuration instructions. There’s lots of information there to help you get started. Thank you, Michelangelo G.