# USB Audio Cards with a Raspberry Pi 

## Instructions

![](https://cdn-learn.adafruit.com/assets/assets/000/011/003/medium800/raspberry_pi_1475pi_LRG.jpg?1379448251)

The Raspberry Pi has an on-board audio jack, which is super handy for all kinds of sound effects and speech, just plug and go! However, for when you want better audio for music playback, a USB audio card can greatly improve the sound quality and volume, this tutorial will show you how.

This guide will also show you how to record audio via the headphone jack on the adapter

# Pre-requisites
First up, you will need a fully set up Raspberry Pi that is otherwise working and you can log into. [We have tons of tutorials on that front](http://learn.adafruit.com/category/raspberry-pi), so [get your SD card loaded with Raspbian](http://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi)[(that's what we're using in this tutorial), and either](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup)**[ssh](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup)** in, log in with a monitor and keyboard, or [a USB console cable](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable)  
Danger: 

# USB Audio Cards with a Raspberry Pi 

## Figure out your chipset

# Figure out your chipset
  
Start by having your Raspi **turned off/shutdown** (perform a clean shutdown!) and then plugging in your USB audio card. Then boot the Pi as normal.   
  
Once you log in, type **dmesg | grep cm109** to look at the boot messages. You should either see some lines about **cm109** if you have a **CM109** chipset  
[](https://learn.adafruit.com/assets/12947)

[![raspberry_pi_grepcm109.png](/system/assets/assets/000/015/752/medium800/raspberry_pi_grepcm109.png?1396894894)](/assets/15752)

**or** if nothing comes up, try **dmesg | grep Headphone** you will see **the C-Media USB Headphone Set** driver. This means its a **CM-headphone**
![](https://cdn-learn.adafruit.com/assets/assets/000/015/753/medium800/raspberry_pi_headphone.png?1396894932)

 **or** if nothing comes up, try **dmesg | grep C-Media** you will see some C-Media notes but no mention of the cm109 driver. This means its a **CM108 or PCM2902**

![](https://cdn-learn.adafruit.com/assets/assets/000/015/754/medium800/raspberry_pi_cm108.png?1396894999)

 **or** if nothing comes up, try **dmesg | grep General** you will see mention of GeneralPlus. This means it's a **GeneralPlus**

![](https://cdn-learn.adafruit.com/assets/assets/000/053/661/medium800/learn_raspberry_pi_general.png?1525900631)

# USB Audio Cards with a Raspberry Pi 

## CM108 Type

# If you have CM108

If you type in **lsusb** you should see a reference to **C-Media Electronics, Inc. CM108 Audio Adapter&nbsp;** or **Texas Instruments PCM2902 Audio Codec**

![](https://cdn-learn.adafruit.com/assets/assets/000/015/755/medium800/raspberry_pi_lsmodcm108.png?1396895081)

We'll need to update the firmware, this requires Internet access but only takes 15 minutes or so. You might want to run **sudo apt-get update** first if you haven't lately. Then run the following commands in order:

```auto
sudo apt-get update
sudo apt-get upgrade
sudo reboot
```

You may see a lot of stuff happening like the below:

![](https://cdn-learn.adafruit.com/assets/assets/000/015/756/medium800/raspberry_pi_wgetfirmware.png?1396895107)

![](https://cdn-learn.adafruit.com/assets/assets/000/015/757/medium800/raspberry_pi_hexxeh_firmware.png?1396895130)

![](https://cdn-learn.adafruit.com/assets/assets/000/015/758/medium800/raspberry_pi_firmwareupdated.png?1396895149)

Now you can go down to the [**update alsa module options**](../../../../usb-audio-cards-with-a-raspberry-pi/updating-alsa-config) section

# USB Audio Cards with a Raspberry Pi 

## CM-Headphone Type

Type **dmesg** to look at the boot messages. You should see a bunch of lines that talk about **C-Media USB Headphone Set**

![](https://cdn-learn.adafruit.com/assets/assets/000/015/763/medium800/raspberry_pi_USB-Headphone.gif?1448048085)

And if you type in **lsusb** you should see a reference to **C-Media Electronics Audio Adapter** but no mention of **CM108** and the VID/PID is 0x0d8c:0x00c

![](https://cdn-learn.adafruit.com/assets/assets/000/015/764/medium800/raspberry_pi_lsusb.gif?1448048080)

Nothing special needs to be done! Hurray! Continue on to the **Updating ALSA Config section**

# USB Audio Cards with a Raspberry Pi 

## CM109 Type

Type **dmesg** to look at the boot messages. You should see a bunch of lines that talk about **cm109**

![](https://cdn-learn.adafruit.com/assets/assets/000/015/759/medium800/raspberry_pi_cm109.gif?1448048108)

And if you type in **lsusb** you should see a reference to **C-Media Electronics Audio Adapter** but no mention of **CM108**

![](https://cdn-learn.adafruit.com/assets/assets/000/015/760/medium800/raspberry_pi_lsusb.gif?1448048103)

[](https://learn.adafruit.com/assets/10977)
 Nothing special needs to be done! Hurray! Continue on to the next section
# USB Audio Cards with a Raspberry Pi 

## GeneralPlus

Type **dmesg** to look at the boot messages. You should see a bunch of lines that talk about **GeneralPlus**

![](https://cdn-learn.adafruit.com/assets/assets/000/053/662/medium800/learn_raspberry_pi_dmesggen.png?1525900917)

And if you type in **lsusb** you should see a reference to **Generalplus Technology** with ID `1b3f:2008`

![](https://cdn-learn.adafruit.com/assets/assets/000/053/663/medium800/learn_raspberry_pi_lsusb.png?1525900990)

Nothing special needs to be done! Hurray! Continue on to the next section

# USB Audio Cards with a Raspberry Pi 

## Updating ALSA Config

# Raspbian Bullseye - Updating alsa options

First make sure you can see the alsa card for the USB audio device with

`cat /proc/asound/cards`

And look for something that says "USB Audio" or similar

Depending on whether you are running a Pi 4 or other, it may be device 1, 2 or 3.

![](https://cdn-learn.adafruit.com/assets/assets/000/120/232/medium800/learn_raspberry_pi_image.png?1681658566)

we used to recommend manually setting the device number to be your USB audio card but that turned out to be fragile because the HDMI audio device numbers would change.&nbsp;

So now we suggest just disabling the built in headphone jack audio, and letting the USB audio card be 'first'

Start by disabling the built-in headphone jack with

`sudo nano /etc/modprobe.d/raspi-blacklist.conf`

and typing in&nbsp;

`blacklist snd_bcm2835`

hit return, then save with **Control-X** then **Y then Return** (to save)

&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/120/234/medium800/learn_raspberry_pi_image.png?1681661002)

Then enable the USB audio card with

`sudo nano /lib/modprobe.d/aliases.conf`

find the line with

`options snd-usb-audio index=-2`

and put a **#** in the beginning of that line. Then exit and save file.

![](https://cdn-learn.adafruit.com/assets/assets/000/120/235/medium800/learn_raspberry_pi_image.png?1681661088)

Then `sudo reboot` to 'set' the changes

Upon reboot, if you run&nbsp; **sudo aplay -l&nbsp;** to list the interface, the USB audio card will be first and the default!

![](https://cdn-learn.adafruit.com/assets/assets/000/120/236/medium800/learn_raspberry_pi_image.png?1681661174)

# USB Audio Cards with a Raspberry Pi 

## Testing Audio

# Testing!

OK now that you've configured ALSA depending on your OS...that's it! Now reboot with **sudo reboot** and log in again, you can test with **speaker-test** by running

`speaker-test -c2`

Which will play white noise through the left and right 'speakers' on the audio card. Once you've got something coming out, try to play an audio file with **speaker-test** (for WAV files, not MP3)

`speaker-test -c2 --test=wav -w /usr/share/sounds/alsa/Front_Center.wav`

If you want to play a stream of music, you can try

`sudo apt-get install mpg123`  
`mpg123 http://ice1.somafm.com/u80s-128-mp3`

[If you want to play MP3's on command, check out this tutorial which covers how to set that up](http://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi "Link: http://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi")

# Headphone vs Audio card

Don't forget, you still have the built in headphone jack on the Pi, if you edited alsa.conf it might be called **card 1** now (not the default **card 0** )

You can run **aplay -l** to **l** ist the devices

![](https://cdn-learn.adafruit.com/assets/assets/000/035/688/medium800/raspberry_pi_aplay-l.gif?1473730469)

![](https://cdn-learn.adafruit.com/assets/assets/000/035/689/medium800/raspberry_pi_alsali.png?1473730484)

If you want to **aplay** through a specific card, specify **card 1** with **-D plughw:1,0** or card 0 **-D plughw:0,0** etc

`speaker-test -c2 -D plughw:1,0`

`aplay --device=hw:1,0 test.wav`

# USB Audio Cards with a Raspberry Pi 

## Setting Audio Levels

You can set audio levels for both output and input with

`alsamixer -c 1`

Use the arrow keys and return/escape to set and save the settings. It's a sorta-cute text-graphics system

![](https://cdn-learn.adafruit.com/assets/assets/000/035/687/medium800/raspberry_pi_amixer.png?1473729209)

# USB Audio Cards with a Raspberry Pi 

## Recording Audio

At least with the CM-Headphone type adapter, you can also _record_ audio.

` arecord --device=hw:1,0 --format S16_LE --rate 44100 -c1 test.wav`

Will record signed 16-bit (`S16_LE`) audio at 44100 Hz (`--rate 44100`) mono (`-c1`) audio to **test.wav**. We've noted that any audio input will be _echoed_ out the speakers as well

You can have a little VU meter show up if you add to the`-V mono` command line. Press control-C to quit

![](https://cdn-learn.adafruit.com/assets/assets/000/035/690/medium800/raspberry_pi_arecord.png?1473730815)

Once you're done recording you can play back with

`aplay --device=plughw:1,0 test.wav`

# USB Audio Cards with a Raspberry Pi 

## Troubleshooting!

If you're using a Raspberry Pi and notice the output isnt totally clean, some USB Audio adapters don't like USB-1.2 and produce crackling in the output. You can work around the problem by adding `dwc_otg.speed=1` to **/boot/cmdline.txt** and setting the USB ports to USB-1.1 mode.

You can get user access to the audio hardware with other devices by granting access using&nbsp;`sudo usermod -a -G audio username`


## Featured Products

### USB Audio Adapter - Works with Raspberry Pi

[USB Audio Adapter - Works with Raspberry Pi](https://www.adafruit.com/product/1475)
The Raspberry Pi has an on-board audio jack, which is super handy for all kinds of sound effects and speech, just plug and go! However, for when you want better audio for music playback, a USB audio card can greatly improve the sound quality and volume. That's because the on-board audio is...

In Stock
[Buy Now](https://www.adafruit.com/product/1475)
[Related Guides to the Product](https://learn.adafruit.com/products/1475/guides)
### Stereo 3.5mm Plug/Plug Audio Cable - 6 feet

[Stereo 3.5mm Plug/Plug Audio Cable - 6 feet](https://www.adafruit.com/product/876)
This basic cable comes with two 3.5mm (1/8" headphone jack size) stereo connectors. It's fairly straight forward, you'll commonly need these to connect two audio devices together.  
  
Cable is 6 ft long.

In Stock
[Buy Now](https://www.adafruit.com/product/876)
[Related Guides to the Product](https://learn.adafruit.com/products/876/guides)
### Raspberry Pi Model B 512MB RAM

[Raspberry Pi Model B 512MB RAM](https://www.adafruit.com/product/998)
Adafruit ships the **Raspberry Pi Model B 512MB RAM** as of 10/18/2012.  
  
The Raspberry Pi® is a single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of stimulating the teaching of basic computer science in schools. The Raspberry...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/998)
[Related Guides to the Product](https://learn.adafruit.com/products/998/guides)

## Related Guides

- [Raspberry Pi Care and Troubleshooting](https://learn.adafruit.com/raspberry-pi-care-and-troubleshooting.md)
- [Raspberry Pi Hosting Node-Red](https://learn.adafruit.com/raspberry-pi-hosting-node-red.md)
- [BNO055 Absolute Orientation Sensor with Raspberry Pi & BeagleBone Black](https://learn.adafruit.com/bno055-absolute-orientation-sensor-with-raspberry-pi-and-beaglebone-black.md)
- [Adafruit's Raspberry Pi Lesson 7. Remote Control with VNC](https://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc.md)
- [Networked Thermal Printer using Raspberry Pi and CUPS](https://learn.adafruit.com/networked-thermal-printer-using-cups-and-raspberry-pi.md)
- [3.5" PiTFT OctoPrint Rig](https://learn.adafruit.com/3-dot-5-pitft-octoprint-rig.md)
- [RasPi - Animated GIF Picture Frame](https://learn.adafruit.com/raspi-animated-gif-picture-frame.md)
- [Simple Raspberry Pi Robot](https://learn.adafruit.com/simple-raspberry-pi-robot.md)
- [Coffee Rater](https://learn.adafruit.com/coffee-rater.md)
- [Piezo Ring Tones with Raspberry Pi](https://learn.adafruit.com/piezo-ring-tones-with-raspberry-pi.md)
- [Web Enabled PIXEL on Raspberry Pi](https://learn.adafruit.com/web-enabled-pixel-on-raspberry-pi.md)
- [Node.js Embedded Development on the Raspberry Pi](https://learn.adafruit.com/node-embedded-development.md)
- [NeoPixels on Raspberry Pi](https://learn.adafruit.com/neopixels-on-raspberry-pi.md)
- [reef-pi Guide 6: pH Monitoring](https://learn.adafruit.com/reef-pi-guide-7-ph-monitoring.md)
- [Speech Synthesis on the Raspberry Pi](https://learn.adafruit.com/speech-synthesis-on-the-raspberry-pi.md)
