From owner-freebsd-questions Fri Dec 6 19:55:56 1996 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id TAA27647 for questions-outgoing; Fri, 6 Dec 1996 19:55:56 -0800 (PST) Received: from dan.emsphone.com (-@dan.emsphone.com [199.67.51.101]) by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id TAA27641 for ; Fri, 6 Dec 1996 19:55:53 -0800 (PST) Received: (from dan@localhost) by dan.emsphone.com (8.7.5/8.7.3) id VAA11470; Fri, 6 Dec 1996 21:46:44 -0600 (CST) Message-ID: Date: Fri, 6 Dec 1996 21:46:44 -0600 From: dnelson@emsphone.com (Dan Nelson) To: S.Brandenburg@tu-bs.de Cc: freebsd-questions@freebsd.org Subject: Re: O si o [sound question] References: <199612062248.RAA08354@dyson.iquest.net> <32A8CD96.41C67EA6@algieba.ts.rz.tu-bs.de> X-Mailer: Mutt 0.50 Mime-Version: 1.0 In-Reply-To: <32A8CD96.41C67EA6@algieba.ts.rz.tu-bs.de>; from "Sven Brandenburg" on Dec 7, 1996 02:51:18 +0100 Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk In the last eposode (Dec 7), Sven Brandenburg said: > What do you use to play/record ? > (which program and how configured, tell me everything :) > Should a "cat iama16bitsample.au > /dev/audio" give you 16 bit output? > (A BIG candidate for the lame-question-of-the-year, sorry!) Here are the ones I use. 'listen' is mono-only, but that's only another ioctl() away. 'play' will also play to the speaker with the -s switch. -Dan Nelson dnelson@emsphone.com --- listen.c --- #include #include #include #include main(int argc, char *argv[]) { int fd = open("/dev/dsp", O_RDONLY); int rate = 8012; int bits = 8; int c; int len; char buf[1024]; while ((c = getopt(argc, argv, "hr:b:")) != EOF) { switch (c) { case 'r': rate = atoi(optarg); break; case 'b': bits = atoi(optarg); break; case '?': case 'h': printf ("listen -r rate -b bits\n"); exit(1); break; } } ioctl(fd, SNDCTL_DSP_SETFMT, &bits); ioctl(fd, SOUND_PCM_WRITE_RATE, &rate); while ((len = read(fd, buf, sizeof(buf))) > 0) write(fileno(stdout), buf, len); } --- END --- --- play.c --- #include #include #include #include #include main(int argc, char *argv[]) { int fd; int rate = 8012; int bits = 8; int speaker = 0; int channels = 1; int c; int len; char buf[1024]; while ((c = getopt(argc, argv, "r:b:c:s")) != EOF) { switch (c) { case 's': speaker = 1; break; case 'r': rate = atoi(optarg); break; case 'c': channels = atoi(optarg); break; case 'b': bits = atoi(optarg); break; case '?': case 'h': printf ("play [-s] [-c channels] [-r rate] [-b bits]\n"); exit(1); break; } } if (speaker) { audio_info_t ait; ait.play.sample_rate = rate; ait.play.encoding = AUDIO_ENCODING_RAW; ait.play.gain = 150; ait.play.pause = -1; fd = open("/dev/pcaudio", O_WRONLY); ioctl(fd, AUDIO_SETINFO, &ait); } else { fd = open("/dev/dsp", O_WRONLY); ioctl(fd, SNDCTL_DSP_SETFMT, &bits); ioctl(fd, SOUND_PCM_WRITE_RATE, &rate); ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &channels); } while ((len = read(fileno(stdin), buf, sizeof(buf))) > 0) write(fd, buf, len); } ---END---