From 750fce6029243b410d4b819b9cb7a8d43336a408 Mon Sep 17 00:00:00 2001 From: Andrea Bondavalli Date: Wed, 8 Dec 2021 17:31:09 +0100 Subject: [PATCH] Fixes to run_latency_sh script and latency test application --- run_latency_test.sh | 4 ++-- test/latency.cc | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/run_latency_test.sh b/run_latency_test.sh index e38942e..1d3e64f 100755 --- a/run_latency_test.sh +++ b/run_latency_test.sh @@ -13,12 +13,12 @@ function cleanup { } function usage { - echo 'Usage run_latenvy_test.sh sample_format sample_rate channels duration' >&2 + echo 'Usage run_latenvy_test.sh sample_format sample_rate channels duration frames' >&2 echo ' sample_format can be one of S16_LE, S24_3LE, S32_LE' >&2 echo ' sample_rate can be one of 44100, 48000, 96000' >&2 echo ' channels can be one of 1, 2, 4' >&2 echo ' duration in seconds' >&2 - echo ' buffer size in frames' >&2 + echo ' frames buffer size in frames' >&2 exit 1 } diff --git a/test/latency.cc b/test/latency.cc index 8e90397..c48ea15 100644 --- a/test/latency.cc +++ b/test/latency.cc @@ -239,20 +239,20 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int *bufsize) snd_pcm_hw_params_get_buffer_size(p_params, &p_size); if (p_psize * 2 < p_size) { - snd_pcm_hw_params_get_periods_min(p_params, &val, NULL); - //printf("p period_min = %u\n", val); - if (val > 2) { - printf("playback device does not support 2 periods per buffer\n"); + snd_pcm_hw_params_get_periods_min(p_params, &val, NULL); + //printf("p period_min = %u\n", val); + if (val > 2) { + //printf("playback device does not support 2 periods per buffer\n"); //exit(0); } //goto __again; } snd_pcm_hw_params_get_buffer_size(c_params, &c_size); if (c_psize * 2 < c_size) { - snd_pcm_hw_params_get_periods_min(c_params, &val, NULL); + snd_pcm_hw_params_get_periods_min(c_params, &val, NULL); //printf("c period_min = %u\n", val); if (val > 2 ) { - printf("capture device does not support 2 periods per buffer\n"); + //printf("capture device does not support 2 periods per buffer\n"); //exit(0); } //goto __again; @@ -355,13 +355,14 @@ long timediff(snd_timestamp_t t1, snd_timestamp_t t2) long readbuf(snd_pcm_t *handle, char *buf, long len, size_t *frames, size_t *max) { long r; + long nread = 0; if (!block) { do { r = snd_pcm_readi(handle, buf, len); } while (r == -EAGAIN); if (r > 0) { - *frames += r; + nread += r; if ((long)*max < r) *max = r; } @@ -373,14 +374,14 @@ long readbuf(snd_pcm_t *handle, char *buf, long len, size_t *frames, size_t *max if (r > 0) { buf += r * frame_bytes; len -= r; - *frames += r; + nread += r; if ((long)*max < r) *max = r; } // printf("r = %li, len = %li\n", r, len); } while (r >= 1 && len > 0); } - + *frames += nread; timespec tp; if (clock_gettime(CLOCK_MONOTONIC, &tp) != 0) { @@ -389,11 +390,9 @@ long readbuf(snd_pcm_t *handle, char *buf, long len, size_t *frames, size_t *max } uint64_t sentMs, recvMs = tp.tv_sec * 1000000 + tp.tv_nsec / 1000; - for (int i = 0; i < (r - 12); i++) { + for (int i = 0; i < (nread - 12); i++) { if (!memcmp(buf + i, header, 4)) { memcpy(&sentMs, buf + i + 4, 8); - //printf("elpased %lu ms\n", recvMs - sentMs); - if ((recvMs - sentMs) < 1000000) { end_to_end_latency += ((double)recvMs - (double)sentMs) / 1000; end_to_end_samples++;