Using the Raspberry Pi as a Streaming Radio Source

A friend of mine from Mutiny Radio picked up a Raspberry Pi as a potential replacement for their on-the-fly mp3-encoding / up-streaming machine. Theoretically the 700MHz chip on this little computer should be able to handle the job, so this past weekend I started the process of exploring its capabilities.

Raspberry Pi: "It takes a while!"

After deactivating Raspbian’s tremendously greedy GUI, the rPi has horsepower to spare. However, its Linux distro “raspbian” is limited by the fact that it is itself a subset of a limited debian distribution for ARM processors.

Consequently, while darkice can be found in raspbian’s standard repositories, you can’t get mp3 streaming due to debian’s draconian anti-mp3 laws, and you won’t get mp3 support just by installing liblame. You gotta compile darkice from source.

Fortunately, Steffan Muller over here wrote a nice tutorial on how to compile darkice for raspbian, which was sweet because I hate mucking around with debian distro stuff. His tutorial shows you how to compile mp3 and alsa support into darkice and then fold it back into the debian package system.

Just be aware, compiling from source on the raspbian is… let’s just say it takes me back to the early days of Gentoo. Which makes sense, because 700MHz basically represents a top-of-the-line laptop circa 2000.

With a streaming source (finally, arduously) compiled, I needed to then find a suitable USB audio device. The MAudio Transit lying in my “audio gadgets” box was a lost cause, but a beat up old Griffin iMic, despite failing to work on both my MacBook Pro and my Windows 7 desktop, worked like a charm, save for a bit of distortion that doesn’t resolve when I adjust the levels.

The power handling on the rPi is damn impressive, but it’s possible that the audio distortion comes from running a USB wifi card alongside the USB audio device. I don’t have a powered USB hub at my disposal, so I will update this post when I got a hold of one and try that out.

I have now run darkice continuously for 24 hours from the Raspberry Pi, streaming it up to my linode-based server (which also hosts Mutiny Radio and Radio Feliz Navidad Forever as well as yet another toy radio station in the works that I will reveal in a week or two).

The load average just running darkice to produce a 128kbps stream (with no recording) has been about 0.9, making this setup just fine as a single-serving appliance. In the past we’ve liked to run dual encodings, one at 128kbps and one at 192kbps, with the latter serving as an “archival” stream to be recorded, but there are less CPU-wrecking ways to achieve this, like splitting the audio off to a separate machine to record it there. With the RPi as inexpensive as it is, the idea of getting a second one to handle the recordings makes a lot of sense and contributes to the sort of “appliance-y” feel of this approach.

So with the audio distortions sorted out, and potentially producing my own mini raspbian repo for darkice and attendant libraries, I’d say using the Raspberry Pi to run a streaming radio station is a sure thing.

Update: it does seem that the old iMic was causing the distortions. Hooray for throwing money at a problem.

I’m now using a behringer U-Control UCA202 “ultra-low latency” 2 In / 2 Out USB interface, bought from Amazon for roughly $30. The Raspberry Pi recognizes this device right away.

The only weird part is that this device has no capture controls. Like, when you go to alsamixer to adjust levels for your cards, you get nothing for the input controls on this device. Indeed, the chip has no capture controls.

Despite that little piece of configuration vertigo, darkice can “hear” the RCA input just fine. I have my device line set to hw:1,0 to capture.

All in all, using the Raspberry Pi has felt a lot like… well, like setting up a laptop from the year 2000. It took a lot of updating the OS and compiling quite a few libraries from source to get things going, which involved a few hours of waiting.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

  • Oren Beck

    Good work on getting someone=me:} intrigued by potentials. It’s now time for me to get a Pi and learn how these layers work. I may make an over-the-summer project of seeing if any Puppy Linux incarnations for Pi could make shorter work of this. Specifically being Slacko Puppy as it’s Less Liable to be Audio Impaired..

    Hmn- What of Other Codecs? Just thinking dare the pun- Aloud.

    • nthmost

      Hey Oren — do report back on the use of Slacko on raspi. I’ve been a fan of Slackware since 1996. :)

      Other codecs, aside from mp3 and ogg? Even though darkice supports ’vorbis’, ’mp3’, ’mp2’ and ’aac’ (‘vorbis’ meaning ogg, basically), it’s hard to recommend using any.

      The problem with straying too far afield when it comes to codecs is ability to listen to the output in various clients. Even ogg is pretty unevenly supported (it’s not even supported in iTunes).

      Meanwhile, Firefox has stopped supporting mp3 due to its status as a patented, non-free codec. (Technically, anybody who implements the mp3 codec should be paying a patent license fee!)

      Most players do support aac these days, but I am not sure how much I can guarantee that. On top of that, when I want to manipulate audio feeds to do interesting things like automatic crossfading between sources, AAC throws a huge monkey-wrench in those plans. I have not found an audio toolkit yet that didn’t choke on AAC stream manipulations.

      It all just bites, basically. There are no correct answers to the codec question right now.

  • Patapoe

    I am replacing the server for our radiostation to a raspberry pi and i wonder if you changed anything in the alsa configuration? Like setting usb to be default?
    You State the behringer was immediately recognized but is is it also default in alsa mixer?
    You also write that your config setting in darkice.cfg is hw:1,0, this make me think you indeed changed USB to be the default device!

    Nice write up!

    • nthmost

      Hi Patapoe,

      I didn’t have to change anything in alsa configuration. To be honest I find ALSA to be a bunch of voodoo.

      Any USB device you plug into the R Pi will /not/ become the default, and I didn’t set it to be default, either.

      You should just be able to plug in hw:1,0 to the device field of the darkice settings and have it work. Unless, of course, you’re plugging in TWO usb devices audio devices and you want to have the third one for darkice, in which case you’d probably end up doing “hw:2,0” — get my drift?

      Thanks for the kind words! Good luck and please report back on this post if you have any success or trouble!