version 1.3, 1997/01/05 19:00:51 |
version 1.4, 2000/07/01 19:54:36 |
|
|
#include <machine/endian.h> |
#include <machine/endian.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
#include <unistd.h> |
#include <unistd.h> |
|
#include <err.h> |
|
|
/* |
/* |
* aucat: concatinate and play Sun 8-bit .au files |
* aucat: concatinate and play Sun 8-bit .au files |
|
|
* device. Return 0 on sucess, -1 on failure. |
* device. Return 0 on sucess, -1 on failure. |
*/ |
*/ |
int |
int |
playfile(int fd) |
playfile(fd, dev) |
|
int fd; |
|
char *dev; |
{ |
{ |
static int afd = -1; |
static int afd = -1; |
int rd; |
int rd; |
char buf[5120]; |
char buf[5120]; |
|
|
if (afd == -1) |
if (afd == -1 && (afd = open(dev, O_WRONLY)) < 0) { |
if ((afd = open("/dev/audio", O_WRONLY)) < 0) { |
warn("can't open %s", dev); |
perror("open /dev/audio"); |
return(-1); |
return(-1); |
} |
} |
while ((rd = read(fd, buf, sizeof(buf))) > 0) { |
while ((rd = read(fd, buf, sizeof(buf))) > 0) { |
write(afd, buf, rd); |
write(afd, buf, rd); |
if (rd < sizeof(buf)) |
if (rd < sizeof(buf)) |
break; |
break; |
} |
} |
|
|
return (0); |
return (0); |
|
} |
} |
|
|
int |
int |
main(int argc, char **argv) |
main(argc, argv) |
|
int argc; |
|
char **argv; |
{ |
{ |
int fd; |
int fd, ch; |
int argcInc = 0; /* incrementing version of argc */ |
unsigned long data; |
unsigned long data; |
char magic[5]; |
char magic[5]; |
char *dev; |
|
|
while (--argc) { |
dev = getenv("AUDIODEVICE"); |
++argcInc; |
if (dev == 0) |
if ((fd = open(argv[argcInc], O_RDONLY)) < 0) { |
dev = "/dev/audio"; |
perror("open file"); |
|
exit(1); |
|
} |
|
|
|
read(fd, magic, 4); |
while ((ch = getopt(argc, argv, "f:")) != -1) { |
magic[4] = '\0'; |
switch(ch) { |
if (strcmp(magic, ".snd")) { |
case 'f': |
/* not an .au file, bad header. Assume raw audio data since that's |
dev = optarg; |
* what /dev/audio generates by default. |
break; |
*/ |
} |
lseek(fd, 0, SEEK_SET); |
} |
} else { |
argc -= optind; |
read(fd, &data, sizeof(data)); |
argv += optind; |
data = ntohl(data); |
|
lseek(fd, (off_t)data, SEEK_SET); |
while (argc) { |
} |
if ((fd = open(*argv, O_RDONLY)) < 0) |
if (playfile(fd) < 0) |
err(1, "cannot open %s", *argv); |
exit(1); |
|
} |
read(fd, magic, 4); |
exit(0); |
magic[4] = '\0'; |
|
if (strcmp(magic, ".snd")) { |
|
/* |
|
* not an .au file, bad header. |
|
* Assume raw audio data since that's |
|
* what /dev/audio generates by default. |
|
*/ |
|
lseek(fd, 0, SEEK_SET); |
|
} else { |
|
read(fd, &data, sizeof(data)); |
|
data = ntohl(data); |
|
lseek(fd, (off_t)data, SEEK_SET); |
|
} |
|
if (playfile(fd, dev) < 0) |
|
exit(1); |
|
argc--; |
|
argv++; |
|
} |
|
exit(0); |
} |
} |