From owner-freebsd-multimedia Tue Nov 5 14:24:51 1996 Return-Path: owner-multimedia Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id OAA29735 for multimedia-outgoing; Tue, 5 Nov 1996 14:24:51 -0800 (PST) Received: from dyson.iquest.net ([198.70.144.127]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id OAA29719 for ; Tue, 5 Nov 1996 14:24:36 -0800 (PST) Received: (from root@localhost) by dyson.iquest.net (8.8.2/8.6.9) id RAA01853; Tue, 5 Nov 1996 17:22:46 -0500 (EST) From: "John S. Dyson" Message-Id: <199611052222.RAA01853@dyson.iquest.net> Subject: Re: Rec/play on the SoundBlaster To: gjm@hal2.soas.ac.uk (geoff martindale) Date: Tue, 5 Nov 1996 17:22:46 -0500 (EST) Cc: freebsd-multimedia@freebsd.org In-Reply-To: <9611060312.AA11990@soas.ac.uk> from "geoff martindale" at Nov 5, 96 08:12:52 pm Reply-To: dyson@freebsd.org 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-multimedia@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > > Hello, > > Does anyone know of any tools/source code > for doing record/playback on a SoundBlaster 16? > We want to sample speech at 16kHz, linear PCM. > Currently we can playback by using sox and > 'cat speech.voc > /dev/dsp0'. > > System - FreeBSD 2.1.5 and Pentium Pro > Here is my "stupid" record program, and following, my "stupid" play program, you can change the parameters as needed, and note that these programs only do raw file formats: #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: #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); }