summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2008-11-16 16:30:23 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2008-11-16 16:30:23 +0000
commit1ceac89becb8b9bfe05eeeadda1ddb4f289cd2ed (patch)
tree5f727297157c40b204558195377f59ab6101228b /usr.bin
parent04ff6503a6913923896c17eec5af905fbced51a6 (diff)
Make clients inherit the volume parameter when the -v option is used in
server mode. It gives the maximum volume a client may have. This wastes dynamic range, but allows volume to stay constant when other clients connect or disconnect.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/aucat/abuf.h7
-rw-r--r--usr.bin/aucat/aproc.c20
-rw-r--r--usr.bin/aucat/aucat.111
-rw-r--r--usr.bin/aucat/aucat.c19
-rw-r--r--usr.bin/aucat/dev.c6
-rw-r--r--usr.bin/aucat/dev.h4
-rw-r--r--usr.bin/aucat/listen.c7
-rw-r--r--usr.bin/aucat/listen.h5
-rw-r--r--usr.bin/aucat/sock.c8
-rw-r--r--usr.bin/aucat/sock.h7
10 files changed, 60 insertions, 34 deletions
diff --git a/usr.bin/aucat/abuf.h b/usr.bin/aucat/abuf.h
index 22b052aad2d..933be36a8ae 100644
--- a/usr.bin/aucat/abuf.h
+++ b/usr.bin/aucat/abuf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: abuf.h,v 1.13 2008/11/10 23:25:37 ratchov Exp $ */
+/* $OpenBSD: abuf.h,v 1.14 2008/11/16 16:30:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -32,8 +32,9 @@ struct abuf {
* there can be only one aproc that absorbs xruns in any
* intput->output path.
*/
- int mixweight; /* volume of the source stream */
- unsigned mixvol; /* volume in the range defined by wight */
+ int mixweight; /* dynamic range for the source stream */
+ int mixmaxweight; /* max dynamic range allowed */
+ unsigned mixvol; /* volume within the dynamic range */
unsigned mixodone; /* bytes done on the dest stream */
unsigned mixitodo; /* bytes to do on the source stream */
unsigned subidone; /* bytes copied from the source stream */
diff --git a/usr.bin/aucat/aproc.c b/usr.bin/aucat/aproc.c
index 8f842d1fbed..8bcb21abedf 100644
--- a/usr.bin/aucat/aproc.c
+++ b/usr.bin/aucat/aproc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aproc.c,v 1.23 2008/11/10 23:25:37 ratchov Exp $ */
+/* $OpenBSD: aproc.c,v 1.24 2008/11/16 16:30:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -534,8 +534,8 @@ mix_newin(struct aproc *p, struct abuf *ibuf)
ibuf->mixodone = 0;
ibuf->mixvol = ADATA_UNIT;
ibuf->mixweight = ADATA_UNIT;
+ ibuf->mixmaxweight = ADATA_UNIT;
ibuf->xrun = XRUN_IGNORE;
- mix_setmaster(p);
}
void
@@ -600,12 +600,20 @@ mix_setmaster(struct aproc *p)
{
unsigned n;
struct abuf *buf;
+ int weight;
n = 0;
- LIST_FOREACH(buf, &p->ibuflist, ient)
- n++;
- LIST_FOREACH(buf, &p->ibuflist, ient)
- buf->mixweight = ADATA_UNIT / n;
+ LIST_FOREACH(buf, &p->ibuflist, ient) {
+ n++;
+ }
+ LIST_FOREACH(buf, &p->ibuflist, ient) {
+ weight = ADATA_UNIT / n;
+ if (weight > buf->mixmaxweight)
+ weight = buf->mixmaxweight;
+ buf->mixweight = weight;
+ DPRINTF("mix_setmaster: %p: %d/%d -> %d\n", buf,
+ buf->mixweight, buf->mixmaxweight, weight);
+ }
}
void
diff --git a/usr.bin/aucat/aucat.1 b/usr.bin/aucat/aucat.1
index e1684b1a79e..18058a0439c 100644
--- a/usr.bin/aucat/aucat.1
+++ b/usr.bin/aucat/aucat.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: aucat.1,v 1.32 2008/11/11 19:44:19 ratchov Exp $
+.\" $OpenBSD: aucat.1,v 1.33 2008/11/16 16:30:22 ratchov Exp $
.\"
.\" Copyright (c) 2006 Alexandre Ratchov <alex@caoua.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 11 2008 $
+.Dd $Mdocdate: November 16 2008 $
.Dt AUCAT 1
.Os
.Sh NAME
@@ -110,6 +110,13 @@ options.
Software volume attenuation of the playback stream.
The value must be between 1 and 127,
corresponding to \-42dB and \-0dB attenuation.
+In server mode, clients inherit this parameter.
+Reducing the volume in advance reduces client's dynamic range,
+but allows client volume to stay independend from the number
+of clients as long as their number is small enough.
+A good compromise is to use -4dB attenuation (12 volume units)
+for each additional client expected (eg. 115 if 2 clients are expected,
+103 for 3 clents, and so on).
.It Fl x Ar policy
Action when the output stream cannot accept
recorded data fast enough or the input stream
diff --git a/usr.bin/aucat/aucat.c b/usr.bin/aucat/aucat.c
index a04b97a8272..d6860be706d 100644
--- a/usr.bin/aucat/aucat.c
+++ b/usr.bin/aucat/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.39 2008/11/12 19:36:39 ratchov Exp $ */
+/* $OpenBSD: aucat.c,v 1.40 2008/11/16 16:30:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -252,7 +252,8 @@ newinput(struct farg *fa)
proc = rpipe_new((struct file *)f);
aproc_setout(proc, buf);
abuf_fill(buf); /* XXX: move this in dev_attach() ? */
- dev_attach(fa->name, buf, &fa->par, fa->xrun, NULL, NULL, 0);
+ dev_attach(fa->name, buf, &fa->par, fa->xrun,
+ NULL, NULL, 0, ADATA_UNIT);
dev_setvol(buf, MIDI_TO_ADATA(fa->vol));
}
@@ -287,7 +288,7 @@ newoutput(struct farg *fa)
proc = wpipe_new((struct file *)f);
buf = abuf_new(nfr, &fa->par);
aproc_setin(proc, buf);
- dev_attach(fa->name, NULL, NULL, 0, buf, &fa->par, fa->xrun);
+ dev_attach(fa->name, NULL, NULL, 0, buf, &fa->par, fa->xrun, 0);
}
int
@@ -298,10 +299,11 @@ main(int argc, char **argv)
struct farglist ifiles, ofiles;
struct aparams ipar, opar, dipar, dopar;
struct sigaction sa;
- unsigned ivol, bufsz;
+ unsigned bufsz;
char *devpath, *dbgenv, *listenpath;
const char *errstr;
extern char *malloc_options;
+ unsigned volctl;
malloc_options = "FGJ";
@@ -321,7 +323,7 @@ main(int argc, char **argv)
SLIST_INIT(&ofiles);
hdr = HDR_AUTO;
xrun = XRUN_IGNORE;
- ivol = MIDI_MAXCTL;
+ volctl = MIDI_MAXCTL;
bufsz = 44100 * 4 / 15; /* XXX: use milliseconds, not frames */
while ((c = getopt(argc, argv, "b:c:C:e:r:h:x:v:i:o:f:lu")) != -1) {
@@ -347,10 +349,10 @@ main(int argc, char **argv)
opar.rate = ipar.rate;
break;
case 'v':
- opt_vol(&ivol);
+ opt_vol(&volctl);
break;
case 'i':
- opt_file(&ifiles, &ipar, ivol, hdr, xrun, optarg);
+ opt_file(&ifiles, &ipar, volctl, hdr, xrun, optarg);
break;
case 'o':
opt_file(&ofiles, &opar, 127, hdr, xrun, optarg);
@@ -462,7 +464,8 @@ main(int argc, char **argv)
listenpath = getenv("AUCAT_SOCKET");
if (!listenpath)
listenpath = DEFAULT_SOCKET;
- (void)listen_new(&listen_ops, listenpath);
+ (void)listen_new(&listen_ops, listenpath,
+ MIDI_TO_ADATA(volctl));
}
/*
diff --git a/usr.bin/aucat/dev.c b/usr.bin/aucat/dev.c
index 07993241a4c..e1d3b7ea0f8 100644
--- a/usr.bin/aucat/dev.c
+++ b/usr.bin/aucat/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.17 2008/11/12 19:36:39 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.18 2008/11/16 16:30:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -397,7 +397,7 @@ dev_sync(struct abuf *ibuf, struct abuf *obuf)
void
dev_attach(char *name,
struct abuf *ibuf, struct aparams *sipar, unsigned underrun,
- struct abuf *obuf, struct aparams *sopar, unsigned overrun)
+ struct abuf *obuf, struct aparams *sopar, unsigned overrun, int vol)
{
struct abuf *pbuf = NULL, *rbuf = NULL;
struct aparams ipar, opar;
@@ -442,6 +442,8 @@ dev_attach(char *name,
aproc_setin(dev_mix, ibuf);
abuf_opos(ibuf, -dev_mix->u.mix.lat);
ibuf->xrun = underrun;
+ ibuf->mixmaxweight = vol;
+ mix_setmaster(dev_mix);
}
if (obuf) {
opar = *sopar;
diff --git a/usr.bin/aucat/dev.h b/usr.bin/aucat/dev.h
index 6c7c94244aa..a131064d2c1 100644
--- a/usr.bin/aucat/dev.h
+++ b/usr.bin/aucat/dev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.h,v 1.6 2008/11/10 23:25:37 ratchov Exp $ */
+/* $OpenBSD: dev.h,v 1.7 2008/11/16 16:30:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -37,7 +37,7 @@ int dev_getep(struct abuf **, struct abuf **);
void dev_sync(struct abuf *, struct abuf *);
void dev_attach(char *,
struct abuf *, struct aparams *, unsigned,
- struct abuf *, struct aparams *, unsigned);
+ struct abuf *, struct aparams *, unsigned, int);
void dev_setvol(struct abuf *, int);
void dev_clear(void);
diff --git a/usr.bin/aucat/listen.c b/usr.bin/aucat/listen.c
index 2e73147e34a..5c10217289b 100644
--- a/usr.bin/aucat/listen.c
+++ b/usr.bin/aucat/listen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: listen.c,v 1.2 2008/10/29 22:40:56 ratchov Exp $ */
+/* $OpenBSD: listen.c,v 1.3 2008/11/16 16:30:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -46,7 +46,7 @@ struct fileops listen_ops = {
};
struct listen *
-listen_new(struct fileops *ops, char *path)
+listen_new(struct fileops *ops, char *path, int maxweight)
{
int sock;
struct sockaddr_un sockname;
@@ -83,6 +83,7 @@ listen_new(struct fileops *ops, char *path)
exit(1);
}
f->fd = sock;
+ f->maxweight = maxweight;
return f;
}
@@ -122,7 +123,7 @@ listen_revents(struct file *file, struct pollfd *pfd)
close(sock);
return 0;
}
- (void)sock_new(&sock_ops, sock, "socket");
+ (void)sock_new(&sock_ops, sock, "socket", f->maxweight);
}
return 0;
}
diff --git a/usr.bin/aucat/listen.h b/usr.bin/aucat/listen.h
index 042287fcbc2..298daee825a 100644
--- a/usr.bin/aucat/listen.h
+++ b/usr.bin/aucat/listen.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: listen.h,v 1.1 2008/10/26 08:49:44 ratchov Exp $ */
+/* $OpenBSD: listen.h,v 1.2 2008/11/16 16:30:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -25,9 +25,10 @@ struct listen {
struct file file;
char *path;
int fd;
+ int maxweight; /* max dynamic range for clients */
};
-struct listen *listen_new(struct fileops *, char *);
+struct listen *listen_new(struct fileops *, char *, int);
int listen_nfds(struct file *);
int listen_pollfd(struct file *, struct pollfd *, int events);
int listen_revents(struct file *, struct pollfd *);
diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c
index ad71bfa69aa..50d0fe398a5 100644
--- a/usr.bin/aucat/sock.c
+++ b/usr.bin/aucat/sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.c,v 1.3 2008/11/11 19:21:20 ratchov Exp $ */
+/* $OpenBSD: sock.c,v 1.4 2008/11/16 16:30:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -260,7 +260,7 @@ struct aproc_ops wsock_ops = {
* parameters
*/
struct sock *
-sock_new(struct fileops *ops, int fd, char *name)
+sock_new(struct fileops *ops, int fd, char *name, int maxweight)
{
struct aproc *rproc, *wproc;
struct sock *f;
@@ -280,6 +280,7 @@ sock_new(struct fileops *ops, int fd, char *name)
f->bufsz = 2 * dev_bufsz;
f->round = dev_round;
f->odelta = f->idelta = 0;
+ f->maxweight = maxweight;
f->vol = ADATA_UNIT;
wproc = aproc_new(&wsock_ops, name);
@@ -387,7 +388,8 @@ sock_attach(struct sock *f, int force)
*/
dev_attach(f->pipe.file.name,
(f->mode & AMSG_PLAY) ? rbuf : NULL, &f->rpar, f->xrun,
- (f->mode & AMSG_REC) ? wbuf : NULL, &f->wpar, f->xrun);
+ (f->mode & AMSG_REC) ? wbuf : NULL, &f->wpar, f->xrun,
+ f->maxweight);
if (f->mode & AMSG_PLAY)
dev_setvol(rbuf, f->vol);
diff --git a/usr.bin/aucat/sock.h b/usr.bin/aucat/sock.h
index ff8b12c7e17..83b24dc2416 100644
--- a/usr.bin/aucat/sock.h
+++ b/usr.bin/aucat/sock.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.h,v 1.2 2008/11/11 19:21:20 ratchov Exp $ */
+/* $OpenBSD: sock.h,v 1.3 2008/11/16 16:30:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -50,10 +50,11 @@ struct sock {
unsigned bufsz; /* total buffer size */
unsigned round; /* block size */
unsigned xrun; /* one of AMSG_IGNORE, ... */
- unsigned vol;
+ int vol; /* requested volume */
+ int maxweight; /* max dynamic range */
};
-struct sock *sock_new(struct fileops *, int fd, char *);
+struct sock *sock_new(struct fileops *, int fd, char *, int);
extern struct fileops sock_ops;
#endif /* !defined(SOCK_H) */