15 September 2018

With our powers combined

Out of nowhere, a post. Still working. No brainspace. But I needed to fix my PulseAudio again (surprise!), as the "Simultaneous output" option in paprefs doesn't seem to work anymore, so here's how I did it:

Searching around tells me I can install my own combined output with the pacmd program, loading the 'module-combine-sink' module and specifying which sinks to combine. Which requires the 'list-sinks' argument to determine what the name of the devices are as far as Pulse is concerned. Gosh, PulseAudio, you're so user friendly!

While we're at it, I can take the opportunity to combine just two of my outputs, the Avantree Leaf USB dongle and the normal speakers. I also have outputs created by my Yeti microphone and for HDMI output but I don't need that combined with everything else, and I suspect it just causes lag and other problems.

Was almost going to do it in Bash but... no, come on, a quick Perl 5 script will do nicely:

#!/usr/bin/env perl

# Quick and dirty script to fix stupid broken pulseaudio and re-enable the combined output option.
# In this case, I only want to combine two outputs - those that match the names specified below:

use strict;
use warnings;
use v5.16;
use List::Util qw/any/;
use Term::ANSIColor;

my @sinks = map { /<([^>]+)>/ && $1 } grep /name: <([^>]+)>/, `pacmd list-sinks`;
my @combine = grep /( Avantree_Leaf | pci-0000_00 )/xi, @sinks;
my $cmd = "pacmd load-module module-combine-sink"
        . " sink_name=combined sink_properties=device.description=CombinedOutput"
        . " slaves=" . join(',', @combine)
        . " channels=2";
say colored("Running: ", 'bold cyan') . colored($cmd, 'cyan');

Now I can select the new combined output in pavucontrol:

No comments:

Post a Comment