Author Topic: Sound Tip: PulseAudio and JACK Integration  (Read 5729 times)

String6

  • Guest
Sound Tip: PulseAudio and JACK Integration
« on: June 25, 2010, 12:48:43 PM »
Hello All.
I thought I'd share my really good sound set up for those
interested in all-round integration.

OVERVIEW:-
After logging in, PulseAudio asserts itself as the desktop
sound daemon. This remains the case until a JACK application
is started. QjackCtl (jackd) is started, briefly terminating
PulseAudio then restarting it again using a JACK sink profile.

This keeps the application compatibility benefits of PulseAudio
by connecting to JACK instead of the sound card.
This isn't a pro-audio setup per se as PulseAudio would normally
be terminated as to not hinder JACK latency performance unnecessarily.

REQUIREMENTS:-
Working PulseAudio installation.
Pulseaudio-module-jack is installed.

CAVEATS:-
1) If suspending to RAM / hibernating be sure to stop JACK from running
allowing PulseAudio to take over, as JACK is not supported in this way.
2) Pause/stop playback of clients first when starting/stopping JACK.
3) Allow one or two seconds between any successive stopping and starting
of JACK.

Okay then!
Create the following BASH scripts and make them executable:-

1)
.............................................................
#!/bin/bash
pulseaudio -kkk
#sleep 1
pulseaudio -nF /etc/pulse/jack-sink.pa -D
exit
.............................................................
Create the above script as /usr/local/bin/jack-pulse


2)  EXAMPLE JACK CLIENT START SCRIPT (Phasex)                   
.............................................................
#!/bin/bash
if [ "$(pidof qjackctl)" ]; then phasex &
else
qjackctl &
sleep 2
phasex &
fi
exit
.............................................................
Create the above script as /usr/local/bin/phasex-qjackctl
Change Phasex to JACK app of choice. Create more as required.
This script will check for a running instance of QjackCtl
and run it first if needed before launching the application
itself.
This script should be executed by a custom menu/desktop application
launcher.

3) Create a JACK SINK profile for PulseAudio:-

Use your existing '/etc/pulse/default.pa' as a template and add the
following:-
......................................
load-module module-jack-sink
load-module module-jack-source
......................................

Then save as /etc/pulse/jack-sink.pa


4) QJACKCTL CONFIGURATION

This configuration will start minimized in the system tray and handle
PulseAudio.
Save as  '.config/rncbc.org/QjackCtl.conf' in your home directory.

See Below:- (Config only, not an executable)
................................................

[Splitter]
AudioConnectView\sizes=267, 86, 267
MidiConnectView\sizes=34, 20, 34
AlsaConnectView\sizes=34, 20, 34
PatchbayView\sizes=34, 20, 34

[Settings]
Server=jackd
Realtime=false
SoftMode=true
Monitor=true
Shorts=false
NoMemLock=false
UnlockMem=false
HWMon=true
HWMeter=true
IgnoreHW=false
Priority=0
Frames=1024
SampleRate=48000
Periods=3
WordLength=16
Wait=21333
Chan=0
Driver=alsa
Interface=
Audio=0
Dither=0
Timeout=500
InDevice=
OutDevice=
InChannels=0
OutChannels=0
InLatency=0
OutLatency=0
StartDelay=1
Verbose=false
PortMax=256
MidiDriver=none

[Geometry]
qjackctlMessagesForm\x=0
qjackctlMessagesForm\y=0
qjackctlMessagesForm\width=328
qjackctlMessagesForm\height=200
qjackctlMessagesForm\visible=false
qjackctlStatusForm\x=0
qjackctlStatusForm\y=0
qjackctlStatusForm\width=386
qjackctlStatusForm\height=238
qjackctlStatusForm\visible=false
qjackctlConnectionsForm\x=0
qjackctlConnectionsForm\y=0
qjackctlConnectionsForm\width=567
qjackctlConnectionsForm\height=286
qjackctlConnectionsForm\visible=false
qjackctlPatchbayForm\x=0
qjackctlPatchbayForm\y=0
qjackctlPatchbayForm\width=740
qjackctlPatchbayForm\height=385
qjackctlPatchbayForm\visible=false
qjackctlMainForm\x=0
qjackctlMainForm\y=0
qjackctlMainForm\width=486
qjackctlMainForm\height=100
qjackctlMainForm\visible=false

[Program]
Version=0.3.4

[Presets]
DefPreset=(default)

[Options]
StartJack=true
StartupScript=true
StartupScriptShell=pulseaudio -k
PostStartupScript=true
PostStartupScriptShell=jack-pulse
ShutdownScript=true
ShutdownScriptShell=
PostShutdownScript=true
PostShutdownScriptShell=killall jackd
StdoutCapture=false
XrunRegex=xrun of at least ([0-9|\\.]+) msecs
XrunIgnoreFirst=true
ActivePatchbay=true
ActivePatchbayPath=
MessagesLog=false
MessagesLogPath=qjackctl.log
BezierLines=false
TimeDisplay=0
TimeFormat=0
MessagesFont="Sans,9,-1,5,50,0,0,0,0,0"
MessagesLimit=true
MessagesLimitLines=1000
DisplayFont1="Sans,12,-1,5,75,0,0,0,0,0"
DisplayFont2="Sans,9,-1,5,50,0,0,0,0,0"
DisplayEffect=true
DisplayBlink=true
JackClientPortAlias=0
ConnectionsIconSize=0
ConnectionsFont="Sans,9,-1,5,50,0,0,0,0,0"
QueryClose=true
KeepOnTop=false
SystemTray=true
StartMinimized=true
DelayedSetup=false
ServerConfig=true
ServerConfigName=.jackdrc
ServerConfigTemp=false
QueryShutdown=true
AlsaSeqEnabled=true
AliasesEnabled=false
AliasesEditing=false
LeftButtons=true
RightButtons=true
TransportButtons=true
TextLabels=true
BaseFontSize=0

[Defaults]
PatchbayPath=
.................................................

That's it. Good Luck!  8)

P.S. For JACK clients that are unable to connect automatically,
a patchbay XML file will need to be created using QjackCtl and
set to 'active'.

 

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Sound Tip: PulseAudio and JACK Integration
« Reply #1 on: June 25, 2010, 02:49:37 PM »
Nice write up!   ;)

What benefit is there for normal use of PC in using Jack?

I never tried it and never seemed to be missing anything ......

Offline djohnston

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6227
  • I don't do Windows
Re: Sound Tip: PulseAudio and JACK Integration
« Reply #2 on: June 25, 2010, 07:06:33 PM »
Nice write up!   ;)

What benefit is there for normal use of PC in using Jack?

I never tried it and never seemed to be missing anything ......

JACK is mainly used for audio recording. It makes device interfacing a lot easier. I don't use pulseaudio on a JACK system, as pulseaudio introduces latency, the enemy of recording. I agree, though. Very nice writeup. He's covered the bases.
Bare metal                           VBox
AMD Athlon 7750 Dual-Core    Single core
4GiB RAM                              1GiB RAM
nVidia GeForce FX 5200          64MB video
LXDE 32bit                            KDE 64bit

Registered Linux User #416378

String6

  • Guest
Re: Sound Tip: PulseAudio and JACK Integration
« Reply #3 on: June 25, 2010, 09:49:07 PM »
Thanks guys!
Well there's no real benefit or requirement for 'mainstream/everyday' users in
productivity terms.
Having a working sound daemon (be it PulseAudio,ESD,Phonon) is needed for
simultaneous playback of audio streams, for example listening to music via
Rhythmbox/Amarok while watching videos and hearing desktop event sounds
that might occur.
But, if you are interested in audio production, or just plain curious to see what
those applications do, the above set up will give a good base configuration from
which to start.
The main benefits of JACK are:-
Low latency (lag or delay of 'live' sound recording and playback)
Transport control (pause/play) for all connected clients (Ardour,Hydrogen,Qtractor etc) from any
single client or QjackCtl. Great for getting your 'virtual band members' to all start playing at the
same time!  :D
Patchbay (virtual in/output client connectivity) customization for specific needs.
Think recording studio mixing desk and all wired music hardware.

My personal desires in addition to the above, is the kudos of all sound applications appearing
to run smoothly without conflict and not needing clumsy manual stop/start of sound daemons
in addition to the sound applications themselves. (21st century stuff folks!) ;D

Oh, and here's my custom patchbay XML file:-

<!DOCTYPE patchbay>
<patchbay version="0.3.4" name="qjackctl-patchbay">
 <output-sockets>
  <socket exclusive="off" client="system" type="audio" name="system">
   <plug>capture_1</plug>
   <plug>capture_2</plug>
  </socket>
  <socket exclusive="off" client="alsa_pcm" type="audio" name="alsa_pcm">
   <plug>monitor_1</plug>
   <plug>monitor_2</plug>
  </socket>
  <socket exclusive="off" client="PulseAudio JACK Sink" type="audio" name="PulseAudio JACK Sink">
   <plug>front-left</plug>
   <plug>front-right</plug>
  </socket>
  <socket exclusive="off" client="ZynAddSubFX" type="audio" name="ZynAddSubFX">
   <plug>out_1</plug>
   <plug>out_2</plug>
  </socket>
  <socket exclusive="off" client="Qtractor" type="audio" name="Qtractor">
   <plug>Master/out_1</plug>
   <plug>Master/out_2</plug>
  </socket>
  <socket exclusive="off" client="fluidsynth" type="audio" name="fluidsynth">
   <plug>left</plug>
   <plug>right</plug>
  </socket>
  <socket exclusive="off" client="qsynth" type="audio" name="qsynth">
   <plug>left</plug>
   <plug>right</plug>
  </socket>
  <socket exclusive="off" client="phasex" type="audio" name="phasex">
   <plug>out_1</plug>
   <plug>out_2</plug>
  </socket>
  <socket exclusive="off" client="Midi Through" type="midi" name="Midi Through">
   <plug>Midi Through Port-0</plug>
  </socket>
  <socket exclusive="off" client="Qtractor" type="midi" name="Qtractor Midi">
   <plug>Master</plug>
  </socket>
  <socket exclusive="off" client="VMPK Output" type="midi" name="VMPK Midi">
   <plug>VMPK Output</plug>
  </socket>
 </output-sockets>
 <input-sockets>
  <socket exclusive="off" client="system" type="audio" name="system">
   <plug>playback_1</plug>
   <plug>playback_2</plug>
  </socket>
  <socket exclusive="off" client="PulseAudio JACK Source" type="audio" name="PulseAudio JACK Source">
   <plug>front-left</plug>
   <plug>front-right</plug>
  </socket>
  <socket exclusive="off" client="Qtractor" type="audio" name="Qtractor">
   <plug>Master/in_1</plug>
   <plug>Master/in_2</plug>
  </socket>
  <socket exclusive="off" client="phasex" type="audio" name="phasex">
   <plug>in_1</plug>
   <plug>in_2</plug>
  </socket>
  <socket exclusive="off" client="Midi Through" type="midi" name="Midi Through">
   <plug>Midi Through Port-0</plug>
  </socket>
  <socket exclusive="off" client="ZynAddSubFX" type="midi" name="ZynAddSubFX">
   <plug>ZynAddSubFX</plug>
  </socket>
  <socket exclusive="off" client="Qtractor" type="midi" name="Qtractor">
   <plug>Master</plug>
  </socket>
  <socket exclusive="off" client="FLUID Synth \(FluidSynth\)" type="midi" name="FLUID Synth (FluidSynth)">
   <plug>Synth input port \(FluidSynth:0\)</plug>
  </socket>
  <socket exclusive="off" client="FLUID Synth \(qsynth\)" type="midi" name="FLUID Synth (qsynth)">
   <plug>Synth input port \(qsynth:0\)</plug>
  </socket>
  <socket exclusive="off" client="PHASEX Synthesizer" type="midi" name="PHASEX Synthesizer">
   <plug>PHASEX Port 0</plug>
  </socket>
  <socket exclusive="off" client="VMPK Input" type="midi" name="VMPK Input">
   <plug>VMPK Input</plug>
  </socket>
 </input-sockets>
 <slots/>
 <cables>
  <cable output="system" input="PulseAudio JACK Source"/>
  <cable output="system" input="phasex"/>
  <cable output="system" input="Qtractor"/>
  <cable output="PulseAudio JACK Sink" input="system"/>
  <cable output="ZynAddSubFX" input="system"/>
  <cable output="Qtractor" input="system"/>
  <cable output="Qtractor" input="FLUID Synth (FluidSynth)"/>
  <cable output="qsynth" input="system"/>
  <cable output="phasex" input="system"/>
  <cable output="Midi Through" input="FLUID Synth (FluidSynth)"/>
  <cable output="VMPK Midi" input="FLUID Synth (qsynth)"/>
  <cable output="VMPK Midi" input="PHASEX Synthesizer"/>
 </cables>
</patchbay>

..................................................................................

Save as qjackctl-patchbay.xml in your home directory. Open QjackCtl
enter 'Setup --> Options --> Connections' and select the file and tick
'Activate Patchbay persistence'.

Enjoy!  ;)



Offline djohnston

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6227
  • I don't do Windows
Re: Sound Tip: PulseAudio and JACK Integration
« Reply #4 on: June 25, 2010, 09:55:51 PM »
Thanks, String6. I've saved all this to text files for future reference. Honestly, I've seen too many pulseaudio horror stories. Makes me scared to try to implement it, as I don't have a need to stream over a network. And I tend to record one track at a time, then mix. But very good info for future reference.
Bare metal                           VBox
AMD Athlon 7750 Dual-Core    Single core
4GiB RAM                              1GiB RAM
nVidia GeForce FX 5200          64MB video
LXDE 32bit                            KDE 64bit

Registered Linux User #416378

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Sound Tip: PulseAudio and JACK Integration
« Reply #5 on: June 26, 2010, 03:22:45 AM »
Thanks for the explanations guys.

I have Pulse installed here and it is doing everything described, except most likely there is a bit of latency which is not problematic in the normal course of events.

It does though achieve the one thing that has been missing in all audio controls up to now ......  an easy way to allow the user access to the full features of the fitted hardware.

Such features as being easily (mouse click) able to determine the sink (output device) of each application individually, mix inputs and mix outputs, and whether the mixed output is sent to a hardware device or not, or maybe sent to a Null device for monitoring and so on.

So far I have found Pulse solid, and reliable and easy implement in its standard setting, with easy implementation of extra features ----  the usual edit of a config file  :)

The only negative I have encountered is that there are some apps that do not yet have a Pulse plugin available and are thus not yet compatible.
Gizmo5 comes to mind ......  it may be the only one  ...

Of course there are alternatives to that like Ekiga which integrate well.

I will keep this thread bookmarked for reference in case I need a Jack setup in the future.

Thanks again String6 for posting the information.

regards.

Offline Village Idiot

  • Hero Member
  • *****
  • Posts: 2345
  • Have A Nice Day.
Re: Sound Tip: PulseAudio and JACK Integration
« Reply #6 on: June 26, 2010, 03:38:59 AM »
Thanks, String6. I've saved all this to text files for future reference. Honestly, I've seen too many pulseaudio horror stories. Makes me scared to try to implement it, as I don't have a need to stream over a network. And I tend to record one track at a time, then mix. But very good info for future reference.


yup. +1

 :-X (Forum readers will be spared. This time.... ;) )
$ fortune
No Microsoft products were used in any way for the creation of this message.
If you are using a Microsoft product to view it, BEWARE! - I'm not
responsible for any harm you might encounter as a result.

String6

  • Guest
Re: Sound Tip: PulseAudio and JACK Integration
« Reply #7 on: June 26, 2010, 06:04:04 AM »
Just one other thing to mention about output sinks.
If (like me) you are using IEC958 (SPDIF) output, you will need to select these sinks
individually with PulseAudio and QjackCtl applications, as they are of course not linked.
By default both PulseAudio and QjackCtl will normally use stereo analog outputs.

Additionally, changing PulseAudio's hardware profile causes the MASTER output to be
muted (work around anyone?). Be sure to open your mixer to uncheck this.

#### PulseAudio Tweaks ######
Experimental as always, here are my tweaks to '/etc/pulse/daemon.conf' :-

  default-sample-format = s16le
  default-sample-rate = 48000
  default-sample-channels = 2
  default-channel-map = front-left,front-right

  default-fragments = 3
  default-fragment-size-msec = 30

..............................................................................

Sample rate to match that of JACK. Fragments? Take your pick  :D

P.S. Make sure you remove the ' ; ' to uncomment the line!
« Last Edit: June 26, 2010, 06:12:10 AM by String6 »

Offline fraxinus

  • Hero Member
  • *****
  • Posts: 518
Re: Sound Tip: PulseAudio and JACK Integration
« Reply #8 on: July 02, 2010, 08:10:24 AM »
Thanks very much indeed, String6. I have found Jack the biggest challenge (both practically and conceptually) that I have yet faced in six years of everyday Linux usage. Your write-up may help me come to terms with it at last.

Offline Village Idiot

  • Hero Member
  • *****
  • Posts: 2345
  • Have A Nice Day.
Re: Sound Tip: PulseAudio and JACK Integration
« Reply #9 on: July 02, 2010, 01:57:56 PM »
Thanks very much indeed, String6. I have found Jack the biggest challenge (both practically and conceptually) that I have yet faced in six years of everyday Linux usage. Your write-up may help me come to terms with it at last.

 ;D  lol

It's spaghetti audio routing without all those damn messy wires to trip over.  :)
$ fortune
No Microsoft products were used in any way for the creation of this message.
If you are using a Microsoft product to view it, BEWARE! - I'm not
responsible for any harm you might encounter as a result.