Managing audio on Arch Linux

Map media buttons

On my Thinkpad T420 my media buttons do not work out of the box on Arch with dwm, so we have to map them manually. They did work when I was still using GNOME. See here for more details.

You can use xev to check the key codes of the media buttons. For me:

  • Toggle mute, keycode 121, XF86AudioRaiseVolume
  • Volume down, keycode 122, XF86AudioLowerVolume
  • Volume up, keycode 123, XF86AudioMute
  • (Mute mic, keycode 198, XF86AudioMicMute)

Possibly also map:

  • XF86AudioNext
  • XF86AudioPrev

See here for adjusting ~/.xbindkeysrc.

Install xbindkeys first: pacman -S xbindkeys.

Initiate template configuration: xbindkeys -d > ~/.xbindkeysrc.

To find out information on keys, use xbindkeys --key or xbindkeys --multikey. You can then press the key you want to assign a command to. The command will output a snippet you can enter in ~/.xbindkeysrc.

# Increase volume
"pactl set-sink-volume @DEFAULT_SINK@ +1000"
   XF86AudioRaiseVolume

# Decrease volume
"pactl set-sink-volume @DEFAULT_SINK@ -1000"
   XF86AudioLowerVolume

# Mute volume
"pactl set-sink-mute @DEFAULT_SINK@ toggle"
   XF86AudioMute

# Mute microphone
"pactl set-source-mute @DEFAULT_SOURCE@ toggle"
   XF86AudioMicMute

Apply the changes simply by running xbindkeys.

Make the changes permanent by running xbindkeys before the line that starts the window manager, either by placing it in ~/.xinitrc or ~/.xprofile (depends on your display manager). I placed it in my ~/.xprofile because I use LightDM, which natively sources .xprofile.

Controllers

My "driver" is pulseaudio (not sure if "driver" is the right term for this).

  • pavucontrol
    • This is the most useful GUI tool I've seen so far. Gives a great overview.
    • Without this one, I wasn't able to change my input device in order to record with gnome-sound-recorder.
    • Update: see pacmd below to interface with pulseaudio.
  • pactl
    • Command line interface for PulseAudio sound server.
  • gnome-sound-recorder
    • annoyingly doesn't have an option to select an input device.
    • which I get now. You have other programs for that. Linux eh? Do one thing only and do it right.
  • amixer
  • alsamixer
    • Can select device with
  • speaker-test -c 2
    • speaker-test -D default:PCH -c 8
    • find device with aplay -L | grep :CARD.
    • probably can also use pacmd for this.

Pulseaudio

Everything under here you can do easily with pavucontrol, but if you need to do stuff from the command line some time, this is a handy guide.

Use pulseaudio instead of programs like alsamixer.

The config is in /etc/pulse/default.pa. There you can set default behavior for example:

load-module module-switch-on-connect
load-module switch-on-port-available

These are not enabled by default.

There's also behavior for what to do when a bluetooth device connects.

### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

This perhaps did load drivers (not sure if the if statement passed), but in any case this did not yet autoswitch to the bluetooth output. If I want that, I could set the autoswitch option from above. But I think this behavior is not necessarily desired in general, because I can image this overrides your default audio device if you plug in a new one.

Command line interaction with pulseaudio can be down with pacmd.

The pulseaudio command itself is just for running the audio deamon.

There's also pacmd list-sinks. That should show your output devices.

I think the best way to change output sinks is to change the default sink. You can use the name or the index under pacman list-sinks.

pacmd set-default-sink 1

After having set the default device to this one, the audio actually switched to bluetooth automaitcally after connecting with bluetoothctl

Also pactl list, which seems to do the very same thing... Maybe see what the difference is. You can list sinks (or modules etc) simply with pactl list sinks.

Just get the names: pactl list sinks | grep "Name".

When i run it now, i indeed see that a device connected to bluetooth is running.

Moving input

pacmd list-sink-inputs

Changing the default sink while audio is already playing doesn't do anything though. In this specific case, you need to move the input stream explicitly to another sink.

pacmd list-sink-inputs.

1 sink input(s) available. index: 5 driver:

We now know that we want to move the input stream 5 to sink 1 by calling

pacmd move-sink-input 5 1

Awesome! Works.

Bluetooth input

Bluetooth headsets usually have a profile for high fidelity playback, and another profile where you use both bluetooth and playback. In the latter case the playback quality is significantly worse.

In pavucontrol , go to "configuration" and there you can select the profile. The profiles are:

  1. High Fidelity Playback (A2DP sink)
  2. Headset Head Unit (HSP/HWP)

Select profile 2 if you need the mic. The mic will then show up under "inputs" in pavucontrol.

Visualization

audio visualizers for linux