Chris Marquardt's Soapbox

MP3 Streaming Mini Server Based On Raspberry Pi

Update: you can see a picture of it set up and in action here

So I do this German photography podcast called Happy Shooting, and almost every week, we record the show and stream the recording live to our listeners. Usually Tuesdays at about 5pm. Check it out if you want to improve your German. …on second thought, not too sure how much your language skills could benefit from it :)

Long story short, my co-host lives an hour South from here, so we do our recordings remotely. Back when we still used Skype, that wasn't too hard, we'd use Nicecast on the Mac to stream to our Icecast2 streaming server and all was good. But when we tried to switch to Mumble (better sound quality, uses the legendary Opus codec and has less latency), despite the name Nicecast wouldn't play nice with it.

Many tests later I was ready to try a hardware solution. Just that there wasn't such a solution available on the market within the limits of my budget.

A friend pointed me towards the Raspberry Pi, a tiny credit-card sized USB-powered computer. He was spot on.

Gladly I'm geek enough (and have a serious unix command line history) that this proved just to be the right challenge. I ordered a bare-bones Raspberry Pi (35 EUR on and a plexiglass case (8 EUR) and an 8GB SD card (11 EUR). Power supply is generally not needed, as the RPi gets its power through a micro USB port, so any powered hub or computer can power it.

Here's a quick account of how I turned the Raspberry Pi into a server streaming MP3. You'll need to be happy to use the command line to do this:
  1. download the latest Raspbian image (that's a Debian distribution prepped for Raspberry) and prepare an SD card with it. » link (make sure you don't dd the image onto the wrong disk or you might hose your system)
  2. boot the RPi off the card, no HDMI screen required, it'll come up in headless mode, it will grab an IP from your DHCP server and allow you to log in via ssh (user pi, pass: raspberry - change the password!)
  3. run "sudo raspi-config" to expand the filesystem, change the user password, enable boot into command line, set overclocking (see below), set the hostname (mine's "streamer"), change the memory split to 16MB for the GPU to (smallest amount possible, as it's headless), update the tool itself
  4. hook up a USB sound card. In my case it's an ESI U24XL
  5. set up darkice as the streaming software. darkice will grab audio from the ESI's inputs and stream it for example to an icecast2 server. » link (I compiled mp3 support into the system based on this page). To list the available audio inputs, try "arecord -l"
  6. I had to overclock the RPi to 950MHz to stop the buffer overflows
  7. As a single-task device are too many unneeded services running in the background, so whenever I start the stream, I first disable the clutter. There's a script here that helped me tremendously.
On the receiving end (a linux server at a hoster) I run an icecast2 server that receives the stream and distributes it to the audience.

Now I hook up whatever I want to stream to the ESI audio interface, start the stream and voila: sound sent out to the world.

Of course, solving one problem often results in the need to solve more problems on the way and this case was exactly one of those. Namely: how do you get analog sound out of your Mac that contains both sides of a Mumble conversation while not feeding back their own voice to your Mumble contact. We call that "mix minus one" and it requires some Mac-internal routing. Long story short: JackOSX to the rescue. Takes some time to understand the routing (watch a few YouTube videos and you'll learn) but it seems powerful and flexible enough to do exactly what I need it to do. I might go into more detail in a separate post one day, but for now that'll have to do.

Oh, one last thing. I noticed that with the overclocking the processor got a bit hot to the touch, so I did some measurements using the "/opt/vc/bin/vcgencmd measure_temp" command which returns degrees Celsius and it was constantly beyond 50C. Not too hot, but I still ordered some heatsinks (amazon, 5 EUR). They simply stick on and reduce the temperature by a few degrees. Might help prolong its life, but hey, even if it doesn't, who cares, it looks really cool.