Wednesday, September 4, 2013

PiTunes with USB Sound

Continuing my ever improving efforts towards my PiTunes system, I've made some modifications.  The most recent modifications were to address two different problems: 1) sound quality isn't great and 2) WiFi.

First, the sound quality.  We've noticed sometimes that the sound playback isn't great.  Sometimes the sound skips or pops.  This is apparently an issue with the analog audio port on the Raspberry Pi.  I'm not totally versed on it, but basically, it's not a regular audio out port.  The RPi guys skimped by not putting in a dedicated digital to audio converter (to convert the digital signal from the chip to analog) so they used a workaround that isn't great.  Since most people use the digital signal through the HDMI port it isn't a problem.  The workaround is to use a separate sound card.  I opted for a USB sound card.  They're pretty cheap and fairly ubiquitous. I got mine for $2.51 plus shipping.  Not bad.  I installed the USB card and rebooted the Pi.  Now all I had to do was get the Pi to recognize the USB sound card as the default instead of the on board analog out port.  I wouldn't have figured this one out without the help of my good friend down under, SirLagz.  He's got a lot of cool stuff about RPi on his blog.  Check it out!  No seriously, you need to look at it.
So, to disable the on board sound card, the /etc/modprobe.d/alsa-base.conf file needs to be edited.  Mine now looks like this:

 After a reboot, the USB device became the primary.  Then I had to update my script so that it would change the volume on the proper output port.  To find out what it had to be changed to, I ran alsamixer and looked at the name at the bottom of the slider.  In my case, the name was 'Speaker'.  So, here's what my script looks like now.  I've tested it once, we'll see how it works tonight.  So far, the sound quality is much better: