A music system with a Raspberry Pi plugged in to an amplifier playing music that you choose with your mobile phone. The music can come from MP3s on your phone, from files on your server, files “in the cloud” or from internet radio stations. If there’s more than one Android phone in your household you can have them all synchronised, showing the same playlist and controlling the same music. If you have multiple Raspberry Pis you can put one in each room and choose which one to play the music with. This is all achieved with free software and open standards. I’ve just written some instructions to show how to do it.
I have blogged on this topic two times previously (here and here). Each time it gets simpler as the Raspberry Pi eco-system evolves. I needed a new Raspberry Pi UPnP renderer to be attached to an amplifier and speakers.
My previous post explains lots more about how the system as a whole works, how to test it and how you control the music. This post merely updates the instructions for installing gmediarender and includes some info on using a USB sound card.
As usual I started from the latest Raspbian distribution (2014-01-07) which needs a 4GB SDCard card apparently. Once the Raspberry Pi is up and running and on the network, log in (user: “pi”, password “raspberry”), run the first-time configuration command and then update to the very latest firmware. These following commands also show the before and after versions in case that is useful for people:
$ uname -a Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l GNU/Linux $ sudo raspi-config $ sudo apt-get install rpi-update $ sudo shutdown -r now
Once it has rebooted, log in again check the new status and upgrade all the installed packages:
Henner Zeller has made the gmrender-resurrect UPnP renderer and it is known to work best with gstreamer 1.0. Unfortunately Raspbian currently still comes with gstreamer 0.10. Fortunately, Christi Scarborough has compiled the necessary gstreamer 1.0 packages for the Raspberry Pi and provided them as debian packages. She has documented it all and very honestly included the warning that using these packages means you have to trust her not to have slipped in some malware or something. Some of the instructions on this page are just a duplication of hers. Christi also provides a ready-made build of gmediarender but as I wasn’t sure which version that was, I wanted to use Henner’s directly.
First we have to install Christi’s GPG key to show that we trust her packages:
$ sudo wget -O - http://firstname.lastname@example.org \ | sudo apt-key add -
Then, using “vi”, “nano” or whatever, create a new file to hold the address of Christi’s Debian repository, call it /etc/apt/sources.list.d/upnprender.list and add just one line: deb http://www.chiark.greenend.org.uk/~christi/debian/ wheezy main
We then need to update the local cache of available packages to include Christi’s packages and then follow Henner’s instructions for installing gmrender-resurrect:
Continuing with Henner’s instructions:
$ cd $ git clone https://github.com/hzeller/gmrender-resurrect.git $ cd gmrender-resurrect $ sudo apt-get install autoconf $ ./autogen.sh $ ./configure $ sudo make install
This puts gmediarender into /usr/local/bin and a couple of icons into /usr/local/share/gmediarender
Henner has provided an init script to start and stop the gmediarender software, so we’ll copy this into the appropriate place:
Edit the init script if you need to (e.g. set the name of the renderer). Then use the update-rc.d command to put in the necessary symbolic links to the init script that start or stop the service at different runlevels (the following ls command shows these for interest):
$ sudo update-rc.d gmediarenderer defaults $ ls -l /etc/rc*.d/*gmed* lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc0.d/K01gmediarenderer -> ../init.d/gmediarenderer lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc1.d/K01gmediarenderer -> ../init.d/gmediarenderer lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc2.d/S04gmediarenderer -> ../init.d/gmediarenderer lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc3.d/S04gmediarenderer -> ../init.d/gmediarenderer lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc4.d/S04gmediarenderer -> ../init.d/gmediarenderer lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc5.d/S04gmediarenderer -> ../init.d/gmediarenderer lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc6.d/K01gmediarenderer -> ../init.d/gmediarenderer
Rebooting now should give us a system with gmediarender running, which we can test with ps:
$ sudo shutdown -r now (wait a bit and log in again) $ ps aux|grep gmed pi 2078 15.5 9.1 198996 40828 ? Ssl 11:05 0:05 /usr/local/bin/gmediarender -f Garden -d -u bd1dcf3e746aa69812943cb1d00f7ebc --gstout-audiosink=alsasink --gstout-audiodevice=sysdefault --gstout-initial-volume-db=-10 pi 2123 0.0 0.1 3548 800 pts/0 S+ 11:06 0:00 grep --color=auto gmed
Basically it all works at this point, though using the built-in audio output of the Raspberry Pi never gives a great quality sound. There are various really interesting high quality DAC cards now available for the RPi which connect directly to the circuit board but for now I went for the simple option of getting a dirt-cheap USB audio card (for 99p you can’t really go wrong…). It does sound much better than the built-in output and is automatically picked up by the latest Raspbian version.
Plug in your USB audio card (which can cause the RPi to reboot…) and then set it up by following an Adafruit tutorial.
I have a CM109 chipset so all I had to do was edit /etc/modprobe.d/alsa-base.conf and change options snd-usb-audio index=-2 to options snd-usb-audio index=0
Reboot again and decent sound comes out of the USB sound card!