Audio Devices - dh1tw/remoteAudio GitHub Wiki

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 get pretty complex, please 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
        format S16_LE # might be needed to force sound card to produce 16bit little endian samples
        rate 48000  # might be needed to force sound card into 48kHz sampling rate
}

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

Remove Alsa Warnings

When using external USB sound cards, Alsa might throw some warnings at the startup of remoteAudio:

tobias@orangepizero:~$ ./remoteAudio server nats
Using config file: /home/tobias/.remoteAudio.toml
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline

While these warnings can be safely ignored, you can also disable them by commenting out the extended PCM definitions in /usr/share/alsa/alsa.conf

#  PCM interface
#

# redirect to load-on-demand extended pcm definitions
pcm.cards cards.pcm
pcm.default cards.pcm.default
pcm.sysdefault cards.pcm.default
# pcm.front cards.pcm.front
# pcm.rear cards.pcm.rear
# pcm.center_lfe cards.pcm.center_lfe
# pcm.side cards.pcm.side
# pcm.surround21 cards.pcm.surround21
# pcm.surround40 cards.pcm.surround40
# pcm.surround41 cards.pcm.surround41
# pcm.surround50 cards.pcm.surround50
# pcm.surround51 cards.pcm.surround51
# pcm.surround71 cards.pcm.surround71
# pcm.iec958 cards.pcm.iec958
# pcm.spdif iec958
# pcm.hdmi cards.pcm.hdmi
pcm.dmix cards.pcm.dmix
pcm.dsnoop cards.pcm.dsnoop
# pcm.modem cards.pcm.modem
# pcm.phoneline cards.pcm.phoneline