Aprofundint en el JACK
Contingut
Introducció
- http://www.ubustu.com/globe/2007/05/29/how-to-configure-jack-in-ubuntu-studio/
- http://wiki.jacklab.net/index.php/JACK_first_steps
JACK és un servidor d'audio, i que serveix per configurar les opcions d'audio i així obtenir la performance òptima de tot el conjunt.
JACK (Jack Audio Connection Kit) és el servidor de so amb latència baixa que corre en un sistema Linux. Permet que qualsevol software compatible es pugui interconnectar utilitzant patch cords virtuals, d'una manera increïblement flexible. Per exemple, pots connectar les teves guitarres i els teus micròfons a les entrades de la teva targeta de so; el teclat es pot connectar al port USB per a grabació MIDI; l'audio es pot enregistrar en una aplicació DAW mentre que el MIDI es pot enregistrar en un seqüenciador MIDI separat. La sortida de totes les aplicacions es pot enregistrar de forma simultània a un fitxer WAV estereo d'una tercera aplicació. Totes les aplicacions estan sincronitzades de forma conjunta i perfecta. Aquest és un exemple de la potència de JACK.
El servidor de JACK ha de ser tunejat per tal de treure de la targeta de so la màxima performance, sense Xruns (més avall està explicat què són els Xruns).
JackControl (QJackCTL)
El QJackCTL és la interfície gràfica d'usuari (GUI) del servidor JACK. Permet modificar la configuració de les targetes de so i fer patches utilitzant el virtual patchbay.
JACK en mode comanda
Engeguem el JACK amb la configuració per defecte, i mirem la finestra de missatges. Podem veure amb quines opcions es crida al dimoni de JACK (jackd). Aquestes opcions són les que puc configurar en el Setup:
/usr/bin/jackd -R -dalsa -dhw:0 -r44100 -p1024 -n2
- -R: tinc marcada la casella RealTime
- -d és el driver que utilitzem: alsa. JACK treballa per defecte sobre ALSA. Altres possibilitats portaudio, oss, freebob, firewire
- -dhw:0 és el dispositiu que utilitzem hw:0 representa la targeta interna del portàtil (ICH6). Si tinc connectat el EDIROL UA-25EX, posaré -dhw:1
- -r44100 és la freqüencia de mostreig. Si escullo una freqüència més gran, per exemple 48000 o 96000, la latència es redueix. La sample rate significa que, quan es graba, cada segon es prenen 44100 mostres. En el Edirol el Sample Rate es pot seleccionar amb un botó. Influeix en la latència.
- -p1024 és el Frames/Period. Pot anar de 16 a 4096. Com més petita és el valor, més petita és la latència. És el factor que més influeix en la latència.
- -n2 és el Periods/Buffer (no significa periodes dividit per buffer, sinó que ho podem anomenar periode o buffer). També influeix en la latència.
A frame of audio means 1 sample per channel.. E.g. if you have a 6-channel signal and you process one frame of it you have processed one sample per channel, 6 samples in total.. frames/period means frames per processing cycle (e.g. if you have 64 frames/period, then the buffersize per channel is 64 samples) periods/buffer means how many periods are there [on windows a period is more often called a "buffer"]. But in a typical double buffer scheme you have e.g. two buffers combined into a single chunk of memory.. And in alsa speak, this combined buffer is the "buffer" and the individual chunks in the buffers are called periods [kinda, the terminology is a little squishy] So one period is the first half of the buffer and the other period is the second half of the buffer..
Per exemple, canvio els paràmetres, escullo la UA-25EX com a interfície, i ara en la sortida de missatges obtinc:
11:04:38.987 JACK is starting... 11:04:38.988 /usr/bin/jackd -R -dalsa -dhw:1 -r44100 -p256 -n2 11:04:39.009 JACK was started with PID=4659. no message buffer overruns jackd 0.116.1 Copyright 2001-2005 Paul Davis and others. jackd comes with ABSOLUTELY NO WARRANTY This is free software, and you are welcome to redistribute it under certain conditions; see the file COPYING for details JACK compiled with System V SHM support. cannot lock down memory for jackd (Cannot allocate memory) loading driver .. apparent rate = 44100 creating alsa driver ... hw:1|hw:1|256|2|44100|0|0|nomon|swmeter|-|32bit control device hw:1 configuring for 44100Hz, period = 256 frames (5.8 ms), buffer = 2 periods ALSA: final selected sample format for capture: 24bit little-endian ALSA: use 2 periods for capture ALSA: final selected sample format for playback: 24bit little-endian ALSA: use 2 periods for playback JACK: unable to mlock() port buffers: Cannot allocate memory JACK: unable to mlock() port buffers: Cannot allocate memory 11:04:41.110 Server configuration saved to "/home/joan/.jackdrc". 11:04:41.113 Statistics reset. 11:04:41.117 Client activated.. M'explico: per a un periode de 256 frames (256 frames/period), sempre surt el valor de 5,8 ms, però aquest no és el valor que surt com a latència en el setup del JACK. Per calcular-lo, he de multiplicar el 5,8 ms pels periods/buffer. Per exemple, amb frames/period=256 i periods/buffer=4 obtinc una latència de:
- frames/period=256 (5,8 ms)
- periods/buffer=4
- latencia=5,8 ms * 4 = 23,2 ms
11:04:41.123 JACK connection change. 11:04:41.162 JACK connection graph change. cannot lock down memory for RT thread (Cannot allocate memory)
Fixem-nos que en el missatge ens surt el valor de 5.8ms, que és un valor relacionat amb la latència, però no és exactament el valor de la latència que em diu el QjackCtl. Veure més avall el càlcul de la latència
Fixem-nos també que a partir de les dades de configuració del JACK. es crea el driver ALSA amb aquestes dades de configuració. És a dir, el setup del JACK és al cap i a la fi el setup del ALSA:
creating alsa driver ... hw:1|hw:1|256|2|44100|0|0|nomon|swmeter|-|32bit
El Input Device (gravació) i el Output Device (playback) podrien ser diferents. Anem a veure com es tradueix si escullo com a Input Device el hw:1 i com a Output Device el hw:0. Primer de tot s'ha de constatar que la combo box de la interfície es deshabilita (això passa sempre que edito Input Device i Output Device).
11:16:34.599 Startup script... 11:16:34.600 artsshell -q terminate sh: artsshell: not found 11:16:35.002 Startup script terminated with exit status=32512. 11:16:35.003 JACK is starting... 11:16:35.003 /usr/bin/jackd -R -dalsa -r44100 -p256 -n5 -D -Chw:0 -Phw:1 11:16:35.026 JACK was started with PID=4971. no message buffer overruns jackd 0.116.1 Copyright 2001-2005 Paul Davis and others. jackd comes with ABSOLUTELY NO WARRANTY This is free software, and you are welcome to redistribute it under certain conditions; see the file COPYING for details JACK compiled with System V SHM support. cannot lock down memory for jackd (Cannot allocate memory) loading driver .. apparent rate = 44100 creating alsa driver ... hw:1|hw:0|256|5|44100|0|0|nomon|swmeter|-|32bit control device hw:1 configuring for 44100Hz, period = 256 frames (5.8 ms), buffer = 5 periods ALSA: final selected sample format for capture: 16bit little-endian ALSA: use 5 periods for capture ALSA: final selected sample format for playback: 24bit little-endian ALSA: use 5 periods for playback JACK: unable to mlock() port buffers: Cannot allocate memory JACK: unable to mlock() port buffers: Cannot allocate memory 11:16:37.070 Server configuration saved to "/home/joan/.jackdrc". 11:16:37.073 Statistics reset. 11:16:37.077 Client activated. 11:16:37.084 JACK connection change. 11:16:37.119 JACK connection graph change. cannot lock down memory for RT thread (Cannot allocate memory)
Ara tenim:
/usr/bin/jackd -R -dalsa -r44100 -p256 -n5 -D -Chw:0 -Phw:1
he ficat -n5 (5 buffers per periode, per provar), ara no tinc l'opció -d de interfície per defecte, i en canvi tinc -C (dispositiu d'entrada, record, Capture) i -P (dispositiu de sortida, Playback). Aix`en el alsa driver es tradueix com a:
creating alsa driver ... hw:1|hw:0|256|5|44100|0|0|nomon|swmeter|-|32bit
és a dir, seguint l'ordre: Playback (hw:1), Record (hw:0), frames/period (256), periods/buffer (5), 44100 (sample rate) i la resta no sé a què fa referència.
JackControl-QJackCTL: altres opcions
- Execute script on startup: és el script que s'executa quan engeguem el dimoni:
artsshell -q terminate
No trobo on està aquest script.
- Execute script after shutdown: killall jackd. És a dir, ens assegurem de que no quedi cap dimoni de jackd executant-se
- Save Audio Jack Configuration to: senzillament guardem la configuració de com arrenguem el JACK
/home/joan/.jackdrc $ cat .jackdrc /usr/bin/jackd -R -dalsa -dhw:0 -r44100 -p256 -n4
- Messages log file: qjackctl.log (per defecte no es guarda el log). El que es guarda és senzillament la sortida dels missatges.
És important, doncs, adonar-se que per executar el dimoni ho puc fer tot sense la interfície gràfica: executo el dimoni jackd amb les opcions adients, puc mirar el log, puc establir les connexions (aconnect),...
XRUNS
http://wiki.jacklab.net/index.php/JACK_first_steps
The JACK server needs to be 'tuned' to your soundcard to get the best possible performance without any Xruns. What are Xruns?
Simply speaking, Xruns are either sound buffer overruns or sound buffer underruns.
- A buffer overrun happens during recording, when your sound card tries to write data to buffer, but your software has not yet emptied it.
- A buffer underrun happens during playback, when your sound card tries to read data from the buffer, but your software has not yet filled it.
It is okay to get a couple of Xruns when you start or close an application. However, any Xruns during recording and you will probably get a very horrible click sound in your audio file. Therefore, it is very important to reduce the possibility of Xruns to an absolute minimum level.
A la captura de pantalla del penell del QJackCTL es pot observar el número que apareix en vermell: 1(1). Són els Xruns. Els Xruns s'han de mantenir el més baixos possibles. Per aconseguir-ho hem de tunejar la configuració del JACK.
Tailoring the settings for best performance is really and trial and error process as there so many variables involved. Your system speed, soundcard and driver and kernel configuration all effect the performance of the JACK server. The settings you need to concentrate on are: Sample Rate, Frames/Period and Periods/Buffer.
We suggest you start with the Sample Rate of 44100Hz for greater compatibility with other digital equipment and especially if you are going to master to CD. Some sound cards don't work very well at 44.1KHz, especially Soundblaster cards. In this case use 48KHz.
As you can see from the screenshot above, with the sample rate at 44100Hz, 64 Frames/Period and 2 Periods/Buffer, we get a latency of 2.9 milliseconds. This is perfectly adequate for realtime effects and software synthesizers. It is perfectly normal operating practice to change the settings of JACK as you progress through a project. For example, for initial track laying and recording of softsynths you will need a very low latency - this is okay as long as minimal live effects and processing are needed. Further into the project when you start mixing, you will need to increase the latency to cope with (fer front a) more processing and effects without encountering any Xruns - this should be okay as live recording isn't needed.
After you have made your settings, click 'save' to exit the configuration. Then press the 'start' button as is shown below:
If everything is okay, then the JACK server will start. If there are problems you will see error messages shown in a pop-up dialogue box.
QJackCTL is the heart of a linux-based professional audio system, the more you get to know it and what it can and can't do - the more productive your linux music session will be.
Després de llegir això, sembla ser que hi ha un compromís entre la latència i els Xruns, i depenent de la situació és més important l'un o l'altre. Si estic executant i fent sonar amb el fluidsynth, m'interessa tenir la latència baixa. En fase de postproducció, quan mesclo, etc., m'interessa no tenir Xruns (i puc augmentar la latència).
Aquí va el mail d'un que té un bon equip destinat per a audio, i que canvia la configuració de la latència en funció de si està grabant o està mesclant:
On Wednesday 13 May 2009 22.50.08 Brent Busby wrote:
...
> Wow...just for reference, what kind of motherboard/cpu was this? There
> are probably a lot of people (like me) that would like to know the
> hardware when a success story is achieved. Also, what audio card and
> distro?
>
> (Less than a millisecond??) :-O
Yes, less than a millisecond. :-) ..but I still have to send "nosmp" to the
kernel in Grub's menu.lst-file - or the system freezes; I wasn't aware of that
when I wrote to this list yesterday - so it's still a lot of potential for
improvements; just as with the proprietary nvidia driver for my previos GPU,
the proprietary ATI driver don't play nice with the rt-kernel, but I have a
much quicker and stable sustem with the ST GPU. So I guess that it's a problem
with the Ubuntu RT-kernel (2.6.28-3-rt) and possible in combination with some
motherboard issues that I haven't figured out yet.
Anyway, the system is quick and stable even with this quirks, here are the
specs (and some extended info because I'm in the mood for it):
MB: MSI K9N SLI Platinum
CPU: Athlon64 X2 6400+, 3.2 GHz
RAM: 8GB: 2 * Kingston ValueR. DDR2 PC6400 4096MB CL5, Kit w/two
matched ValueRAM 2048MB DDR2 (total of 4 pieces)
GPU: Asus Radeon HD 3450 256MB DDR2, PCI-Express 2.0, DVI, Passive
(that means no fan, making the machine more quiet)
SC: M-Audio DELTA 1010 which is Jack driven and the ALSA driven
MB's card, an Intel HDA, which serves for light monitoring and
ordinary usage purposes.
OS: Kubuntu 9.04 64 bit with 2.6.28-3-rt running and with almost
every music related apps and libraries compiled from scratch.
Jack: In normal use, the setting are: Frames: 64, sample rate 44100,
periods: 2 which gives 2.9 ms of latency. I normally reduce
the frames down to 16 (0.726 ms) when i do recording and up
to 512 (23.2 ms) and rarely even up to 1024 (46.4 ms) when
mixing. I have experienced xruns if the latency is to high,
perhaps some apps or HW are impatience? :-)
I suspect that the MSI K9N is not an ideal solution for Audio, but that the
power of CPU and the system at large makes everything good anyway.
The main apps are Ardour, Rosegarden and Linuxsampler (loaded with 4-5 GB of
sounds, NDK, pianos, brass and bass) and occasionally zynaddsubfx and
FluidSynth (Qsynth).
I use to do files in 44100 and 24 bit. I believe that 48000 is not (very)
audible, in order to be audible it should be 96000 which I'm not ready to use
as a standard yet. I always record samples and synths and any sequencer
related stuff into Ardour before mixing, freeing resources to plugins.
Speaking of plugins: I really love the Calf plugins, especially the compressor
for drums, awesome! For Guitar work, I use a POD or micing up amplifiers with
SM 57's. IMO the POD sounds great in the mix, but the compressor really sucks,
so I have a Marshall ED-1 first in the chain when using guitars with low
output SC. I use QtPod for controlling the POD from the computer. Keyboard
controller is an Edirol PCR 800.
The average or sane user will probably use a ready music distro or additions
like CCRMA with the apps from the repository. I use Kubuntu because I like it
and mainly use Ubuntu (both desktop and servers) for work. This makes my life
easier. I also use a similar setup on my Laptop, but with a Edirol UM-2ex
interface for MIDI and a M-Audio MobilePRE USB audio interface.
I hope that this info can be of some value for someone that wonders where to
go or just are interested.
Jostein
Latència
Per a un periode de 256 frames (256 frames/period) i una freqüència de 44100, la latència té un valor de 5,8 ms, i aquest és el valor que s'informa en el log de quan engeguem el Jack. Per obtenir el valor senzillament hem de fer la divisió:
configuring for 44100Hz, period = 256 frames (5.8 ms), buffer = 2 periods 256 frames/44100 Hz = 0,0058 s = 5,8 ms
Però aquest no és el valor que surt com a latència en el setup del JACK. Per calcular-lo, he de multiplicar el 5,8 ms pels periods (o buffer, depèn de la nomenclatura). Si periods/buffer=4 obtinc una latència de:
latència = 5,8 ms * 4 = 23,2 ms
i aquest sí que és el valor que em proporciona el JACK.
Per tant, surt bé el càlcul numèric i el càlcul dimensional:
256 frames/period * 4 period
latència = ______________________________ = 23,2 msec
44100 frames/sec
man jackd
jackd (1)
NAME
jackd, jackstart - JACK Audio Connection Kit sound server
SYNOPSYS
jackd [ options ] -d driver [ driver options ]
jackstart [ options ] -d driver [ driver options ]
jackd --help
DESCRIPTION
jackd invokes the JACK audio server daemon. When using JACK's built-in
support for realtime capabilities, use the jackstart command, instead.
All options are the same.
JACK is a low-latency audio server, originally written for the
GNU/Linux operating system. It can connect a number of different JACK
client applications to an audio device, and also to each other. Most
clients are external, running in their own processes as normal applica-
tions. JACK also supports internal clients, which run within the jackd
process using a loadable "plugin" interface.
JACK differs from other audio servers in being designed from the ground
up for professional audio work. It focuses on two key areas: syn-
chronous execution of all clients, and low latency operation.
For the latest JACK information, please consult the web site,
<http://jackit.sourceforge.net>.
OPTIONS
-h, --help
Print a brief usage message describing the main jackd options.
These do not include driver options, which are obtained using
the --help option for that specific driver, instead.
-a, --asio
Force absolute realtime behaviour on the system. Rather than
allowing clients to take a time determined by the kernel, they
are determined to have timed out on receipt of the next inter-
rupt from the audio interface. This only makes sense when used
with an ASIO-style configuration where there are 2 periods per
buffer (see --nperiods). It is safe to omit this parameter, if
you don't need to enforce strict realtime limits. It can be
useful for testing the realtime behavior of a new JACK clients.
-t, --timeout int
Set client timeout limit in microseconds. The default is 500
msec when not in realtime mode (see: -R).
-R, --realtime
Use realtime scheduling. This is needed for reliable low-
latency performance. It requires jackd to run with special
scheduler and memory allocation privileges, which may be
obtained in two ways. The first method is to run jackd with
root privileges, which means that all JACK clients must also run
as root. The second method requires a kernel with "POSIX draft
capabilities" enabled (see the <linux/capability.h> include
-v, --verbose
Give verbose output.
-V, --version
Print the current JACK version number and exit.
-d, --driver driver [ driver-options ]
Select the output driver. The only driver currently documented
is alsa (see below).
ALSA DRIVER OPTIONS
-h, --help Print a brief usage message describing only the
alsa driver options.
-d, --device name
The ALSA pcm device name to use ("default" if none specified).
-r, --rate int
Specify the sample rate. The default is 48000.
-p, --period int
Specify the number of frames between JACK process() calls. The
default is 1024. If you need low latency, set -p as low as you
can go without seeing xruns. A larger period size yields higher
latency, but makes xruns less likely.
-n, --nperiods int
Specify the number of periods in the hardware buffer. The
default is 2. The period size (-p) times --nperiods times four
is the JACK buffer size in bytes.
-D, --duplex
Provide both capture and playback ports (the default).
-C, --capture
Provide only capture ports.
-P, --playback
Provide only playback ports.
-H, --hwmon
Enable hardware monitoring of capture ports. This is a method
for obtaining "zero latency" monitoring of audio input. It
requires support in hardware and from the underlying ALSA device
driver.
When enabled, requests to monitor capture ports will be satis-
fied by creating a direct signal path between audio interface
input and output connectors, with no processing by the host com-
puter at all. This offers the lowest possible latency for the
monitored signal.
Presently (March 2003), only the RME Hammerfall series and cards
based on the ICE1712 chipset (M-Audio Delta series, Terratec,
and others) support --hwmon. In the future, some consumer cards
may also be supported by modifying their mixer settings.
-s, --softmode
Ignore xruns reported by the ALSA driver. This makes JACK less
likely to disconnect unresponsive ports when running without
--realtime.
-z, --dither [rectangular,triangular,shaped,none]
Set dithering mode. If none or unspecified, dithering is off.
Only the first letter of the mode name is required.
EXAMPLES
Print usage message for options specific to the alsa driver.
jackd -d alsa --help
Run the JACK daemon with realtime priority using the first ALSA hard-
ware card defined in /etc/modules.conf. This must be run on a kernel
with capabilities enabled.
jackstart --realtime --driver=alsa --device=hw:0
Run the JACK daemon with low latency. A reasonably well-tuned current-
generation system with a decent sound card and a low-latency kernel
with capabilities enabled can handle these values reliably. Some can
do better. If you get xrun messages, try a larger buffer. Tuning a
system for low latency is challenging. The JACK FAQ,
<http://jackit.sourceforge.net/docs/faq.php> has some useful sugges-
tions.
jackstart -R -d alsa -d hw:0 -p 128 -n 3 -r 44100
Run jackd with realtime priority using the "sblive" ALSA device defined
in ~/.asoundrc. Apply shaped dithering to playback audio. This must
be run as root.
jackd -R -d alsa -d sblive --dither=shaped
Run jackd with no special privileges using the "sblive" ALSA device
defined in ~/.asoundrc. Any xruns reported by the ALSA driver will be
ignored. The larger buffer helps reduce data loss. Rectangular
dithering will be used for playback.
jackd -d alsa -d sblive -p1024 -n3 --softmode -zr
SEE ALSO:
<http://www.alsa-project.org>
Utilitat: jack_lsp
Es pot estudiar el codi font:
NAME
jack_lsp - JACK toolkit client to list informtion on ports
SYNOPSIS
jack_lsp [ -s | --server servername ] [ -AclLptvh ]
DESCRIPTION
jack_lsp lists all known ports associated with a JACK server. It can also optionally list various kinds of
information about each port.
$ jack_lsp -t system:capture_1 32 bit float mono audio system:capture_2 32 bit float mono audio system:playback_1 32 bit float mono audio system:playback_2 32 bit float mono audio
the playback device "hw:0" is already in use
Aquest problema va apareixent de forma esporàdica quan vull iniciar el JACK.
the playback device "hw:0" is already in use. Please stop the application using it and run JACK again cannot load driver module alsa
Some program was probably hogging your sound card. The usual culprit is esd (the Enlightened Sound Daemon). per matar el dimoni:
$ ps aux|grep esd $ sudo killall esd
If its not esd, then its generally software that uses OSS (the open sound system) which is severly deprecated, but yet some programs insist on using them.
Millor és reiniciar ALSA:
$ sudo /etc/init.d/alsa-utils restart
no ho soluciona, en canvi, sí que ho soluciona fer:
$ sudo /sbin/alsa force-reload
creat per Joan Quintana Compte, maig 2009