simpleaudio-alsa: handle underruns better; print '#'

This commit is contained in:
Kamal Mostafa 2012-10-01 19:02:39 -07:00
parent b97aeb0778
commit 151ee0e004
1 changed files with 17 additions and 11 deletions

View File

@ -45,21 +45,27 @@ sa_alsa_read( simpleaudio *sa, void *buf, size_t nframes )
snd_pcm_t *pcm = (snd_pcm_t *)sa->backend_handle; snd_pcm_t *pcm = (snd_pcm_t *)sa->backend_handle;
while ( frames_read < nframes ) { while ( frames_read < nframes ) {
ssize_t r; ssize_t r;
r = snd_pcm_readi(pcm, buf+frames_read*sa->backend_framesize, nframes-frames_read); void * data = buf+frames_read*sa->backend_framesize;
if (r < 0) { ssize_t count = nframes-frames_read;
/* recover from e.g. overruns, and try once more */ r = snd_pcm_readi(pcm, data, count);
fprintf(stderr, "snd_pcm_readi: reset for %s\n", snd_strerror(r)); if ( r >= 0 ) {
frames_read += r;
if ( r != count )
fprintf(stderr, "#short+%zd#\n", r);
continue;
}
if (r == -EPIPE) { // Underrun
fprintf(stderr, "#");
snd_pcm_prepare(pcm); snd_pcm_prepare(pcm);
r = snd_pcm_readi(pcm, buf+frames_read*sa->backend_framesize, nframes-frames_read); } else {
}
if (r < 0) {
fprintf(stderr, "snd_pcm_readi: %s\n", snd_strerror(r)); fprintf(stderr, "snd_pcm_readi: %s\n", snd_strerror(r));
return -1; if (r == -EAGAIN || r== -ESTRPIPE)
snd_pcm_wait(pcm, 1000);
else
return r;
} }
if (r == 0)
break;
frames_read += r;
} }
// fprintf(stderr,("[%zd]\n"), frames_read);
return frames_read; return frames_read;
} }