Can a local server stream FLAC to Roon?

So here we go. One of the few things I’ve been missing in Roon is the ability to get any source like a phono, player, CD, player, etc and have that distributed to multiple rooms. I wasn’t particularly keen to do this with lossy formats. However, now when Internet Radio with FLAC is possible, I’ve been keen to do this for a while.
I just never got around to do it but this thread triggered my interest and Andy’s pointer to Icecast, finally got me going. My use case is that I want to be able to distribute input from Turntables in living room, dining room and office through Roon to all my Roon Zones.

I used Icecast2 as Radio Streaming seriice and Liquidsoap to capture audio in and acting as an icecast client sending that to the Icecast server. Initially I had both running in the same server, an NUC-like Dell. Since that Dell is not in anywhere close any of my Turntables, I changed the setup to run liquidsoap in an RPI3, which is located close to one of my phono pre-amps.

For this to work (with my setup examples) you need:

  • Roon up and running flawlessly
  • No network issues in your LAN
  • Server intended for Icecast up and running with Ubuntu (server) 18.04 LTS
  • Server intended for Liquidsoap, an RPI3, up and running with the latest Raspbian Stretch Lite
  • Both servers need internet access to download software (and patches)
  • A USB ADC or other digital input device is connected to the RPI3 (and some audio playing into it)

Login to your server intended to be Icecast server with ssh,

This server does not need to be connected to your ADC
In my case this is a Dell similar to NUC i5 running Ubuntu Server 18.04 LTS

Get latest patches and install Icecast2

sudo apt update && sudo apt dist-upgrade -y
sudo apt install icecast2 -y
#Enable start at boot, start and check status of the iceast2 service
sudo nano /etc/default/icecast2 
sudo service icecast2 start
sudo service icecast2 status

If everything went ok you should see the service running now
In case your concerned with security change the admins an client passwords but for instruction purposes I left it default keeping this setup simple
#sudo vi /etc/icecast2/icecast.xml
#sudo service icecast2 restart

Check the error log to see that it seems to be running and for error from Client connections, etc.
tail -f /var/log/icecast2/error.log

With a browser you should now be able to access your Icecast server on http://ipaddress_of_youriecastserver:8000
When prompted for username and password, username is admin and password hackme

In another Terminal Window login to server you intend to use as Liquidsoap server and Icecastclient
With the setup here your ADC (or other digital input) must be connected to this server
In my case, this is an RPI3 running latest Raspbian Stretch Lite

Install latest pacthes and install alsa, in case it’s not already installed

sudo apt update && sudo apt dist-upgrade -y
sudo apt install alsa-utils -y 
#Add user pi to group audio so you can run alsa stuff without sudo at next login
sudo usermod -a -G audio pi

#Install Liquidsoap and plugins for alsa, flac and ogg        
sudo apt install liquidsoap  liquidsoap-plugin-alsa liquidsoap-plugin-flac liquidsoap-plugin-ogg -y

#Add liquidsoap user to audio group (see above) and pi to  liquidsoap group for similar reasons 
sudo usermod -a -G audio liquidsoap 
sudo usermod -a -G liquidsoap pi

Change permissions on various liquid soap directories and files, probably a bit too open

    sudo chmod 666 /etc/logrotate.d/liquidsoap
    sudo chmod 777 /var/log/liquidsoap
    touch /var/log/liquidsoap/phono.log
    sudo chmod 666 /var/log/liquidsoap/phono.log
    sudo chmod 777 /run/liquidsoap
    sudo chown liquidsoap:liquidsoap /etc/logrotate.d/liquidsoap
    sudo chown root:root /var/log/liquidsoap
    sudo chown liquidsoap:liquidsoap /var/log/liquidsoap/phono.log
    sudo chown liquidsoap:liquidsoap /var/run/liquidsoap
    sudo touch /etc/liquidsoap/phono.liq
    sudo chmod +x /etc/liquidsoap/phono.liq

Now we can setup liquidsoap
First we check what’s the device number for your ADC

`sudo aplay -l`
#This was the output for me
pi@liquidsoap:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card *1: M20 [MC-1.2 USB 2.0], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

As can be seen device number was 1 for me, this will be used in the setup below
Then we check if your icecast server is reachable via name or ip.
Remember to change mydell.local to your icecast servers hostname or ip address.

ping mydell.local

Finally we edit the iquidsoap script

#sudo vi /etc/liquidsoap/phono.liq
sudo nano /etc/liquidsoap/phono.liq

You can paste the below

#!/usr/bin/liquidsoap
#set the path and permissions for the logfile
set("log.file.path","/var/log/liquidsoap/phono.log")
set("log.file.perms",777)
set("log.unix_timestamps",true)
#input from soundcard
phono = input.alsa(bufferize=true,fallible=false,device="plughw:1")
#stream it to local icecast, default port and password
output.icecast(%ogg(%flac(samplerate=44100,channels=2,compression=5,bits_per_sample=16)), 
   mount='/phono', name='Phono', format='audio/ogg', description='Phono FLAC', 
  password='hackme',  host='mydell.loca'l, port=8000, url='http://mydell.local:8000/phono', 
  genre ='Misc', phono)

Then change
“plughw:1” to use the device number from aplay -l and mydell.local to resolvable hostname or ip address of your icecast server. Now, save and exit from the editor

(Those fluent in alsa will notice that I used plughw, if you can get hw:1 to work that might suit you better.)

You can start liquid-soap now.

/etc/liquidsoap/phono.liq

If everything is set up correctly, it should start, if not, it will return with our without error message
To find out more

tail -400f /var/log/liquidsoap/phono.log

Given that it went fine you should now see the mount point /phono at http://ipaddress_of_youriecastserver:8000/admin/
Copy the value of the server_url, then click “+Add a Station” in Roon “Internet Radio Stations”, paste the url and click Add Station, and confirmed
Now you should have a Radio Station in Roon that plays whatever you send input into your liquidsoap server

Comments.
To my surprise liquid soap didn’t need any setup at all to auto start at boot, it just worked after reboot.
Meaning no extra setup for restart at boot This may or may not be the case for you.

To get liquidsoap to work in Ubuntu 18.04 LTS, I had to deinstall the opus plugin, i.e.
apt remove liquidsoap-plugin-opus -y

If the stream stops Roon May throw an error message and you need to press play again.
I have not looked into why yet but pretty sure there’s a setting in icecast and or liquidsoap.

Credits
Credit goes to Icecast & Liquidsoap teams, IOT-Solutions and of course Roon and Andy. Cheers guys!

http://www.icecast.org/

http://liquidsoap.info

16 Likes