Annotation of src/usr.bin/aucat/aucat.c, Revision 1.1
1.1 ! kstailey 1: /* $OpenBSD$ */
! 2: /*
! 3: * Copyright (c) 1997 Kenneth Stailey. All rights reserved.
! 4: *
! 5: * Redistribution and use in source and binary forms, with or without
! 6: * modification, are permitted provided that the following conditions
! 7: * are met:
! 8: * 1. Redistributions of source code must retain the above copyright
! 9: * notice, this list of conditions and the following disclaimer.
! 10: * 2. Redistributions in binary form must reproduce the above copyright
! 11: * notice, this list of conditions and the following disclaimer in the
! 12: * documentation and/or other materials provided with the distribution.
! 13: * 3. All advertising materials mentioning features or use of this software
! 14: * must display the following acknowledgement:
! 15: * This product includes software developed by Kenneth Stailey.
! 16: * 4. The name of the author may not be used to endorse or promote products
! 17: * derived from this software without specific prior written permission.
! 18: *
! 19: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 20: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 21: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 22: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 23: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! 24: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 25: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 26: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 27: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! 28: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 29: */
! 30:
! 31: #include <sys/types.h>
! 32: #include <machine/endian.h>
! 33: #include <fcntl.h>
! 34: #include <stdio.h>
! 35: #include <unistd.h>
! 36:
! 37: /*
! 38: * aucat: concatinate and play Sun 8-bit .au files
! 39: */
! 40:
! 41: /* function playfile: given a file which is positioned at the beginning
! 42: * of what is assumed to be an .au data stream copy it out to the audio
! 43: * device. Return 0 on sucess, -1 on failure.
! 44: */
! 45: int
! 46: playfile(int fd)
! 47: {
! 48: static int afd = -1;
! 49: int rd;
! 50: char buf[5120];
! 51:
! 52: if (afd == -1)
! 53: if ((afd = open("/dev/audio", O_WRONLY)) < 0) {
! 54: perror("open /dev/audio");
! 55: return(-1);
! 56: }
! 57: while ((rd = read(fd, buf, sizeof(buf))) > 0) {
! 58: write(afd, buf, rd);
! 59: if (rd < sizeof(buf))
! 60: break;
! 61: }
! 62:
! 63: return (0);
! 64: }
! 65:
! 66: int
! 67: main(int argc, char **argv)
! 68: {
! 69: int fd;
! 70: int argcInc = 0; /* incrementing version of argc */
! 71: unsigned long data;
! 72: char magic[5];
! 73:
! 74: while (--argc) {
! 75: ++argcInc;
! 76: if ((fd = open(argv[argcInc], O_RDONLY)) < 0) {
! 77: perror("open file");
! 78: exit(1);
! 79: }
! 80:
! 81: read(fd, magic, 4);
! 82: magic[4] = '\0';
! 83: if (strcmp(magic, ".snd")) {
! 84: /* not an .au file, bad header. Assume raw audio data since that's
! 85: * what /dev/audio generates by default.
! 86: */
! 87: lseek(fd, 0, SEEK_SET);
! 88: } else {
! 89: read(fd, &data, sizeof(data));
! 90: if (BYTE_ORDER != BIG_ENDIAN)
! 91: data = htonl(data);
! 92: lseek(fd, (off_t)data, SEEK_SET);
! 93: }
! 94: if (playfile(fd) < 0)
! 95: exit(1);
! 96: }
! 97: exit(0);
! 98: }