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/05/23 18:08]
slackermedia [JACK Enabled Apps]
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;​}kernel|]] 
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​margin-left:​2.5em;​}workflow|]] 
  
  
-====== Studio Sound ======+====== Studio Sound Tweaks ​====== 
 + 
 +<WRAP info> 
 +**TL;DR** \\ 
 +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>​
  
 If you are working with pro audio applications,​ then you'll be working with JACK, the low latency sound system for Linux with robust sound routing capabilities so that the internals of your computer are a fully stocked recording studio with an endless supply of virtual cables and patchbays. ​ If you are working with pro audio applications,​ then you'll be working with JACK, the low latency sound system for Linux with robust sound routing capabilities so that the internals of your computer are a fully stocked recording studio with an endless supply of virtual cables and patchbays. ​
Line 16: 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 54: 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 63: 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.
  
-To make all ALSA applications use this device by defaultedit ''​~/​.asoundrc''​ and add this block of code:+You could go into each application'​s **Preferences** or **Settings** menu and set the output to your bridge. For example, to configure ''​VLC''​ to pipe its output to the ALSA/JACK bridge: 
 + 
 +[{{ 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 a 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>
 This solution will create some latency: the ALSA JACK plugin has to use a buffer between the data being sent by the application and JACK itself to avoid clicks and dropouts. ​ This solution will create some latency: the ALSA JACK plugin has to use a buffer between the data being sent by the application and JACK itself to avoid clicks and dropouts. ​
  
-Assuming that you are using non-JACK applications as auxiliary applications ​to your pro audio work, the latency likely will not matterHowever, if you are doing something unique in which your ALSA application ​is an integral part of your realtime work, then this is not the best solution for you.+This may or may not matter, depending on what you are using; playing media over the web tends to suffersince the buffers for the data can get malignedIf all you are doing is auditioning short clips from sound effect or loop librariesyou probably won't notice, but if you're streaming a movie then the sound will suffer...but in that event, ​you should probably get back to work anyway.
 </​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 320: 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 331: Line 467:
 This method is technologically the easiest method, although it does require effort to find JACK-enabled alternatives to the normal tools that you might have become accustomed to using outside of JACK. And in some cases, it might not be pragmatic; for instance, quickly firing up ''​Firefox''​ to grab a Creative Commons sample from the internet becomes a much more complex thing than it should be if you can't preview the sound without quitting your DAW, your effect rack, synths, and stopping JACK. This method is technologically the easiest method, although it does require effort to find JACK-enabled alternatives to the normal tools that you might have become accustomed to using outside of JACK. And in some cases, it might not be pragmatic; for instance, quickly firing up ''​Firefox''​ to grab a Creative Commons sample from the internet becomes a much more complex thing than it should be if you can't preview the sound without quitting your DAW, your effect rack, synths, and stopping JACK.
  
 +===== The Firefox Bug =====
  
 +Regardless of the option you choose, there is a bug in Firefox that [[https://​bugzilla.mozilla.org/​show_bug.cgi?​id=812900|prevents sound from playing over an ALSA-JACK bridge]]. So if you need to play something with sound in a web browser whilst running JACK, Firefox is not the browser to use. Alternate browsers that do work include [[https://​www.chromium.org|Chromium]] and [[http://​www.twotoasts.de/​index.php/​midori|Midori]] (build scripts for both are available from slackbuilds.org).
  
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​float:​right;​}workflow|]][[{arrowp.png|border:​0;​background:​none;​width:​0;​float:​right;​}kernel|]]+<WRAP centeralign>​ 
 +<wrap fa>[[jack|R]]</​wrap>​ <wrap fa>[[start|S]]</​wrap>​ <wrap fa>​[[ffmpeginstall|Q]]</​wrap>​ 
 +</​WRAP>​