Lines Matching defs:d

161 		p += snprintf(p, p < end ? end - p : 0, "play %d:%d", pmin, pmax);
165 p += snprintf(p, p < end ? end - p : 0, "%s%s %d:%d", sep,
176 dev_midi_send(struct dev *d, void *msg, int msglen)
181 if (o->dev != d)
278 logx(3, "%s: mtc full frame at %d, %d fps", mtc->dev->path, mtc->delta, mtc->fps);
304 dev_midi_vol(struct dev *d, struct slot *s)
311 dev_midi_send(d, msg, 3);
318 dev_midi_master(struct dev *d)
324 if (d->master_enabled)
325 master = d->master;
330 strcmp(c->group, d->name) != 0 ||
334 if (c->u.any.arg0 != d)
351 dev_midi_send(d, (unsigned char *)&x, SYSEX_SIZE(master));
358 dev_midi_slotdesc(struct dev *d, struct slot *s)
368 if (s->opt != NULL && s->opt->dev == d)
372 dev_midi_send(d, (unsigned char *)&x, SYSEX_SIZE(slotdesc));
376 dev_midi_dump(struct dev *d)
382 dev_midi_master(d);
384 if (s->opt != NULL && s->opt->dev != d)
386 dev_midi_slotdesc(d, s);
387 dev_midi_vol(d, s);
395 dev_midi_send(d, (unsigned char *)&x, SYSEX_SIZE(dumpend));
437 dev_mix_badd(struct dev *d, struct slot *s)
442 odata = DEV_PBUF(d);
477 in, s->mix.resampbuf, s->round, d->round);
483 cmap_add(&s->mix.cmap, in, odata, vol, d->round);
488 cmap_add(&s->mix.cmap, in + offs, odata, vol, d->round);
494 cmap_add(&s->mix.cmap, in, odata + offs, vol, d->round);
504 dev_mix_adjvol(struct dev *d)
510 for (i = d->slot_list; i != NULL; i = i->next) {
515 if (d->autovol) {
521 for (j = d->slot_list; j != NULL; j = j->next) {
533 i->mix.weight = d->master_enabled ?
534 ADATA_MUL(weight, MIDI_TO_ADATA(d->master)) : weight;
536 logx(3, "%s%u: set weight: %d / %d", i->name, i->unit, i->mix.weight,
546 dev_sub_bcopy(struct dev *d, struct slot *s)
563 moffs = d->poffs + d->round;
564 if (moffs == d->psize)
566 idata = d->pbuf + moffs * d->pchan;
568 idata = d->rbuf;
592 cmap_copy(&s->sub.cmap, idata, cmap_out, vol, d->round);
597 cmap_add(&s->sub.cmap, idata + offs, cmap_out, vol, d->round);
603 cmap_copy(&s->sub.cmap, idata, cmap_out + offs, vol, d->round);
608 s->sub.resampbuf, resamp_out, d->round, s->round);
622 dev_cycle(struct dev *d)
632 if (d->slot_list == NULL && d->idle >= d->bufsz &&
633 (mtc_array[0].dev != d || mtc_array[0].tstate != MTC_RUN)) {
634 logx(2, "%s: device stopped", d->path);
635 dev_sio_stop(d);
636 d->pstate = DEV_INIT;
637 if (d->refcnt == 0)
638 dev_close(d);
642 if (d->prime > 0) {
644 logx(4, "%s: empty cycle, prime = %u", d->path, d->prime);
646 base = (unsigned char *)DEV_PBUF(d);
647 nsamp = d->round * d->pchan;
649 if (d->encbuf) {
650 enc_do(&d->enc, (unsigned char *)DEV_PBUF(d),
651 d->encbuf, d->round);
653 d->prime -= d->round;
657 d->delta -= d->round;
659 logx(4, "%s: full cycle: delta = %d", d->path, d->delta);
661 if (d->mode & MODE_PLAY) {
662 base = (unsigned char *)DEV_PBUF(d);
663 nsamp = d->round * d->pchan;
666 if ((d->mode & MODE_REC) && d->decbuf)
667 dec_do(&d->dec, d->decbuf, (unsigned char *)d->rbuf, d->round);
668 ps = &d->slot_list;
671 logx(4, "%s%u: running, skip = %d", s->name, s->unit, s->skip);
673 d->idle = 0;
706 dev_mix_adjvol(d);
744 dev_sub_bcopy(d, s);
748 logx(3, "%s%u: prime = %d", s->name, s->unit,
755 dev_mix_badd(d, s);
761 if ((d->mode & MODE_PLAY) && d->encbuf) {
762 enc_do(&d->enc, (unsigned char *)DEV_PBUF(d),
763 d->encbuf, d->round);
771 dev_onmove(struct dev *d, int delta)
776 d->delta += delta;
778 if (d->slot_list == NULL)
779 d->idle += delta;
781 for (s = d->slot_list; s != NULL; s = snext) {
787 (long long)s->delta * d->round +
789 s->delta = pos / (int)d->round;
790 s->delta_rem = pos % d->round;
792 s->delta_rem += d->round;
799 if (mtc_array[0].dev == d && mtc_array[0].tstate == MTC_RUN)
804 dev_master(struct dev *d, unsigned int master)
809 logx(2, "%s: master volume set to %u", d->path, master);
811 if (d->master_enabled) {
812 d->master = master;
813 if (d->mode & MODE_PLAY)
814 dev_mix_adjvol(d);
817 if (c->scope != CTL_HW || c->u.hw.dev != d)
820 strcmp(c->group, d->name) != 0 ||
838 struct dev *d, **pd;
844 d = xmalloc(sizeof(struct dev));
845 d->path = path;
846 d->num = dev_sndnum++;
848 d->reqpar = *par;
849 d->reqmode = mode;
850 d->reqpchan = d->reqrchan = 0;
851 d->reqbufsz = bufsz;
852 d->reqround = round;
853 d->reqrate = rate;
854 d->hold = hold;
855 d->autovol = autovol;
856 d->refcnt = 0;
857 d->pstate = DEV_CFG;
858 d->slot_list = NULL;
859 d->master = MIDI_MAXCTL;
860 d->master_enabled = 0;
861 d->alt_next = d;
862 snprintf(d->name, CTL_NAMEMAX, "%u", d->num);
865 d->next = *pd;
866 *pd = d;
867 return d;
874 dev_adjpar(struct dev *d, int mode,
877 d->reqmode |= mode & MODE_AUDIOMASK;
879 if (d->reqpchan < pmax + 1)
880 d->reqpchan = pmax + 1;
883 if (d->reqrchan < rmax + 1)
884 d->reqrchan = rmax + 1;
896 dev_allocbufs(struct dev *d)
905 d->rbuf = xmalloc(d->round * d->rchan * sizeof(adata_t));
908 if (!aparams_native(&d->par)) {
909 dec_init(&d->dec, &d->par, d->rchan);
910 d->decbuf = xmalloc(d->round * d->rchan * d->par.bps);
912 d->decbuf = NULL;
919 d->poffs = 0;
920 d->psize = d->bufsz + d->round;
921 d->pbuf = xmalloc(d->psize * d->pchan * sizeof(adata_t));
922 d->mode |= MODE_MON;
925 if (!aparams_native(&d->par)) {
926 enc_init(&d->enc, &d->par, d->pchan);
927 d->encbuf = xmalloc(d->round * d->pchan * d->par.bps);
929 d->encbuf = NULL;
936 memset(d->rbuf, 0, d->round * d->rchan * sizeof(adata_t));
938 logx(2, "%s: %dHz, %s, %s, %d blocks of %d frames",
939 d->path, d->rate,
940 (aparams_enctostr(&d->par, enc_str), enc_str),
942 d->mode & (MODE_PLAY | MODE_REC),
943 0, d->pchan - 1, 0, d->rchan - 1), chans_str),
944 d->bufsz / d->round, d->round);
953 dev_open(struct dev *d)
955 d->mode = d->reqmode;
956 d->round = d->reqround;
957 d->bufsz = d->reqbufsz;
958 d->rate = d->reqrate;
959 d->pchan = d->reqpchan;
960 d->rchan = d->reqrchan;
961 d->par = d->reqpar;
962 if (d->pchan == 0)
963 d->pchan = 2;
964 if (d->rchan == 0)
965 d->rchan = 2;
966 if (!dev_sio_open(d)) {
967 logx(1, "%s: failed to open audio device", d->path);
970 if (!dev_allocbufs(d))
973 d->pstate = DEV_INIT;
981 dev_abort(struct dev *d)
989 if (s->opt == NULL || s->opt->dev != d)
996 d->slot_list = NULL;
999 if (o->dev != d)
1013 if (d->pstate != DEV_CFG)
1014 dev_close(d);
1022 dev_freebufs(struct dev *d)
1025 logx(3, "%s: closing", d->path);
1027 if (d->mode & MODE_PLAY) {
1028 if (d->encbuf != NULL)
1029 xfree(d->encbuf);
1030 xfree(d->pbuf);
1032 if (d->mode & MODE_REC) {
1033 if (d->decbuf != NULL)
1034 xfree(d->decbuf);
1035 xfree(d->rbuf);
1043 dev_close(struct dev *d)
1045 d->pstate = DEV_CFG;
1046 dev_sio_close(d);
1047 dev_freebufs(d);
1049 if (d->master_enabled) {
1050 d->master_enabled = 0;
1051 ctl_del(CTL_DEV_MASTER, d, NULL);
1056 dev_ref(struct dev *d)
1059 logx(3, "%s: device requested", d->path);
1061 if (d->pstate == DEV_CFG && !dev_open(d))
1063 d->refcnt++;
1068 dev_unref(struct dev *d)
1071 logx(3, "%s: device released", d->path);
1073 d->refcnt--;
1074 if (d->refcnt == 0 && d->pstate == DEV_INIT)
1075 dev_close(d);
1082 dev_init(struct dev *d)
1084 if ((d->reqmode & MODE_AUDIOMASK) == 0) {
1086 logx(1, "%s: has no streams", d->path);
1090 if (d->hold && !dev_ref(d))
1099 dev_done(struct dev *d)
1102 logx(3, "%s: draining", d->path);
1104 if (mtc_array[0].dev == d && mtc_array[0].tstate != MTC_STOP)
1106 if (d->hold)
1107 dev_unref(d);
1113 struct dev *d;
1115 for (d = dev_list; d != NULL; d = d->next) {
1116 if (d->num == num)
1117 return d;
1126 dev_del(struct dev *d)
1131 logx(3, "%s: deleting", d->path);
1133 if (d->pstate != DEV_CFG)
1134 dev_close(d);
1135 for (p = &dev_list; *p != d; p = &(*p)->next) {
1138 logx(0, "%s: not on the list", d->path);
1143 *p = d->next;
1144 xfree(d);
1148 dev_roundof(struct dev *d, unsigned int newrate)
1150 return (d->round * newrate + d->rate / 2) / d->rate;
1157 dev_wakeup(struct dev *d)
1159 if (d->pstate == DEV_INIT) {
1160 logx(2, "%s: started", d->path);
1162 if (d->mode & MODE_PLAY) {
1163 d->prime = d->bufsz;
1165 d->prime = 0;
1167 d->idle = 0;
1168 d->poffs = 0;
1174 d->delta = 0;
1176 d->pstate = DEV_RUN;
1177 dev_sio_start(d);
1361 mtc_setdev(struct mtc *mtc, struct dev *d)
1365 if (mtc->dev == d)
1368 logx(2, "%s: set to be MIDI clock source", d->path);
1376 mtc->dev = d;
1398 struct dev *d = s->opt->dev;
1404 0, d->pchan - 1,
1413 if (s->rate != d->rate) {
1414 resamp_init(&s->mix.resamp, s->round, d->round,
1417 xmalloc(d->round * s->mix.nch * sizeof(adata_t));
1422 dev_nch = d->pchan < (s->opt->pmax + 1) ?
1423 d->pchan - s->opt->pmin :
1434 d->pchan : d->rchan;
1443 if (s->rate != d->rate) {
1444 resamp_init(&s->sub.resamp, d->round, s->round,
1447 xmalloc(d->round * s->sub.nch * sizeof(adata_t));
1474 d->round * s->sub.nch * sizeof(adata_t));
1735 struct dev *d = s->opt->dev;
1752 dev_wakeup(d);
1758 (long long)s->delta * d->round +
1759 (long long)d->delta * s->round;
1760 s->delta = pos / (int)d->round;
1761 s->delta_rem = pos % d->round;
1763 s->delta_rem += d->round;
1768 logx(2, "%s%u: attached at %d + %d / %d",
1778 s->next = d->slot_list;
1779 d->slot_list = s;
1782 dev_mix_adjvol(d);
1813 struct dev *d = s->opt->dev;
1822 logx(2, "%s%u: %dHz, %s, %s, %d blocks of %d frames",
1836 s->sub.prime = d->bufsz / d->round;
1844 s->delta = -(long long)d->bufsz * s->round / d->round;
1862 struct dev *d = s->opt->dev;
1865 for (ps = &d->slot_list; *ps != s; ps = &(*ps)->next) {
1876 * adjust clock, go back d->delta ticks so that slot_attach()
1880 (long long)s->delta * d->round -
1881 (long long)d->delta * s->round;
1882 s->delta = pos / (int)d->round;
1883 s->delta_rem = pos % d->round;
1885 s->delta_rem += d->round;
1890 logx(2, "%s%u: detached at %d + %d / %d",
1891 s->name, s->unit, s->delta, s->delta_rem, d->round);
1894 dev_mix_adjvol(d);
1927 logx(3, "%s%u: stopping (drain = %d)", s->name, s->unit, drain);
2137 p += snprintf(p, p < end ? end - p : 0, "%d", c->unit);
2196 logx(3, "ctl%u: %d: out of range", c->addr, val);
2299 logx(2, "ctl%u: %s = %d at %s: added", c->addr,
2410 dev_getdisplay(struct dev *d)
2418 c->u.hw.dev == d &&
2420 strcmp(c->group, d->name) == 0 &&
2430 dev_ctlsync(struct dev *d)
2440 c->u.hw.dev == d &&
2442 strcmp(c->group, d->name) == 0 &&
2448 if (d->master_enabled && found) {
2449 logx(2, "%s: software master level control disabled", d->path);
2450 d->master_enabled = 0;
2451 ctl_del(CTL_DEV_MASTER, d, NULL);
2452 } else if (!d->master_enabled && !found) {
2453 logx(2, "%s: software master level control enabled", d->path);
2454 d->master_enabled = 1;
2455 ctl_new(CTL_DEV_MASTER, d, NULL,
2456 CTL_NUM, "", d->name, "output", -1, "level",
2457 NULL, -1, 127, d->master);
2463 display = dev_getdisplay(d);
2466 c->u.opt_dev.dev != d ||
2476 if (s->opt->dev == d)