Xonotic Forums
PulseJacking: How to pwn PulseAudio and stream it through JACK - Printable Version

+- Xonotic Forums (https://forums.xonotic.org)
+-- Forum: Community (https://forums.xonotic.org/forumdisplay.php?fid=6)
+--- Forum: Off Topic (https://forums.xonotic.org/forumdisplay.php?fid=15)
+--- Thread: PulseJacking: How to pwn PulseAudio and stream it through JACK (/showthread.php?tid=2587)



PulseJacking: How to pwn PulseAudio and stream it through JACK - Minkovsky - 02-06-2012

prestart.sh:
Code:
#!/bin/bash
pacmd suspend true #suspend PA to release the sound card

poststart.sh:
Code:
#!/bin/bash
pactl load-module module-jack-sink channels=2
pactl load-module module-jack-source channels=2
pacmd set-default-sink jack_out
pacmd set-default-source jack_in
pacmd suspend false #required; allows you to play sound via PA to JACK

prestop.sh:
Code:
#!/bin/bash
pacmd suspend true #suspend PA to unload modules
SINKID=$(pactl list | grep -B 1 "Name: module-jack-sink" | grep Module | sed 's/[^0-9]//g')
SOURCEID=$(pactl list | grep -B 1 "Name: module-jack-source" | grep Module | sed 's/[^0-9]//g')
pactl unload-module $SINKID
pactl unload-module $SOURCEID
sleep 5

poststop.sh:
Code:
#!/bin/bash
pacmd suspend false #bring pulse back!

These go into QJackCtl's slots for before starting, after starting, before stopping and after stopping JACK. The effect: Add PA modules to JACK and JACK modules to PA. Then, you just have to connect PA Sink to system out in JACK and you're set, though sometimes some applications might need to be directed to JACK sink manually in pavucontrol.

Sounds clear enough? I'll try to elaborate later.

The Elaboration, part 1
I have been looking for this kind of setup for a long time, and I think I finally found it. True, it requires having pavucontrol constantly open, but it's worth it. Imagine the possibilities. (True, the proper fix would be to extend this and have each application go into its own PulseAudio module, but this is close.)

So what it does, is, step by step:
1. Suspend PulseAudio and make it release the sound card for JACK to grab.
2. Start JACK, then add Pulse/JACK modules - PulseAudio Sink and Source. Make those default so Pulse won't try to grab sound card again, just to fail miserably.
3. Unsuspend PulseAudio so that desktop audio can flow through it.
4. Now, the per-application volume control means you'll have to use pavucontrol to manually route every application into the JACK sink.

When you shut JACK down, it suspends Pulse, removes Pulse/JACK modules and unsuspends Pulse, so that it can get the sound card again. The applications previously routed to JACK will most likely get routed to the sound card automatically.

What it means, is that PulseAudio now acts as any other sound-producing application, although with an internal mixer (so you won't be able to record Skype only without also recording your music, if you use Totem or Banshee or whatever).

This might not be an issue if you're recording, say, a game session with sound from the game AND the conversation with your teammates on Skype. How would you do that? Well, recordMyDesktop supports JACK input, so you'll probably have to do the following:
capture_1 → PulseAudio Source (L+R is recommended if you have a mono mic)
capture_1 → JACK Mixer (L+R)
PulseAudio Sink → JACK Mixer
Select the output from JACK Mixer in gtk-recordMyDesktop as sound input.

(This is theory and it is unchecked).


RE: PulseJacking: How to pwn PulseAudio and stream it through JACK - Mr. Bougo - 02-06-2012

I changed your php forum code to code. More readable.