Latency:
Filter:
SpeakersCorner/classes (extension) | Utilities

Latency
ExtensionExtension

Measure audio latency for multiple channels

Description

Latency is the time delay between when one initiates something and when it happens. There are several places in the SC architecture where latencies occur:

The Latency class is intended for measuring audio hardware latency, and overall latency, which includes sound travel through air. Latency does its measuring by generating pulses on one or several output channels, and measuring time until each pulse registers again at a given audio input. [ interpreter latency is covered in the examples section below ]

Interpreter latency

This is the time between entering a command and the time it is executed in the client (sclang). This depends on how much code runs "at once" and how complex the calculations are. For many cases, it is near zero.

Network latency

sclang and scserver communicate via network (OpenSoundControl, usually UDP, or also TCP/IP); until a network packet sent from sclang to the server arrives, an undetermined time passes. On the same machine, with little other network traffic, this can be as low as 0.02 seconds, depending mainly on the server's hardware buffer size. This can be measured with:

To ensure that messages arrive at the server in the correct order, and with exact relative timing, the server has a latency value s.latency which can be tuned. By default, this is rather high with 0.2 secs. For tigher interaction, e.g. when playing an instrument-like interface, one can tune this value down until occasional late messages appear, and then go up until they disappear again.

Measuring effective audio hardware latency

scsynth passes buffers (one block of numbers per channel) to the audio hardware; the size of these buffers determines the time it takes between when a sound is calculated internally and when it actually is heard. The same goes for audio inputs, which are passed to SC as blocks, so there is some latency between when e.g. a trigger happens at the analog audio input, and when it is detected with e.g. a Trig Ugen.

While hardware buffer size and other factors can be set directly with utility software for audiocards, such software often does not consider all the factors: E.g. the operating system itself, firewire or USB connections, and intermediate layers like Jack may introduce extra buffering and thus accumulate delay time. Thus, connecting the first audio output to the first audio input electrically is the most accurate measuring methods, as it includes all such delays.

Measure overall delay times for multiple loudspeakers

For multi-speaker setups, distances to any listening position introduce delays, so measuring overall audio latency can be useful. This is done by setting up all loudspeakers as desired, putting a single mic in the "sweet spot", or another typical listening position, and recording responses over all acoustic channels.

Class Methods

.testAudio

main method to measure audio latency

Arguments:

numChans

the number of output channels to send pulses on

maxDT

maximum expected delay time, determines pulse cycle time

server

the server to play on, default is Server.default

inChan

the input channel on which incoming pulses are measured

.verbose

get and set a flag whether to post verbosely

.threshold

get and set amplitude threshold for pulses on input channel

.stop

stop measurement

.latencies

the latest measured latencies for all channels

.post

post the latest measured latencies

.lastTime

the most recent measurement: [outputIndex, latencyInSamples ]

.serv

the server to use

.syn

the synth that runs the latency test

.resp

the OSCFunc that listens for pulse triggers