/* * callback to start the stream, invoked by the MIDI control code */ void wav_startreq(void *arg) { struct wav *f = (struct wav *)arg; switch (f->pstate) { case WAV_INIT: #ifdef DEBUG if (debug_level >= 2) { wav_dbg(f); dbg_puts(": skipped (failed to seek)\n"); } #endif return; case WAV_READY: if (f->mode & MODE_RECMASK) f->endpos = f->mmcpos + f->startpos; (void)wav_attach(f, 0); break; #ifdef DEBUG default: wav_dbg(f); dbg_puts(": not in READY state\n"); dbg_panic(); break; #endif } }
/* * close method of the file structure */ void wav_close(struct file *file) { struct wav *f = (struct wav *)file, **pf; if (f->mode & MODE_RECMASK) { pipe_trunc(&f->pipe.file, f->endpos); if (f->hdr == HDR_WAV) { wav_writehdr(f->pipe.fd, &f->hpar, &f->startpos, f->endpos - f->startpos); } } pipe_close(file); if (f->pstate != WAV_CFG) dev_unref(f->dev); for (pf = &wav_list; *pf != f; pf = &(*pf)->next) { #ifdef DEBUG if (*pf == NULL) { dbg_puts("wav_close: not on list\n"); dbg_panic(); } #endif } *pf = f->next; }
/* * callback to relocate the stream, invoked by the MIDI control code * on a stopped stream */ void wav_locreq(void *arg, unsigned int mmc) { struct wav *f = (struct wav *)arg; #ifdef DEBUG if (f->pstate == WAV_RUN) { wav_dbg(f); dbg_puts(": in RUN state\n"); dbg_panic(); } #endif f->mmcpos = f->startpos + ((off_t)mmc * f->hpar.rate / MTC_SEC) * aparams_bpf(&f->hpar); (void)wav_seekmmc(f); }
/* * read samples from the file and possibly start it */ int wav_rdata(struct wav *f) { struct aproc *p; struct abuf *obuf; p = f->pipe.file.rproc; obuf = LIST_FIRST(&p->outs); if (obuf == NULL) return 0; if (!ABUF_WOK(obuf) || !(f->pipe.file.state & FILE_ROK)) return 0; if (!rfile_do(p, obuf->len, NULL)) return 0; switch (f->pstate) { case WAV_START: if (!ABUF_WOK(obuf) || (f->pipe.file.state & FILE_EOF)) f->pstate = WAV_READY; /* PASSTHROUGH */ case WAV_READY: if (dev_slotstart(f->dev, f->slot)) (void)wav_attach(f, 0); break; case WAV_RUN: break; case WAV_MIDI: return 1; #ifdef DEBUG default: wav_dbg(f); dbg_puts(": bad state\n"); dbg_panic(); #endif } if (f->rbytes == 0 && f->mmc) { #ifdef DEBUG if (debug_level >= 3) { wav_dbg(f); dbg_puts(": trying to restart\n"); } #endif if (!wav_seekmmc(f)) return 0; } return 1; }
void siofile_cb(void *addr, int delta) { struct siofile *f = (struct siofile *)addr; struct aproc *p; #ifdef DEBUG if (delta < 0 || delta > (60 * RATE_MAX)) { file_dbg(&f->file); dbg_puts(": "); dbg_puti(delta); dbg_puts(": bogus sndio delta"); dbg_panic(); } if (debug_level >= 4) { file_dbg(&f->file); dbg_puts(": tick, delta = "); dbg_puti(delta); dbg_puts(", load = "); dbg_puti((file_utime - f->utime) / 1000); dbg_puts(" + "); dbg_puti((file_wtime - f->wtime) / 1000); dbg_puts("\n"); } f->wtime = file_wtime; f->utime = file_utime; #endif if (delta != 0) { p = f->file.wproc; if (p && p->ops->opos) p->ops->opos(p, NULL, delta); p = f->file.rproc; if (p && p->ops->ipos) p->ops->ipos(p, NULL, delta); } if (f->onmove) f->onmove(f->arg, delta); f->wtickets += delta * f->wbpf; f->rtickets += delta * f->rbpf; }
/* * switch to the ``INIT'' state performing * necessary actions to reach it */ void wav_reset(struct wav *f) { switch (f->pstate) { case WAV_START: case WAV_READY: if (dev_slotstart(f->dev, f->slot)) (void)wav_attach(f, 1); /* PASSTHROUGH */ case WAV_RUN: wav_freebuf(f); /* PASSTHROUGH */ case WAV_INIT: /* nothing yet */ break; #ifdef DEBUG case WAV_MIDI: dbg_puts("wav_reset: in midi mode\n"); dbg_panic(); #endif } }