From: Steinar H. Gunderson Date: Sun, 13 Oct 2013 23:10:25 +0000 (+0200) Subject: Make the ALSA reader handle and recover from underruns. X-Git-Url: https://git.sesse.net/?p=pitch;a=commitdiff_plain;h=HEAD Make the ALSA reader handle and recover from underruns. --- 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;