Monday, 27 February 2017

Preferentially using an external USB Audio Interface as a primary/default pulseaudio sink when available.

On my Lenovo laptop, there is an internal Intel HDA sound card, but a far superior TASCAM audio interface is plugged into my dock, which is in turn wired up to my speakers. When docked, I want the laptop to use the TASCAM sound card, but when roaming, I want it to switch to the internal.


entropy@symplex:~$ pactl list short cards
0 alsa_card.pci-0000_00_03.0 module-alsa-card.c
1 alsa_card.usb-TEAC_Corporation_US-2x2-00 module-alsa-card.c
2 alsa_card.pci-0000_00_1b.0 module-alsa-card.c
entropy@symplex:~$

I'm talking about the TEAC one, of course; TASCAM is a TEAC offshoot. The third one you see is just HDMI, and we'll ignore it for now.

In your modules list, you should see a module called module-default-device-restore. This is the module that will do the magic, but it doesn't do what we want out of the box. The module is meant to save your configured default-sink and restore it on boot. What happens is that when you boot with the laptop undocked, the module sees that the default-saved-sink is not available, and goes back to the internal one (what we want), but when you shut down, it saves the current default-sink as the new default-saved-sink, which means that the next time you boot-up docked, the internal card will still be the active default sink.


entropy@symplex:~$ pactl list short modules 0 module-device-restore
1 module-stream-restore
2 module-card-restore
3 module-augment-properties
4 module-switch-on-port-available
5 module-udev-detect
6 module-alsa-card device_id="0" name="pci-0000_00_03.0" card_name="alsa_card.pci-0000_00_03.0" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes card_properties="module-udev-detect.discovered=1"
7 module-alsa-card device_id="2" name="usb-TEAC_Corporation_US-2x2-00" card_name="alsa_card.usb-TEAC_Corporation_US-2x2-00" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes card_properties="module-udev-detect.discovered=1"
9 module-alsa-card device_id="1" name="pci-0000_00_1b.0" card_name="alsa_card.pci-0000_00_1b.0" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes card_properties="module-udev-detect.discovered=1"
10 module-bluetooth-policy
11 module-bluetooth-discover
12 module-bluez5-discover
13 module-native-protocol-unix
14 module-default-device-restore
15 module-rescue-streams
16 module-always-sink
17 module-intended-roles
18 module-suspend-on-idle
19 module-systemd-login
20 module-position-event-sounds
21 module-filter-heuristics
22 module-filter-apply
23 module-x11-publish display=:0.0
24 module-x11-bell display=:0.0 sample=bell.ogg
25 module-x11-cork-request display=:0.0
26 module-x11-xsmp display=:0.0 session_manager=local/symplex:@/tmp/.ICE-unix/1407,unix/symplex:/tmp/.ICE-unix/1407
entropy@symplex:~$

The way to do this is to simply remove write permissions from the file to which the module saves the default-sink to. This is in the pulse configuration directory. If you have many of the *-default-sink files, then check their timestamps and perform the procedure on the latest one. The hash is a machine ID that pulse uses to associate configurations to machines. The one with the latest timestamp is most likely your current machine ID hash.

entropy@symplex:~$ ls ~/.config/pulse/
cookie
ffdf15cb76974ed4aaa951b2d3564f7b-card-database.tdb
ffdf15cb76974ed4aaa951b2d3564f7b-default-sink
ffdf15cb76974ed4aaa951b2d3564f7b-default-source
ffdf15cb76974ed4aaa951b2d3564f7b-device-volumes.tdb
ffdf15cb76974ed4aaa951b2d3564f7b-stream-volumes.tdb
entropy@symplex:~$ cat ~/.config/pulse/ffdf15cb76974ed4aaa951b2d3564f7b-default-sink
alsa_output.usb-TEAC_Corporation_US-2x2-00.analog-stereo
entropy@symplex:~$ 

First make sure that the you are docked and the external card is the currently-saved card as the default-sink (as in the above example), then remove the permissions.


entropy@symplex:~$ chmod a-w ~/.config/pulse/ffdf15cb76974ed4aaa951b2d3564f7b-default-sink
entropy@symplex:~$ 

Done.

Pulse will always try to restore the external card as the default-sink, and failing that revert to the internal card.

5 comments:

  1. I am grateful for this blog to distribute knowledge about this significant topic. Here I found different segments and now I am going to use these new instructions with new enthusiasm.
    Dell PowerEdge R430

    ReplyDelete
  2. I am thankful for this blog to gave me much knowledge regarding my area of work. I also want to make some addition on this platform which must be in knowledge of people who really in need. Thanks.
    ซื้อ เซิ ฟ เวอร์

    ReplyDelete
  3. Your blog is very informative. Eating mindfully has been very hard for people these days. It's all because of their busy schedules, work or lack of focus on themselves. As a student I must admit that I have not been eating mindfully but because of this I will start now. It could help me enjoy my food and time alone. Eating mindfully may help me be aware of healthy food and appreciating food.
    Nutanix Xpress 3Node

    ReplyDelete
  4. Now you buy one the top rate bitcoin mining machine asic antminer s9 for sale at very low price, it is on sale direct from china, Yes, 100% brand new working fine with complete packing and free shipment

    ReplyDelete
  5. Do you want to convert cryptocurrency into real money, then bitcoin exchanger is dream website for this purpose, you can make your transaction here easily with full confidence.

    ReplyDelete