wiki:MeasuringSoundLatency

Version 1 (modified by bennylp, 16 years ago) (diff)

--

Measuring Sound Latency

This article describes how to measure both sound device latency and overall (end-to-end) latency of pjsua. The objective of the test is to measure the latency introduced by both the sound device and the pjmedia framework.

Requirements

You will need:

  • pjsua
  • a computer with microphone and loudspeaker (not headset)
  • tock8.wav WAV file (see the attachment on the bottom of this page)
  • a WAV waveform display/analyzer to visually see the latency (such as Cool Edit on Windows)
  • or latency.c file (see the attachment on the bottom of this page) if you don't have WAV waveform analyzer program.

Setup

  • You MUST make sure that the loudspeaker level is set high enough so that the output is fed-back to the microphone (i.e. we deliberately want to capture the audio echo)
  • Build pjsua and the latency.c

Measuring Sound Device Latency

This test will measure the total latency introduced by:

  • microphone and speaker device buffering (both in application layer, driver layer, and hardware itself)
  • conference bridge buffering

Test method:

  • play a special WAV file to the speaker device, and simultaneously record WAV file
  • as the audio is played in the speaker, capture the signal in the microphone (i.e. similar to how sound echo is captured)
  • record the microphone capture to WAV file.

By looking in the recorded WAV file we should be able to know the sound device latency by measuring the interval between the recording of original signal and recording of the echo signal.

Running the Test

Run pjsua:

pjsua --no-tones --ec-tail 0 --rec-file rec1.wav --clock-rate 8000 --snd-clock-rate 8000 --play-file tock8.wav

Run this script all at once (i.e. copy these and paste it to pjsua):

cc 0 0
cc 1 0
cc 1 2
cc 0 2
sleep 10000
cd 0 0
cd 1 0
cd 1 2
cd 0 2
q

The command above will play the tock8.wav file to the speaker over and over for 10 seconds, while at the same time both the WAV file and the microphone signal will be recorded to rec1.wav file.

Analyzing the result with WAV analyzer

Here's what the recorded signal (rec1.wav) looks like in my WAV analyzer:

The highlighted area in above picture shows one recording of both original signal and the echo.

If we zoom-in the highlighted area, it will look like this:

And to find out the latency, just measure the interval between original signal and echoed signal:

In this test, I found out that the latency is approximately 171 milliseconds.

Analyzing the result with latency analyzer

If you don't have WAV waveform analyzer, you can measure the latency using latency.c application.

 C:\> latency.exe rec1.wav
Latency average = 197
Latency minimum = 173
Latency maximum = 213
Number of data  = 9

Attachments (8)

Download all attachments as: .zip