Linux

Operating SystemDebian 7

Introduction

I’ve recently bought an Enermax keyboard (Caesar) and have input and output audio directly on the keyboard! That’s great and better when it works. Unfortunately, as I have a minimal OS, it doesn’t work out of the box. So here is how I could achieve it.

I will present 2 ways to make it work and I personally use the manual way.

Manual way

First of all, you need to see if you could find your USB Audio device (normally there is no reason why you shouldn’t see it):

1
2
3
4
> lsusb
[...]
Bus 003 Device 004: ID 0d8c:0105 C-Media Electronics, Inc. CM108 Audio Controller
[...]

Then check this module is loaded:

1
2
> lsmod | grep snd_usb_audio
snd_usb_audio          84836  2

If it’s not the case, add it to your module list and load it:

1
2
echo "snd_usb_audio" >> /etc/modules
modprobe snd_usb_audio

Now find the corresponding card ID (you could also have it in AlsaMixer):

1
2
3
4
5
6
> aplay -l
[...]
card 1: Device [USB Multimedia Audio Device], périphérique 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
[...]

My card number is 1! Nice, now let’s add to our personal configuration (replace 1 at the end of the lines by your card number):

1
2
defaults.ctl.card 1
defaults.pcm.card 1

Now reboot to make it work!

Automatic way

For the automatic rules, we’re going to play with udev. Simply create a rule for it:

1
2
3
4
5
# Set USB device as default sound card when plugged in
KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/bin/sh -c 'K=%k; K=$${K#pcmC}; K=$${K%%D*}; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"

# Restore default sound card when USB device unplugged
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"

Udev will do the work to make it automatically work :-)

References

https://archlinux.me/w0ng/2012/07/06/alsa-switch-audio-usb-headset/

Last updated 23 May 2013, 15:00 CEST. history