From c6df40a5397fea49c1a8edb2ac8d5f3e74792606 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Mon, 27 May 2013 14:27:42 +0530 Subject: [PATCH] tests: Make loopback latency test more accurate This makes sure that we always take the timing at the point when we write out the pulse, making the overall latency measurement more accurate. --- src/tests/lo-latency-test.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tests/lo-latency-test.c b/src/tests/lo-latency-test.c index 124693d..ad5e7a5 100644 --- a/src/tests/lo-latency-test.c +++ b/src/tests/lo-latency-test.c @@ -54,12 +54,17 @@ static void nop_free_cb(void *p) { static void write_cb(pa_stream *s, size_t nbytes, void *userdata) { pa_lo_test_context *ctx = (pa_lo_test_context *) userdata; static int ppos = 0; - int r, nsamp = nbytes / ctx->fs; + int r, nsamp; + + /* Get the real requested bytes since the last write might have been + * incomplete if it caused a wrap around */ + nbytes = pa_stream_writable_size(s); + nsamp = nbytes / ctx->fs; if (ppos + nsamp > N_OUT) { - r = pa_stream_write(s, &out[ppos][0], (N_OUT - ppos) * ctx->fs, nop_free_cb, 0, PA_SEEK_RELATIVE); - nbytes -= (N_OUT - ppos) * ctx->fs; - ppos = 0; + /* Wrap-around, write to end and exit. Next iteration will fill up the + * rest */ + nbytes = (N_OUT - ppos) * ctx->fs; } if (ppos == 0) -- 2.7.4