Building a Logitech Media Server using a Raspberry Pi and HifiBerry DAC

Recipe for building a high-end media server using Logitech Media Server and a HifiBerry DAC+ PRO, Spotify, using a USB CD/DVD player and using Inguz Equalizer/Roomcorrection plugin.

Alternative: try PiCorePlayer. This works out of the box as a LMS player (nice!).
The beta version supports Logitech Media Server as well. I didn't tried this out yet but it may be a good alternative (but CD player probably not supported yet).

 

Hardware:

  • Raspberry PI model 3
  • Micro SD card (buy a fast one, at least 90 Mb/s read, 40 Mb/s write). For programming you need a USB (micro) card reader and SD adapter
  • Keyboard, mouse and HDMI monitor are only needed during first installation
  • HifiBerry DAC+ PRO card (has low jitter clock!)
  • For storing the media files you can:
    • use a large (256Gb) micro SD card 
    • use an external disk: memory stick, external SSD (needs conversion cable, e.g. Delock Converter SATA, connected via a powered USB HUB)
    • use a NAS
  • Cabinet suitable for Raspberry Pi and HifiBerry DAC.
  • To improve the audio quality dramatically: add some filtering in the powersupply (resistor + capacitor); see picture below
  • External USB CD/DVD player with own power supply

Also interesting (I did not try this out yet myself) is the HiFiBerry Amp+ board because it has build in power amplifiers. May be not high end, but useful for in the kitchen.

 

How does the HifiBerry sound?

After the modification (see below), it sounds fabulous!
At first, I compared the HifiBerry DAC+ Pro against my other media player with a high-end DAC ("B-DAC").
Unfortunately, the difference was rather big: the stereo image was not very detailed and it sounded a bit dull.
I think the reason for this is the noisy power supply of the Raspberry Pi.
Luckily it is easy to filter the power supply received from the Raspberry Pi board on the HifiBerry card.
This improved the audio quality a lot! I cannot tell the difference with the high-end DAC anymore!

So how do you do this?
First you have to remove R14 (0 Ohm) SMD resistor.
The filter consists of an inductor of 100 uH (Conrad art.number 1406004), two ceramic capacitors of 22 nF, a resistor of 22 Ohm and two capacitors of 4700 uF/10V (Conrad art.number 422027).
The inductor and resistor are placed in series and replace R14.
The ceramic capacitor is connected between the connection of inductor and resistor and ground.
The two capacitors of 4700 uF are placed in parallel after the resistor and connected to ground.
Check that the electrotrolytic capacitors are mounted with the right polarity!

Do not place the capacitor at the right hand side above de DAC chip!
The capacitor might become too hot and start leaking and thus damaging the print.

 

How to install the Operating System

  • Install the latest Raspian OS (this comes with the HifiBerry driver installed).
  • You can install the image on a micro SD card using Win32DiskImager
  • Connect a monitor, keyboard and mouse.
  • Configure: Menu --> Preferences --> Raspiberry Pi Configuration:
    • Interfaces: VNC
    • Localization: set locale, set timezone, set keyboard (US International), set wifi country
    • The default username is: "pi" and the default password is "raspberry"
  • Expand file system: sudo raspi-config --expand-rootfs
  • Configure Wifi (optionally): click on wifi icon on the top bar at the righthand side.
  • After configuring Wifi, you can access the desktop using Real VNC Viewer instead of the attached keyboard and mouse.
  • Upgrade the OS to the latest version:
    • sudo apt-get update
      sudo apt-get upgrade     (this might take a while)
  • Download a VNC client for your computer (e.g. RealVNC) and connect (e.g. 192.168.2.17) remotely if you wish.

How to install Logitech Media Server

How to install Samba (file sharing)

Install and configure Samba using this link or this link:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install samba samba-common-bin
  • sudo smbpasswd -a pi
  • (you are asked to type a password twice. I use the same password as for the pi)
  • sudo mkdir -m 1777 /media/pi
  • sudo leafpad /etc/samba/smb.conf
  • workgroup = WORKGROUP
    wins support = yes
  • Reboot the system. Now you should be able to access the share Media on the Raspberry from any PC at home.

How to automatically reboot the system every night

Rebooting the system at night (e.g. at 5 am) can improve stability:

  • Enter command: crontab -e
    Add as the last line:
    0 5 * * * sudo /sbin/shutdown -r now

How to configure a CD player

You can attach a USB DVD player/burner to play audio CD's.
The Raspberry is not capable of supplying enough current via the USB port.
So either use an external drive with own power supply (there are a lot of secondhand available) or use a powered USB hub.
Be sure to disable the power connector pin in the USB connector (e.g. by using tape).
I prefer the old drives because they are heavy. The modern lightweight drives have to be operated with two hands.

Before you can use the CDPlayer plugin, you must run the following commands to install the cdda2wav tool in this way:

  • sudo apt-get install icedax
  • sudo ln -s /usr/bin/icedax /usr/bin/cdda2wav
  • sudo adduser squeezeboxserver cdrom
  • File Manager --> Edit --> Preferences --> Volume Management --> uncheck: "Show available options for removable media"

Next you must enable the CDPlayer plugin:
From any browser: use the IP address of the raspberry followed by ":9000". E.g.: 192.168.2.18:9000

  • In the lower right corner you will see the Settting icon.
  • Open the Plugins tab.
  • Check "CDPlayer"

I found out that the Raspberry did not boot in combination with a Soundblaster USB dongle when the CD drive was powered on.
It did boot when the CD drive was powered off during booting however.

How to configure Spotty plugin

You need Spotify Premium account to get this working.
With the latest version of Logitech Media server, the Triode Spotify plugin is not supported anymore.
Instead , you can install the Spotty plugin.

But first you have to install:

  • sudo apt-get install libnet-ssleay-perl
  • sudo apt-get install libio-socket-ssl-perl

How to control Spotify

After installing the Spotty plugin, there are two ways to use Spotify:

  • From your app (e.g. iPeng, SqueezeControl) that you use to control Logitech Media Server.
  • From your Spotify app on your tablet or mobile phone.
    The Spotify app offers more functions.
    It allows you to stream the music to your Logitech Media player.
    You can configure this as follows:
    From any browser: use the IP address of the raspberry followed by ":9000". E.g.: 192.168.2.18:9000
    Click on Settings button (bottom right).
    Select second tab (Music System)
    In the second dropdown box, select: Spotty Spotify for Squeezebox
    Enable the checkbox.

How to prepare a large (256Gb) intern SD  card

Instead of a small (8Gb) SD card and an external disk you can use a large internal SD card.
Suppose a configured image file of 8 Gb is available on your Windows PC.
With Win32 Disk Imager, the image is copied to the SD disk.
With Windows Disk Management you can now see a FAT boot partition of 42 Mb.
Next to that you will see a 7.4 Gb partition (containing the Raspian OS).
And next to that you will see an unallocated partition of 231 Gb.
The unallocated partition must be formatted, preferrably with NTFS on Windows, otherwise with exFAT on a Mac.
When formatted, put the SD card in the Raspberry.
You can find the name of the disk/device using the "df" command.
Create folder for mount point on the :
sudo mkdir /media/internaldisk
sudo chmod 777 /media/internaldisk
sudo mkdir /media/internaldisk/Music
sudo chmod 777 /media/internaldisk/Music
sudo leafpad /etc/fstab

Add line:
/dev/mmcblk0p3 /media/internaldisk ntfs-3g defaults,nofail 0 0

if the partition was formatted with exFAT, then add the following line instead:
/dev/mmcblk0p3 /media/internaldisk vfat defaults,nofail 0 0

Add section for network share:

sudo leafpad /etc/samba/smb.conf
Add section:
-----------------------------------------------
[InternalDisk]
comment=Raspberry Pi Media Share
path=/media/internaldisk/Music
browseable=Yes
writeable=Yes
only guest=no
create mask=0777
directory mask=0777
public=yes
-----------------------------------------------
After Logitech Media Server has started, you can configure the new media folder ("media/internaldisk").

 

My basic setting page looks like this (support internal dis and external USB disk):

 

How to prepare for an external SSD/USB disk

  • For attaching an SSD disk you need a conversion cable SATA to USB. The SSD might take too much current from the Raspberry, so a powered HUB might be needed.
  • Prepare the SSD/USB disk e.g. on Windows:
    • Format the disk with NTFS (preferably)
    • Attach a SSD/USB disk to the USB port of the Raspberry using an USB adapter
  • Start the system
  • The disk is automatically mounted under: /media/pi/Media. Unfortunately, the permission cannot be changed this way.
  • sudo umount /media/pi/Media
  • sudo apt-get install ntfs-3g
  • Disable auto mounting in the File Manager:
    Edit --> Preferences --> Volume Management
    Uncheck:
    - Mount mountable Volume ...
    - Mount removable media ..
  • Create a mount point:
  • sudo mkdir /media/usbdisk
  • sudo chmod 777 /media/usbdisk
  • sudo mkdir /media/usbdisk/Music
  • sudo chmod 777 /media/usbdisk/Music
  • Edit fstab: sudo leafpad /etc/fstab
  • Add line (the nofail option means that you can boot when the USB drive is not attached):
    /dev/sda1 /media/usbdisk ntfs-3g defaults,nofail 0 0
  • If you did not format with NTFS, but with exFAT, you have to change "ntfs-3g" to "vfat".
  • Reboot the system. Now the SSD disk is mounted with the right permission.
  • Add some music from your PC to the SSD/USB disk using the share "Media".
  • Find the IP address of your system: ifconfig
  • Now start any browser on any PC at home and type as URL (use the correct IP address): http://192.168.2.xxx:9000
  • You can now configure Logitech Media Server with the location of the music (/media/pi) 

Add section for network share:
sudo leafpad /etc/samba/smb.conf
Add section:
-----------------------------------------------
[UsbDisk]
comment=Raspberry Pi Media Share
path=/media/usbdisk/Music
browseable=Yes
writeable=Yes
only guest=no
create mask=0777
directory mask=0777
public=yes
-----------------------------------------------

How to add a new USB memory stick

If you want to add or replace the USB disk/memory stick, while the software on Raspberry already has been configured:

  • Format the disk with NTFS on Windows. Otherwise format with exFAT (e.g. on a Mac).
  • Create folder "Music" on this disk

If the disk was formatted with exFAT, you have to modify file "/etc/fstab":

  • sudo leafpad /etc/fstab
  • Modify line: 
    /dev/sda1 /media/usbdisk ntfs-3g defaults,nofail 0 0
  • to:
    /dev/sda1 /media/usbdisk vfat defaults,nofail 0 0

 

How to use a NAS for storage

Instead of using local storage for the music, you could use an existing NAS.
Suppose the location of the NAS is: //192.168.2.8/Music
Preferrably you should use a name instead of the IP number.
Now enter the following commands to test the connection:

  • sudo mkdir /media/nas
  • sudo chmod 777 /media/nas
  • sudo mount -t cifs -o user=guest,password=guest  //192.168.2.8/Music /media/nas

You can now configure Logitech Media Server with the location of the music (/media/nas)

To mount the NAS automatically at boot time do:

  • sudo leafpad /etc/fstab
    Add line:
    //192.168.2.8/Music /media/nas cifs defaults,nofail,user=guest,password=guest,uid=pi,gid=pi,x-systemd.automount 0 0

 

How to install SqueezeLite (player)

Install Squeeze Lite (see this link).
Alternatively (I did not yet tried out): enable the "Local player" plugin.

mkdir squeezelite
cd squeezelite
wget -O squeezelite-armv6hf http://ralph_irving.users.sourceforge.net/pico/squeezelite-armv6hf-noffmpeg
sudo mv squeezelite-armv6hf /usr/bin
sudo chmod a+x /usr/bin/squeezelite-armv6hf
cd /home/pi/squeezelite
sudo wget http://www.gerrelt.nl/RaspberryPi/squeezelite_settings.sh
sudo mv squeezelite_settings.sh /usr/local/bin
sudo chmod a+x /usr/local/bin/squeezelite_settings.sh
sudo wget http://www.gerrelt.nl/RaspberryPi/squeezelitehf.sh
sudo mv squeezelitehf.sh /etc/init.d/squeezelite
sudo chmod a+x /etc/init.d/squeezelite
sudo wget http://www.gerrelt.nl/RaspberryPi/squeezelite.service
sudo mv squeezelite.service /etc/systemd/system
sudo systemctl enable squeezelite.service
cd /home/pi

Find your USB card name: sudo /usr/bin/squeezelite-armv6hf -l
For the HifiBerry card you should see "sndrpihifiberry" listed.
If not (e.g. with older HifiBerry cards, hardware version 2.2), then (see: https://support.hifiberry.com/hc/en-us/articles/205377651-Configuring-Linux-4-x-or-higher)

    • sudo leafpad /boot/config.txt
    • Remove line: dtparam=audio=on
    • Add line: dtoverlay=hifiberry-dacplus
    • reboot

Edit the script: sudo leafpad /usr/local/bin/squeezelite_settings.sh

  • modify: SL_SOUNDCARD="sysdefault:CARD=ALSA" to: SL_SOUNDCARD="sysdefault:CARD=sndrpihifiberry"
  • (For SoundBlaster USB device change to: SL_SOUNDCARD="sysdefault:CARD=U0x41e0x30d3")
  • uncomment line: SB_SERVER="127.0.0.1"
  • Reboot the system

 

How to control the Logitech Media Server

From your smartphone or tablet: use various apps. Search in the store for "SqueezeBox".
I personally like: Squeeze Control (for Android) and IPeng (for iPhone/iPad).
From any browser. Use the IP address followed by ":9000". E.g.: 192.168.2.18:9000

 

Use ethernet cable or Wifi?

Using a network cable is highly preferable above a wifi connection:

  • Uploading music is much faster.
  • More reliable connection (especially important for radio).
  • No network configuration needed (but indeed: you only have to do this once).

 

How to configure the Wifi connection?

You can configure the Wifi connection by attaching a keyboard, mouse and HDMI monitor.
In the upper right corner you will see the Wifi icon which allows you to configure the Wifi connection.
But your monitor might not have a HDMI connection. So here is an alternative using a PC or tablet.

  • Connect the Raspberry Pi to a the network using a network cable. Now the Raspberry automatically receives an IP number.
  • Find out what the IP number is (e.g. 192.168.2.18). E.g. you can use an IP scanner app (e.g. IPScan on Windows or Android Fing). Or you can find out on the web interface of your router.
  • Install "VNC Viewer" on your tablet or PC.
  • Start the VNC Viewer and enter the IP address. E.g.: 192.168.2.18
  • Now you can connect to the Raspberry and configure the Wifi connection.

 

How to put your music on the server 

On a Windows PC: 

 

How to synchronize with the music collection on a PC

For reliability reasons it is important to have a copy of your music collection somewhere else.
Suppose you have your master collection on a Windows PC in folder "c:\MyMusic".
And the music on the Rasperry is accessible via share \\RaspberryPi\InternalDisk\Music.
Then you can use the following batch file to make a copy (mirror) of the files from the PC on the Raspberry:

robocopy.exe "c:\MyMusic" "\\RaspberryPi\InternalDisk\Music" /MIR

 

Help: the radio does not work

Sometimes no music is heard when a radio channel is selected (e.g. NPO radio 4).
The reason is that the default format of the stream for the selected radio is not supported by Logitech Media Server.
The solution is to select another stream format. This is how:

  • First, find an URL that works. Search in Google for example for "npo radio 4 url". I found: http://icecast.omroep.nl/radio4-bb-mp3
  • See also: https://www.mp3streams.nl
  • Or look at this nice overview: http://www.hendrikjansen.nl/henk/streaming.html
  • From any browser: use the IP address of the raspberry followed by ":9000". E.g.: 192.168.2.38:9000
  • Goto menu: Radio -> URL
  • Now enter the URL found and press the button next to it.
  • If this URL works, the next step is to add this to the favourites.
  • You can do this by clicking on the M (more) button on the right hand side of the screen (only visible when you hover the mouse over the music item on the right hand side).
  • Now more information for the stream is shown on the left hand side of the screen.
  • Here you can click on the first item: Save to favorites. Nice user interface!
  • Unfortunately, the added title is sometimes cryptic and cannot be changed easily.
  • If you really want to change the title, you can change this with a text editor (as super user) on the server in: /var/lib/squeezeboxserver/prefs/favorites.opml

 This is the list I added for my music server:

  

How to configure Inguz EQ plugin

This is a plugin for supplying equalizer functionallity and DRC (Digital Room Correction).
It also supplies test signals like left/right identifier, noise, etc.
You can find the software here: https://github.com/hughpyle/inguz-InguzDSP

There is no support any more for this plugin unfortunately.
But I can confirm that the plugin works with the latest LMS (7.9.1) if you follow the steps below.
The new LMS version requires a small change in the file Plugin.pm.

An alternative plugin for Room Correction (I did not yet try this) is: http://drc-fir.sourceforge.net

I did not tried this one yet. There is a lot of configuration involved.
You can check out: http://archimago.blogspot.nl/2016/03/howto-logitech-media-server-brutefirdrc.html

How to install the Inguz EQ plugin:

First, update the OS:
sudo apt-get update
sudo apt-get upgrade
Now get Mono (this supplies .NET functionallity):
sudo apt-get install mono-complete

Download two zip files: EQ processor and DSP processor from: http://inguzaudio.com/EQ
After downloading you will find the downloads in: /home/pi/Downloads
In File Manager right click on the InguzEQ.zip file and do: Extract here (extracts a folder).
In File Manager right click on the InguzDSP.zip file and do: Extract here (extracts 3 files).

sudo mv /home/pi/Downloads/InguzEQ /usr/share/squeezeboxserver/Plugins
sudo chown squeezeboxserver /usr/share/squeezeboxserver/Plugins/InguzEQ
sudo mv /home/pi/Downloads/InguzDSP.exe /usr/sbin
sudo mv /home/pi/Downloads/InguzDSP.exe.config /usr/sbin
sudo mv /home/pi/Downloads/DSPUtil.dll /usr/sbin
cd /usr/sbin
sudo chmod +x DSPUtil.dll
sudo chmod +x InguzDSP.exe
sudo mkdir /usr/share/squeezeboxserver/.wapi
sudo chown squeezeboxserver /usr/share/squeezeboxserver/.wapi

Now create the file /usr/sbin/InguzDSP:
sudo leafpad /usr/sbin/InguzDSP
Enter contents:
#! /bin/sh
mono /usr/sbin/InguzDSP.exe $* 2>/usr/share/InguzEQ/error

Next:
sudo chmod +x /usr/sbin/InguzDSP
sudo chmod 777 InguzEQ/

There is some deprecated code in Plugin.pm that prevents the plugin from starting.

sudo leafpad /usr/share/squeezeboxserver/Plugins/InguzEQ/Plugin.pm
Change line 3138 to ("%h->" change to "$h"):

         $request->addResultLoop( 'Points_loop', $cnt, $ff, $h{$ff} );

In Settings of LMS enable the EQ plugin.

Multiple reboots might be needed in order to get it working (it did not the first time with me).
Configuration and log files are created in: /usr/share/InguzEQ

The equalizer settings files are created in:
/usr/share/InguzEQ/Settings

To restart the Logitech Media Server:
sudo service logitechmediaserver stop
sudo service logitechmediaserver start

You cannot configure the plugin from the browser anymore because this requires SilverLight (which is deprecated).
But you can configure the plugin (equalizer, room correction) from your app on your phone or tablet.

Create a folder for the room correction files:
sudo mkdir /usr/share/InguzEQ
sudo mkdir /usr/share/InguzEQ/Impulses

When sharing this folder for everyone, also change the folder permission:
sudo chmod 777 /usr/share/InguzEQ/Impulses

Make a share for the Impulses folder:
sudo leafpad /etc/samba/smb.conf
Add section:
[Impulses]
 comment=Room correction files
 path=/usr/share/InguzEQ/Impulses
 browseable=Yes
 writeable=Yes
 only guest=no
 create mask=0777
 directory mask=0777
 public=yes

 

How to create a DRC correction file

This can be done using one of the following tools:

  • DrcDesigner: http://www.alanjordan.org/DRCDesigner/DrcDesignerHelp.html
    This tool works nicely.
    One quirk: on the tab "Generate Standard Filters", the button "Generate Selected Filters" becomes active only after reselecting the Sampling Rate.
    The generated correction files can be found in: c:\DRCDesigner\ConvolverFilters

Room correction files (44100 hz) must be saved to: /usr/share/InguzEQ/Impulses