version 1.6, 2002/02/16 21:27:44 |
version 1.7, 2002/12/10 09:03:37 |
|
|
* POSSIBILITY OF SUCH DAMAGE. |
* POSSIBILITY OF SUCH DAMAGE. |
*/ |
*/ |
|
|
|
/* |
|
* audioctl(1) - a program to control audio device. |
|
*/ |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <fcntl.h> |
#include <fcntl.h> |
|
|
|
|
FILE *out = stdout; |
FILE *out = stdout; |
|
|
char *prog; |
|
|
|
audio_device_t adev; |
audio_device_t adev; |
|
|
audio_info_t info; |
audio_info_t info; |
|
|
}; |
}; |
|
|
struct field * |
struct field * |
findfield(name) |
findfield(char *name) |
char *name; |
|
{ |
{ |
int i; |
int i; |
for(i = 0; fields[i].name; i++) |
for(i = 0; fields[i].name; i++) |
if (strcmp(fields[i].name, name) == 0) |
if (strcmp(fields[i].name, name) == 0) |
return &fields[i]; |
return &fields[i]; |
return 0; |
return (0); |
} |
} |
|
|
void |
void |
prfield(p, sep) |
prfield(struct field *p, char *sep) |
struct field *p; |
|
char *sep; |
|
{ |
{ |
u_int v; |
u_int v; |
char *cm; |
char *cm; |
|
|
} |
} |
|
|
void |
void |
rdfield(p, q) |
rdfield(struct field *p, char *q) |
struct field *p; |
|
char *q; |
|
{ |
{ |
int i; |
int i; |
u_int u; |
u_int u; |
|
|
} |
} |
|
|
void |
void |
getinfo(fd) |
getinfo(int fd) |
int fd; |
|
{ |
{ |
int pos, i; |
int pos = 0, i = 0; |
|
|
if (ioctl(fd, AUDIO_GETDEV, &adev) < 0) |
if (ioctl(fd, AUDIO_GETDEV, &adev) < 0) |
err(1, "AUDIO_GETDEV"); |
err(1, "AUDIO_GETDEV"); |
for(pos = 0, i = 0; ; i++) { |
for(;;) { |
audio_encoding_t enc; |
audio_encoding_t enc; |
enc.index = i; |
enc.index = i++; |
if (ioctl(fd, AUDIO_GETENC, &enc) < 0) |
if (ioctl(fd, AUDIO_GETENC, &enc) < 0) |
break; |
break; |
if (pos) |
if (pos) |
encbuf[pos++] = ','; |
encbuf[pos++] = ','; |
sprintf(encbuf+pos, "%s:%d%s", enc.name, |
pos += snprintf(encbuf+pos, sizeof(encbuf)-pos, "%s:%d%s", |
enc.precision, |
enc.name, enc.precision, |
enc.flags & AUDIO_ENCODINGFLAG_EMULATED ? "*" : ""); |
enc.flags & AUDIO_ENCODINGFLAG_EMULATED ? "*" : ""); |
pos += strlen(encbuf+pos); |
|
} |
} |
if (ioctl(fd, AUDIO_GETFD, &fullduplex) < 0) |
if (ioctl(fd, AUDIO_GETFD, &fullduplex) < 0) |
err(1, "AUDIO_GETFD"); |
err(1, "AUDIO_GETFD"); |
|
|
} |
} |
|
|
void |
void |
usage() |
usage(void) |
{ |
{ |
fprintf(out, "%s [-n] [-f file] -a\n", prog); |
extern char *__progname; /* from crt0.o */ |
fprintf(out, "%s [-n] [-f file] name [...]\n", prog); |
|
fprintf(out, "%s [-n] [-f file] -w name=value [...]\n", prog); |
fprintf(stderr, |
|
"usage: %s [-f file] [-n] -a\n" |
|
" %s [-f file] [-n] name [...]\n" |
|
" %s [-f file] [-n] -w name=value [...]\n", __progname, |
|
__progname, __progname); |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
int |
int |
main(argc, argv) |
main(int argc, char **argv) |
int argc; |
|
char **argv; |
|
{ |
{ |
int fd, i, ch; |
int fd, i, ch; |
int aflag = 0, wflag = 0; |
int aflag = 0, wflag = 0; |
|
|
char *file; |
char *file; |
char *sep = "="; |
char *sep = "="; |
|
|
file = getenv("AUDIOCTLDEVICE"); |
if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') |
if (file == 0) |
|
file = "/dev/audioctl"; |
file = "/dev/audioctl"; |
|
|
prog = *argv; |
|
|
|
while ((ch = getopt(argc, argv, "af:nw")) != -1) { |
while ((ch = getopt(argc, argv, "af:nw")) != -1) { |
switch(ch) { |
switch(ch) { |
|
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
fd = open(file, O_WRONLY); |
if ((fd = open(file, wflag ? O_RDWR : O_RDONLY)) < 0) |
if (fd < 0) |
|
fd = open(file, O_RDONLY); |
|
if (fd < 0) |
|
err(1, "%s", file); |
err(1, "%s", file); |
|
|
/* Check if stdout is the same device as the audio device. */ |
/* Check if stdout is the same device as the audio device. */ |
|
|
if (!wflag) |
if (!wflag) |
getinfo(fd); |
getinfo(fd); |
|
|
if (argc == 0 && aflag && !wflag) { |
if (!argc && aflag && !wflag) { |
for(i = 0; fields[i].name; i++) { |
for(i = 0; fields[i].name; i++) { |
if (!(fields[i].flags & ALIAS)) { |
if (!(fields[i].flags & ALIAS)) { |
prfield(&fields[i], sep); |
prfield(&fields[i], sep); |
|
|
while(argc--) { |
while(argc--) { |
char *q; |
char *q; |
|
|
q = strchr(*argv, '='); |
if (q = strchr(*argv, '=')) { |
if (q) { |
|
*q++ = 0; |
*q++ = 0; |
p = findfield(*argv); |
p = findfield(*argv); |
if (p == 0) |
if (p == 0) |