static int handle(struct device *dv) { signed short pcm[FRAME * DEVICE_CHANNELS]; int samples; struct oss *oss = (struct oss*)dv->local; /* Check input buffer for recording */ if (oss->pe->revents & POLLIN) { samples = pull(oss->fd, pcm, FRAME); if (samples == -1) return -1; device_submit(dv, pcm, samples); } /* Check the output buffer for playback */ if (oss->pe->revents & POLLOUT) { device_collect(dv, pcm, FRAME); samples = push(oss->fd, pcm, FRAME); if (samples == -1) return -1; } return 0; }
static void process_deck(struct device *dv, jack_nframes_t nframes) { int n; jack_default_audio_sample_t *in[DEVICE_CHANNELS], *out[DEVICE_CHANNELS]; jack_nframes_t remain; struct jack *jack = (struct jack*)dv->local; assert(dv->timecoder != NULL); assert(dv->player != NULL); for (n = 0; n < DEVICE_CHANNELS; n++) { in[n] = jack_port_get_buffer(jack->input_port[n], nframes); assert(in[n] != NULL); out[n] = jack_port_get_buffer(jack->output_port[n], nframes); assert(out[n] != NULL); } /* For large values of nframes, communicate with the timecoder and * player in smaller blocks */ remain = nframes; while (remain > 0) { signed short buf[MAX_BLOCK * DEVICE_CHANNELS]; jack_nframes_t block; if (remain < MAX_BLOCK) block = remain; else block = MAX_BLOCK; /* Timecode input */ interleave(buf, in, block); device_submit(dv, buf, block); /* Audio output is handle in the inner loop, so that * we get the timecoder applied in small steps */ device_collect(dv, buf, block); uninterleave(out, buf, block); remain -= block; } }
static int playback(struct device *dv) { int r; struct alsa *alsa = (struct alsa*)dv->local; device_collect(dv, alsa->playback.buf, alsa->playback.period); r = snd_pcm_writei(alsa->playback.pcm, alsa->playback.buf, alsa->playback.period); if (r < 0) return r; if (r < alsa->playback.period) { fprintf(stderr, "alsa: playback underrun %d/%ld.\n", r, alsa->playback.period); } return 0; }