My home music system - Logitech Media Server & Squeezelite

Background


Since RaspberryPi was released I have been testing how it could be used as home media center. I had quite good results with XBMC but I also realized the limited performance of RaspberryPi.

I bought a new TV last summer and since then I have not needed a separate media player for video. I still needed good audio player. I first tested RaspyFi distribution. The software is controlled via web gui or via client software on Android or Apple phone or tablet. Only problem I had was that the indexing of music was really slow and adding new content took too much time to index.

Logitech Media Server and Squeezelite


Then I found Logitech Media Server (LMS). LMS was originally built as backend for Logitech Squeezebox players but today there are also software clients available. LMS can run on most operating systems.

Squeezelite is a squeezebox software emulator. I can run on Windows or Linux and there is also RaspberryPi version available. Squeezelite supports 192KHz playback.

Things that I like in LMS:
-very good free client for Android phones, iPhone and iPad
-plays all my files (wav, mp3, flac, alac)
-supports Spotify via 3rd party plugin
-plays web radios out of the box, found all local stations automatically
-lot of plugins available
-supports Digital Room Correction with BruteFir plugin
-can act as Airport server



Hardware





Lacie 2Big 6TB NAS
- Storage for my files, all music is stored here
http://www.lacie.com/products/product.htm?id=10584



Asus Eee Box B206
- Logitech Media Server
http://www.theregister.co.uk/2009/05/07 ... ox_b206/



RaspberryPi
- Squeezelite music player
http://www.raspberrypi.org/faqs



DIYINHK ES9023 DAC
- 24Bit/192kHz I2S DAC
http://www.diyinhk.com/shop/home/26-24b ... lator.html



HD44780 4x20 character LCD
- Display for raspberryPi
http://www.partco.biz/verkkokauppa/prod ... cts_id=207

Installation



Logitech Media Server (LMS)



Setting up LMS is quite straightforward. I first installed 32-bit version on Ubuntu Server 13.04 to Asus Eee Box. During the install I selected to install OpenSSH Server. When installation was ready I logged in to the server with SSH.

I followed this install guide:
http://www.havetheknowhow.com/Install-t ... erver.html

Here are the steps I did:

First, edit /etc/apt/sources.list:
sudo nano /etc/apt/sources.list

Add this line to the end of the file, save and exit:
deb http://debian.slimdevices.com stable main

Get updates:
sudo apt-get update

Install Logitech Media Server:
sudo apt-get install logitechmediaserver

To start LMS you can just reboot or type:
sudo service logitechmediaserver restart

After that you can access to your server from web browser:
http://MyMediaServer:9000
(where MyMediaServer is IP or dns resolvable hostname of the LMS server)

Web configuration part of the server is quite self explaining.

Cifs install (if you want mount you media library from windows file share):

On CIFS install I mostly followed this guide:
http://ubuntuforums.org/showthread.php?t=288534

Install Cifs utils :
sudo apt-get install cifs-utils

Update the unmount order to prevent CIFS from hanging during shutdown.
sudo update-rc.d -f umountnfs.sh remove
sudo update-rc.d umountnfs.sh stop 15 0 6 .


Make folder for mount:
cd /mnt
sudo mkdir /mnt/nas
sudo chmod 777 /mnt/nas


Making permanent mounts was described here:
http://forums.slimdevices.com/showthrea ... box-server

Permanent mount:
sudo nano /etc/fstab

I added line:
//x.x.x.x/Public /mnt/nas cifs guest,iocharset=utf8 0 0

(where x.x.x.x is my Lacie NAS box IP-address)

Squeezelite player and RaspberryPi



Raspbian Linux image can be downloaded from raspberrypi.org:
http://www.raspberrypi.org/downloads

I used Win32DiskImager to copy Raspbian image to SD card.

When Raspberry Pi is powered on for the first time it starts raspi-config automatically.

You can run it later from command line:
sudo raspi-config

Changes I made:
-Expand filesystem, this allows you to use whole SD-card
-Change User Password
-Advanced Options:
--Change hostname, I used hostname “livingroom”
--Memory Split, I set GPU mem to 16MB
--Enable SSH
-Internalization Options
--Set ISO8859-15 or UTF-8 character set

First update system to use latest kernel:
sudo rpi-update
sync
sudo reboot



I followed installation guide on Rapsberry Pi forum:
http://www.raspberrypi.org/phpBB3/viewt ... mp;t=25778

Download necessary libraries:
sudo apt-get install libflac-dev libfaad2

Make new folder and download squeezelite:
mkdir squeezelite
cd squeezelite
wget http://squeezelite.googlecode.com/files/squeezelite-armv6hf


Move it to /usr and make it executable:
sudo mv squeezelite-armv6hf /usr/bin
cd /usr/bin
sudo chmod u+x squeezelite-armv6hf


Enable modules that are required for I2S. Add the following lines to the file /etc/modules:
snd_soc_bcm2708
snd_soc_bcm2708_i2s
bcm2708_dmaengine
snd_soc_pcm5102a
snd_soc_hifiberry_dac


(I found I2S enabling instructions from here: http://www.hifiberry.com/products/dac/h ... -software/)

Reboot RaspberryPi to enable I2S.

To get list of available sound cards type:
sudo squeezelite-armv6hf -l

And you should see this output:

Output devices:
null - Discard all samples (playback) or generate zero samples (capture)
pulse - PulseAudio Sound Server
default:CARD=ALSA - bcm2835 ALSA, bcm2835 ALSA - Default Audio Device
sysdefault:CARD=ALSA - bcm2835 ALSA, bcm2835 ALSA - Default Audio Device
default:CARD=sndrpihifiberry - snd_rpi_hifiberry_dac, - Default Audio Device
sysdefault:CARD=sndrpihifiberry - snd_rpi_hifiberry_dac, - Default Audio Device


Starting Squeezelite with I2S support:
/usr/bin/squeezelite-armv6hf -o default:CARD=sndrpihifiberry -n Livingroom

When this was working, I followed the guide and made Squeezelite to start automatically:

cd /home/pi/squeezelite
sudo wget http://www.gerrelt.nl/RaspberryPi/squeezelitehf.sh
sudo mv squeezelitehf.sh /etc/init.d/squeezelite

cd /etc/init.d
sudo chmod u+x squeezelite

sudo update-rc.d squeezelite defaults


Then edit settings:
sudo nano squeezelite

Modify the following lines:

SL_NAME=”Livingroom”
SL_SOUNDCARD="default:CARD=sndrpihifiberry"


Then save the file. Squeezelite will not start automatically on next reboot.
Use this command to reboot:
sudo shutdown -r now

You can also manually start, stop and update squeezelite:
sudo /etc/init.d/squeezelite start
sudo /etc/init.d/squeezelite stop
sudo /etc/init.d/squeezelite update


Adding LCD support



To get LCD display working with Rpi I first tested pyLCD:
https://github.com/Mezgrman/pyLCD

I had to do some changes to get all four lines of the display working properly. I was going to write some own code to get information to display but then I found SqueezeBerry:
http://www.emmaanuel.com/SqueezeBerry-a ... ayer-based

I was able to get squeezeberry working, but it was not suitable for my use. Squeezeberry updates the display only when it is controlled via it’s own control buttons.

LCDProc + lcdlms

After some googling I found out lcd_lms.pl script from this page:
http://programmablehardware.blogspot.fi ... g-lcd.html

lcd_lms is a perl script that communicates with Logitech Media Server and output information to LCDProc.
To get this working I first installed LCDProc using this guide:
http://ncid.sourceforge.net/lcdncid/INS ... spbian.txt

First I installed LCDProc using apt to get it start automatically::
sudo apt-get install lcdproc

LCDProc needs to be built from sources to support HD44780 display.
I started by downloading the source and extracting it:

sudo wget http://lcdproc.sourceforge.net/nightly/lcdproc-CVS-stable-0-5-x.tar.gz
tar xvfz lcdproc-CVS-*.tar.gz
cd lcdproc


To install needed build tools I had to do this:
sudo apt-get install cvs autoconf automake

Build LCDProc:

sudo sh autogen.sh
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-drivers=hd44780
make


Modify /etc/LCDd.conf:
sudo nano /etc/LCDd.conf


Here are the lines I modified:

DriverPath=/usr/lib/lcdproc/
Driver=hd44780
ServerScreen=no

[hd44780]

pin_BL=18
pin_RS=7
pin_EN=8
pin_D4=25
pin_D5=24
pin_D6=23
pin_D7=22

ConnectionType=raspberrypi
Backlight=yes
Size=20x4
CharMap=hd44780_default


Save file and test if LCDProc works:
server/LCDd -f

Install it:
sudo make install

After LCDProc was working I continued with lcd_lms install. First download the file and make it executable:

wget https://gist.github.com/jscrane/5261703/raw/3e2b6096d9984fa92eb14f7b8b1a26cc02fc3ac8/lcd_lms.pl
chmod u+x lcd_lms.pl


Lcd_lms need URI::Escape Perl library. Install it with these commands:
perl -MCPAN -e shell
->yes->sudo->yes

In Perl Shell type:
install URI::Escape

Exit when installation is done:
exit


Edit lcd_lms.pl:
sudo nano lcd_LMS.pl

Edit LMS server address:
my $LMS = "x.x.x.x";

Then save and exit.

Run lcd_lms by typing:
./lcd_lms.pl Livingroom

To make lcd_lms start automatically I followed this guide:
http://www.stuffaboutcode.com/2012/06/r ... rt-up.html

Create startup file:
sudo nano /etc/init.d/lcd_lms


Paste this into it:
#! /bin/sh
# /etc/init.d/lcd_lms

### BEGIN INIT INFO
# Provides: lcd_lms
# Required-Start: $remote_fs $syslog LCDd
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Lcd_lms
# Description: Start lcd_lms at startup. Wait that LCDProc is running first.
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting lcd_lms"
# run application you want to start
/home/pi/lcd_lms.pl Livingroom &
;;
stop)
echo "Stopping lcd_lms"
# kill application you want to stop
killall lcd_lms.pl
;;
*)
echo "Usage: /etc/init.d/noip {start|stop}"
exit 1
;;
esac

exit 0


Then save and exit

Make script executable, start it and make it start automatically:
sudo chmod 755 /etc/init.d/lcd_lms
sudo /etc/init.d/lcd_lms start
sudo update-rc.d lcd_lms defaults


Fixing äö and å characters



Lcd_lms was working fine, but I still had problems with scandinavian characters. I tried to configure LCDProc settings but I was not able to make conversion happen automatically. I ended up to modify lcd_lms script to change UTF-8 charecters to characters supported by HD44780 character set.

I wrote this conversion function:

sub map_ascends {
my $string = shift;
$string =~ s/\xC3\xA4/\x84/g;
$string =~ s/\xC3\xA5/\x86/g;
$string =~ s/\xC3\xB6/\x94/g;
$string =~ s/\xC3\x84/\x8E/g;
$string =~ s/\xC3\x85/\x8F/g;
$string =~ s/\xC3\x96/\x99/g;
return $string;
}


And used it here (# lines are replaced with new):

sub playlist {
my $cmd = shift;
switch ($cmd) {
case "clear" { clear_track; }
case "stop" { set_playing 0; set_status $cmd; }
case "pause" { lms_query_send "mode"; }
# case "title" { shift; set_title uri_unescape(shift); }
case "title" { shift; set_title map_ascends(uri_unescape(shift)); }
# case "album" { shift; set_album uri_unescape(shift); }
case "album" { shift; set_album map_ascends(uri_unescape(shift)); }
# case "artist" { shift; set_artist uri_unescape(shift); }


I used these character maps to make the string conversions:
http://www.robotc.net/wiki/Tutorials/VEX_LCD_Characters
http://www.utf8-zeichentabelle.de/

Spotify



Spotify addon can be installed directly from LMS gui. Official Spotify plugin does not work, but verion on Recommend third party plugins is working fine.

BruteFirDRC



Will be updated...

Airplay support



Will be updated...

Connecting Display and DAC to RaspberryPI



Will be updated...