Under pure ALSA we need to use a configuration file to set the default audio output device and a udev rule to apply the configuration file when the device is connected.
Setting the default output device
For this guide we are going to use an asound.conf file to apply the configuration system-wide.
First use this command without the device plugged in to see the available audio devices and their ID:
Code: Select all
find /proc/asound -type l -exec basename {} \;
Code: Select all
~$ find /proc/asound -type l -exec basename {} \;
Generic
Generic_1
~$
Now plug in the USB DAC and run the command again. Here is the output from my system:
Code: Select all
~$ find /proc/asound -type l -exec basename {} \;
v1
Generic
Generic_1
~$
With this information we can create a configuration file to set v1 as the default device:
Code: Select all
pcm.v1 {
type hw
card "v1"
}
ctl.!default {
type hw
card "v1"
}
pcm.!default {
type plug
slave {
pcm "v1"
rate "unchanged"
}
}
Save this file to /etc/asound.conf.bak
Creating a udev rule
Now we need a udev rule to copy /etc/asound.conf.bak to /etc/asound.conf so that it is read by ALSA.
To do this we need to find the product name recognised by udev:
Code: Select all
udevadm info -a /sys/class/sound/$(readlink /proc/asound/v1) | grep ATTRS{product}
Sample output from my box:
Code: Select all
~$ udevadm info -a /sys/class/sound/$(readlink /proc/asound/v1) | grep ATTRS{product}
ATTRS{product}=="AudioQuest DragonFly Cobalt v1.0"
ATTRS{product}=="xHCI Host Controller"
~$
Code: Select all
SUBSYSTEM=="usb", ATTRS{product}=="AudioQuest DragonFly Cobalt v1.0", ACTION=="add", RUN+="/bin/cp /etc/asound.conf.bak /etc/asound.conf"
SUBSYSTEM=="usb", ATTRS{product}=="AudioQuest DragonFly Cobalt v1.0", ACTION=="remove", RUN+="/bin/rm /etc/asound.conf"
Save the rule to /etc/udev/rules.d/00-dac.rules
The rule copies /etc/asound.conf.bak to /etc/asound.conf when the device is added, this "activates" the configuration file. The second line deletes /etc/asound.conf when the device is removed thus "deactivating" the configuration and reverting to the usual audio output device.
See http://reactivated.net/writing_udev_rules.html for a more complete treatment of udev rule implementation.
Finally remove the device and reload the udev rules to apply the new addition:
Code: Select all
# udevadm control --reload