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:
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.