https://wiki.archlinux.org/api.php?action=feedcontributions&user=Kearnmachine&feedformat=atomArchWiki - User contributions [en]2024-03-29T12:16:19ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=JACK_Audio_Connection_Kit&diff=449577JACK Audio Connection Kit2016-09-06T05:11:54Z<p>Kearnmachine: /* Firewire */ typo</p>
<hr />
<div>[[Category:Sound]]<br />
[[fr:Jack]]<br />
[[ja:JACK Audio Connection Kit]]<br />
{{Related articles start}}<br />
{{Related|Professional audio}}<br />
{{Related articles end}}<br />
<br />
==Installation==<br />
In order for JACK to work properly, your user needs to be [[Users and groups#Group management|added]] to the {{ic|audio}} group for access to higher ulimits defined in {{ic|/etc/security/limits.d/99-audio.conf}}, which is needed for realtime audio processing.<br />
{{Note|You need to manually add your user to the {{ic|audio}} group even if you're using logind, since logind just handles access to direct hardware.}}<br />
<br />
There are two JACK implementations, see [https://github.com/jackaudio/jackaudio.github.com/wiki/Q_difference_jack1_jack2 this comparison] for the difference between the two. In short, Jack 1 and Jack 2 are equivalent implementations of the same protocol. Programs compiled against Jack 1 will work with Jack 2 without recompile (and vice versa). <br />
<br />
===JACK2===<br />
'''JACK2''' is a C++ implementation with SMP support. [[Install]] it with the {{Pkg|jack2}} package. If you are on a 64-bit installation and need to run 32-bit applications that require JACK, also install the {{Pkg|lib32-jack2}} package from the [[multilib]] repository.<br />
<br />
====JACK2 D-Bus====<br />
JACK2 with [[D-Bus]] can be installed via {{Pkg|jack2-dbus}}. It is the same as the {{Pkg|jack2}} package but does not provide the legacy "jackd" server.<br />
<br />
It is controlled by the {{ic|jack_control}} utility. The important commands are listed below:<br />
jack_control start - starts the jack server<br />
jack_control stop - stops the jack server<br />
jack_control ds alsa - selects alsa as the driver (backend)<br />
jack_control eps realtime True - set engine parameters, such as realtime<br />
jack_control dps period 256 - set the driver parameter period to 256<br />
<br />
===JACK===<br />
'''JACK''' uses a C API and supports more than one soundcard on Linux (plus MIDI). [[Install]] it with the {{pkg|jack}} package. If you are on a 64-bit installation and need to run 32-bit applications that require JACK, also install the {{Pkg|lib32-jack}} package from the [[multilib]] repository.<br />
<br />
===GUI===<br />
If you want a GUI control application, the most widely used one is {{Pkg|qjackctl}}.<br />
<br />
Also, [http://kxstudio.linuxaudio.org/Applications:Cadence cadence] offers a set of applications and eases some advanced jack configurations. It is available on [https://aur.archlinux.org/packages/cadence/ aur].<br />
<br />
==Basic Configuration==<br />
<br />
===Overview===<br />
<br />
[http://www.linux-magazine.com/content/download/63041/486886/version/1/file/JACK_Audio_Server.pdf This Linux Magazine article] is a very good general overview, although do not worry about manual compilations, quite a few JACK tools work right off the wire now, ''after'' JACK is configured correctly.<br />
<br />
Most tutorials are advising a realtime kernel, which is quite helpful for live synthesis and FX; but for purposes of recording and editing it is not necessary, as long as you set up for non-realtime latencies -- 10-40+ ms (100-500+ ms for older hardware).<br />
<br />
The right configuration for your hardware and application needs, depends on several factors.<br />
<br />
===A shell-based example setup===<br />
<br />
<br />
<br />
{{Accuracy|The JACK FAQ points to this specific section as an example of a myth that needs debunking. [https://github.com/jackaudio/jackaudio.github.com/wiki/FAQ_and_Myths It says], "No you do not [have to set up realtime scheduling of each audio application]. There are countless examples e.g. archwiki which demonstrate elaborate scripts to raise the priority of audio-processing applications. In fact they all achieve the opposite."}}<br />
<br />
The D-Bus edition of JACK2 can make startup much easier. Formerly, we had to have QjackCtl start it for us, or use a daemonizer, or some other method. But using {{Pkg|jack2-dbus}}, we can easily start and configure it via a shell script.<br />
<br />
Create a shell script that can be executed at X login:<br />
<br />
{{hc|start_jack.sh|<br />
#!/bin/bash<br />
<br />
jack_control start<br />
sudo schedtool -R -p 20 `pidof jackdbus`<br />
jack_control eps realtime true<br />
jack_control ds alsa<br />
jack_control dps device hw:HD2<br />
jack_control dps rate 48000<br />
jack_control dps nperiods 2<br />
jack_control dps period 64<br />
sleep 10<br />
/usr/bin/a2jmidid -e &<br />
sleep 10<br />
qjackctl &<br />
sleep 10<br />
qmidiroute ~/All2MIDI1.qmr &<br />
sleep 10<br />
yoshimi -S &<br />
sleep 10<br />
}}<br />
<br />
The above will start a complete realtime JACK live-synthesis setup, integrating several tools. Details of each line follow. When discovering your own best configuration, it is helpful to do trial and error using QjackCtl's GUI with a non-D-Bus JACK2 version.<br />
<br />
====Details of the shell-based example setup====<br />
<br />
jack_control start<br />
Starts JACK if it is not already started.<br />
sudo schedtool -R -p 20 `pidof jackdbus`<br />
Set JACK to realtime mode in the Linux kernel, priority 20 (options range 1-99).<br />
jack_control eps realtime true<br />
Sets JACK to realtime mode in its own internal setup.<br />
jack_control ds alsa<br />
Sets JACK to use the ALSA driver set.<br />
jack_control dps device hw:HD2<br />
Sets JACK to use ALSA-compatible sound card named HD2. One can find the names with {{ic|cat /proc/asound/cards}}. Most ALSA tutorials and default configurations use card numbers, but this can get confusing when external MIDI devices are in use; names make it easier.<br />
jack_control dps rate 48000<br />
Sets JACK to use 48000 khz sampling. Happens to work very well with this card. Some cards only do 44100, many will go much higher. The higher you go, the lower your latency, but the better your card and your CPU has to be, and software has to support this as well.<br />
jack_control dps nperiods 2<br />
Sets JACK to use 2 periods. 2 is right for motherboard, PCI, PCI-X, etc.; 3 for USB.<br />
jack_control dps period 64<br />
Sets JACK to use 64 periods per frame. Lower is less latency, but the setting in this script gives 2.67 ms latency, which is nicely low without putting too much stress on the particular hardware this example was built for. If a USB sound system were in use it might be good to try 32. Anything less than 3-4 ms should be fine for realtime synthesis and/or FX, 5 ms is the smallest a human being can detect. There are many cases of perfect-storm-gorgeous hardware which can handle 1 ms latency without stressing the CPU, but definitely this is not always the case! QjackCtl will tell you how you are doing; at no-load, which means no clients attached, you will want a max of 3-5% CPU usage, and if you cannot get that without xruns (the red numbers which mean the system cannot keep up with the demands), you will have to improve your hardware. There are many inexpensive USB sound systems which produce very good quality at very low latency if the USB is good on the motherboard, but not all. <br />
sleep 10<br />
Wait for the above to settle.<br />
/usr/bin/a2jmidid -e &<br />
Start the ALSA-to-JACK MIDI bridge. Good for mixing in applications which take MIDI input through ALSA but not JACK.<br />
sleep 10<br />
Wait for the above to settle.<br />
qjackctl &<br />
Load QjackCtl. GUI configuration tells it to run in the system tray. It will pick up the JACK session started by D-Bus just fine, and very smoothly too. It maintains the patchbay, the connections between these applications and any other JACK-enabled apps to be started manually. The patchbay is set up using manual GUI, but connections pre-configured in the patchbay are automatically created by QjackCtl itself when apps are started.<br />
sleep 10<br />
Wait for the above to settle.<br />
<br />
qmidiroute ~/All2MIDI1.qmr &<br />
Load qmidiroute, loading a custom-created configuration file which will rewrite all MIDI events on all channels to channel 1. This is useful when plugging the PC into any keyboard anywhere -- no matter what the keyboard's channel defaults to, qmidiroute will send the signal to the synth on channel 1, where it needs it. qmidiroute is capable of very complex and useful configurations of many sorts, including multiple simultaneous translations, transpositions, signal type rewrites, etcetera.<br />
sleep 10<br />
Wait for the above to settle.<br />
yoshimi -S &<br />
Load the Yoshimi synthesizer, using the pre-saved default state.<br />
sleep 10<br />
Wait for the above to settle.<br />
<br />
With all of the above in a script run at logon, and with the QjackCtl patchbay set correctly, all we have to do is plug the PC/laptop into a MIDI keyboard using a USB-to-MIDI adapter, or simply the USB-in MIDI capability of many modern keyboards, and you are ready to play!<br />
<br />
The essence of QJackCtl is described fairly well in [http://www.linuxjournal.com/article/8354?page=full this article.]<br />
<br />
===A GUI-based example setup===<br />
<br />
The shell-based example above, lays out in detail lots of things you may well need to know, and it does work well. If you want something much more GUI, however, do this:<br />
<br />
* Install {{Pkg|jack2-dbus}}.<br />
<br />
* Copy {{ic|/etc/asound.conf}} to {{ic|/etc/asound.conf.ORIGINAL}}, and replace it with this:<br />
<br />
pcm.pulse {<br />
type pulse<br />
}<br />
ctl.pulse {<br />
type pulse<br />
}<br />
pcm.!default {<br />
type pulse<br />
}<br />
ctl.!default {<br />
type pulse<br />
}<br />
<br />
* Install {{Pkg|pulseaudio}}.<br />
* Install {{Pkg|pulseaudio-alsa}}.<br />
* Install {{Pkg|qjackctl}}, and tell your GUI window/desktop system to run it at startup.<br />
* Make sure QjackCtl is told to:<br />
** use the D-Bus interface,<br />
** run at startup,<br />
** save its configuration to the default location,<br />
** start the JACK audio server on application startup,<br />
** enable the system tray icon, and<br />
** start minimized to sytem tray.<br />
* Reboot.<br />
* After logging in, you will see QjackCtl in your system tray. Left-click on it.<br />
* Start tweaking in the QjackCtl GUI. The info embedded in the shell-script setup above may be of some help :-) As may be the info in [http://www.linuxjournal.com/article/8354 this article]. Just remember that you have to get your latency down to less than 5ms for live tone production or filtration of any sort, or the delay will be obvious to player and listener alike.<br />
* From the [[AUR]], install {{AUR|non-sessionmanager-git}}; it has the function of setting up "sessions": sets of other audio software items which Jack (through the QjackCtl patchbay or not!) will wire together. NSM can handle as many different sessions as you wish to set up; and as a result, it's all GUI, apart from the one rc.local edit in the beginning.<br />
<br />
===Playing nice with ALSA===<br />
To allow Alsa programs to play while jack is running you must install the jack plugin for alsa with {{Pkg|alsa-plugins}}.<br />
<br />
And enable it by editing (or creating) /etc/asound.conf (system wide settings) to have these lines:<br />
{{bc|<nowiki><br />
# convert alsa API over jack API<br />
# use it with<br />
# % aplay foo.wav<br />
<br />
# use this as default<br />
pcm.!default {<br />
type plug<br />
slave { pcm "jack" }<br />
}<br />
<br />
ctl.mixer0 {<br />
type hw<br />
card 1<br />
}<br />
<br />
# pcm type jack<br />
pcm.jack {<br />
type jack<br />
playback_ports {<br />
0 system:playback_1<br />
1 system:playback_2<br />
}<br />
capture_ports {<br />
0 system:capture_1<br />
1 system:capture_2<br />
}<br />
}</nowiki>}}<br />
<br />
You need not restart your computer or anything. Just edit the alsa config files, start up jack, and there you go...<br />
<br />
Remember to start it as a '''user'''. If you start it with {{ic|jackd}} -d alsa" as user X, it will not work for user Y.<br />
<br />
Another approach, using ALSA loopback device (more complex but probably more robust), is described in [http://alsa.opensrc.org/Jack_and_Loopback_device_as_Alsa-to-Jack_bridge this article].<br />
<br />
=== gstreamer ===<br />
Example: watching a live stream without gconf<br />
{{bc|<nowiki>gst-launch-0.10 playbin2 uri=http://streamer.stackingdwarves.net/bewerungeroom.ogv audio-sink="jackaudiosink"</nowiki>}}<br />
<br />
Setting gstreamer to use jack using gconftool-2<br />
gconftool-2 --type string --set /system/gstreamer/0.10/audio/default/audiosink "jackaudiosink buffer-time=2000000"<br />
gconftool-2 --type string --set /system/gstreamer/0.10/audio/default/musicaudiosink "jackaudiosink buffer-time=2000000"<br />
gconftool-2 --type string --set /system/gstreamer/0.10/audio/default/chataudiosink "jackaudiosink buffer-time=2000000"<br />
<br />
Further information: http://jackaudio.org/gstreamer_via_jack<br />
<br />
=== PulseAudio ===<br />
If you need to keep {{Pkg|pulseaudio}} installed (in the event it is required by other packages, like {{Pkg|gnome-settings-daemon}}), you may want to prevent it from spawning automatically with X and taking over from JACK.<br />
<br />
Edit {{ic|/etc/pulse/client.conf}}, uncomment "autospawn" and set it to "no":<br />
;autospawn = yes<br />
autospawn = no<br />
<br />
''If you want both to play along, see: [[PulseAudio/Examples#PulseAudio through JACK]]''<br />
<br />
=== Firewire ===<br />
In order to prevent ALSA from messing around with your firewire devices you have to blacklist all firewire related kernel modules. This also prevents PulseAudio from using firewire. Create the following file:<br />
<br />
{{hc|/etc/modprobe.d/alsa-no-jack.conf|<br />
blacklist snd-fireworks<br />
blacklist snd-bebob<br />
blacklist snd-oxfw<br />
blacklist snd-dice<br />
blacklist snd-firewire-digi00x<br />
blacklist snd-firewire-tascam<br />
blacklist snd-firewire-lib<br />
blacklist snd-firewire-transceiver<br />
blacklist snd-fireface<br />
blacklist snd-firewire-motu<br />
}}<br />
<br />
''The list of modules is the most recent available at the time of writing at [https://github.com/takaswie/snd-firewire-improve Alsa Firewire Improve Repository].''<br />
<br />
Now you can unload your loaded firewire modules or reboot.<br />
<br />
==MIDI==<br />
<br />
JACK can handle one soundcard very well, and an arbitrary number of MIDI devices (connected e.g. via USB).<br />
If you start JACK and want to use a MIDI keyboard or a synthesizer or some other pure MIDI device, you have to start JACK with a proper soundcard (one that actually outputs or inputs PCM sound).<br />
As soon you have done that, you can connect the MIDI device. E.g. with QjackCtl ({{pkg|qjackctl}}), you click on the connect button and you will find your device listed under JACK-MIDI or ALSA-MIDI, depending on the driver.<br />
<br />
For JACK-MIDI, you may want to set the '''MIDI Driver''' to '''seq''' or '''raw''' in QjackCtl ''Setup > Settings''. This should make your MIDI device appear under the ''MIDI'' tab. You can also change the name of the client (from a generic "midi_capture_1" to something more descriptive), if you enable ''Setup > Display > Enable client/port aliases'' and then ''Enable client/port aliases editing (rename)''.<br />
<br />
For ALSA-MIDI, make sure to turn on '''Enable ALSA Sequencer support''' in QjackCtl ''Setup > Misc''. This will add the ''ALSA'' tab in QjackCtl ''Connect'' window where your MIDI controller will show up.<br />
<br />
For bridging ALSA-MIDI to JACK-MIDI, you may consider using a2jmidid ({{Pkg|a2jmidid}}). The following command will export all available ALSA MIDI ports to JACK MIDI ports:<br />
$ a2jmidid -e<br />
They will be visible in QjackCtl under the ''MIDI'' tab labelled "a2j" client.<br />
You can automate starting of a2jmidid by adding to QjackCtl ''Setup > Options > Execute script after Startup'': {{ic|/usr/bin/a2jmidid -e &}}<br />
{{note|When connecting MIDI keyboard controllers in QjackCtl, make sure to ''Expand All'' first and connect the desired ''Output Ports'' (below the ''Readable Clients'') to the ''Input Ports'' (below the ''Writable Clients''). As a shortcut, if you select a writable client instead of individual ports as your destination, it should connect all its currently displayed output ports underneath.}}<br />
<br />
*'''Q:''' What is the difference between JACK-MIDI and ALSA-MIDI?<br />
*'''A:''' The former has improved timing and sample accurate MIDI event alignment. It extends or may even replace the latter but at this point they both co-exist.<br />
<br />
To install some M-Audio MIDI keyboards, you will need the firmware package {{AUR|midisport-firmware}} in the [[AUR]]. Also, the snd_usb_audio module has to be available.<br />
For more information about specific USB MIDI devices, see http://alsa.opensrc.org/USBMidiDevices.<br />
<br />
==Troubleshooting==<br />
==="Cannot lock down memory area (Cannot allocate memory)" message on startup===<br />
<br />
See [[Realtime process management#Configuring PAM]] and ensure that the user is in the {{ic|audio}} [[group]].<br />
<br />
===jack2-dbus and qjackctl errors===<br />
Still having the "Cannot allocate memory" and/or "Cannot connect to server socket err = No such file or directory" error(s) when pressing qjackctl's start button (assuming that you have package jack2-dbus installed) ?<br />
<br />
Please delete {{ic|~/.jackdrc}}, {{ic|~/.config/jack/conf.xml}}, {{ic|~/.config/rncbc.org/QjackCtl.conf}}. Kill ''jackdbus'' and restart from scratch :)<br />
(Thanks to nedko)<br />
<br />
Also try running <br />
$ fuser /dev/snd/*<br />
and check the resulting PID's with<br />
$ ps ax | grep [PID here]<br />
This will hopefully show the conflicting programs.<br />
<br />
===Problems with specific applications===<br />
====VLC - no audio after starting JACK====<br />
Run VLC and change the following menu options:<br />
* Tools > Preferences<br />
* Show settings: All<br />
* Audio > Output modules > Audio output module: JACK audio output<br />
* Audio > Output modules > JACK: Automatically connect to writable clients (enable)</div>Kearnmachine