Skip to content

Instantly share code, notes, and snippets.

@Ghostbird
Last active June 26, 2023 01:02
Show Gist options
  • Save Ghostbird/6f810a03f7c07dae7b2389082accf6ed to your computer and use it in GitHub Desktop.
Save Ghostbird/6f810a03f7c07dae7b2389082accf6ed to your computer and use it in GitHub Desktop.
Add extra pulseaudio - jack bridge connections to allow jack routing for pulseaudio applications
#!/bin/bash
sources=(telegram zoom teams discord extra)
sinks=(telegram kodi zoom teams discord extra)
startTime=$(date +%s)
function capitalise() {
echo $1 | sed -e "s/\b\(.\)/\u\1/g"
}
function start() {
for sink in "${sinks[@]}"
do
# echo $(capitalise ${sink}) Sink
pactl load-module module-jack-sink client_name="'$(capitalise ${sink})'" sink_name="${sink}" sink_properties="starttime=$startTime" connect=no > /dev/null
done
for source in "${sources[@]}"
do
# echo $(capitalise ${source}) Source
pactl load-module module-jack-source client_name="'$(capitalise ${source}) '" source_name="${source}" source_properties="starttime=$startTime" connect=no > /dev/null
done
echo "Added extra PulseAudio connections"
}
function stop() {
pactl list modules short | grep $startTime | cut -f1 | xargs -n 1 pactl unload-module
echo "Removed extra PulseAudio connections"
}
# Kill sleep on any of these signals
trap '[[ $pid ]] && kill $pid' TERM INT HUP QUIT
start
sleep infinity & # Run infinite sleep in background
pid=$! # Save PID of sleep program
wait $pid # Wait for sleep to be killed by the trap
stop
@Ghostbird
Copy link
Author

Ghostbird commented Jun 26, 2023

I ran into an issue where I'd get a lot of Failure: Module initialization failed lines when trying to run the script.
In sudo journalctl -f I saw that this was because pulseaudio was hitting the maximum number of files that it was allowed to keep open.
The solution was:

sudo nano /usr/lib/systemd/user/pulseaudio.service

In the section [Service] add al line that says:

LimitNOFILE=1024

Note: You can use a higher number than 1024 files if necessary.

Afterwards reload the file and restart pulseaudio:

systemctl --user daemon-reload
systemctl --user restart pulseaudio.service

DON'T run these commands with sudo. PulseAudio is a per-user service, hence the --user flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment