Sunday, May 24, 2015

Getting a USB sound card configured for Raspberry Pi 2

I recently tried to get a USB sound card working on a Raspberry Pi 2. My motivation was to start working on audio applications like writing my own synth. It's something I've wanted to do for a long time, but some odd reason never got around to it. At first, I simply tried to output sound via the built-in sound card. This experiment was successful of course, but there was a lot of noise in the output. I tested using the SonicPi program that comes with the Pi.

My next experiment was to use a USB sound card that I had gotten for cheap. Apparently, these are hit and miss and if I were to do it over again, I would get one from Adafruit where they sell ones that have been tested for the Pi. Everything worked out so I lucked out, but the path to success was not obvious. For your information, I used the CMedia HS100 from NRGtech. I also used the latest version of Raspbian (Debian Wheezy) and updated my pi firmware with "sudo rpi-update" before I even started since most guides mentioned to do this for latency.

Before I begin, I was repeatedly given the ALSA (Advanced Linux Sournd Architecture) document. There's a lot of information in there. I hope to spend sometime read it more thoroughly, but when you're trying to get something simple working, it's like drinking from a fire hose.


  1. Plugin the USB sound card.
  2. Navigate to the Menu>Preferences>Audio Device Settings.
  3. At the top of the dialog, there is a drop down for the sound card. Mine displayed "bcm2835 ALSA mixer) (Default)". Click it and you should see your new USB sound card. Again, mine displayed "USB PnP Sound Device (Alsa Mixer)".
  4. Select the USB sound card.
  5. Click "Make Default" button.
  6. You can click "Select Controls..." which brings up a dialog for you to be able to select things it can use to change settings on your sound card. I selected everything.
  7. Make sure volume is up and USB soundcard is connected to either headphones or speakers. To verify, my speaker setup, I used the built-in audio output first before connecting USB sound card.
  8. Edit /etc/modprobe.d/alsa-base.conf with your favorite editor (sudo vi /etc/modprobe.d/alsa-base.conf). I strongly recommend making a backup of this file. You can also follow this from an Adafruit article as well.
  9. Find the line "options snd-usb-audio index=-2" and change it to "options snd-usb-audio index=0".
  10. Add another line below the edited line: "options snd_bcm2835 index=1"
  11. Save the alsa-base.conf and reboot the pi (sudo reboot).
  12. speaker-test -c2 -D hw:0,0. This should work. You will hear white noise from left to right on your speakers.
  13. aplay -D hw:0,0 /usr/share/sounds/alsa/Front_Center.wav
  14. Success? Or did you get "Channels count non available". If success, you can stop now and celebrate. Have some fun with SonicPi!
  15. sudo aplay -D hw:0,0 /usr/share/sounds/alsa/Front_Center.wav
  16. This probably worked. If so, the answer is simple. Edit the $HOME/.asoundrc (vi $/.asoundrc). Back up the original is again strongly recommended.
  17. Clear the existing contents of the .asoundrc.
  18. Add "defaults.ctl.card 0"
  19. Add "defaults.pcm.card 0"
  20. Add "defaults.pcm.device 0"
  21. Save .asoundsrc. Try "aplay -D hw:0,0 /usr/share/sounds/alsa/Front_Center.wav" again.
  22. Success? Excellent. Glad this guide can help. If you are still having issues: this article and this one too helped me figure out what was going.
I wrote this guide up mainly for myself so I don't forget it and to use again. Hope it helps you as well.