From 2633b1bd601da3675b5ace211736ea102ff9a8ec Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 1 Nov 2015 12:39:21 -0700 Subject: [PATCH] PulseAudio: pass the latency test --- src/pulseaudio.cpp | 9 +++------ test/latency.cpp | 6 +++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pulseaudio.cpp b/src/pulseaudio.cpp index 3aea0b6..a91bb30 100644 --- a/src/pulseaudio.cpp +++ b/src/pulseaudio.cpp @@ -699,9 +699,8 @@ static int outstream_open_pa(SoundIoPrivate *si, SoundIoOutStreamPrivate *os) { ospa->buffer_attr.tlength = buffer_length; } - pa_stream_flags_t flags = (pa_stream_flags_t)(PA_STREAM_START_CORKED|PA_STREAM_AUTO_TIMING_UPDATE); - if (outstream->software_latency > 0.0) - flags = (pa_stream_flags_t) (flags | PA_STREAM_ADJUST_LATENCY); + pa_stream_flags_t flags = (pa_stream_flags_t)(PA_STREAM_START_CORKED | PA_STREAM_AUTO_TIMING_UPDATE | + PA_STREAM_INTERPOLATE_TIMING); int err = pa_stream_connect_playback(ospa->stream, outstream->device->id, &ospa->buffer_attr, @@ -938,9 +937,7 @@ static int instream_start_pa(SoundIoPrivate *si, SoundIoInStreamPrivate *is) { SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; pa_threaded_mainloop_lock(sipa->main_loop); - pa_stream_flags_t flags = PA_STREAM_AUTO_TIMING_UPDATE; - if (instream->software_latency > 0.0) - flags = (pa_stream_flags_t) (flags|PA_STREAM_ADJUST_LATENCY); + pa_stream_flags_t flags = (pa_stream_flags_t)(PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_INTERPOLATE_TIMING); int err = pa_stream_connect_record(ispa->stream, instream->device->id, diff --git a/test/latency.cpp b/test/latency.cpp index 3019438..eecc607 100644 --- a/test/latency.cpp +++ b/test/latency.cpp @@ -16,7 +16,7 @@ #include static int usage(char *exe) { - fprintf(stderr, "Usage: %s [--backend dummy|alsa|pulseaudio|jack|coreaudio|wasapi]\n", exe); + fprintf(stderr, "Usage: %s [--backend dummy|alsa|pulseaudio|jack|coreaudio|wasapi] [--latency seconds]\n", exe); return 1; } @@ -129,6 +129,7 @@ static void underflow_callback(struct SoundIoOutStream *outstream) { int main(int argc, char **argv) { char *exe = argv[0]; enum SoundIoBackend backend = SoundIoBackendNone; + double software_latency = 0.0; for (int i = 1; i < argc; i += 1) { char *arg = argv[i]; if (arg[0] == '-' && arg[1] == '-') { @@ -152,6 +153,8 @@ int main(int argc, char **argv) { fprintf(stderr, "Invalid backend: %s\n", argv[i]); return 1; } + } else if (strcmp(arg, "--latency") == 0) { + software_latency = atof(argv[i]); } else { return usage(exe); } @@ -186,6 +189,7 @@ int main(int argc, char **argv) { outstream->format = SoundIoFormatFloat32NE; outstream->write_callback = write_callback; outstream->underflow_callback = underflow_callback; + outstream->software_latency = software_latency; if (soundio_device_supports_format(device, SoundIoFormatFloat32NE)) { outstream->format = SoundIoFormatFloat32NE;