+ pcm_written_frames = snd_pcm_writei(pcm,
+ playing->buffer + playing->start,
+ avail_frames);
+ D(("actually play %zu frames, wrote %d",
+ avail_frames, (int)pcm_written_frames));
+ if(pcm_written_frames < 0) {
+ switch(pcm_written_frames) {
+ case -EPIPE: /* underrun */
+ error(0, "snd_pcm_writei reports underrun");
+ if((err = snd_pcm_prepare(pcm)) < 0)
+ fatal(0, "error calling snd_pcm_prepare: %d", err);
+ return;
+ case -EAGAIN:
+ return;
+ default:
+ fatal(0, "error calling snd_pcm_writei: %d",
+ (int)pcm_written_frames);
+ }
+ }
+ written_frames = pcm_written_frames;
+ written_bytes = written_frames * bpf;
+#else
+ assert(!"reached");
+#endif
+ } else {
+ if(avail_bytes > frames * bpf)
+ avail_bytes = frames * bpf;
+ written_bytes = write(kidfd, playing->buffer + playing->start,
+ avail_bytes);
+ D(("actually play %zu bytes, wrote %d",
+ avail_bytes, (int)written_bytes));
+ if(written_bytes < 0) {
+ switch(errno) {
+ case EPIPE:
+ error(0, "hmm, kid died; trying another");
+ fork_kid();
+ return;
+ case EAGAIN:
+ return;
+ }