X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=_manual%2F19_synchronization%2F02_latency-and-latency-compensation.html;h=6b11a6be8fefeb00e36642ac43ac699c4a99d0e1;hb=26d592b95119669e5121a4f34862ded1e9a6915e;hp=c478a5c1281210edfb626bd59c8fb01408717ceb;hpb=e7b78767392c9f7d705799ff94724dd6d2a21a71;p=ardour-manual-diverged diff --git a/_manual/19_synchronization/02_latency-and-latency-compensation.html b/_manual/19_synchronization/02_latency-and-latency-compensation.html index c478a5c..6b11a6b 100644 --- a/_manual/19_synchronization/02_latency-and-latency-compensation.html +++ b/_manual/19_synchronization/02_latency-and-latency-compensation.html @@ -1,160 +1,248 @@ --- layout: default title: Latency and Latency-Compensation +menu_title: Latency --- -

Latency

-

-When speaking about synchronization, there is no way around also mentioning Latency: -Latency is how you call the reaction time of a system to a certain stimulus. There are many factors that contribute to the total latency of a given system. -In order to achieve exact time synchronization all sources of latency need to be take into account and compensated for. + Latency + is a system's reaction time to a given stimulus. There are many factors that + contribute to the total latency of a system. In order to achieve exact time + synchronization all sources of latency need to be taken into account and + compensated for.

- -

Figure 1: Latency chain

-

Figure 1: Latency chain. The numbers are an example for a typical PC. With professional gear and an optimized system the total roundtrip latency is usually lower. The important point is that latency is always additive and a sum of many independent factors.

+

Sources of Latency

+

Sound propagation through the air

-There is not much that can done about the first two other than using headphones or sitting near the loudspeaker and buying quality gear. + Since sound is a mechanical perturbation in a fluid, it travels at + comparatively slow speed + of about 340 m/s. As a consequence, your acoustic guitar or piano has a + latency of about 1–2 ms, due to the propagation time of the sound + between your instrument and your ear.

- +

Digital-to-Analog and Analog-to-Digital conversion

-Processing latency is usually divided into capture latency and playback latency: + Electric signals travel quite fast (on the order of the speed of light), + so their propagation time is negligible in this context. But the conversions + between the analog and digital domain take a comparatively long time to perform, + so their contribution to the total latency may be considerable on + otherwise very low-latency systems. Conversion delay is usually below 1 ms.

- - - +

Digital Signal Processing

-But this division is an implementation detail of no great interest. What really matters is the combination of both. It is called processing roundtrip latency: the time necessary for a certain audio event to be captured, processed and played back. + Digital processors tend to process audio in chunks, and the size of that chunk + depends on the needs of the algorithm and performance/cost considerations. + This is usually the main cause of latency when you use a computer and one you + can try to predict and optimize.

- +

Computer I/O Architecture

-It is important to note that processing latency in a jackd is a matter of choice: It can be lowered within the limits imposed only by the hardware and audio driver. But the lower it is, the more likely the system will fail to meet its processing deadline and the dreaded xrun will make its appearance more often, leaving its merry trail of clicks, pops and crackles. + A computer is a general purpose processor, not a digital audio processor. + This means our audio data has to jump a lot of fences in its path from the + outside to the CPU and back, contending in the process with some other parts + of the system vying for the same resources (CPU time, bus bandwidth, etc.)

+

The Latency chain

+ +Latency chain

-The digital I/O latency is usually negligible for integrated or PCI audio devices but for USB or FireWire interfaces the bus clocking and buffering can add some milliseconds. + Figure: Latency chain. + The numbers are an example for a typical PC. With professional gear and an + optimized system the total roundtrip latency is usually lower. The important + point is that latency is always additive and a sum of many independent factors.

-The JACK Audio Connection Kit has a few parameters to configure the latency. However the settings are constrained by hardware (audio-device, CPU and bus-speed). Lower latencies increase the load on the computer-system (it needs to process the audio in smaller chunks which arrive much more frequently). If the system can not keep up: an x-run (short for buffer over-run and buffer under-run) occurs which usually results in audible clicks or dropouts. + Processing latency is usually divided into capture latency (the time + it takes for the digitized audio to be available for digital processing, usually + one audio period), and playback latency (the time it takes for + In practice, the combination of both matters. It is called roundtrip + latency: the time necessary for a certain audio event to be captured, + processed and played back. +

+

+ It is important to note that processing latency in a jackd is a matter of + choice. It can be lowered within the limits imposed by the hardware (audio + device, CPU and bus speed) and audio driver. Lower latencies increase the + load on the system because it needs to process the audio in smaller chunks + which arrive much more frequently. The lower the latency, the more likely + the system will fail to meet its processing deadline and the dreaded + xrun (short for buffer over- or under-run) will make its + appearance more often, leaving its merry trail of clicks, pops and crackles.

-Low-latency is not always a feature you want to have. It comes with a couple of drawbacks: the most prominent is increased power-consumption because the CPU needs to process many small chunks of audio-data, it is constantly active and can not enter power-saving mode. Furthermore, if more than one application (sound-processor) is involved in processing the sound, the operating system performs a context-switch to run each of these for each audio-cycle which results in a much higher system-load and an increased chance of x-runs. + The digital I/O latency is usually negligible for integrated or + PCI audio devices, but + for USB or FireWire interfaces the bus clocking and buffering can add some + milliseconds.

+ +

Low Latency usecases

-Reliable low-latency (≤10ms) on GNU/Linux can usually only be achieved by running realtime-kernel. + Low latency is not always a feature you want to have. It + comes with a couple of drawbacks: the most prominent is increased power + consumption because the CPU needs to process many small chunks of audio data, + it is constantly active and can not enter power-saving mode (think fan-noise). + Since each application that is part of the signal chain must run in every + audio cycle, low-latency systems will undergocontext switches + between applications more often, which incur a significant overhead. + This results in a much higher system load and an increased chance of xruns.

-

-Yet there are only few situations where a very low-latency is really important, because they require very quick response from the computer. Some examples that come quickly to mind are: + For a few applications, low latency is critical:

- - +

Playing virtual instruments

-In many other cases - such as playback, recording, overdubbing, mixing, mastering, etc. latency is not important, It can be relatively large and easily be compensated for. + A large delay between the pressing of the keys and the sound the instrument + produces will throw-off the timing of most instrumentalists (save church + organists, whom we believe to be awesome latency-compensation organic systems.)

- +

Software audio monitoring

-To explain the last statement: during mixing or mastering you don't care if it take 10 or 100ms between the instant you press the play button and sound coming from the speaker. The same is true when recording. + If a singer is hearing her own voice through two different paths, her head + bones and headphones, even small latencies can be very disturbing and + manifest as a tinny, irritating sound.

- +

Live effects

-During tracking, it is however important that the sound that is currently played back is internally aligned with the sound that is being recorded. + Low latency is important when using the computer as an effect rack for + inline effects such as compression or EQ. For reverbs, slightly higher + latency might be tolerable, if the direct sound is not routed through the + computer.

- +

Live mixing

-This is where latency-compensation comes into play: There are two possibilities to compensate for latency in a DAW: read-ahead the DAW actually starts playing a bit early. So that the sound hits the speakers a short time later, it is exactly aligned with the timecode of the material that is being recorded. -and write-behind since we know that the sound that is being played back has latency, the incoming audio can be delayed by the same amount to line things up again. + Some sound engineers use a computer for mixing live performances. + Basically that is a combination of the above: monitoring on stage, + effects processing and EQ.

-

-As you may see the second approach has various issues implementation issues regarding timecode and transport synchronization. Ardour uses internal read-ahead to compensate for latency. The time displayed in the Ardour clock corresponds to the audio-signal that you hear on the speakers (and is not where ardour reads files from disk). + In many other cases, such as playback, recording, overdubbing, mixing, + mastering, etc. latency is not important, since it can easily be + compensated for.
+ To explain that statement: During mixing or mastering you don't care + if it takes 10ms or 100ms between the instant you press the play button + and sound coming from the speaker. The same is true when recording with a count in.

+

Latency compensation

-NB. this is also one of the reasons why many projects start at timecode 01:00:00:00. When compensating for output-latency the DAW will need to read data from before the start of the session so that the audio arrives in time at the output when the timecode hits 01:00:00:00. Ardour3 does handle the case of 00:00:00:00 properly but not all systems/software/hardware that you may inter-operate with may behave the same. + During tracking it is important that the sound that is currently being + played back is internally aligned with the sound that is being recorded.

- - -

Latency compensation and clock sync

-

-To achieve sample accurate timecode synchronization, the latency introduced by the audio-setup needs to be known and compensated for. + This is where latency-compensation comes into play. There are two ways to + compensate for latency in a DAW, read-ahead and + write-behind. The DAW starts playing a bit early (relative to + the playhead), so that when the sound arrives at the speakers a short time + later, it is exactly aligned with the material that is being recorded. + Since we know that play-back has latency, the incoming audio can be delayed + by the same amount to line things up again. +

+

+ As you may see, the second approach is prone to various implementation + issues regarding timecode and transport synchronization. Ardour uses read-ahead + to compensate for latency. The time displayed in the Ardour clock corresponds + to the audio-signal that you hear on the speakers (and is not where Ardour + reads files from disk).

-

-In order to compensate for Latency, JACK or JACK applications need to know exactly how long a certain signal needs to be read-ahead or delayed: + As a side note, this is also one of the reasons why many projects start at + timecode 01:00:00:00. When compensating for output latency the + DAW will need to read data from before the start of the session, so that the + audio arrives in time at the output when the timecode hits 01:00:00:00. + Ardour3 does handle the case of 00:00:00:00 properly but not all + systems/software/hardware that you may inter-operate with may behave the same.

-

Figure 2: Jack Latency Compensation

-

Figure 2: Jack Latency Compensation. This figure outlines the jack latency API. -- excerpt from http://jackaudio.org/files/jack-latency.png

+

Latency Compensation And Clock Sync

-In Figure 2, clients A and B need to be able to answer the following two questions: + To achieve sample accurate timecode synchronization, the latency introduced + by the audio setup needs to be known and compensated for. +

+

+ In order to compensate for latency, JACK or JACK applications need to know + exactly how long a certain signal needs to be read-ahead or delayed: +

+Jack Latency Compensation +

+ Figure: Jack Latency Compensation. +

+

+ In the figure above, clients A and B need to be able to answer the following + two questions:

-JACK includes an API that allows applications to determine the answers to above questions. However JACK can not know about the additional latency that is introduced by the computer architecture, operating system and soundcard. These values indicated by -I and -O in Figure 2 and vary from system to system but are generally constant values. On a general purpose computer system the only way to accurately learn about the total latency is to measure it. + JACK features an API + that allows applications to determine the answers to above questions. + However JACK can not know about the additional latency that is introduced + by the computer architecture, operating system and soundcard. These values + can be specified by the JACK command line parameters -I + and -O and vary from system + to system but are constant on each. On a general purpose computer system + the only way to accurately learn about the total (additional) latency is to + measure it.

-

Calibrating JACK latency

- +

Calibrating JACK Latency

-Linux DSP guru Fons Adriaensen wrote a tool called jack_delay to accurately measure the roundtrip latency of a closed loop audio chain, with sub-sample accuracy. JACK itself includes a variant of this called jack_iodelay. + Linux DSP guru Fons Adriaensen wrote a tool called jack_delay + to accurately measure the roundtrip latency of a closed loop audio chain, + with sub-sample accuracy. JACK itself includes a variant of this tool + called jack_iodelay.

-

-Jack_iodelay allows you to measure the total latency of the system, subtracts the known latency of JACK itself and suggests parameters for jackd's audio-backend -I and -O options. + Jack_iodelay allows you to measure the total latency of the system, + subtracts the known latency of JACK itself and suggests values for + jackd's audio-backend parameters.

-

-jack_[io]delay works by emitting some rather annoying tones, capturing them again after a round trip through the whole chain, and measuring the difference in phase so it can estimate with great accuracy the time taken. This is not a theoretical estimation, jack_delay is a measuring tool that will provide very accurate answers. + jack_[io]delay works by emitting some rather annoying tones, capturing + them again after a round trip through the whole chain, and measuring the + difference in phase so it can estimate with great accuracy the time taken.

-

-You can close the loop in a number of ways: + You can close the loop in a number of ways:

-

-Once you have closed the loop you have to: + Once you have closed the loop you have to:

    -
  1. Launch jackd with the configuration you want to test.
  2. -
  3. Launch jack_delay.
  4. -
  5. Make the appropriate connections between your jack ports so the loop is closed.
  6. -
  7. Adjust the playback and capture levels in your mixer.
  8. +
  9. Launch jackd with the configuration you want to test.
  10. +
  11. Launch jack_delay on the commandline.
  12. +
  13. Make the appropriate connections between your jack ports so the loop is closed.
  14. +
  15. Adjust the playback and capture levels in your mixer.
-