| 1 | = Measuring Sound Latency = |
| 2 | |
| 3 | This article describes how to measure both sound device latency and overall (end-to-end) latency of [http://www.pjsip.org/pjsua.htm pjsua]. The objective of the test is to measure the latency introduced by both the sound device and the [http://www.pjsip.org/pjmedia/docs/html/index.htm pjmedia] framework. |
| 4 | |
| 5 | == Requirements == |
| 6 | |
| 7 | You will need: |
| 8 | * [http://www.pjsip.org/pjsua.htm pjsua] |
| 9 | * a computer with microphone and loudspeaker (not headset) |
| 10 | * {{{tock8.wav}}} WAV file (see the attachment on the bottom of this page) |
| 11 | * a WAV waveform display/analyzer to visually see the latency (such as Cool Edit on Windows) |
| 12 | * or {{{latency.c}}} file (see the attachment on the bottom of this page) if you don't have WAV waveform analyzer program. |
| 13 | |
| 14 | == Setup == |
| 15 | |
| 16 | * 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) |
| 17 | * Build pjsua and the latency.c |
| 18 | |
| 19 | |
| 20 | == Measuring Sound Device Latency == |
| 21 | |
| 22 | This test will measure the total latency introduced by: |
| 23 | * microphone and speaker device buffering (both in application layer, driver layer, and hardware itself) |
| 24 | * conference bridge buffering |
| 25 | |
| 26 | Test method: |
| 27 | * play a special WAV file to the speaker device, and simultaneously record WAV file |
| 28 | * as the audio is played in the speaker, capture the signal in the microphone (i.e. similar to how sound echo is captured) |
| 29 | * record the microphone capture to WAV file. |
| 30 | |
| 31 | 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. |
| 32 | |
| 33 | |
| 34 | === Running the Test === |
| 35 | |
| 36 | Run pjsua: |
| 37 | |
| 38 | {{{ |
| 39 | pjsua --no-tones --ec-tail 0 --rec-file rec1.wav --clock-rate 8000 --snd-clock-rate 8000 --play-file tock8.wav |
| 40 | }}} |
| 41 | |
| 42 | Run this script all at once (i.e. copy these and paste it to pjsua): |
| 43 | |
| 44 | {{{ |
| 45 | cc 0 0 |
| 46 | cc 1 0 |
| 47 | cc 1 2 |
| 48 | cc 0 2 |
| 49 | sleep 10000 |
| 50 | cd 0 0 |
| 51 | cd 1 0 |
| 52 | cd 1 2 |
| 53 | cd 0 2 |
| 54 | q |
| 55 | |
| 56 | }}} |
| 57 | |
| 58 | 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. |
| 59 | |
| 60 | === Analyzing the result with WAV analyzer === |
| 61 | |
| 62 | Here's what the recorded signal ({{{rec1.wav}}}) looks like in my WAV analyzer: |
| 63 | |
| 64 | |
| 65 | The highlighted area in above picture shows one recording of both original signal and the echo. |
| 66 | |
| 67 | If we zoom-in the highlighted area, it will look like this: |
| 68 | |
| 69 | And to find out the latency, just measure the interval between original signal and echoed signal: |
| 70 | |
| 71 | In this test, I found out that the latency is approximately 171 milliseconds. |
| 72 | |
| 73 | |
| 74 | === Analyzing the result with latency analyzer === |
| 75 | |
| 76 | If you don't have WAV waveform analyzer, you can measure the latency using {{{latency.c}}} application. |
| 77 | |
| 78 | {{{ |
| 79 | C:\> latency.exe rec1.wav |
| 80 | Latency average = 197 |
| 81 | Latency minimum = 173 |
| 82 | Latency maximum = 213 |
| 83 | Number of data = 9 |
| 84 | }}} |
| 85 | |
| 86 | |