summaryrefslogtreecommitdiff
path: root/usr.bin/aucat/dev.c
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2011-10-12 07:20:05 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2011-10-12 07:20:05 +0000
commit1000619d5c878b666a9d2ca0f084116e0db82287 (patch)
tree9780ea7d5f9aa13502408ac23af531e6a4cdc9bf /usr.bin/aucat/dev.c
parent8cca00d73e143fc10aa31d89c64de9c96fef267e (diff)
Simplify and improve the way options are parsed and remove ~300 lines
of code that becomes unused. Few command line arguments changes are required though: - stream definitions (-ios) now must follow devices definitions they are attached to (-fMn) - the -n option is now a special "loopback" device and is thus used like -f, eg it must precede streams - in midicat, midi thru boxes are not created automatically anymore, the new "-M" option must be used for that - channel numbers (-Cc options) correspond always to channel numbers of the hardware. - the -u option isn't needed anymore - increase the log verbosity so user errors are logged without using -d tested by many, help from jmc
Diffstat (limited to 'usr.bin/aucat/dev.c')
-rw-r--r--usr.bin/aucat/dev.c188
1 files changed, 107 insertions, 81 deletions
diff --git a/usr.bin/aucat/dev.c b/usr.bin/aucat/dev.c
index d674f2454ac..449898b1078 100644
--- a/usr.bin/aucat/dev.c
+++ b/usr.bin/aucat/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.66 2011/06/20 20:18:44 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.67 2011/10/12 07:20:04 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -113,8 +113,7 @@ struct dev *dev_list = NULL;
* Create a sndio device
*/
struct dev *
-dev_new_sio(char *path,
- unsigned mode, struct aparams *dipar, struct aparams *dopar,
+dev_new(char *path, unsigned mode,
unsigned bufsz, unsigned round, unsigned hold, unsigned autovol)
{
struct dev *d;
@@ -127,79 +126,51 @@ dev_new_sio(char *path,
d->ctl_list = NULL;
d->path = path;
d->reqmode = mode;
- if (mode & MODE_PLAY)
- d->reqopar = *dopar;
- if (mode & MODE_RECMASK)
- d->reqipar = *dipar;
+ aparams_init(&d->reqopar, NCHAN_MAX, 0, 0);
+ aparams_init(&d->reqipar, NCHAN_MAX, 0, 0);
d->reqbufsz = bufsz;
d->reqround = round;
d->hold = hold;
d->autovol = autovol;
+ d->autostart = 0;
d->pstate = DEV_CLOSED;
d->next = dev_list;
dev_list = d;
- if (d->hold && !dev_open(d)) {
- dev_del(d);
- return NULL;
- }
return d;
}
/*
- * Create a loopback synchronous device
+ * adjust device parameters and mode
*/
-struct dev *
-dev_new_loop(struct aparams *dipar, struct aparams *dopar, unsigned bufsz)
+void
+dev_adjpar(struct dev *d, unsigned mode,
+ struct aparams *ipar, struct aparams *opar)
{
- struct aparams par;
- unsigned cmin, cmax, rate;
- struct dev *d;
-
- d = malloc(sizeof(struct dev));
- if (d == NULL) {
- perror("malloc");
- exit(1);
- }
- d->ctl_list = NULL;
- cmin = (dipar->cmin < dopar->cmin) ? dipar->cmin : dopar->cmin;
- cmax = (dipar->cmax > dopar->cmax) ? dipar->cmax : dopar->cmax;
- rate = (dipar->rate > dopar->rate) ? dipar->rate : dopar->rate;
- aparams_init(&par, cmin, cmax, rate);
- d->reqipar = par;
- d->reqopar = par;
- d->rate = rate;
- d->reqround = (bufsz + 1) / 2;
- d->reqbufsz = d->reqround * 2;
- d->reqmode = MODE_PLAY | MODE_REC | MODE_LOOP | MODE_MIDIMASK;
- d->pstate = DEV_CLOSED;
- d->hold = 0;
- d->path = "loop";
- d->next = dev_list;
- dev_list = d;
- return d;
+ d->reqmode |= (mode | MODE_MIDIMASK);
+ if (mode & MODE_REC)
+ aparams_grow(&d->reqipar, ipar);
+ if (mode & MODE_PLAY)
+ aparams_grow(&d->reqopar, opar);
}
/*
- * Create a MIDI thru box device
+ * Initialize the device with the current parameters
*/
-struct dev *
-dev_new_thru(int hold)
+int
+dev_init(struct dev *d)
{
- struct dev *d;
-
- d = malloc(sizeof(struct dev));
- if (d == NULL) {
- perror("malloc");
- exit(1);
+ if ((d->reqmode & (MODE_AUDIOMASK | MODE_MIDIMASK)) == 0) {
+#ifdef DEBUG
+ dbg_puts(d->path);
+ dbg_puts(": has no streams, skipped\n");
+#endif
+ return 1;
}
- d->ctl_list = NULL;
- d->reqmode = MODE_MIDIMASK;
- d->pstate = DEV_CLOSED;
- d->hold = hold;
- d->path = "midithru";
- d->next = dev_list;
- dev_list = d;
- return d;
+ if (d->hold && d->pstate == DEV_CLOSED && !dev_open(d)) {
+ dev_del(d);
+ return 0;
+ }
+ return 1;
}
/*
@@ -219,10 +190,8 @@ devctl_add(struct dev *d, char *name, unsigned mode)
c->mode = mode;
c->next = d->ctl_list;
d->ctl_list = c;
- if (d->pstate != DEV_CLOSED) {
- if (!devctl_open(d, c))
- return 0;
- }
+ if (d->pstate != DEV_CLOSED && !devctl_open(d, c))
+ return 0;
return 1;
}
@@ -265,7 +234,7 @@ dev_open(struct dev *d)
struct aparams par;
struct aproc *conv;
struct abuf *buf;
- unsigned siomode;
+ unsigned siomode, cmin, cmax, rate;
d->mode = d->reqmode;
d->round = d->reqround;
@@ -281,6 +250,24 @@ dev_open(struct dev *d)
d->midi = NULL;
d->rate = 0;
+ if (d->opar.cmin > d->opar.cmax) {
+ d->opar.cmin = 0;
+ d->opar.cmax = 1;
+ }
+ if (d->ipar.cmin > d->ipar.cmax) {
+ d->ipar.cmin = 0;
+ d->ipar.cmax = 1;
+ }
+ if (d->opar.rate > d->ipar.rate)
+ d->ipar.rate = d->opar.rate;
+ else
+ d->opar.rate = d->ipar.rate;
+ if (d->opar.rate == 0)
+ d->opar.rate = d->ipar.rate = 44100; /* XXX */
+
+ if (d->mode & MODE_THRU)
+ d->mode &= ~MODE_AUDIOMASK;
+
/*
* If needed, open the device (ie create dev_rec and dev_play)
*/
@@ -316,39 +303,79 @@ dev_open(struct dev *d)
return 0;
}
d->rate = d->mode & MODE_REC ? d->ipar.rate : d->opar.rate;
+ if (d->mode & MODE_REC) {
+ d->rec = rsio_new(f);
+ d->rec->refs++;
+ }
+ if (d->mode & MODE_PLAY) {
+ d->play = wsio_new(f);
+ d->play->refs++;
+ }
+ }
+ if (d->mode & MODE_LOOP) {
+ if (d->mode & MODE_MON) {
#ifdef DEBUG
- if (debug_level >= 2) {
- if (d->mode & MODE_REC) {
- dbg_puts(d->path);
- dbg_puts(": recording ");
- aparams_dbg(&d->ipar);
- dbg_puts("\n");
+ if (debug_level >= 1) {
+ dbg_puts("monitoring not allowed "
+ "in loopback mode\n");
}
- if (d->mode & MODE_PLAY) {
- dbg_puts(d->path);
- dbg_puts(": playing ");
- aparams_dbg(&d->opar);
- dbg_puts("\n");
+#endif
+ return 0;
+ }
+ if ((d->mode & MODE_PLAYREC) != MODE_PLAYREC) {
+#ifdef DEBUG
+ if (debug_level >= 1) {
+ dbg_puts("both play and record streams "
+ "required in loopback mode\n");
}
+#endif
+ return 0;
}
+ if (d->ctl_list) {
+#ifdef DEBUG
+ if (debug_level >= 1) {
+ dbg_puts("MIDI control not allowed "
+ "in loopback mode\n");
+ }
#endif
+ return 0;
+ }
+ cmin = (d->ipar.cmin < d->opar.cmin) ?
+ d->ipar.cmin : d->opar.cmin;
+ cmax = (d->ipar.cmax > d->opar.cmax) ?
+ d->ipar.cmax : d->opar.cmax;
+ rate = (d->ipar.rate > d->opar.rate) ?
+ d->ipar.rate : d->opar.rate;
+ aparams_init(&par, cmin, cmax, rate);
+ d->ipar = par;
+ d->opar = par;
+ d->rate = rate;
+ d->round = rate;
+ d->bufsz = 2 * d->round;
+ }
+#ifdef DEBUG
+ if (debug_level >= 2) {
if (d->mode & MODE_REC) {
- d->rec = rsio_new(f);
- d->rec->refs++;
+ dbg_puts(d->path);
+ dbg_puts(": recording ");
+ aparams_dbg(&d->ipar);
+ dbg_puts("\n");
}
if (d->mode & MODE_PLAY) {
- d->play = wsio_new(f);
- d->play->refs++;
+ dbg_puts(d->path);
+ dbg_puts(": playing ");
+ aparams_dbg(&d->opar);
+ dbg_puts("\n");
}
}
-
+#endif
/*
* Create the midi control end, or a simple thru box
* if there's no device
*/
if (d->mode & MODE_MIDIMASK) {
- d->midi = (d->mode & (MODE_PLAY | MODE_RECMASK)) ?
- ctl_new("ctl", d) : thru_new("thru");
+ d->midi = (d->mode & MODE_THRU) ?
+ thru_new("thru") : ctl_new("ctl", d);
d->midi->refs++;
}
@@ -379,7 +406,6 @@ dev_open(struct dev *d)
d->mix->flags |= APROC_QUIT;
d->sub->flags |= APROC_QUIT;
- d->rate = d->opar.rate;
}
if (d->rec) {
aparams_init(&par, d->ipar.cmin, d->ipar.cmax, d->rate);