From a500a1c540da51bdb686bdb9657b354c4238bcb2 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 14 Oct 2013 01:10:25 +0200 Subject: [PATCH] Make the ALSA reader handle and recover from underruns. --- linux_audio.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/linux_audio.cpp b/linux_audio.cpp index 8b0d756..c07e6bb 100644 --- a/linux_audio.cpp +++ b/linux_audio.cpp @@ -86,8 +86,13 @@ void read_chunk(snd_pcm_t *handle, short *in, unsigned num_samples) printf("EOF\n"); exit(0); } - if (ret == -1) { - perror("read"); + if (ret == -EPIPE) { + fprintf(stderr, "ALSA underrun\n"); + snd_pcm_prepare(handle); + continue; + } + if (ret < 0) { + fprintf(stderr, "snd_pcm_readi: %s\n", snd_strerror(ret)); exit(1); } in += ret; -- 2.39.2