Getting nice sound from the Raspberry Pi

Published: February 28, 2013
Tags: audio behringer dac pwm uac202 raspberry pi

For Christmas last year, my wife bought me a Raspberry Pi, which earned her some serious brownie points! I had quite a few teething problems getting started with it, but it's working quite nicely at the moment, doing two main tasks: acting as a mini file server using a USB hard drive and Samba, and acting as a music player (I've got it hooked up to my home made amplifier).

Probably the single greatest disappointment I have with the Pi is with regards to sound. The Pi comes with a standard 3.5mm stereo socket for analog audio out (it can also go digital audio over HDMI), and when I first wanted to start playing music over the Pi I used a 3.5mm TRS to RCA converter to plug it into my amplifier. Big mistake! The DAC for the Pi's analog audio out uses pulse width modulation, which is a technique I've actually used before myself to get audio out of an Arduino. It's not really an ideal solution for music, and in the case of the Pi the DAC has an effective resolution of just 11 bits!. CD quality audio uses 16 bits, which means the Pi's resolution is 32 times lower than what you need for CD quality. I am definitely not one of those golden-eared audiophile types (see again my dirt cheap single chip amplifier, with electrolytic capacitors in the signal path!), but the low quality sound of the Pi is certainly noticeable if you're paying attention. When your music gets resampled to 11 bit resolution you lose a lot of dynamic range and things sound kind of dull and muddy. There's also a well-documented problem where the DAC is deactivated each time a program closes the audio device and reactivated when it is next opened, which leads to popping or clicking sounds between songs and is not fun. In short, the sound quality you can get from the Pi's built in audio output socket is just not up to scratch for listening to music. It's probably fine for other applications, though.

Luckily for me, I happened to already own a Behringer UAC202, which I've used for recording audio from my Arduino experiments to my computer. However, the UAC202 can also be used to play audio, and it turns out it's quite good at it. So I've used that to connect my Pi to my amplifier, using standard RCA cables, and it sounds just great. I had no problems getting the UAC202 to work under Raspbian, no driver installation required or anything like that. The UAC202 is $34 on the US Amazon, which on the one hand is more than an actual Raspberry Pi, but on the other hand is still pretty cheap for what you get (which is good, because I'll have to buy a second one next time I want to record something to my laptop). I definitely recommend it as a straightforward plug-and-play solution to getting nice sound from the Raspberry Pi.

Feeds
Archives
Top tags