X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=include%2Flatency-and-latency-compensation.html;h=59cb28415cb0bb651cf75260922539c3fea1c981;hb=252cfd80174df0772747e8c2589014937cbed0e3;hp=c688393932b10e9825efcb9ab1aea42b3ebd2f29;hpb=88d6f39b5f8b0f791b6833bb1512aa774b59d4f8;p=ardour-manual diff --git a/include/latency-and-latency-compensation.html b/include/latency-and-latency-compensation.html index c688393..59cb284 100644 --- a/include/latency-and-latency-compensation.html +++ b/include/latency-and-latency-compensation.html @@ -14,10 +14,11 @@

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 + of about 340 m/s. As a consequence, an 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. + between the instrument and the player's ear.

+

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

Electric signals travel quite fast (on the order of the speed of light), @@ -26,41 +27,52 @@ 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

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. + This is usually the main cause of latency when using a computer and the one that + can be predicted and optimized.

+

Computer I/O Architecture

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 + This means the 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 +

+ Note! the rest of this document assumes the use of jackd for the audio + backend. While many of the concepts are true, the specifics may be different. +

+
+ Latency chain +
+ Latency chain +
+
+

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

-

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 + one audio period), and playback latency (the time it takes for the + audio that has been processed to be available in digital form). In practice, the combination of both matters. It is called round-trip 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 + It is important to note that processing latency in Ardour 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 @@ -77,33 +89,36 @@ milliseconds.

-

Low Latency use cases

+

- Low latency is not always a feature you want to have. It + Low latency is not always a feature one wants 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). + 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 + audio cycle, low-latency systems will undergo context switches between applications more often, which incur a significant overhead. This results in a much higher system load and an increased chance of xruns.

For a few applications, low latency is critical:

+

Playing virtual instruments

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 + 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

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

Low latency is important when using the computer as an effect rack for @@ -111,6 +126,7 @@ latency might be tolerable, if the direct sound is not routed through the computer.

+

Live mixing

Some sound engineers use a computer for mixing live performances. @@ -120,10 +136,12 @@

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. + compensated for. +

+

+ To explain that statement: During mixing or mastering, one doesn't care + if it takes 10ms or 100ms between the instant the play button is pressed + and the sound coming from the speaker. The same is true when recording with a count in.

Latency compensation

@@ -132,19 +150,19 @@ played back is internally aligned with the sound that is being recorded.

- This is where latency-compensation comes into play. There are two ways to + 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 + Since we know that playback 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 + 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 + to the audio signal that is heard on the speakers (and is not where Ardour reads files from disk).

@@ -152,7 +170,7 @@ 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 + Ardour 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.

@@ -166,10 +184,14 @@ 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. -

+ +
+ Jack Latency Compensation +
+ Jack Latency Compensation +
+
+

In the figure above, clients A and B need to be able to answer the following two questions: @@ -197,7 +219,6 @@ measure it.

-

Calibrating JACK Latency

Linux DSP guru Fons Adriaensen wrote a tool called jack_delay @@ -206,7 +227,7 @@ called jack_iodelay.

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

@@ -216,7 +237,7 @@ difference in phase so it can estimate with great accuracy the time taken.

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

- Once you have closed the loop you have to: + Once the loop has been closed, one must:

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

+ On Linux, the latency of USB audio interfaces is not constant. It may + change when the interface is reconnected, on reboot and even when xruns + occur. This is due the buffer handling in the Linux USB stack. As a + workaround, it is possible to recalibrate the latency at the start of each + session and each time an xrun occurs. +