Post by MartinT on Apr 6, 2015 16:37:25 GMT
How to Build a Raspberry Pi Based Audio Streamer
This How-To Guide takes you step by step through the building of an audio streamer / media player using a Raspberry Pi general purpose single board computer. The guide is the distillation of the long thread on Raspberry Pi based audio streamers here and is a construction guide only. All discussion should go into the main thread please.
The Raspberry Pi is an extremely inexpensive but fully functioning single board computer which is built into a unit approximately the size of a credit card. This build will use an operating system called Volumio (based on Debian Linux) to run it. Volumio is dedicated entirely to making the Pi play music and nothing else. It will access files from storage on other computers, USB devices or the internet. It can stream internet radio stations or Spotify (for which you will need a Spotify Premium account at £9.99 per month).
The result of the build will be a self-contained device which, depending on the other hardware options you select, will:
- in the most basic and cheapest form, provide music via a 3.5mm jack directly to an amplifier or headphones, or via a USB output to a suitable external DAC
- provide an optical and/or coaxial digital output to connect to an external DAC
- have an onboard DAC to output directly into your system's amp
- have an onboard amplifier to output directly to a pair of speakers
The lowest cost option will be about £30-£40, depending on the case you choose. The other, better sounding configurations will cost about £100 or more.
0. Shopping List
- Raspberry Pi 1 Model B+ or (preferably) Raspberry Pi 2 Model B
- 8GB fast MicroSD card (Class 10 for best speed)
- Case (type depends on whether an add-on board will be used)
- 5V micro USB mains power supply or 5V USB phone extender battery with micro USB to USB adapter cable
- Music files: these can be stored on your networked PC, Mac or NAS store, or a USB memory stick plugged into the RPi
- Music can also be sourced from a Spotify Premium account or internet radio
- Ethernet cable or wi-fi network
- Laptop, tablet or phone with browser for controlling Volumio. This can also be done via your desktop computer if necessary
- Addon board with S/PDIF digital outputs for using an external DAC (e.g. HiFiBerry Digi+)
- Onboard DAC with direct line level outputs (e.g. HiFiBerry DAC+, IQaudIO Pi-DAC+)
- Onboard amp with direct speaker outputs (e.g. HiFiBerry Amp+, IQaudIO Pi-AMP+)
If you use any of these options, you will need a different size case from standard.
1. Starting the Build
Assemble the RPi into its case, taking care not to force any components. Some cases are easier to assemble than others. Add the Wi-Fi USB dongle if required.
You will need to setup the RPi over Ethernet cable even if you eventually intend to use it wirelessly. Connect it via a spare Ethernet cable to your broadband/Infinity/cable router.
2. Preparing the OS Boot Disk
You need to download two files:
1. The latest Volumio image v1.55 for RPi
An 8GB size MicroSD card is more than enough for Volumio. The Class 10 speed (10 in a broken circle) ensures that performance is fast.
Unzip the Volumio image, putting it somewhere temporary for the disk image program to use.
Put the MicroSD into your card reader slot (you may need to use an adapter, frequently supplied with the card, to convert it to a full size SD card) and use Win32DiskImager to write the image file to your MicroSD card. Progress should look something like this:
Note the speed in the bottom-left corner is somewhat less than the claimed 20MB/s for a Class 10 card. When you get a comfirming 'Write Ok', the OS is ready and you can insert the MicroSD card into the RPi.
3. Finding the RPi Interface
You must use an ethernet cable for setting up and plug it into the RPi. The other end should go into your router.
Make sure the MicroSD card is plugged in and power up the RPi. Give it a couple of minutes to boot up first time. You should see the red power and green activity LEDs, you should also see the Ethernet port activity LEDs flicker.
The RPi will have collected an automatic IP address from the router, this process is known as DHCP or automatic IP configuration. The trick is finding it so that you can browse to the RPi and start configuring Volumio. Depending on your router, the RPi will most likely have collected an IP address in the range 192.168.x.x or 10.1.x.x. This is not helpful as you could be there all night searching for it.
Volumio suggests browsing to volumio.local/ and that is the first thing to try in your browser address bar:
If this doesn't work, continue as below. If you see the Volumio interface appear, then you're done for this section!
Since your router has issued the IP address, the best thing to do is to go to the router and find out directly. In my example below, I have a BT Home Hub and have browsed to 192.168.1.254 (as that is the default address for BT Home Hubs), entered the advanced menu and gone to the DHCP Table, as below:
The address of your router will depend on the brand of router you have. Common brands and their default addresses include:
Linksys - 192.168.1.1
3Com - 192.168.1.1
D-Link - 192.168.0.1
Belkin - 192.168.2.1
Netgear - 192.168.0.1
BT Home Hub - 192.168.1.254
You may still need to find the address through other means. Consult the manual! Sometimes the router will have the default address and password printed on its underside. Check the labels for reference. If your router’s IP address cannot be found, search for the address on the Internet by visiting the "Support" section of the router manufacturer's website or if the router was supplied by your internet service provider, check their website or contact them directly as they will be able to help.
You will see in the example above that this RPi/Volumio is located at 192.168.1.80, so you can now browse to:
in the browser. Your IP address is not likely to be the same as this! If you've done everything right, by means of one of the several methods shown you should see the Volumio interface pop up.
3a. Configuring Wi-Fi Networking
Go to Menu | Network and scroll down to Wireless Connection. Add your wi-fi's Network Name (the SSID, which can be viewed in your router, see section 3), the type of encryption (if in doubt, try WPA/WPA2 which is the most secure system) and the Wi-Fi password. When you click SAVE CHANGES there will be a pause and you should then be rewarded with a Staus: Connected display (see below for an example). You may now remove the Ethernet cable after a restart. Remember that the IP of the Wi-Fi interface will be different, so take a note of it here before restarting the RPi.
3b. Setting Up Audio
This will depend entirely on which audio output option you select. If you intend to use the 3.5mm audio jack in the RPi for either line out duties into an amplifier or for use with headphones, this will give you the lowest audio quality achievable and you may skip the rest of this section.
HiFiBerry Digi+ & DAC+
4. Testing With Webradio
The easiest way to test your audio streamer, before setting up the Library, is to play a webradio station and test for successful audio output. Go to Browse and select WEBRADIO. Select a radio station (anything will do for testing), right-click on the Actions icon on the right and select Add, replace and play. If you hear music from the audio jack (assuming no addon boards have been fitted), you are clear to move on to further configuration.
4a. Configuring a Share for the Library
There are two key steps here: set up a share in your selected host machine, then configure it in the Library section of Volumio. The former is going to depend greatly on the machine type and version of OS you have. Here's my example for Windows 8.1, but the essential methodology (if not the exact steps) should be the same for Mac or Linux machines or a NAS server.
Go to your top level folder or drive containing the music folders & files. This one is called simply Music. Right-click, select Share with and then Specific people...
Then you are presented with a Window where you are asked who to share the contents with. It's easiest to select yourself, otherwise you will have to go to the Control Panel and create a new user specifically for the share. Here you can see that the owner account is selected, which automatically gives a permission level of Owner. For other accounts, you need only select Read permission.
Once you click Share the system will take a few moments to apply the permission to every folder and file in the menu tree. Make note of the Share name (usually the folder name). You have now set up the necessary share on your system. Now go to the Volumio interface and select Menu | Library.
Now scroll down to NAS Mounts and click ADD NEW MOUNT. Here you will be presented with a screen where you fill in the share information, some of which you created above.
Give the Library a name (I've simply called it Music); select SMB for the file share protocol; the IP address is that of the host PC, Mac or NAS box, not your RPi/Volumio device (see Section 4a for finding your host computer IP address). The Remote directory is the Share name of the host machine, in this case Music. Username and Password are the credentials you have used in setting up the share - the Windows account used in the example above. Click SAVE MOUNT. You are returned to the Library screen.
Click UPDATE MPD DATABASE to start scanning your share files and build an internal list in Volumio. If your collection is large, you may need to have a cup of tea while it builds the library tree inside the RPi.
4a. Finding Your Host Computer IP Address
You can skip this section if you do not need to know your IP address. In Windows 7 / 8 / 8.1 go to Control Panel | Network and Internet | Network Connections. Right-click on the active ethernet connection, select Status and then Details...
Shown above is the host computer's IPv4 address (192.168.1.66) - this is the one you need. Yours will be different!
Alternatively, and for older versions of Windows, open a Command prompt (Win-R, cmd) and type ipconfig <Enter>. This will also provide your IP address (IPv4) as shown below (192.168.1.66).
7a. Adding Last.fm Scrobbling
If you want Last.fm to record all your listening, go into your RPi's command line interface using PuTTY (Windows) or Terminal (Mac). Install the mpdscribble utility:
sudo apt-get install mpdscribble
Then you need to edit the mpdscribble configuration file with your Last.fm login name and password. After saving it, you need to change its permissions to allow execution again (it's a Linux thing):
sudo nano /etc/mpdscribble.conf
sudo chmod 777 /etc/mpdscribble.conf
Then change the MPD_SYSTEMWIDE=0 parameter in mpdscribble to 1
sudo nano /etc/default/mpdscribble
sudo chmod 777 /etc/default/mpdscribble
Finally, restart the RPi:
sudo shutdown -r -t 0 0