From owner-freebsd-hackers Sun Aug 23 19:54:25 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id TAA06738 for freebsd-hackers-outgoing; Sun, 23 Aug 1998 19:54:25 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id TAA06729 for ; Sun, 23 Aug 1998 19:54:16 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.8.8/8.8.8) id VAA24587; Sun, 23 Aug 1998 21:53:15 -0500 (CDT) (envelope-from dan) Message-ID: <19980823215315.B24497@emsphone.com> Date: Sun, 23 Aug 1998 21:53:15 -0500 From: Dan Nelson To: David Kott , System Administrator Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: sound card programming References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=SLDf9lqlvOQaIe6s X-Mailer: Mutt 0.94.2i In-Reply-To: ; from "David Kott" on Fri Aug 21 19:03:25 GMT 1998 X-OS: FreeBSD 2.2.7-STABLE Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --SLDf9lqlvOQaIe6s Content-Type: text/plain; charset=us-ascii In the last episode (Aug 21), David Kott said: > On Fri, 21 Aug 1998, System Administrator wrote: > > I need play file on the sound card and record to file from sound > > card. Where I can find examples of source code for this ? I have > > fbsd 2.2.6 > > Here is a slightly modified piece of source that I found on one of > the mailing list archives that does precisely 1/2 of your request. > It was written by one of the FreeBSD gurus/core team (forgive me, but > I don't remember precisely who) and did almost exactly what I wanted. And here are mine; both play and listen default to 8khz, 8bit, mono, but that's easy enough to change, either via the commandline options, or changing the constants in the code. Play will also play to the PC speaker, if you use -s and have enabled the pca device in the kernel. -Dan Nelson dnelson@emsphone.com --SLDf9lqlvOQaIe6s Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="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 channels = 1; int c; int len; char buf[1024]; while ((c = getopt(argc, argv, "hr:b:c:")) != EOF) { switch (c) { case 'r': rate = atoi(optarg); break; case 'b': bits = atoi(optarg); break; case 'c': channels = atoi(optarg); break; case '?': case 'h': printf ("listen -r rate -b bits -c channels\n"); exit(1); break; } } ioctl(fd, SNDCTL_DSP_SETFMT, &bits); ioctl(fd, SOUND_PCM_WRITE_RATE, &rate); ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &channels); while ((len = read(fd, buf, sizeof(buf))) > 0) write(fileno(stdout), buf, len); } --SLDf9lqlvOQaIe6s Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="play.c" #include #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); } --SLDf9lqlvOQaIe6s-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message