bool SoundProcessor::Record(){ SetUpRecorder(); snd_pcm_sframes_t fwdframes=snd_pcm_forwardable(handle_m); printf("forwarding %d\n",fwdframes); snd_pcm_forward(handle_m,fwdframes); while (true) { rc_m = snd_pcm_readi(handle_m, buffer_m, frames); if (rc_m == -EPIPE) { /* EPIPE means overrun */ fprintf(stderr, "overrun occurred\n"); snd_pcm_prepare(handle_m); } else if (rc_m < 0) { fprintf(stderr, "error from read: %s\n", snd_strerror(rc_m)); } else if (rc_m != (int)frames) { fprintf(stderr, "short read, read %d frames\n", rc_m); } rc_m = write(1, buffer_m, size); if (rc_m != size) fprintf(stderr, "short write: wrote %d bytes\n", rc_m); } snd_pcm_drain(handle_m); snd_pcm_close(handle_m); free(buffer_m); return true; }
static snd_pcm_sframes_t snd_pcm_file_forwardable(snd_pcm_t *pcm) { snd_pcm_file_t *file = pcm->private_data; snd_pcm_sframes_t res = snd_pcm_forwardable(pcm); snd_pcm_sframes_t n = snd_pcm_bytes_to_frames(pcm, file->wbuf_size_bytes - file->wbuf_used_bytes); if (res > n) res = n; return res; }
snd_pcm_sframes_t snd_pcm_generic_forwardable(snd_pcm_t *pcm) { snd_pcm_generic_t *generic = pcm->private_data; return snd_pcm_forwardable(generic->slave); }