]> git.sesse.net Git - pitch/commitdiff
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 8b0d756396faa3937c5c689029e19421a5b6b114..c07e6bb289a543419d608063796ada457157c66c 100644 (file)
@@ -86,8 +86,13 @@ void read_chunk(snd_pcm_t *handle, short *in, unsigned num_samples)
                        printf("EOF\n");
                        exit(0);
                }
                        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;
                        exit(1);
                }
                in += ret;