From owner-freebsd-questions Fri Dec 6 19:10:18 1996 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id TAA26270 for questions-outgoing; Fri, 6 Dec 1996 19:10:18 -0800 (PST) Received: from dyson.iquest.net (dyson.iquest.net [198.70.144.127]) by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id TAA26265 for ; Fri, 6 Dec 1996 19:10:13 -0800 (PST) Received: (from root@localhost) by dyson.iquest.net (8.8.2/8.6.9) id WAA02950; Fri, 6 Dec 1996 22:09:57 -0500 (EST) From: "John S. Dyson" Message-Id: <199612070309.WAA02950@dyson.iquest.net> Subject: Re: O si o [sound question] To: S.Brandenburg@tu-bs.de Date: Fri, 6 Dec 1996 22:09:53 -0500 (EST) Cc: toor@dyson.iquest.net, freebsd-questions@freebsd.org In-Reply-To: <32A8CD96.41C67EA6@algieba.ts.rz.tu-bs.de> from "Sven Brandenburg" at Dec 7, 96 02:51:18 am X-Mailer: ELM [version 2.4 PL24 ME8] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > > 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!) It isn't lame, I use these... > Record program: #include #include #include #include #define DSP "/dev/dsp" int dspfd; int filefd; main(int argc, char *argv[]) { char buffer[256]; int readcount; int toread; int parm; dspfd = open(DSP, O_RDONLY); if (dspfd < 0) { perror("dspopen"); exit(1); } parm = 16; if (ioctl(dspfd, SOUND_PCM_READ_BITS, &parm)) { perror("ioctlrd16"); exit(1); } parm = 16; if (ioctl(dspfd, SOUND_PCM_WRITE_BITS, &parm)) { perror("ioctlwr16"); exit(1); } parm = 2; if (ioctl(dspfd, SOUND_PCM_READ_CHANNELS, &parm)) { perror("ioctlrd2"); exit(1); } parm = 2; if (ioctl(dspfd, SOUND_PCM_WRITE_CHANNELS, &parm)) { perror("ioctlwr2"); exit(1); } parm = 44100; if (ioctl(dspfd, SOUND_PCM_READ_RATE, &parm)) { perror("ioctlsp44100"); exit(1); } parm = 44100; if (ioctl(dspfd, SOUND_PCM_WRITE_RATE, &parm)) { perror("ioctlsp44100"); exit(1); } filefd = dup(1); toread = atoi(argv[1]) * 44100 * 4; fprintf(stderr,"%d samples\n", toread); while ( toread > 0) { readcount = sizeof buffer; if (readcount > toread) readcount = toread; readcount = read(dspfd, buffer, readcount); if (readcount < 0) { perror("dspread"); exit(1); } write(filefd, buffer, readcount); toread -= readcount; } exit(0); } Play program: #include #include #include #include #include #define DSP "/dev/dsp" int dspfd; int filefd; main(int argc, char *argv[]) { char buffer[1024]; int writecount; int toread; int parm; int sfptr; char *readb; struct stat statbuf; dspfd = open(DSP, O_RDWR); if (dspfd < 0) { perror("dspopen"); exit(1); } parm = 16; if (ioctl(dspfd, SOUND_PCM_READ_BITS, &parm)) { perror("ioctlrd16"); exit(1); } parm = 16; if (ioctl(dspfd, SOUND_PCM_WRITE_BITS, &parm)) { perror("ioctlwr16"); exit(1); } parm = 2; if (ioctl(dspfd, SOUND_PCM_READ_CHANNELS, &parm)) { perror("ioctlrd2"); exit(1); } parm = 2; if (ioctl(dspfd, SOUND_PCM_WRITE_CHANNELS, &parm)) { perror("ioctlwr2"); exit(1); } parm = 44100; if (ioctl(dspfd, SOUND_PCM_READ_RATE, &parm)) { perror("ioctlsp44100"); exit(1); } parm = 44100; if (ioctl(dspfd, SOUND_PCM_WRITE_RATE, &parm)) { perror("ioctlsp44100"); exit(1); } sfptr = 0; while ( 1) { toread = read(0, buffer, sizeof buffer); if (toread <= 0) break; writecount = write(dspfd, buffer, toread); if (writecount < 0) { perror("dspwrite"); exit(1); } } exit(0); } John