From 72fde44073826a9468a52c1eb62d581d7921143c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 20 Nov 2015 23:51:16 -0700 Subject: [PATCH] PulseAudio: fix incorrect outstream software_latency Previously, when using PulseAudio, unintended integer division caused SoundIoOutStream::software_latency to be incorrect. --- example/sio_sine.c | 13 +++++++------ src/pulseaudio.c | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/example/sio_sine.c b/example/sio_sine.c index 4e24bfd..c33ce8b 100644 --- a/example/sio_sine.c +++ b/example/sio_sine.c @@ -200,12 +200,6 @@ int main(int argc, char **argv) { } fprintf(stderr, "Output device: %s\n", device->name); - fprintf(stderr, - "'p\\n' - pause\n" - "'u\\n' - unpause\n" - "'P\\n' - pause from within callback\n" - "'c\\n' - clear buffer\n" - "'q\\n' - quit\n"); if (device->probe_error) { fprintf(stderr, "Cannot probe device: %s\n", soundio_strerror(device->probe_error)); @@ -241,6 +235,13 @@ int main(int argc, char **argv) { return 1; } + fprintf(stderr, "Software latency: %f\n", outstream->software_latency); + fprintf(stderr, + "'p\\n' - pause\n" + "'u\\n' - unpause\n" + "'P\\n' - pause from within callback\n" + "'c\\n' - clear buffer\n" + "'q\\n' - quit\n"); if (outstream->layout_error) fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error)); diff --git a/src/pulseaudio.c b/src/pulseaudio.c index 4e8c790..293ec5c 100644 --- a/src/pulseaudio.c +++ b/src/pulseaudio.c @@ -724,7 +724,7 @@ static int outstream_open_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamP } size_t writable_size = pa_stream_writable_size(ospa->stream); - outstream->software_latency = writable_size / bytes_per_second; + outstream->software_latency = ((double)writable_size) / (double)bytes_per_second; pa_threaded_mainloop_unlock(sipa->main_loop);