Afdrukken

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.

Note that the HifiBerry DAC+ DSP allows you to do room correction. When it works, it is great! I had one board failed but got a new one returned.
So I have questions about the reliability.
I got error message: 
"10 filters given, but filter bank has only 0.0 slots." The Hifiberry forum shows that that many people have encountered the same issue.

 

Hardware:

 

How does the HifiBerry DAC+ Pro 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", 1200 euro).
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.
Although the board has a buit-in voltage regulator, this does not work well for high frequency noise that comes from the power supply.
So adding a passive filter before the voltage regulator assures that the noise from the Raspberry doesn't reach the DAC.
Adding this filter improved the audio quality a lot! I cannot tell the difference with the high-end DAC anymore!

So how do you do this for the DAC+ Pro?
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.

  

Which storage devices can I use?

Currently, I use a small SD card for the OS and applications only.
Two 256 Gb SD cards in the USB slots are used to store the music files (but you could use one 512 Gb SD card as well).

Alternatively, you could use just one big internal SD card.

Although it didn't happen to me, SD cards can get corrupt when the power is disconnected.
Therefore I make a backup image of the small SD card.

 

How to install the Operating System

 

 

How to install Logitech Media Server

Install Media Server (see this link):


You can uninstall as follows: sudo apt-get purge logitechmediaserver

To install an older version:

 

How to install the SqueezeLite music player

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

mkdir squeezelite
cd squeezelite
sudo 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 cards (e.g. DAC+ Pro and DAC DSP) 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)

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

You might need to disable the driver for the build-in audio:

CONFIGURE DEVICE TREE OVERLAY FILE:

- FOR DAC FOR RASPBERRY PI 1/DAC+ LIGHT/DAC ZERO/MINIAMP/BEOCREATE/DAC+ DSP:

- FOR DAC+ STANDARD/PRO/AMP2DAC+ STANDARD/PRO/AMP2

 

 

How to install Samba (file sharing)

Install and configure Samba using this link or this link:

 

How to automatically reboot the system every night

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

 

How to configure a CD player

You can attach a USB DVD player/burner to play audio CD's.
The advantage is that you do not need a preamplifier to switch between the Raspberry and CD player.
We found however that such a PC DVD player is a bit noisy sometimes and not always reliable. But you can give it a try.
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:

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

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 (may be not necessary anymore):

How to control Spotify

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

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.
Even 512 Gb SD cards are cheap enough to buy now.
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 Raspbian OS).
And next to that you will see an unallocated partition of 231 Gb.
The unallocated partition must be formatted, preferably 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 USB disk/Memory stick

 

I found, that when having two USB memory sticks, one was not always mounted.
A solution may be, is to add the line boot_delay=3 to /boot/config.txt

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
-----------------------------------------------

If you have a second USB stick, you can create folders and a share in the same way (e.g. /media/usbdisk2).

 

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:

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

 

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:

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

To mount the NAS automatically at boot time do:

  

How to set the volume to maximum?

* sudo apt-get install pimixer

Run pimixer (or alsamixer)

Use arrow up/down or PgUp/PgDn keys to adjust the volume

 

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:

 

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.

 

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:

 This is the list I added for my music server:

  

How to remote shutdown the Raspberry from your smartphone

It is always safer to shutdown the Raspberry Pi than removing the power directly.
This reduces the risk of damaging the SD card.
This can be easily accomplished by installing Node-RED and creating a simple program to shutdown the Raspberry.
With Node-RED it is simple to create a web page with just a shutdown button.
Using the browser on your smartphone you can pin this application to the start screen.

See section: HifiBerry DAC+ DSP filter selection

 

Room correction

 

The HifiBerry DAC+ DSP allows you to do room correction.

When it works, it is great! I had one board failed but got a new one returned.
So I have questions about the reliability.
I got error message: 
"10 filters given, but filter bank has only 0.0 slots." The Hifiberry forum shows that that many people have encountered the same issue.

For configuration see the next chapter.

 

The Inguz plugin does not work any more because it relies upon an old version of Mono.
Also it works only for FLAC files of your own music collection.
So, it does not work for the other sources (Spotify, radio, CD).
Still you could install it because of the test signals it supplies (see below).

An alternative plugin for Room Correction is: http://drc-fir.sourceforge.net
See also: http://archimago.blogspot.com/2016/03/howto-logitech-media-server-brutefirdrc.html
I
t is faster than Inguz plugin but it is complicated to configure. 

 

HifiBerry DAC+ DSP configuration

For making a DSP profile file I ordered the following hardware for my laptop:
* USB-C DAC Toslink Optical AUX Audio Adapter 192kHz 24bit Headset Amplifier USB Sound Card

* 2M Mini 3.5mm Plug Digital Optical Audio Cable SPDIF Optical Fiber Line To Round Mouth TOSLINK Optical Audio Connector Dropship
* miniDSP UMIK-1 Omni-Directional USB Measurement Calibrated Microphone or Dayton Audio UMM-6 measuring microphone UMM-6

I found some issues during installation and configuration. Answers can be found on the Community pages (strangely enough not in the documentation).


After mounting the board, checkout: https://www.hifiberry.com/docs/data-sheets/datasheet-dac-dsp/

It says that you must modify /boot/config.txt:
* sudo nano /boot/config.txt
* add line: 
dtoverlay=hifiberry-dac

The next step is to follow the installation instructions in: https://www.hifiberry.com/docs/software/implementing-room-acoustics-correction-using-rew/
or, on Github: https://github.com/hifiberry/hifiberry-dsp/blob/master/doc/rew-basics.md
Currently there are small differences between these two documents.

Install the dsptoolkit:

* bash <(curl https://raw.githubusercontent.com/hifiberry/hifiberry-dsp/master/install-dsptoolkit)
You will see that the last command fails: mv: failed to preserve ownership for '/boot/config.txt': Operation not permitted
This error message can be ignored and is due to the fact that the boot folder is on a FAT partition.
Check:
* sudo nano /boot/config.txt
* Assure that the following line exists: dtparam=spi=on

Reboot the Raspberry Pi.

The DSP is loaded with some profile in the factory.
When you would install a filter right now, you get error message: "15 filters given, but filter bank has only 0 slots".
Therefore you have to install first a default profile: 
* dsptoolkit install-profile https://raw.githubusercontent.com/hifiberry/hifiberry-dsp/master/sample_files/xml/dacdsp-default.xml

I found that after a power down, I cannot load filters any more. I have to reinstall the profile.
This command seems to help: dsptoolkit store
The documentation of the dsptoolkit is not very clear about this: 
https://pypi.org/project/hifiberrydsp/0.10/


Note that this profile reversed the left and right output.
The Hifiberry team has no intention to correct this. Probably they don't have the knowledge any more.

This profile has an automute function. This gives a problem if you play the music (or radio) very softly.
This is very annoying. In the Community pages of Hifiberry.com this issue is mentioned and it is advised to load profile dspdac-noautomute.xml.
However, this profile creates a DC offset of 1V at the output. No idea why. This gave me a problem with my amplifier.
I made an issue for this. This is there answer: "
We don't work on this profile anymore. The profile is provided as-is. There won't be any further updated from us on this profile."

The next thing to do is to download the program REW and create your profile as described in the documentation.
Note that the DSP supports 16 filters at maximum.
You might prevent REW creating more filters by disabling 5 filters in the Settings menu.
The nice thing is that you can modify the desired curve. You can filters with different slopes and try out what sounds best for you.

 

And the result in one word: fabulous!

 

HifiBerry DAC+ DSP filter selection

Once you have created one or more room correction filters, you want to be able to select them from your phone or tablet.
This can be easily accomplished by a simple program in Node-RED.

You can follow these steps:

Create a folder for the filter files and export this folder via Samba:

* sudo mkdir /media/internaldisk/roomcorrection
* sudo chmod 777 /media/internaldisk/roomcorrection
* sudo leafpad /etc/samba/smb.conf

Add following section and reboot afterwards:
[RoomCorrection]
 comment=Room correction files
 path=/media/internaldisk/roomcorrection
 browseable=Yes
 writeable=Yes
 only guest=no
 create mask=0777
 directory mask=0777
 public=yes


Install Node-RED:

* sudo apt-get update
* sudo apt-get upgrade
* bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
* sudo systemctl enable nodered.service

By adding a setting in settings.js, flow variables are saved automatically every 30 seconds:
* nano .node-red/settings.js
Add setting:
    contextStorage: { default: { module:"localfilesystem" }, },

Now it is time to reboot the Raspberry.

Show the editor: launch a web browser and type in the address bar: <ip address raspberry>:1880

Install "Dashboard" plugin: click on the menu button (three horizontal line in upper right corner) and Manage Palette.
Click on "Install" and type "dashboard" in the search bar. Install: node-red-dashboard

Import the program: click on the menu button (three horizontal line in upper right corner), Import and paste the code from this file.

Install the program: click on the Deploy button in the upper right corner.

Show user interface in your browser: launch a web browser and type in the address bar: <ip address raspberry>:1880/ui
Your browser on your phone and tablet has an option to add this page to your start screen. 
Now it behaves as an app. It has three tabs (or pages). One allows you to shutdown/reboot the Raspberry.

Example screenshot

 

HifiBerry DAC+ DSP power supply modification

3D printed case for Raspberry Pi 3B and HifiBerry DAC+ DSP, designed by Alfred Homsma. You can download the 3D files here.

 

 

This DAC supports room correction.


Although the board has a voltage regulator, this does not work well for higher frequencies.
So adding a passive filter before the voltage regulator assures that the noise from the Raspberry doesn't reach the DAC.

Due to the DSP, the power consumption of this model is higher than the DAC+ Pro.
Therefore the resistor of 22 Ohm is not possible here.
The 3.3V input regulator on the board requires an input voltage of at least 4.2 V.
The Raspberry Pi voltage is at least 5.1V.
Therefor the voltage drop over the inductor is about 0.9V.
With an average current consumption of 0.2A, the resistance of the inductor should be no more than 4.5 Ohm.
The pin layout of the Raspberry Pi can be found here.
Do not place the capacitors above the hot electronic devices (voltage regulators)!

First cut the +5V track.
The filter consists of two inductors of 470 uH and two capacitors of 4700 uF/10V (Conrad art.number 422027).

 

 

 

How to configure the Inguz EQ plugin

Currently, I cannot get it working. An older version of Mono is required!

I tried with the following instructions, but without succes:
https://blog.rubenwardy.com/2016/07/20/rimworld-install-monodevelop-with-dot-net-3.5/

I think that it is only useful for the test signals. The room correction can be done better with the Hifiberry DAC+ DSP.

Inguz EQ is a plugin for supplying equalizer functionality and DRC (Digital Room Correction).
It also supplies test signals like left/right identifier, noise, etc. Very nice!
Those test signals are a good reason to install this plugin anyway!
Once installed, you can find them in menu: Extras --> EQ --> Settings --> Test Signals

You can find the software here: https://github.com/hughpyle/inguz-InguzDSP

There is no support any more for this plugin unfortunately.
Note that a small change in the file Plugin.pm is required for LMS version 7.9.1.

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):

TODO we need an older version of mono. The next line will install the latest mono version!
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 InguzDSP

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.
Note that the user interface is crippled because no Silverlight can be installed (not a real issue).

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 chmod 777 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 room correction 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 for InguzEQ

This can be done using one of the following tools:

For Inguz EQ plugin, room correction files (44100 hz) must be saved to: /usr/share/InguzEQ/Impulses