Changes between Version 4 and Version 5 of MeasuringSoundLatency
- Timestamp:
- Jul 28, 2008 12:37:53 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MeasuringSoundLatency
v4 v5 1 1 = Measuring Sound Latency = 2 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.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 audio latency introduced by both the sound device and the [http://www.pjsip.org/pjmedia/docs/html/index.htm pjmedia] framework. 4 4 5 5 == Requirements == 6 6 7 7 You 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) 10 10 * {{{tock8.wav}}} WAV file attached. 11 * a WAV waveform display/analyzer to visually see the latency (such as Cool Edit on Windows)12 * o r {{{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) 13 13 14 14 == Setup == 15 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 16 * 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. 19 19 20 20 == Measuring Sound Device Latency == 21 21 22 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)23 * microphone and speaker device buffering (both in application layer, driver layer, and in the hardware itself) 24 24 * conference bridge buffering 25 25 26 Test method :27 * play a special WAV file to the speaker device, and simultaneously record WAV file26 Test 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 28 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 29 * record the microphone capture to WAV file. … … 34 34 === Running the Test === 35 35 36 Run pjsua :36 Run pjsua with the following command line arguments: 37 37 38 38 {{{ … … 40 40 }}} 41 41 42 Run this scriptall at once (i.e. copy these and paste it to pjsua):42 Then once pjsua is ready, run this script below all at once (i.e. copy these and paste it to pjsua): 43 43 44 44 {{{ … … 56 56 }}} 57 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.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. The sample {{{rec1.wav}}} result of my test is attached. 59 59 60 60 === Analyzing the result with WAV analyzer === … … 70 70 [[Image(rec1-zoom.PNG, 50%)]] 71 71 72 The 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 72 74 And to find out the latency, just measure the interval between original signal and echoed signal: 73 75 74 76 [[Image(rec1-latency.PNG, 50%)]] 75 77 76 In this test, I found out that the latency is approximately 171 milliseconds. 78 In 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. 77 79 78 80 … … 90 92 91 93 As 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 93 95 * it should measure the latency more precisely 94 96 * it can measure the changes in the latency (as min, max, and average) as the buffers are adapting … … 98 100 99 101 The 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: 102 103 * jitter buffering 103 104 * codec buffering 104 105 * and everything else 105 106 106 Note that in order to measure the latency, we use loopback call for this test (meaning, the pjsua application is makingcall to itself), so this test method cannot be used to measure end-to-end latency of two pjsua instances.107 Note 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. 107 108 108 Test method :109 Test method (note that this will be done automatically by a script): 109 110 * 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 file111 * 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 112 113 * audio/RTP is received by callee, which will play the received the audio to speaker 113 114 * as the audio is played in the speaker, capture the signal in the microphone (i.e. similar to how sound echo is captured) … … 121 122 122 123 {{{ 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 pcmu124 pjsua --no-tones --ec-tail 0 --no-vad --clock-rate 8000 --rec-file rec2.wav --play-file tock8.wav --add-codec pcmu 124 125 }}} 125 126 126 Then copy/paste the script below to pjsua :127 Then copy/paste the script below to pjsua (you need to paste them at the same time): 127 128 128 129 {{{ … … 144 145 cd 1 2 145 146 q 147 146 148 }}} 147 149 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.150 The 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. 149 151 150 152 === Analyzing the result with WAV analyzer === … … 154 156 [[Image(rec2.png, 50%)]]] 155 157 156 And in my measurement, I measured the delay is about 200 milliseconds. 158 And 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. 157 159 158 160 … … 169 171 }}} 170 172 173