Making Squeezelite play well with KODI under Linux

The default settings for Squeezelite on Linux require it capture your sound card and hoard all audio for itself. This can be frustrating when the computer’s audio is shared with other programs.

Sharing is caring

The good news is that the latest version of Squeezelite (1.8) can be configured to release the sound card when it is not playing music. The bad news is that the Ubuntu software center has version 1.4 as of this writing. This is a problem for my Ubuntu-based KODIbuntu boxes. You may be able to find a .deb or a PPA with the latest, but I prefer to break out the terminal and get my hands dirty. Thanks to gene1wood on GitHub, we have a map.

First we install the old version of squeezelite and some build dependencies

sudo apt-get install squeezelite
sudo apt-get install libasound2-dev libflac-dev libmad0-dev libvorbis-dev libfaad-dev libmpg123-dev liblircclient-dev libncurses5-dev git build-essential

Download the source code

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

Compile

cd squeezelite
OPTS=-DINTERACTIVE make

Finally, overwrite the outdated program with the new hotness.

sudo cp squeezelite /usr/bin/squeezelite

Now that we have the latest version we need to configure it to share the sound card. Open /etc/default/squeezelite in your favorite editor and add the -C option to SB_EXTRA_ARGS. Don’t forget to uncomment it by removing the # at the beginning of the line.

sudo nano /etc/default/squeezelite
SB_EXTRA_ARGS="-C 3"

Press Ctrl+x to close and Y to save. These options tell Squeezelite to release the sound card 3 seconds after it has stopped playing. Restart the service and test it out

sudo service squeezelite restart

Choose your own adventure

I also had issues with squeezelite playing on the wrong sound card. I’m sure there is a way to set the default sound card, but since this post is about squeezelite, let’s work with that. To get a list of available sound devices run the following command.

squeezelite -l

This command will produce a lot more devices than you might expect. You should be able to stick to the any devices that start with “hw:” and ignore everything else. If, for example, I wanted squeezelite to send audio to the second HDMI port on my NVIDIA graphics card. I would use this one

hw:CARD=NVidia,DEV=8           - HDA NVidia, HDMI 2 - Direct hardware device without any conversions

The text on the left is the device identifier. In my example: “hw:CARD=NVidia,DEV=8”. We can now enter that ID into /etc/default/squeezelite. Once again, remember to uncomment the line and add your device ID.

SL_SOUNDCARD="hw:CARD=NVidia,DEV=8"

Save the file and restart the service.

sudo service squeezelite restart

 

Starting up smoothly

While Squeezelite is now happy to let other programs take turns with the sound card, it still needs exclusive access to the sound card when it is first started in order to determine the capabilities of the card. This, again, was a problem on my KODI boxes where KODI is given exclusive control during the boot process. To work around this we need to tell Squeezelite the maximum sample rate supported by the sound card so that it does not need to look it up.

We can find out the max sample rate supported by the sound card by running squeezelite in debug mode. For this to work, Squeezelite will need access to the sound card so make sure nothing else is using the sound card, then run:

squeezelite -d output=debug

Press Ctrl+C to stop it after a few seconds. We’re looking for the line that contains “supported rates” followed by a bunch of numbers.

$ squeezelite -d output=debug
[17:54:52.520886] output_init_alsa:817 init output
[17:54:52.520920] output_init_alsa:846 requested alsa_buffer: 40 alsa_period: 4 format: any mmap: 1
[17:54:52.520929] output_init_common:346 outputbuf size: 3528000
[17:54:52.520951] output_init_common:370 idle timeout: 0
[17:54:52.528766] output_init_common:410 supported rates: 192000 176400 96000 88200 48000 44100 32000 24000 22500 16000 12000 11025 8000

Note the biggest number in the list. On my machine that is 192000.

We now return to /etc/default/squeezelite and add the max rate information as follows. Replace 192000 with the number from your machine.

sudo nano /etc/default/squeezelite
SB_EXTRA_ARGS="-C 3 -r 192000"

Save the file and restart the service

sudo service squeezelite restart

Hopefully you can now painlessly play music on your machine via squeezebox, KODI or another music player. I’ve found that switching between programs can take 10-20 seconds sometimes so if the music does not start instantly, wait a minute before you give up on it.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>