It’s a weird one. When it first came out, people were struggling to figure out what to do with it. A surprising feature for something that sold out very quickly – the Raspberry Pi.
Well, we’ve now come up with another use for them – it could replace your current STL codec. No, really. We’ve got a hospital radio station that’s looking to replace an old twisted pair line with an ADSL line for cost reasons. Admittedly the Barix Extreamer is very nice but a bit costly for our purposes. On top of that, we can configure the Pi to have some more complex fallback and alerting options with the LiquidSoap software. And that’s what I’m going to talk you through – setting up a Pi as a remote end codec.
So, without further ado:
- Acquire a Raspberry Pi. Purchasing one from CPC/Farnell is much more appreciated than nicking one from your colleague.
- Install Raspbian. It’s not that complicated and there’s a lot of guides out there.
- However, when you get to the installer wizard bit, we want as little RAM as possible for the GPU (I don’t know of many codecs that need 3D graphics with fancy shaders), to turn off boot to desktop, to set a sensible password for the pi account and to enable SSH.
- Fire up your Pi and install LiquidSoap. The command is literally apt-get install liquidsoap
- If you’re pulling an MP3 stream or planning on using MP3 backup audio, you’ll need to install some of the LiquidSoap plugins.
Create a file called /home/pi/stl.liq and bung in the following contents:
# STL Liquidsoap Config
# Setup our sources
main_url = “http://yourserver:8000/stream_name”
emergency_audio = “/home/pi/emg.wav”
# Now our e-mail alert routine
# Our main source is streaming with silence detection
radio_stream = input.http(main_url)
radio_stream = on_blank(silenceHandler, radio_stream)
# Fall back to an MP3 file
# Also worth noting, if we get this far, we ought to tell someone (if we can)
emg_file = single(emergency_audio)
radio_stream = fallback(track_sensitive = false, [radio_stream, emg_file])
# Finally, pump it out the soundcard
- Add a line to /etc/rc.local before the exit command with the following:
sudo -u pi liquidsoap /home/pi/stl.liq &
That will start LiquidSoap on boot – awesome.
- Copy a backup audio file to the Pi. On this system we called it emg.wav. You can call it whatever you want but you will need to change the above script.
- Run alsamixer and bump the levels all the way up (for most installs).
Reboot and you’ll have a little codec. Try pulling the network lead out and seeing what happens.
So, that’s is all configured and running but what does it do. Well, by default it will pull a web stream from the URL of your choice and play it out of the sound card. If it goes silent, it runs a script called mailsend.pl. This is a shifty little script that we have to e-mail us when things go silent.
However, if the stream fails completely, we fall back to playing the emg.wav file on loop. Sounds good but it’s worth remembering that it will resume the backup file from wherever it stopped last on every subsequent failure. While that might sound odd to the ear, you don’t end up hearing “She Wolf” every three minutes when the ADSL line flaps.
*May not actually be Sony Award winning.
PS – I know there’s a phone number on the CODEC. However, it’s the public studio line so not that big of a deal. 😉