Udev and Pulse
To use a USB DAC (digital-analog audio converter) in Sailfish OS it is necessary to set up udev to respond to the device being plugged in and turn off the internal sound card.
You need to become root:
# devel-su // root
# echo 'ATTRS{id}=="mtsndcard", ENV{PULSE_IGNORE}="1"' > /etc/udev/rules.d/89-pulseaudio-usb.rules
# cd /etc/pulse/xpolicy.conf.d
# mv usbaudio.conf.disabled usbaudio.conf
# exit // back to user
# pactl load-module module-udev-detect
The last command should be done at system boot through pulse. SadlyIt none of the followingMAY work andon youyour needphone toas executeis. thatSadly pactlon loadvolla commandphones after(gigaset reboot.GS5/rephone) it does not. This solution does:
# editas .config/pulse/default.paroot
.includedevel-su
# create /etc/pulse/default.pausr/local/bin/udev-create-flag
# with contents
#!/bin/sh
# called by udev (runs as root)
# write a flag in the user's runtime dir so the user service notices it
USER="defaultuser"
FLAG="/run/user/$(id -u "$USER")/usb-dac-connected.flag"
mkdir -p "$(dirname "$FLAG")"
touch "$FLAG"
# make it executable
chmod 755 /usr/local/bin/udev-create-flag
# create /usr/local/bin/set-usb-dac-volume.sh
# with content this version is NOT setting volume, just making sure the dac is seen
#!/bin/sh
sleep 2
/usr/bin/pactl load-module module-udev-detect
# make it executable
chmod 755 /usr/local/bin/set-usb-dac-volume.sh
# create /home/defaultuser/.config/systemd/user/usb-dac-volume.path
# with contents
[Unit]
Description=Watch for USB DAC flag
[Path]
PathExists=/run/user/%U/usb-dac-connected.flag
Unit=usb-dac-volume.service
[Install]
WantedBy=default.target
# create /home/defaultuser/.config/systemd/user/usb-dac-volume.service
# with contents
[Unit]
Description=Run USB DAC volume script when flag present
After=default.target
[Service]
Type=oneshot
Environment=XDG_RUNTIME_DIR=%t
ExecStart=/usr/local/bin/set-usb-dac-volume.sh
ExecStartPost=/bin/rm -f /run/user/%U/usb-dac-connected.flag
TimeoutStartSec=60
[Install]
WantedBy=default.target
edit /home/defaultuser/.config/systemd/user/pulse_udev.service
[Unit]
Description=udev-pactl-start-usb-dac
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/bin/pactl load-module module-udev-detect
[Install]
WantedBy=multi-user.target
Then run
systemctl --user enable pulse_udev.service
Article discussion: USB DAC playback on Sailfish OS Forum