Search This Blog

Loading...

Friday, January 25, 2013

Squeeze Me Lite


Latest update: 10/08/2013 - Annex  added : Squeezelite on Ubuntu Server

 

I'd like to introduce you to a tiny squeezebox streaming client called Squeezelite.

Squeezelite is a highly efficient squeezebox emulator that runs on all PC platforms, micro PCs like a Raspberry Pi and even on routers and the Squeezebox Touch . 
It's opensource and free of charge.

Squeezelite is written and maintained by Adrian Smith also known as Triode.    
Adrian Smith, the person, who also provides the EDO plugin (USB support) fo
the Squeezebox Touch.


Squeezelite runs headless. Headless because it acts like a systemservice in the background of your OS and it doesn't require a Windows environment. 
You set it up once and then you forget about it.


Annex 1: Installation instructions Ubuntu Server
Annex 2: compiling instructions
Annex 3: a wrapper script you can use on a PC, Raspberry or SB Touch




You can control the Squeezelite via all known Squeezebox remotes. 
At startup SL tries to figure out all parameters automatically. 
You mainly have to configure the output device.
 

Squeezelite also supports gapless playback.


Squeezelite is pretty similar (it adds higher sample rate support and bitdepths) to squeezslave that's been around for years, but never really worked satisfactory. 
It was limited to samplerates up to 24/48khz and also came with other flaws.  


Obviously for running Squeezelite you need to have a Logitechmediaserver up'n running.

You can run Squeezelite and the Logitechmediaserver on the same machine without 
any issues. In this case Squeezelite even passes the networking routines by.


The audio traffic will be routed to your audio interface of choice at up to "32/384khz"! 

Your Dac (or OS driver) sets the limits. DSD is not supported yet.
 
You can use Squeezelite pretty much on all platforms - OSX/WIN/Linux and many different processor architectures (even on your Open-Wrt router or Raspberry PI devices it'll work).

 
On Windows there's no ASIO, Kernel Streaming or WASAPI exclusive support at this stage of the project. I wouldn't consider Windows and OSX the prefered platforms for Squeezelite anyhow.


I made Squeezelite work on the SB Touch. It took me a while to get it working along my Toolbox. It wouldn't mate very well with my Toolbox parameters. I had to reshuffle quite 
some parameter settings. Once done, I realized that this little gadget performs 
better then the standard/tweaked Logitech setup on the Touch. 
It'll use much less resources and acts highly efficient. For sure it'll stay.

If you look for transports replacing your beloved SB Touch or Duet, you might achieve similar performance with e.g. Squeezelite on a Raspberry PI or similar and e.g. a Hifimediy Sabre USB DAC (roughly 35$+45$+some PI gadgets such as power supply, box etc. @ 100$ in total). Obviously the sky is the limit. Attach a very nice DAC or SPDIF interface to the RPi or Cubox or whatever device and you'll end up with a top end audio transport.

There's a project ongoing which is called Community Squeeze  . This project provides complete OS images (Linux based on Fedora)  for PC and Wandboard use.  

It's a non-profit project jointly establisded by Adrian (Triode), John Svensson (who plans to provide audio HW for the Wandboard) and some others.



Beside that there are more little projects popping up every other day, such as PicorePlayer. These folks basically take a basic OS, install Squeezelite and put the image on the net. (( And then it's called "audiophile" ))

As a user with an external DAC or audio interface at hand, you basically buy a Raspberry and copy the provided .iso-image on a SD-card, plug it in, boot your PI up and you're ready to go. 

Those efforts must be highly appreciated. These packages are all free. 
And with these you can easily replace 1k+ equipment as provided by companies like 
Linn or NAD or similar.


Just to mention it: iPad and Droid tablets as well as phones can already be used as squeezeboxes through the commercial apps iPeng-player and squeezeplayer. These
are also Squeezebox emulators.
You'll find these apps for a couple of bucks in the known app stores or as in-app purchases.
If you own a tablet or phone you should consider to use it as streaming client. 
These will do it better than a basic Raspberry Pi (have look at my Raspberry PI article).

Bottom line.



Nowadays we basically can make every linux based coffeemaker in the house part of the Squeeze Streaming Universe at very little efforts. There's no need to spent thousands of $ on commercial streaming clients.



With Squeezelite, as well as Squeezeplayer, or iPeng-player, there's no need to have  Logitech Squeezebox streaming hardware anymore. 

Therefore - no worries - even without SB Touch in the market, we'll survive. And there's a good chance that we have to spent much less for an installation.

One word about the "competition":

When comparing squeezelite to MPD I found that Squeezelite uses roughly 50% of CPU power compared to MPD. Beside that Squeezelite can be configured to buffer a full track
in memory. There are several more reasons, (coverart handling etc.)  why  I prefer squeeze-environment.


 
Thx to Adrian  to drive the opensource evolution of free headless Squeezebox clients.  


Adrian is very open for supporting the community: feedback over @ SB forums.




Great stuff.    Enjoy.    I do.


Stay tuned. 




#######################################################################

Annex 1:

A basic Squeezelite installation on Ubuntu Server

(duration: approx.  20 minutes on top of Ubuntu Server installation)
 
Let's assume you've got an Ubuntu server 13.10 (best to use this one -- even if not officially released yet). You'll get the newest kernels!!! (drivers and networking have been improved a lot form kernel revisions >3.10 onwards), newest Alsa drivers, newest compilers...
I assume you run a 64bit machine (of course you can also run 32bit machines, just download the squeezelite 32 bit binary instead).

There is a reason why I recommend Ubuntu Server as base. By running Ubuntu server,  we do not have a windowsmanager, numerous background services and no pulseaudio installed. I consider this a very good starting point for a headless quality audio server.


Let's get started.


What's needed are roughly 10 commands on command-line to get it working.

What you do is following: 



#################

1. Login as user X.


2. we do everything as superuser (root) from now on


sudo su
cd /usr/local/bin

3. let's install some apps and a lowlatency kernel first


apt-get install wget alsa-base alsa-tools alsa-utils alsa-firmware-loaders
apt-get install flac sox libsoxr0 libsoxr-lsr0 linux-lowlatency


NOTE: I highly recommend to install the latest Ubuntu kernels > 3.10 !
           if you don't use the latest Ubuntu.
           You'll find instructions about it on the net. For now you can skip it.
           Unless your audio device is not recognized or you experience dropouts
           you won't get around a newest kernel anyhow.


4. now we fetch the squeezelite binary for our 64 bit machine from the internet.

wget https://squeezelite.googlecode.com/files/squeezelite-x86-64

cp  squeezelite-x86-64 /usr/local/bin/squeezelite

   on 32-bit machines the binary is called: squeezelite-i386 , change above 
   commands accordingly.

5. now we make the binary executable.

chmod 777 ./squeezelite

6. now we can test if squeezelite is working.

squeezelite -h

    All squeezelite commandline options should be listed.

7. now we backup a file that we use for autostarting squeezelite at boot.

cp /etc/rc.local /etc/rc.local.orig

8. find out about your soundcards and the index linux uses for each of them.
    we do not use the device IDs as listed by squeezelite.
    if your soundcard does not show up you have a problem!

cat /proc/asound/cards

     let's assume your output looks similar to this:

     me@yabba1saucy:~$ cat /proc/asound/cards


      0 [UD501          ]: USB-Audio - TEAC UD-501
                          TEAC Corporation TEAC UD-501 at usb-0000:00:1a.0-1.3, high speed
 

    now we know that our soundcard is recognized and got index 0 assigned.
    the first column in above printout shows a 0. That reflects its index.

9. now we've to prepare the squeezelite command string that goes into /etc/rc.local
    below string should do. In my case it even worked, if run in parallel on the LMS server
    
    My base squeezelite setup: 
    squeezelite runs at realtime-prio 95, the output thread at 97, 
    SL streams bitperfect straight to output hw:0,0 and shows up as yabber1


    The fastest way to get the string into /etc/rc.local, type

echo -e "chrt -f -p 95 /usr/local/bin/squeezelite -o hw:0,0 -p 97 -n yabber1 -z\n$(cat /etc/rc.local | grep -v "^#" | grep -v "^$")" >/etc/rc.local
  
     check the result, by typing

cat /etc/rc.local

      as first line of the printout you'd find our commandline:

      chrt -f 95 /usr/local/bin/squeezelite -o hw:0,0 -p 97 -n yabber1 -z 

      If not, something went wrong! Make sure you get it fixed first before continuing.


      If you're familiar with commandline editors such as nano/vi/vim or similar, you 
      could also use one of those to add above command to /etc/rc.local.

      You can edit /etc/rc.local by running

      nano /etc/rc.local
      to apply any changes.


10. if all looks ok, you can execute rc.local now. Just enter:

/etc/rc.local 

     NO error messages at this point ??? Great. Almost done.
     Check if the squeezelite process is running:

ps -edf | grep squeezelite

11.  now reboot the machine, to activate your new low-latency kernel.

sudo shutdown -r now

       Login again. Check what priorities are assigned to SL AND its threads
       and the new kernel:

ps -eo pid,pri,rtprio,cmd  -L  | grep squeezelite
uname -a

       you'll see the playback thread of squeezelite running @ rtprio 97 and all other
       threads @ rtprio 95.

       Hint:
       you properly shutdown a linux machine by running!!!!


sudo shutdown -h now

12.   To restore the system pretty close to its initial state, just run:


sudo cp /etc/rc.local.orig  /etc/rc.local
sudo apt-get remove low-latency 
sudo shutdown -r 0


13. TRAPS:

      Usually you can't avoid falling into this or that trap.

      1. soundcard not recognised: newer kernel/driver required

      2. no sound even if process is running: alsamixer volume control low

      3. /etc/rc.local messup: restore to original
   



Good Luck, Enjoy


#######################################################################

Annex 2: 

Manual compilation on Ubuntu/Debian based systems
(duration: approx. 10 minutes)


There are all kind of squeezelite binaries available. But you might be forced to compile it on your own.  
I even think it's even better to compile it by yourself, since the code will 100% match your own system environment (kernel/compiler/libraries). 
And beside that you'll always have the very latest squeezelite code at hand.


I prepared a little HowTo. It's really simple.



The process is pretty straight forward:

1. Open a terminal

2. First you have install the required development packages:


sudo apt-get -y install build-essential git wget patch checkinstall  libasound2-dev libmad0-dev
sudo apt-get -y install libflac-dev  libogg-dev libvorbis-dev libfaad-dev libmpg123-dev libsoxr-dev


3. Then you download the sources: 

cd ~
git clone https://code.google.com/p/squeezelite/

4. Now you compile the binaries

cd ~/squeezelite
make clean 
make

5. If everything worked out well, you'll find a squeezelite binary in the folder.

To check it out, type:


./squeezelite -h

If it prints all commandline options, it's working.


6. Now copy the binary to /usr/local/bin and make it executable:


sudo cp -f ./squeezelite /usr/local/bin/squeezelite
sudo chmod 777 /usr/local/bin/squeezelite

Done. Reboot & Enjoy.


#######################################################################

Annexx 3:
 
A wrapper script for Linux  - called "squeeze".

To make life easier, it's good to (automatically) start the squeezelite binary with all its options by a wrapper script

Below you'll find a little guideline. It'll need some minor adjustments from your side.


This exercise is really optional.


Open a Terminal.

cd ~
touch squeeze
nano squeeze

Copy/paste below code into the editor. You need to fill in appropriate parameter in the PARAMETER section below and save it.


#!/bin/sh
#
#
# squeezlite wrapper script
# written by Klaus Schulz
#
# Rev 1: 01/28/2013
#
Rev 2: 09/09/2013
#
###PARAMETER##############################################################################################

LOCALETHERNETPORT=ethX          ## run "ifconfig" to find out the active ethernet port, e.g. eth0, wlan0 or similar
 
AUDIOIF="hw:0,0"                              ## audiointerface as listed by squeezelite -l, or cat /proc/asound/cards
                                                           ## standard alsa naming conventions can be used. E.g. hw:0,0 or plughw:1,0

## below parameters are optional! To activate or disable minimal command line or  extened command line,
## insert/remove a "#" on respective lines in the code

SERVERIP="127.0.0.1"                      ## (optional) This IP is used if squeezelite runs on the server, otherwise put "#" in front of line
#SERVERIP="XXX.XXX.XXX.XXX"    ## (optional )server IP on remote client, run ifconfig to find out, if run on server put "#" in front of line
PLAYERNAME=sl1                             ## (optional-default squeezelite) choose whatever name you want to show up on the controller

MAXSAMPLERATE=96000                ## (optional) This sets maximum samplerate as supported by the local DAC - up 2 384000
ALSABUFFER=32                            ## (optional-default 20000) Alsa outputbuffer in milliseconds
PERIODS=4                                       ## (optional-default 4) Alsa buffer devided into number of periods
BIT=24                                             ## (optional-detected by SL) bit depth of output 16, 32, 24_3 = 3 bytes, 24 = 4 bytes
STREAMINGBUFFERIN=2048           ## (optional-default=2048) streaming buffer input kilobytes

STREAMINGBUFFEROUT=2048       ## (optional-default=3446) streaming buffer output in  kilobytes
MMAP=1                                            ## (optional-default=1) Alsa memory management off/on  0/1
RTPRIO=70                                        ## (optional) realtimepriority of squeezelite

CODEC=pcm                                      ## (optional-default all codecs (flac,pcm... see squeezlite -h) are loaded)

###MAIN#####################################################################################################

BIN="$(which squeezelite)"

[ -f "$BIN" ] || { echo "squeezelite binary not found" ; exit 1 ; } ;

LOCALMAC="$(cat /sys/class/net/$LOCALETHERNETPORT/address)"

[ "$( pgrep squeezelite )" != "" ] &&  killall -9 squeezelite


sleep 1   

## minimal command line - put hash in fronmt of next line, if you use 2nd command line
$BIN -m "$LOCALMAC" -o "$AUDIOIF" -z

## extended command line -- use that if you use script on Touch - remove hashes from next two lines.
#killall jive; sleep1
#chrt -f $RTPRIO $BIN -m "$LOCALMAC" -o "$AUDIOIF" -n "$PLAYERNAME" -c  $CODEC -a "$ALSABUFFER:$PERIODS:$BIT:$MMAP" -b "$STREAMINGBUFFERIN:$STREAMINGBUFFEROUT" -r $MAXSAMPLERATE -z $SERVERIP

exit 0

############################################################################################################ 
#END########################################################################################################
 

Then you copy the script to /usr/local/bin 

sudo cp squeeze /usr/local/bin
 
and make it executable

sudo chmod 777 /usr/local/bin/squeeze

Now you can start it:

squeeze  

Type

ps -edf | grep squeeze

You should see the squeezelite process printed. 
Now check your prefered remote, if you can find the new player id listed. 

Done. 

For automatic start at boot you might add ( above "exit" )  to /etc/rc.local


sudo nano /etc/rc.local

add

/usr/local/bin/squeeze &

above exit 0

save and reboot.


NOTE :  Low-Latency resp. Realtime kernels.

             You might have realized that I lift the process into realtime spheres when
             starting it up.
             That requires an rt-kernel or lowlatency kernel as supplied by Ubuntu Studio.
             Over here you'll find some useful information how to set such kernel up. 
             Keep in mind that those preempted kernels are meant for single-purpose
             machines. These kernels are not recommended for desktop machines or

             servers that run all kind of server duties.

             squeezelite lifts the output thread up to sched_fifo (kernel scheduler) if you
             run a so called preemptible kernel. squeezelite applies priority 45 internally. 
  
 


#############################################################################
####END
############################################################################# 


2 comments :

  1. Is it possible to publish a tutorial on how to install squeezelite on a SB Touch? I haven't got a clou about where to start.

    ReplyDelete
  2. Copy that! I have been searching for a tutorial or description how to install squeezelite on a touch... cant find it :-(
    Would be very much appreciated!

    ReplyDelete