Changes between Version 4 and Version 5 of MeasuringSoundLatency


Ignore:
Timestamp:
Jul 28, 2008 12:37:53 PM (16 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MeasuringSoundLatency

    v4 v5  
    11= Measuring Sound Latency = 
    22 
    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. 
     3This 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 audio latency introduced by both the sound device and the [http://www.pjsip.org/pjmedia/docs/html/index.htm pjmedia] framework. 
    44 
    55== Requirements == 
    66 
    77You will need: 
    8  * [http://www.pjsip.org/pjsua.htm pjsua] 
    9  * a computer with microphone and loudspeaker (not headset) 
     8 * [http://www.pjsip.org/pjsua.htm pjsua] executable (you can build your own, the instructions are on [http://www.pjsip.org pjsip website]). 
     9 * a computer with microphone and loudspeaker (i.e. it's a speaker and not headset) 
    1010 * {{{tock8.wav}}} WAV file attached. 
    11  * a WAV waveform display/analyzer to visually see the latency (such as Cool Edit on Windows) 
    12  * or {{{latency.c}}} file if you don't have WAV waveform analyzer program. This file is included in PJSIP version 0.9.5 and later in {{{pjsip-apps/src/samples}}} directory, or if you use older PJSIP you can find the {{{latency.c}}} file attached. 
     11 * {{{latency.c}}} file if you don't have WAV waveform analyzer program. This file is included in PJSIP version 0.9.5 and later in {{{pjsip-apps/src/samples}}} directory, or if you use older PJSIP you can find the {{{latency.c}}} file attached. You need to build this to get the executable (again the instructions are on [http://www.pjsip.org pjsip website]). 
     12 * optionally a WAV waveform display/analyzer to visually see the latency (such as Cool Edit on Windows) 
    1313 
    1414== Setup == 
    1515 
    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) 
    1716 * Build pjsua and the latency.c 
    18  
     17 * You MUST make sure that the loudspeaker level is set high enough so that the speaker output is fed-back to the microphone (i.e. we deliberately want to capture the audio echo) 
     18 * You need to have a reasonable quiet room to do this test. 
    1919 
    2020== Measuring Sound Device Latency == 
    2121 
    2222This test will measure the total latency introduced by: 
    23  * microphone and speaker device buffering (both in application layer, driver layer, and hardware itself) 
     23 * microphone and speaker device buffering (both in application layer, driver layer, and in the hardware itself) 
    2424 * conference bridge buffering 
    2525 
    26 Test method: 
    27  * play a special WAV file to the speaker device, and simultaneously record WAV file 
     26Test method (this will be done automatically by a script): 
     27 * play a special WAV file to the speaker device, and simultaneously record directly to a WAV file 
    2828 * as the audio is played in the speaker, capture the signal in the microphone (i.e. similar to how sound echo is captured) 
    2929 * record the microphone capture to WAV file. 
     
    3434=== Running the Test === 
    3535 
    36 Run pjsua: 
     36Run pjsua with the following command line arguments: 
    3737 
    3838{{{ 
     
    4040}}} 
    4141 
    42 Run this script all at once (i.e. copy these and paste it to pjsua): 
     42Then once pjsua is ready, run this script below all at once (i.e. copy these and paste it to pjsua): 
    4343 
    4444 {{{ 
     
    5656 }}} 
    5757 
    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.  
     58The 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. The sample {{{rec1.wav}}} result of my test is attached. 
    5959 
    6060=== Analyzing the result with WAV analyzer === 
     
    7070[[Image(rec1-zoom.PNG, 50%)]] 
    7171 
     72The strong signal (at t=0.68) is the recording of original signal directly from the input WAV file, while the weak signal (at t=0.86) is the echoed signal after the audio is played back to the speaker and captured in the microphone. 
     73 
    7274And to find out the latency, just measure the interval between original signal and echoed signal: 
    7375 
    7476[[Image(rec1-latency.PNG, 50%)]] 
    7577 
    76 In this test, I found out that the latency is approximately 171 milliseconds. 
     78In this test, I found out that the latency is approximately 171 milliseconds. This value is only for the first play/echo cycle, and as most buffers in pjmedia are adaptive, the latency may grow or shrink dynamically as time progresses, hence it's probably better to use {{{latency.c}}} to measure the latency in more precise manner. 
    7779 
    7880 
     
    9092 
    9193As you can see above, measuring the latency this way has several advantages: 
    92  * it's more automatic than manually measuring the latency with WAV analyzer. 
     94 * it's more automatic than manually measuring the latency with WAV analyzer 
    9395 * it should measure the latency more precisely 
    9496 * it can measure the changes in the latency (as min, max, and average) as the buffers are adapting 
     
    98100 
    99101The objective of this test is to measure the overall latency of: 
    100  * microphone and speaker device buffering (both in application layer, driver layer, and hardware itself) 
    101  * conference bridge buffering 
     102 * the sound device buffering in the previous test, plus the following: 
    102103 * jitter buffering 
    103104 * codec buffering 
    104105 * and everything else 
    105106 
    106 Note that in order to measure the latency, we use loopback call for this test (meaning, the pjsua application is making call to itself), so this test method cannot be used to measure end-to-end latency of two pjsua instances. 
     107Note that in order to measure the latency, we use loopback call for this test (meaning, the pjsua application will make call to itself), so this test method cannot be used to measure end-to-end latency of two pjsua instances. 
    107108 
    108 Test method: 
     109Test method (note that this will be done automatically by a script): 
    109110 * make loopback call (i.e. pjsua is calling itself, so we have both caller and callee in the same pjsua instance) 
    110  * arrange the conference bridge connection so that audio flow is one way (i.e. microphone -> call1 --> local network/OS --> call2 --> speaker) 
    111  * play a special WAV file to caller, and simultaneously record WAV file 
     111 * arrange the conference bridge connection so that we have one way audio flow (i.e. the audio flow is: microphone -> caller --> loopback network --> callee --> speaker) 
     112 * play a special WAV file to caller, and simultaneously record it to WAV file 
    112113 * audio/RTP is received by callee, which will play the received the audio to speaker 
    113114 * as the audio is played in the speaker, capture the signal in the microphone (i.e. similar to how sound echo is captured) 
     
    121122 
    122123{{{ 
    123 pjsua --no-tones --ec-tail 0 --no-vad --clock-rate 8000 --snd-clock-rate 8000 --rec-file rec2.wav --play-file tock8.wav --add-codec pcmu 
     124pjsua --no-tones --ec-tail 0 --no-vad --clock-rate 8000 --rec-file rec2.wav --play-file tock8.wav --add-codec pcmu 
    124125}}} 
    125126 
    126 Then copy/paste the script below to pjsua: 
     127Then copy/paste the script below to pjsua (you need to paste them at the same time): 
    127128 
    128129{{{ 
     
    144145cd 1 2 
    145146q 
     147 
    146148}}} 
    147149 
    148 The command above will make pjsua calls itself, answer the call, setup the conference bridge interconnection to record the WAV file, and do recording to 10 seconds. Once it's done, the recorded WAV file is in {{{rec2.wav}}} file. 
     150The command above will make pjsua calls itself, answer the call, setup the conference bridge interconnection to record the WAV file, and do recording for 10 seconds, then quit. Once it's done, the recorded WAV file is in {{{rec2.wav}}} file. Please see  {{{rec2.wav}}} from my test attached. 
    149151 
    150152=== Analyzing the result with WAV analyzer === 
     
    154156[[Image(rec2.png, 50%)]]] 
    155157 
    156 And in my measurement, I measured the delay is about 200 milliseconds. 
     158And in my measurement, I measured the delay is about 200 milliseconds. This value is only for the first play/echo cycle, and as most buffers in pjmedia are adaptive, the latency may grow or shrink dynamically as time progresses, hence it's probably better to use {{{latency.c}}} to measure the latency in more precise manner. 
    157159 
    158160 
     
    169171 }}} 
    170172 
     173