Monday, January 14, 2013

Raspberry Pi and Sound Input

If you are a Ham Radio Operator you've probably been looking at the Raspberry Pi with a lot of possibilities.

One of it's downfalls if the lack of an on-board input.  But once you add a USB sound fob, Echolink, remote rig applications, IRLP, and decoding various digital modes like PSK, and so on, are all a reality.

Finding a USB sound device and setting it up can be aggravating.

I recommend the SYBA SD-CM-UAUD USB CM119 audio adapter.

If lsusb doesn't report it as below, you have the wrong one:

root@pi:~# lsusb 
Bus 001 Device 005: ID 0d8c:000e C-Media Electronics, Inc. Audio Adapter (Planet UP-100, Genius G-Talk) 

Next you need to make the usb sound card (0) the default audio device
Check yours like so: cat /proc/asound/modules
0 snd_bcm2835
1 snd_usb_audio

Edit /etc/modprobe.d/alsa-base.conf comment out "options snd-usb-audio index=-2"
You want ""options snd-usb-audio index=0"

After a reboot it should always appear in this order:
0 snd_usb_audio
1 snd_bcm2835

Take this one step further and comment out the kernel module for the onboard sound and add the usb

cat /etc/modules should look like:

While, I did not find the following necessary in my case, I have read to get better latencies out of USB audio devices, it is suggested to also add:

options snd-usb-audio nrpacks=1

Setup /etc/asound.conf to this:

 pcm.dmixer {  
   type dmix  
   ipc_key 1024  
   slave {  
     pcm "hw:0,0"  
     period_time 0  
     period_size 1024  
     buffer_size 8192  
   rate 48000  
   bindings {  
     0 0  
     1 1  
 pcm.asymed {  
     type asym  
     playback.pcm "dmixer"  
     capture.pcm "hw:0,0"  
 pcm.dsp0 {  
   type plug  
   slave.pcm "asymed"  
 pcm.!default {  
     type plug  
     slave.pcm "asymed"  
 pcm.default {  
   type plug  
   slave.pcm "asymed"  
 ctl.mixer0 {  
   type hw  
   card 0  

Since there are some USB issues, I suggest setting the device to boot the USB hub in  USB 1.0 mode, this should fix choppy audio. (I did not find this necessary in my case, but it's not a bad idea)
Add "dwc_otg.speed=1" to /boot/cmdline.txt.

Pulseaudio might be part of your raspberry wheezy default image.  Personally I am not a fan of it, and have read it wasn't working well on the Pi.  I am not sure if that still holds true.  I just removed it:
apt-get purge pulseaudio
I recommend replacing it with Alsa.  It has been around a bit longer:
apt-get install  sox alsa-oss alsa-utils alsa-tools  

Also, I suggest updating the firmware on your Pi.

This should be a good starting point for most.  Hopefully in the future, newer Raspberry wheezy images can make this a bit easier, and more kernel support for other USB sound FOBs.

For my fellow hams you may want to check out these places to congregate:

And for those of you still interested in D-Star: 

I have been running my Pi using a 5 volt, 1 amp supply via the micro USB power port.  I do not use a USB hub.  My model B rev 2 has been running reliably for a few weeks now.

Just as a note.  If you are making connections to the GPIO for keying a radio or whatever, check your local Radio Shack for "Schmartboard Jumpers ."  These are a new thing they are carrying, and are handy.


Robert Garcia said...

Thanks for the tips. I have tested both a CM119 based sound card and a DMK URI with the Pi and slowing the USB bus made a dramatic difference.

I will give some of your other tweaks a try as well.


Hermes Sampedro said...

Hello, in the actual Raspian version I can't find the asound.con file. How can I configure the USB interface?
Thank you.

Steve, KB9MWR said...

Then create one from scratch.