Make the ALSA reader handle and recover from underruns. master
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 13 Oct 2013 23:10:25 +0000 (01:10 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 13 Oct 2013 23:10:25 +0000 (01:10 +0200)
linux_audio.cpp

index 8b0d756..c07e6bb 100644 (file)
@@ -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;