Last active
May 19, 2016 22:29
-
-
Save xenithorb/38f0c86fbc86a543d29d41ad1ca7d83d to your computer and use it in GitHub Desktop.
Setup 3x nvidia (same card) monitors for simultaneous output w/ pulseaudio on Fedora 23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x | |
HOME="$( awk -v user="$SUDO_USER" -F':' '$1 == user { print $6 }' /etc/passwd )" | |
UDEV_RULE_FILE="/etc/udev/rules.d/nvidia-hdmi.rules" | |
HOME_CONF_PULSE="${HOME}/.config/pulse" | |
HOME_DEFAULT_PA="${HOME_CONF_PULSE}/default.pa" | |
HOME_DAEMON_CONF="${HOME_CONF_PULSE}/daemon.conf" | |
USR_SHARE_PULSE="/usr/share/pulseaudio/alsa-mixer/profile-sets" | |
USR_SHARE_PULSE_PROFILE_NAME="nvidia-hdmi.conf" | |
USR_SHARE_PULSE_PROFILE="${USR_SHARE_PULSE}/${USR_SHARE_PULSE_PROFILE_NAME}" | |
LSPCI_NAME="NVIDIA.*Audio" | |
PCI_DEV_NUM="0000:$( lspci -mm | awk -v name="$LSPCI_NAME" '$0 ~ name { print $1 }' )" | |
PCI_DEV_NUM_NOCOL="${PCI_DEV_NUM//:/_}" | |
ALSA_CARD="alsa_card.pci-${PCI_DEV_NUM_NOCOL}" | |
PCI_DEV_ID="/sys/bus/pci/devices/${PCI_DEV_NUM}" | |
VENDOR_DEVICE_UDEV_VARS="$( udevadm info -qproperty -p "${PCI_DEV_ID}/sound/card"[0-9] | awk -F'=' '$1 == "ID_MODEL_ID" { model=$2 }; $1 == "ID_VENDOR_ID" { vendor=$2 }; END { print "ATTRS{vendor}==\""vendor"\", ATTRS{device}==\""model"\"" }' )" | |
if [[ -d "$HOME_CONF_PULSE" ]]; then | |
find "$HOME_CONF_PULSE" -mindepth 1 -delete | |
fi | |
defaultpa_processor() { | |
awk ' | |
BEGIN { | |
udev="module-udev-detect$" | |
} | |
$0 ~ udev { | |
$NF=$NF" tsched=0" | |
} 1 | |
' | |
} | |
# /etc/udev/rules.d/nvidia-hdmi.rules | |
cat <<-EOF > "$UDEV_RULE_FILE" | |
SUBSYSTEM!="sound", GOTO="pulseaudio_end" | |
ACTION!="change", GOTO="pulseaudio_end" | |
KERNEL!="card*", GOTO="pulseaudio_end" | |
SUBSYSTEMS=="pci", ${VENDOR_DEVICE_UDEV_VARS}, ENV{PULSE_PROFILE_SET}="${USR_SHARE_PULSE_PROFILE_NAME}" | |
LABEL="pulseaudio_end" | |
EOF | |
# /usr/share/pulseaudio/alsa-mixer/profile-sets/nvidia-hdmi.conf | |
cat <<-EOF > "$USR_SHARE_PULSE_PROFILE" | |
$( cat "${USR_SHARE_PULSE}/default.conf" ) | |
[Profile output:hdmi-all] | |
description = Digital Stereo (HDMI ALL) | |
output-mappings = hdmi-stereo-extra1 hdmi-stereo-extra2 hdmi-stereo-extra3 | |
skip-probe = yes | |
EOF | |
# ~/.config/default.pa | |
cat <<-EOF > "$HOME_DEFAULT_PA" | |
$( cat /etc/pulse/default.pa | defaultpa_processor ) | |
set-card-profile ${ALSA_CARD} output:hdmi-all | |
load-module module-combine-sink sink_name=all_monitors slaves=alsa_output.pci-${PCI_DEV_NUM_NOCOL}.hdmi-stereo-extra1,alsa_output.pci-${PCI_DEV_NUM_NOCOL}.hdmi-stereo-extra2,alsa_output.pci-${PCI_DEV_NUM_NOCOL}.hdmi-stereo-extra3 | |
update-sink-proplist all_monitors device.description="With our powers combined..." | |
set-default-sink all_monitors | |
# Some settings I like | |
# load-module module-echo-cancel | |
# load-module module-switch-on-connect | |
EOF | |
# Screw flat volumes! (another custom settings) | |
cat <<-EOF > "$HOME_DAEMON_CONF" | |
$( cat /etc/pulse/daemon.conf ) | |
flat-volumes = no | |
default-sample-rate = 48000 | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment