Skip to content

Audio Devices

Tobias Wellnitz edited this page Mar 5, 2017 · 8 revisions

Alsa (Linux)

On Linux, ALSA is the standard sound interface.

Helpful Alsa CLI tools

Alsa provides some handy CLI tools for debugging sound card problems.

In case the tools are not available on your system, you can install them through your packet manager:

$ sudo apt install alsa-utils

Listing available audio devices (brief):

$ aplay -l

Listing available audio devices (detailed):

$ aplay -L

Play a sound on a particular sound card:

$ speaker-test speaker-test -c 2 -D hw:0 -t wav     

will play a test file on the left and right channel of the sound card, registered at hw:0

Alsa also comes with a CLI mixer which helps you to adjust the volume and (un)mute channels:

$ alsamixer

In order to save the changes you have to execute:

$ sudo alasctl store

Configure Alsa devices

The easiest way to configure your Alsa devices is by adding the file .asoundrc to your home directory.

$ sudo vim $HOME/.asoundrc

The content of this file can be pretty complex, and please be encouraged to check out the documentation.

Here is a simple example from an Orange Pi where we want to map the Microham MK2's sound card as our default audio device:

$ aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: audiocodec [audiocodec], device 0: SUNXI-CODEC sndcodec-0 []
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 1: sndhdmi [sndhdmi], device 0: SUNXI-HDMIAUDIO sndhdmi-0 []
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 2: CODEC [microHAM CODEC], device 0: USB Audio [USB Audio]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
$ vim $HOME/.asoundrc

pcm.!default {
        type hw
        card 2
        device 0
}

ctl.!default {
        type hw
        card 2
        device 0
}

Reboot / restart Alsa to apply the changes.

$ sudo reboot

Disable Raspberry Pi build-in sound card

If you want, you can easily disable the build-in sound card of a Raspberry Pi, by blacklisting it's driver.

$ sudo vim /etc/modprobe.d/alsa-blacklist.conf

and add:

blacklist snd_bcm2835

and reboot

$ sudo reboot