mathr / blog / #

JACK on top of Pulseaudio

While evaluating whether to dive in and get a Bela single board computer for low latency processing of external inputs, that I would want to livecode in the C programming language using my clive system, I found that my initial attempts at cross-compiling into a network-shared folder were doomed, because my host system was running Debian Buster (current Testing, next Stable) and my device system (a Raspberry Pi Model 3 B) was running Raspbian Jessie (current OldStable). Jessie has an ancient glibc, the basic libraries that let C programs and libraries work, and my cross-compiled code needed a newer version.

So I installed Debian Buster arm64 from unofficial unsupported sources. After upgrading the system to my liking, I tried the audio through HDMI. The aplay command could make some noise, but it was using a Pulseaudio backend. Try as I might I couldn't get a raw ALSA backend to make any sound, especially not with JACK (which output errors about not supported hardware sample types). So I resorted to radical means. I set up a JACK server using the dummy backend, and hooked Pulseaudio to it with pulseaudio-module-jack. Then adding a loopback Pulseaudio device to route the JACK sources/sinks to the hardware:

$ /usr/bin/jackd -ddummy &

$ tail /etc/pulse/
load-module module-jack-source
load-module module-jack-sink
set-default-sink jack_out
set-default-source jack_in
load-module module-loopback source=jack_in sink=alsa_output.platform-3f902000.hdmi.iec958-stereo

$ mplayer -ao jack somefile.ogg -loop 0 &

$ jack_connect "MPlayer [15406]:out_0" "PulseAudio JACK Source:front-left"
$ jack_connect "MPlayer [15406]:out_1" "PulseAudio JACK Source:front-right"

Note: this is significantly different to the usual software -> Pulse -> JACK -> ALSA -> ears route, it's more like software -> JACK -> Pulse -> ALSA -> ears, though I don't really know what happens beyond Pulse in this setup... All I know is I hear sounds from JACK on the HDMI output, which is all that matters.

Now the last thing is figuring out how to disable the screensaver timeout on the lightdm greeter login prompt, when that kicks in all sound goes off. I can disable the screensaver if I login, but an automatically logged in session is a bit annoying. There is a greeter screensaver timeout variable, but that applies only to lock screen, not login screen. I want to make sounds through HDMI from a remote ssh session.

And another shiny thing would be automatically considering the PulseAudio JACK ports as physical and the JACK dummy system: ports as not, so that automatic connections work as expected (I hear nothing until I manually connect the ports as above).