Differences

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

Link to this comparison view

sound [2015/05/23 18:08]
slackermedia [JACK Enabled Apps]
sound [2021/06/03 19:48]
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 ====== 
- 
-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. ​ 
- 
-Sound good? of course it does. But a peculiarity about JACK is that it seizes control of your sound card in order to ensure near-realtime performance;​ this means that the normal sound system that //usually// drives audio on a Linux desktop cannot access the same sound card. 
- 
-In other words, if you are running applications through JACK in order to gain near-realtime performance and otherwise impossible audio routing capability, when you launch an applications that does not or cannot use JACK, that application will not have sound. 
- 
-There are three options to deal with this. Regardless of which you choose, you must install ''​alsa-plugins''​. This plugin pack is not included in the Slackermedia queue files because for to maximise its usefulness, you should have ''​ffmpeg'',​ ''​JACK'',​ and (optionally,​ if you use it) ''​speex''​ installed before building and installing ''​alsa-plugins''​. 
- 
-If you have these installed, then it is safe to install ''​alsa-plugins''​. It is available from [[http://​slackbuilds.org]]. 
- 
-===== ALSA JACK Plugin ===== 
- 
-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. 
- 
-<WRAP tip> 
-If you are not a full-time musician, this is probably the best solution for you, as it balances ease-of-setup plus flexible functionality. 
-</​WRAP>​ 
-  
-To set up the bridge device, edit (creating it if it does not already exist) the file ''​~/​.asoundrc'':​ 
- 
-<​code>​ 
-pcm.rawjack { 
-    type jack 
-    playback_ports { 
-        0 system:​playback_1 
-        1 system:​playback_2 
-    } 
-    capture_ports { 
-        0 system:​capture_1 
-        1 system:​capture_2 
-    } 
-} 
- 
-pcm.jack { 
-    type plug 
-    slave { pcm "​rawjack"​ } 
-    hint { 
-    description "JACK Audio Tunneling Kit" 
-    } 
-} 
-</​code>​ 
- 
-The first PCM definition defines a virtual audio device called ''​pcm.rawjack''​ that has 2 input channels and two output channels. Each channel definition consists of a number (starting from 0, as computers do), and a JACK port to which it connects. This port, which we arbitrarily call ''​rawjack'',​ requires that the sample rate, sample format, and all other attributes, match the system'​s JACK settings; it is, essentially,​ a mirror of ALSA, or an ALSA portal. 
- 
-The purpose of this definition is to define a sound "​jack",​ that is, something we can plug into other ports. It is a signal //sender// (whether the signal is sound being output from an application,​ or a sound being received via input such as a microphone. 
- 
-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. 
- 
-Test this with this command: 
- 
-<​code>​ 
-aplay -D pcm.jack \ 
-/​usr/​share/​sounds/​alsa/​Front_Center.wav 
-</​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: 
- 
-{{ vlcjack.png }} 
- 
-To make all ALSA applications use this device by default, edit ''​~/​.asoundrc''​ and add this block of code: 
- 
-<​code>​ 
-pcm.!default { 
-    type plug 
-    slave { pcm "​rawjack"​ } 
-} 
-</​code>​ 
- 
-If you do this, you must remove other definitions of ''​pcm.!default''​. There should only be one default. ​ 
- 
-<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. ​ 
- 
-Assuming that you are using non-JACK applications as auxiliary applications to your pro audio work, the latency likely will not matter. However, 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. 
-</​WRAP>​ 
- 
-===== Always-On JACK Daemon ===== 
- 
-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. 
- 
-<WRAP tip> 
-If you are a full-time musician, then this most likely the best solution for you, but for ease of setup you may want to try the first solution to begin with and try this more complex one if it proves to be insufficient. 
-</​WRAP>​ 
- 
-This method was outlined first on the JACK website, but is expanded and explained by AlienBob on his website, [[http://​alien.slackbook.org/​blog/​setting-up-jack-audio-in-slackware/​]]. See his original post for more information and a few more options. 
- 
-Like the first method, this requires a dummy ALSA device to handle non-JACK applications. For that to work, load the ''​snd-aloop''​ module: 
- 
-<​code>​ 
-$ su -c '/​sbin/​modprobe snd-aloop'​ 
-</​code>​ 
- 
-So that this is loaded at boot by default, add it to the file ''/​etc/​rc.d/​rc.local''​ 
- 
-<​code>​ 
-$ su -c 'echo snd-aloop >> /​etc/​rc.d/​rc.local'​ 
-</​code>​ 
- 
-And create a configuration file for it to define how many channels you require from your dummy device. If you are on a surround sound system, then you probably need 7 or 8 (8 is the default), but if you mix only in stereo then you can reduce the number of channels: 
- 
-<​code>​ 
-su -c 'echo \ 
-"​options snd-aloop pcm_substreams=2"​ > \ 
-/​etc/​modprobe.d/​alsaloop.conf 
-</​code> ​ 
- 
-==== ALSA Configuration ==== 
- 
-In order for ALSA to tunnel its way through JACK, you must create a custom ''​~/​.asoundrc''​ file. If one exists, back it up and create this one. If needed, you can integrate your old changes into this one (but more than likely it will be JACK that you customise for system-wide audio, from here on out). 
- 
-<​code>​ 
-# hardware 0,0 : used for ALSA playback 
- 
-pcm.loophw00 { 
-  type hw 
-  card Loopback 
-  device 0 
-  subdevice 0 
-  format S32_LE 
-  rate 48000 
-} 
- 
-# hardware 0,1 : used for ALSA capture 
-pcm.loophw01 { 
-  type hw 
-  card Loopback 
-  device 0 
-  subdevice 1 
-  format S32_LE 
-  rate 48000 
-} 
- 
-# playback PCM device: using loopback subdevice 0,0 
- 
-pcm.amix { 
-  type dmix 
-  ipc_key 196101 
-  slave { 
-    pcm "​loophw00"​ 
-    buffer_size 8192 
-    period_size 4096 
-    periods 2 
-  } 
-} 
- 
-# capture PCM device: using loopback subdevice 0,1 
-pcm.asnoop { 
-  type dsnoop 
-  ipc_key 196102 
-  slave { 
-   pcm loophw01 
-   ​period_size 4096 
-   ​periods 2 
-  } 
-} 
- 
-# software volume 
- 
-pcm.asoftvol { 
-  type softvol 
-  slave.pcm "​amix"​ 
-  control { name PCM } 
-  min_dB -51.0 
-  max_dB ​  0.0 
-} 
- 
- 
-# duplex dev combining PCM devs defined above 
- 
-pcm.aduplex { 
-  type asym 
-  playback.pcm "​asoftvol"​ 
-  capture.pcm "​loophw01"​ 
-  hint { 
-    description "​ALSA-JACK Bridge"​ 
-  } 
-} 
- 
-# Mixer controls 
- 
-ctl.amix { 
-    type hw 
-    card Loopback 
-} 
- 
-ctl.asnoop { 
-    type hw 
-    card Loopback 
-} 
- 
-ctl.aduplex { 
-    type hw 
-    card Loopback 
-} 
- 
- 
-# for jack alsa_out: looped-back signal 
-pcm.ploop { 
-  type hw 
-  card Loopback 
-  device 1 
-  subdevice 1 
-  format S32_LE 
-  rate 48000 
-} 
- 
- 
-# for jack alsa_in: looped-back signal 
-pcm.cloop { 
-  type hw 
-  card Loopback 
-  device 1 
-  subdevice 0 
-  format S32_LE 
-  rate 48000 
-} 
- 
- 
-# default device 
- 
-pcm.!default { 
-  type plug 
-  slave.pcm "​aduplex"​ 
-} 
-</​code>​ 
- 
-When you save that file, its content will re-define your ALSA configuration //​immediately//​. KDE may complain about hardware that was added or went missing; it is safe to ignore these warnings. 
- 
-This new configuration creates a new full-duplex PCM device called ''​pcm.aduplex''​ with a description of “ALSA-JACK Bridge”. Set your ALSA devices to use this as their output. 
- 
-Additionally,​ a PCM device for capturing input (''​pcm.cloop''​) and for playback (''​pcm.ploop''​) are created; these also will be connected to JACK. Your ALSA applications pipe their audio into one end of the loopback device, and JACK interprets the signal as incoming audio and plays it on your speakers. 
- 
-Test your new setup'​s configuration with this command: 
- 
-<WRAP alert> 
-You will not hear anything at this point, since JACK has yet to be configured. However, you should also //not// receive an error back, so that is what you are testing for. 
-</​WRAP>​ 
- 
-<​code>​ 
-aplay -D pcm.jack \ 
-/​usr/​share/​sounds/​alsa/​Front_Center.wav 
-</​code>​ 
- 
-Assuming you get no error back, the ALSA side of the equation is set up. Now it's time to configure JACK. 
- 
- 
-==== JACK Configuration ==== 
- 
-Your JACK settings must match up with your ALSA settings, particularly the sample rate. Typical sample rates are ''​44100''​ and ''​48000''​ (or ''​96000''​ if you have very high-end gear). The example ''​.asoundrc''​ sets the sample rate to ''​48000''​ across the board, so if you use any value other than that, change it in ''​~/​.asoundrc''​. 
- 
-The command to start JACK can be saved in ''​~/​.jackdrc''​ so that whenever JACK is started, it knows exactly what state it should load. 
- 
-For the hardware device name, check ''​aplay'':​ 
- 
-<​code>​ 
-aplay -l | grep card 
-</​code>​ 
- 
-A suitable command for this example setup: 
- 
-<​code>​ 
-/​usr/​bin/​jackd -r -m -dalsa -r48000 -p1024 -n2 -m -H -D -Chw:SB -Phw:SB 
-</​code>​ 
- 
-Now JACK will start with the correct settings, but there'​s nothing to tell ALSA and JACK how to interact. This can be solved with AlienBob'​s custom connection script, which you should place in /​usr/​local/​bin:​ 
- 
-<​code>​ 
-#!/bin/sh 
-# script loop2jack, located in /​usr/​local/​bin 
-# 
-# Start jack if it is not already running: 
-/​usr/​bin/​jack_control start 
- 
-# loop client creation 
- 
-/​usr/​bin/​alsa_out -j ploop -dploop -q 1 2>&1 1> /dev/null & 
-/​usr/​bin/​alsa_in -j  cloop -dcloop -q 1 2>&1 1> /dev/null & 
- 
-# give it some time before connecting to system ports 
-sleep 1 
- 
-# cloop ports -> jack output ports 
-/​usr/​bin/​jack_connect cloop:​capture_1 system:​playback_1 
-/​usr/​bin/​jack_connect cloop:​capture_2 system:​playback_2 
- 
-# system microphone to "​ploop"​ ports 
-/​usr/​bin/​jack_connect system:​capture_1 ploop:​playback_1 
-/​usr/​bin/​jack_connect system:​capture_2 ploop:​playback_2 
- 
-# done 
-exit 0 
-</​code>​ 
- 
-Make the script exectuable: 
- 
-<​code>​ 
-chmod +x /​usr/​local/​bin/​loop2jack 
-</​code>​ 
- 
-And add it to ''​~/​.xprofile''​ (create this file if it does not already exist). If you do not boot into a graphical environment by default, add it to ''​~/​.profile''​. 
- 
-<​code>​ 
-$ echo /​usr/​local/​bin/​loop2jack > \ 
-~/.xprofile 
-</​code>​ 
- 
-Under this method, running JACK is //​required//​. If JACK is not running, you will hear nothing from your speakers because ALSA is set by default to route itself through JACK, rather than directly to your hardware. 
- 
-<WRAP important>​ 
-The system-wide ALSA configuration file ''/​etc/​asound.conf''​ should not but //could//, in theory, interfere with this setup. Your own ''​~/​.asoundrc''​ definitions are only prepended to ''​asound.conf''​ and do not replace them. 
-</​WRAP>​ 
- 
- 
-===== JACK Enabled Apps ===== 
- 
-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 typical workflow for using a JACK-enabled application is that you decide that you want to use a set of pro audio apps to compose or edit sound. This probably means that you're not doing "​normal"​ audio things as well; in other words, you probably don't have music playing in a media player, or a movie playing, you're probably not on a VOIP call, and so on. You're making music or editing sound, so by the nature of the work, you are using //only// JACK-enabled pro audio applications. 
- 
-If the need should arise to launch an application that might not normally be JACK-enabled,​ there is the option to simply use an application that //is// JACK-enabled. For instance, if you are working in pro audio, but you need to launch a music player to compare sounds or review a demo track or listen to a temp track, then rather than using a player that can only play via ALSA (the default sound system), use a media player that can use 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. 
- 
- 
- 
- 
-[[{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|]]