Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
sound [2015/06/03 03:35]
slackermedia
sound [2021/06/03 19:48] (current)
Line 1: Line 1:
-[[{arrowp.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​left:​0;​}jack|]] 
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​margin-left:​2.5em;​}ffmpeginstall|]] 
  
  
Line 8: Line 6:
 <WRAP info> <WRAP info>
 **TL;DR** \\ **TL;DR** \\
-For full sound integration of JACK and non-JACK applications,​ you need to perform one of three configuration mods: either use an ALSA-JACK bridge, use JACK exclusively,​ or use only JACK applications ​whilst ​JACK is running. Also, there'​s a bug in Firefox.+For full sound integration of JACK and non-JACK applications,​ you need to perform one of three configuration mods: either use an [[#​alsajack|ALSA-JACK bridge]], use [[#​jackjack|JACK exclusively]], or be lazy and just [[#​jacktime|use JACK applications]] during the time you have JACK running. Also, there'​s a bug in Firefox.
 </​WRAP>​ </​WRAP>​
  
Line 21: Line 19:
 If you have these installed, then it is safe to install ''​alsa-plugins''​. It is available from [[http://​slackbuilds.org]]. If you have these installed, then it is safe to install ''​alsa-plugins''​. It is available from [[http://​slackbuilds.org]].
  
-===== ALSA JACK Plugin ​=====+{{anchor:​alsajack}} 
 +===== ALSA JACK Bridge ​===== 
 + 
 +**Skill Level:** 
 +//This is an intermediate solution, and the recommended Slackermedia solution.//
  
 The first method, outlined on [[http://​jackaudio.org/​faq/​routing_alsa.html]],​ is to create a dummy ALSA "​loopback"​ device that can be used from within JACK. This means that while JACK is running, a non-JACK application can still play through your system sound cards by piping its way through JACK via an ALSA tunnel, of sorts. The first method, outlined on [[http://​jackaudio.org/​faq/​routing_alsa.html]],​ is to create a dummy ALSA "​loopback"​ device that can be used from within JACK. This means that while JACK is running, a non-JACK application can still play through your system sound cards by piping its way through JACK via an ALSA tunnel, of sorts.
Line 59: Line 61:
 We add a second PCM definition for a device called ''​pcm.jack''​. This uses our ''​rawjack''​ device but also converts between audio data formats. We add a second PCM definition for a device called ''​pcm.jack''​. This uses our ''​rawjack''​ device but also converts between audio data formats.
  
-Log out and log back in (or reboot if you prefer) and from now on, you can set the output device of any ALSA application to ''​pcm.jack''​ if you are using an ALSA-only application whilst running ​JACk.+Log out and log back in (or reboot if you prefer) and from now on, you can set the output device of any ALSA application to ''​pcm.jack''​ if you are using an ALSA-only application whilst running ​JACK.
  
 Test this with this command: Test this with this command:
Line 68: Line 70:
 </​code>​ </​code>​
  
-You can set the ALSA output in non-JACK ​applications ​in that application'​s **Preferences** ​or **Settings** menu. For example, ​to configure ''​VLC''​ to pipe its output ​to the ALSA/JACK bridge:+Most, if not all, applications that you will normally use with or without JACK running are set to send sound to the "​default"​ device. ​
  
-{{ vlcjack.png }}+The problem when running JACK is that the "​default"​ device (ALSA) is useless; the //new// default device while JACK is running should be your JACK tunnel.
  
-Assuming everything is still working at this pointmake all ALSA applications use the new bridge ​device by default:+You could go into each application'​s **Preferences** or **Settings** menu and set the output to your bridge. For exampleto configure ''​VLC''​ to pipe its output to the ALSA/​JACK ​bridge:
  
-Open ''​~/​.asoundrc''​ in a text editor ​and add this block of code:+[{{ vlcjack.png |You probably don't //really// want to do this manually.}}] 
 + 
 +However, you would need to set it //back// to ALSA so you could hear it when JACK is not running. 
 + 
 +Obviously, there is a better way: automatic switching. 
 + 
 + 
 +==== Automatic Switching ==== 
 + 
 +In order for applications to know to use the ALSA-JACK bridge that you have just set up, you should configure the default sound device as the ALSA-JACK bridge whenever JACK is running.  
 + 
 +The easiest way to configure such a switch is a shell script wrapper around starting and stopping JACK. 
 + 
 +First, you need to know what command you want to use to start ''​jackd'',​ and place this command, verbatim, into ''​~/​.jackdrc''​. This is the standard JACK startup file, so it might be over-written by other front-ends to ''​jackd''​ (like **QJackCtl**, ​in particular) if you use them, but that's not necessarily ​bad thing. 
 + 
 +If you do not have a known-good command to start ''​jackd'',​ read the [[jack|JACK]] section. 
 + 
 +It's not a bad idea to get into the habit of backing up useful commands. For instance, something as simple as: 
 + 
 +<​code>​  
 +echo 'jackd -R -d alsa -P hw:0 -X seq' > ~/​jackd.command 
 +</​code>​ 
 + 
 +preserves the syntax ​and known-good command that you can refer to whenever you need. 
 + 
 +Once you have constructed a good JACK command and placed it into ''​~/​.jackdrc'',​  
 +create two versions of ''​~/​.asoundrc'':​ your current version, and another temporary one with this clause at the very end of the file:
  
 <​code>​ <​code>​
-pcm.!default { +  ​pcm.!default { 
-    type plug +  type plug  
-    slave { pcm "​rawjack"​ }+  slave { pcm "​rawjack"​ } 
 +  } 
 +</​code>​ 
 + 
 +This sets the default device to the ''​rawjack''​ device you have created to serve as your ALSA-JACK bridge. 
 + 
 + 
 +Next, create a patch file from the delta between the two files: 
 + 
 +<​code>​ 
 +$ diff -u ~/.asoundrc ~/​.asoundrc-temp > ~/​.asoundrc-switch 
 +$ rm ~/​.asoundrc-temp 
 +</​code>​ 
 + 
 +The resulting file (''​~/​.asoundrc-switch''​):​ 
 + 
 +<​code>​ 
 +--- $HOME/​.asoundrc  ​  ​2015-06-03 01:​28:​04.732320885 +1200 
 ++++ $HOME/​.asoundrc-switch 2015-06-02 18:​06:​18.974253004 +1200 
 +@@ -16,4 +16,9 @@ 
 +     hint { 
 +     ​description "JACK Audio Tunneling Kit" 
 +     } 
 ++} 
 +
 ++pcm.!default { 
 +   type plug 
 +   slave { pcm "​rawjack"​ } 
 + } 
 +\ No newline at end of file 
 +</​code>​ 
 + 
 +And finally, create the shell script wrapper that will activate or de-activate the bridge, and start and stop ''​jackd''​. You can copy and paste the code from here, or you can check for updates at [[https://​gitlab.com/​slackermedia/​cousteau]] 
 + 
 +<​code>​ 
 +#​!/​bin/​bash 
 + 
 +# traps ctrl-c and others for this wrapper script 
 +trap "patch -R ~/.asoundrc ~/​.asoundrc-switch"​ 1 2 9 15 
 + 
 +function jackgo() { 
 +        echo "​Starting jackd.."​ 
 +        sleep 1 
 +        printf "​."​ 
 +        sleep 1 
 +        exec `< ~/.jackdrc`
 } }
 +
 +function hijack()
 +{
 +    DEF=`grep default $HOME/​.asoundrc`
 +    if [ -z "​$DEF"​ ]; then
 +        patch ~/.asoundrc ~/​.asoundrc-switch
 +        jackgo
 +    else
 +        jackgo
 +    fi
 +}
 +
 +hijack &
 +
 +# catches ctrl-c and others for jackd
 +killjack=$!
 +wait $killjack && patch -R ~/.asoundrc ~/​.asoundrc-switch || \
 +    echo "​Unable to restore ALSA config. Check your ~/.asoundrc file." && exit 1
 +
 +exit 0
 </​code>​ </​code>​
  
-If you do this, you must remove ​other definitions of ''​pcm.!default''​. ​There should only be one default+Save this script somewhere handy with a convenient name. I call mine ''​cousteau''​. 
 + 
 +Make it executable:​ 
 + 
 +<​code>​ 
 +$ chmox +x ~/​cousteau 
 +</​code>​ 
 + 
 +To make it handyplace it in a directory in your ''​PATH''​ so that all you have to do to execute it is type ''​cousteau''​ in the terminal.  
 + 
 +It's traditional in UNIX to have a ''​$HOME/​bin''​ directory (where "​bin"​ is short for "​binary",​ or in other words, an executable application):​ 
 + 
 +<​code>​ 
 +$ mkdir ~/bin 
 +$ touch ~/.bashrc 
 +$ echo 'export PATH=$PATH:​$HOME/​bin 
 +$ source ~/.bashrc 
 +$ cp cousteau ~/bin 
 +</​code>​  
 + 
 +Or you may prefer to store it in a standard system-wide location: 
 + 
 +<​code>​ 
 +$ su -c 'cp cousteau /​usr/​local/​bin'​ 
 +</​code>​ 
 + 
 +Now you can use your script to start JACK, and it your ''​~/​.asoundrc'' ​file will be patched automatically for youIf jackd dies or is killed by some other process, or cousteau is killed by some other process (such as pressing ''​ctrl-c''​ in the terminal where cousteau is running), then ''​~/​.asoundrc''​ will be restored to normal. 
  
 <WRAP alert> <WRAP alert>
Line 91: Line 211:
 </​WRAP>​ </​WRAP>​
  
 +{{anchor:​jackjack}}
 ===== Always-On JACK Daemon ===== ===== Always-On JACK Daemon =====
 +
 +
 +**Skill Level:**
 +//This is a complex solution and requires advanced skills.//
  
 The second option is to run JACK all the time, no matter what. This is a more complex setup but it has your computer being an active JACK session all the time, meaning that you can route or hijack any sound to or from any device or application at a moment'​s notice. The second option is to run JACK all the time, no matter what. This is a more complex setup but it has your computer being an active JACK session all the time, meaning that you can route or hijack any sound to or from any device or application at a moment'​s notice.
Line 327: Line 452:
 </​WRAP>​ </​WRAP>​
  
 +{{anchor:​jacktime}}
 ===== JACK Enabled Apps ===== ===== JACK Enabled Apps =====
 +
 +
 +**Skill Level:**
 +//This is the easiest solution; it requires no skill, but its limitations can be annoying.//
  
 The simplest solution, in terms of effort, is to just use JACK-enabled applications whilst you are running an active JACK session. It seems almost too simple, but in practise, depending on your workflow, it ends up being quite realistic. The simplest solution, in terms of effort, is to just use JACK-enabled applications whilst you are running an active JACK session. It seems almost too simple, but in practise, depending on your workflow, it ends up being quite realistic.
Line 343: Line 472:
  
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​float:​right;​}ffmpeginstall|]][[{arrowp.png|border:​0;​background:​none;​width:​0;​float:​right;​}jack|]]+<WRAP centeralign>​ 
 +<wrap fa>[[jack|R]]</​wrap>​ <wrap fa>[[start|S]]</​wrap>​ <wrap fa>​[[ffmpeginstall|Q]]</​wrap>​ 
 +</​WRAP>​