This is an old revision of the document!
Table of Contents
ALSA-only audio on Linux
this is a guide on how to setup ALSA to be enjoyable by itself without an audio server.
I will be showing changes to /etc/asound.conf as to effect all users (including daemons such as MPD). you can also use ~/.asoundrc for setup specific to your user.
devices
multiple commands can list available audio cards and devices.
alsactl can be used:
$ alsactl info 1 # # Sound card # - card: 1 # card number. id: sofhdadsp name: sof-hda-dsp longname: driver_name: sof-hda-dsp mixer_name: Realtek ALC233 components: controls_count: 54 pcm: - stream: PLAYBACK devices: - device: 1 # device number. id: HDA Analog (*) # name. name: subdevices: - subdevice: 0 name: subdevice #0 ...
by default alsactl info will show card 0. you most likely have multiple cards.
aplay will also list sound cards and devices.
$ aplay -l **** List of PLAYBACK Hardware Devices **** card 0: HDMI [HDA ATI HDMI], device 0: HDMI 0 [HDMI 0] Subdevices: 1/1 Subdevice #0: subdevice #0 ... card 1: sofhdadsp [sof-hda-dsp], device 1: HDA Analog (*) [] Subdevices: 1/1 Subdevice #0: subdevice #0 ...
card 1 and device 1 will be used for this guide. in most places, this is specified with “hw:1,1”. the first number is the card and the second is the device.
mixing
dmix is a software mixer for audio output. it will allow multiple programs to simultaneously play sound at the same time.
in asound.conf, the following configuration could be used to create a software mixer that can be accessed by multiple users.
- /etc/asound.conf
pcm.mixer { type dmix ipc_key 1024 ipc_key_add_uid false # remove these two lines to only allow ipc_perm 0666 # one user to use the mixer at a time. slave { pcm "hw:1,1" # hardware output device to use. } } pcm.!default plug:mixer # set the default device to the mixer.
Bluetooth
BlueALSA can be used to easily play audio on Bluetooth audio devices.
the pcm and ctl 'bluealsa' is created automatically, and in most cases they can be used directly. see the project's wiki for more information on configuration.
- ~/.asoundrc
pcm.!default bluealsa ctl.!default bluealsa
you can use bluealsa-cli to get information on your Bluetooth devices.
$ bluealsa-cli list-pcms /org/bluealsa/hci1/dev_XX_XX_XX_XX_XX_XX/a2dpsrc/sink $ bluealsa-cli info -vv /org/bluealsa/hci1/dev_XX_XX_XX_XX_XX_XX/a2dpsrc/sink ... Format: S32_LE Channels: 2 Sampling: 96000 Hz Available codecs: ... LDAC:... [channels: 1 2 2] [sampling: 44100 48000 88200 96000] # supported sample rates. Selected codec: LDAC:... [channels: 2] [sampling: 96000] ...
LDAC
on Sony and other brand products which support it, LDAC provides a high bit depth and sample rate. BlueALSA supports LDAC, but some packages are built without it.
on Arch Linux, the package in the AUR disables LDAC support so you must edit the PKGBUILD or compile it manually. uncomment/pass –enable-ldac.
if wokring correctly, BlueALSA will automatically use LDAC on supported devices, and adjust the sample rate depending on the audio.
S/PDIF multichannel
the a52 alsa plugin can be used to output Dolby Digital 5.1 (or lower) multichannel audio through S/PDIF.
you must have the plugin installed. look in your distribution's repositories for a package similar to “alsa-plugins”. it may be in a separate package such as “alsa-plugins-a52”, as on Alpine Linux.
here is an example configuration:
- /etc/asound.conf
pcm.surround { type a52 slavepcm "hw:1,1" channels 6 bitrate 1000 rate 48000 format S16_LE }
equalization
alsaequal is a 10-band software equalizer in the form of an ALSA plugin.
each user has their own persistent settings, stored in ~/.alsaequal.bin. if, for example, you are running MPD as its own mpd user, you must either copy or link the alsaequal.bin file to its home directory, or manually configure it seperately.
the following configuration builds on the previous section on dmix. an asoundrc using solely alsaequal can be very simple.
- /etc/asound.conf
pcm.dmix_stereo { type dmix ipc_key 1024 ipc_key_add_uid false ipc_perm 0666 slave { pcm "hw:1,1" period_time 0 period_size 1024 buffer_size 4096 rate 48000 } bindings { # channel configuration (stereo, quad, 5.1, ...). 0 0 1 1 } } pcm.plug_eq_stereo { type equal slave.pcm "plug:dmix_stereo" } pcm.eq_stereo { # this plug is needed to make the alsaequal output suitable for use by most applications. type plug slave.pcm "plug_eq_stereo" } ctl.eq_stereo { # this ctl is what allows adjustment in alsamixer (or similar utilities). type equal } pcm.!default eq_stereo
with this configuration, the equalizer can be changed with ctl eq_stereo:
alsamixer -D eq_stereo
multichannel
here is an example of using alsaequal with a52.
- /etc/asound.conf
... pcm.surround { type a52 slavepcm "hw:1,1" channels 6 bitrate 1000 rate 48000 format S16_LE } pcm.plug_eq_surround { type equal channels 6 # changes channel configuration to 5.1. controls ".alsaequal.surround.bin" # sets the control information file to at ~/.alsaequal.surround.bin. this must be changed if there are to be multiple alsaequals of differing channel configurations. slave.pcm "plug:surround" } pcm.eq_surround { type plug slave.pcm "plug_eq_surround" } ctl.eq_surround { type equal channels 6 controls ".alsaequal.surround.bin" } ...
the surround equalizer can be changed with ctl eq_surround using this configuration.