On Fri, Apr 05, 2019 at 06:38:59PM -0400, Tim wrote: > [PC] -->--[ex. Par. port]-->--[Triggers]-->--[Sin oscs] > --- | > | | > --<--[Audio input]---------------<--------- > > It's similar to how round-trip latency might be measured, > except there the sines are generated digitally by audio output.
You don't even need the oscillators. Just connect the digital output to a line input. If you make sure the pulse doesn't overload the audio input (using resistors to attenuate it if necessary), then the delay can easily be measured with sub-sample accuracy. The tricky part of is how to define input or output latency in an unambiguous way, and to understand when and how it matters. It doesn't for example when you record a new track via the sound card (i.e. using a mic or DI of an external instrument) while listening to already recorded tracks. In that case only the round-trip latency matters. It *does* matter when recording a new track which is not input from the sound card, but generated internally. In that case you have input latency on the MIDI input which drives the software instrument, and output latency on the audio output playing back the already recorded tracks. This again is a round-trip latency, but with the two components originating in different systems. It also matters when you you want to find out to which audio sample a mouse click or keyboard event corresponds, e.g. to mark a position for editing. Let's assume you can generate a digital output pulse at a time measured by jack_time(). On a Raspberry for example you could use one of GPIO pins which can be manipulated from user space with almost no system delay. Somewhat later, a Jack client will detect this pulse in the audio stream. Note that the time at which this Jack client runs is irrelevant. A Jack client can run anywhere in the current cycle, it doesn't make any difference for the audio processing. The time that matters is the start time of the Jack cycle in which the pulse is detected in the audio stream, plus the time represented by the position of the pulse in the current period. You can get the start and end times of the current cycle using jack_get_cycle_times(). With Tp = jack time at which the digital pulse is generated T0, T1 = the start and end times of the current cycle k = the position (in samples) of the pulse in the period N = the period size then the input latency (in microsends) is T0 + k * (T1 - T0) / N - Tp Ciao, -- FA _______________________________________________ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev