Monday, 11 February 2013

Adding an Audio Input Device

The Raspberry Pi comes with a 3.5mm analogue stereo audio output, but no input. As a radio amateur I am interested in using the Raspberry Pi to decode various digital modes, but for it to do this I need an audio input. This can be achieved by connecting a USB audio device to your Raspberry Pi (like this one supplied by Cut Price Cables).

Make sure your Raspberry Pi is turned off and insert the USB audio device into one of the USB sockets on the Raspberry Pi, and then power up your Raspberry Pi. The USB audio device should be automatically installed. Go in to the LXDE GUI and open a LXTerminal window and type the following and press Enter:

pi@raspberrypi ~ $ sudo apt-get install alsa-utils_

You may already have this package on your system, but entering this command won't do any harm even if you do. This will install a package of ALSA utilities if you don't already have them (ALSA stands for Advances Linux Sound Architecture). Then type "alsamixer" and press Enter:

pi@raspberrypi ~ $ alsamixer_

This will run the AlsaMixer application in a LXTerminal window:

This shows the on-board audio device's playback control (note that the chip is called "Broadcom Mixer"). Press "F6" and you should see a small pop-up "window" with all the available sound cards listed.

 The item "0 bcm2835 ALSA" is the on-board audio device, and the item "1 C-MediaUSB Audio Device" is the USB audio device. Use the arrow keys to select the "1 C-MediaUSB Audio Device" item and press Enter:

This shows the playback controls for the USB audio device. Use the right and left arrow keys to select the control you wish to adjust and then use the up and down arrow keys to adjust the level. With "Speaker" selected, pressing "m" key on your keyboard will toggle the mute function on the audio output (when muted, "MM" appears instead of "OO" at the bottom of the control). Likewise, the "Mic" control  (which actually refers to the level of microphone input fed back through to the audio output) can be muted, and is shown so in the above screenshot (note the "MM" at the bottom of the control). The "Auto Gain Control" item can not be adjusted with the arrow keys, but can be turned on and off by pressing the "m" key.

Now, if you press "F4" the display will change to show the audio capture control for the USB audio device:

This control is used to adjust the level of audio input from the audio device to the Raspberry Pi, and may be muted by pressing the space bar on your keyboard (but this will not mute the audio fed back through to the audio output).

If you press "F5" you will be able to see and adjust the playback and capture controls together in the same window:

The above screenshot shows the "Speaker" playback control set to 50%, the "Mic" capture control set to 50%, but the "Mic" playback control is muted (and also reduced to zero) and the "Auto Gain Control" is turned on.

The following final section of this post is optional....

There is a "proper" graphical user interface available for the AlsaMixer application. To download and install it type the following at the command line prompt and press Enter:

pi@raspberrypi ~ $ sudo apt-get install alsamixergui_

Once installed, you will find the "Alsamixergui" application under the "Sound & Vision" submenu of the "Start Menu" in the LXDE GUI.

This application works in a similar way to the AlsaMixer application (although note that in the above screenshot the "Mic" controls have been swapped over). In practice I actually found the basic AlsaMixer application (when run in a LXTerminal window) easier to use than the AlsaMixerGUI version, not least of all because the GUI version does not allow you to choose which audio device you want to control - you can only control the "default" ALSA audio device.

To make the USB audio device the default ALSA audio device, you need to create a file called ".asoundrc" in the "/home/pi" folder containing the following text:

pcm.!default {
       type hw
       card 1
ctl.!default {
       type hw
       card 1

If there already is a file called ".asoundrc" in the "/home/pi" folder then append the above text to the end of the existing file. Have a look at this post if you need help creating or editing files.

Once you have saved and closed the ".asoundrc" file you should be able to control the USB audio device using the AlsaMixerGUI application. The above procedure assumes that the on-board audio device is designated "card 0" and that the USB audio device is designated "card 1", but this should be the case as long as you do not have any other audio devices connected to your Raspberry Pi.


  1. This is great! Thanks for sharing!!!

  2. Great introduction.

    I am interested in decoding a quadrature I/Q signal, and hence need stereo input. My first attempt at buying a USB sound card, had only mono input. Does the one you refer to have stereo input?


    1. Hi Anders,

      I think that even though the audio capture control shows "L" and "R" channels the mic input is mono. However, when I remove the outer casing of the audio device I see that the actual input jack for the mic is stereo (i.e. it has three terminals, the same as the output jack). I also note that the USB audio device uses the CM119 chipset.

      I would be very interested in hearing how you get on - I have also been considering using the Raspberry Pi as part of a Software Defined Radio.

      What SDR software are you running on the Pi?

    2. Anyone find a cheap "stereo" audio input device for the Pi?
      I also need to do I/Q input.

      A good wide low noise response would be wonderful. John, KW7A

  3. Well, the stereo/mono input of cheap USB sondcards seem to be shrouded in mystery. My Logilink (10EUR) device also have stereo jack, but mono input. Many of the cheaper cards also boast a "stereo input jack", but few of them state whether the mic-input is actually stereo.

    I have just bought the "ASUS Xonar U3", and that has stereo input - both in the brochure and in reality !!! But at 4-times the price, and twice the size.
    .... But now I can proceed.

    I write my own software, I am not decoding ordinary radio, but am playing around with a 24GHz transceiver, using it as Doppler RADAR. The Doppler frequency appear in the audible range, making a sound-card an excellent sampling device, and making simple C programs feasible for signal processing.

    Since I want to make a system with 10 nodes, I am still looking for the cheapest possible USB soundcard with stereo input.

  4. Thanks so much for your great 'how-to'.

    I'm currently trying to invert a small frequency range and than output this signal directly to some active speakers.

    Have you or has anyone here tried that before?
    Could you give me some advice on how to continue?


    1. Hi,

      Thanks for your comment, but I'm afraid I can't offer any advice on what you're trying to do... sorry!



  5. When I run alsamixer and select the USB codex, when I select f4, I get the error message that the device has no audio input. Any ideas what I am missing. If I run arecord -l, it dose list the USB codec as an input device as Subdevices: 0/1 , so it seems the raspberry pi is seeing the device.

    Larrie, KD7HRJ

  6. Hi Larrie, maybe the USB sound card you're using isn't fully compatible with the Raspberry Pi? I've tried two different USB sound cards, and they both worked, although they used similar chipsets. Anyhow, when running AlsaMixer make sure the card is listed as the USB Audio Device and not the onboard bcm2835.

  7. if everything working fine, is it possible to capture audio input data by Java/Python app? Thanks for reply

  8. can I connect the dtmf tones to the audio jack

  9. Can this device record input at 8khz?

  10. great . thank you somuch !

  11. Hi, thanks for the post. I have problems with the capture. When I use it for record some audio it comes with a noise and a tone from 600Hz. It could be something wrong by the configuration or the compatibility with raspberry pi B+ or it could be that my sound card is broken?
    Thank you very much.

  12. don't you still need a mic to plug into the sound card if you want to work on speech recognition?

  13. or is it possible to use a usb microphone as well as the sound card to do it?

  14. can i give input through same sd card on which os is installed

  15. can I add multiple USB microphones (up to 4)?

    1. Did you ever get an answer on the 4 Mic question? maybe with two stereo usb cards.

    2. Did you ever get an answer on the 4 Mic question? maybe with two stereo usb cards.

  16. I installed alsamixergui on pi3 with raspbian. too bad it did not work. i was hoping that i could use the utility. i will settle for alsamixer. it actually responds to my keyboard. the gui looks good. it just does not work. no response to mouse or keyboard. nice try, folks.

  17. Hi,

    Will a USB sound adapter like the one that you have mentioned suffice or do I have to plugin a 3.5 mm microphone along with this ? I tried using a usb adapter together with my earphones that have inline microphone in them. They dont seem to work. Can you please guide me ?

    Thanks a lot.

  18. We are dealing with Corporate audio visual with good quality. Here are options for the audio visual installations, av installations and audio installation melbourne or Projectors Melbourne.

  19. dai ly vietnam airlines xin được tư vấn cho du khách cách đặt mua ve may bay di nga gia re giá rẻ để bạn có thể đến với xứ sở bạch dương xinh đẹp. Nếu bạn là người yêu thích sự năng động và hiện đại của đảo quốc sư tử thì còn chần chừ gì mà không sở hữu nagy tấm ve may bay di singapore gia re.
    Với nền văn hóa đặc sắc, đất nước Thái lan chính là một điểm đến tuyệt vời dành cho du khách muốn khám phá nền Phật Giáo lâu đời tại đây, hãy đặt ve may bay di thai lan gia re ngay hôm nay
    Hoa Kỳ là một trong những quốc gia mơ ước của các tín đồ du lịch, bạn có thể đặt mua ve may bay di my hoặc ve may bay di my gia re
    Không chỉ có những địa danh nổi tiếng của Thế Giới, mùa hè này bạn cũng có thể đến với những địa danh nổi tiếng của việt nam như Nha Trang, Phú Quốc, Đà Nẵng bằng cách nhanh tay đặt mua vé giá rẻ tại:
    - ve may bay di nha trang gia re
    - ve may bay di phu quoc gia re