Date: Fri, 6 Dec 1996 22:09:53 -0500 (EST) From: "John S. Dyson" <toor@dyson.iquest.net> To: S.Brandenburg@tu-bs.de Cc: toor@dyson.iquest.net, freebsd-questions@freebsd.org Subject: Re: O si o [sound question] Message-ID: <199612070309.WAA02950@dyson.iquest.net> In-Reply-To: <32A8CD96.41C67EA6@algieba.ts.rz.tu-bs.de> from "Sven Brandenburg" at Dec 7, 96 02:51:18 am
next in thread | previous in thread | raw e-mail | index | archive | help
>
> 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 <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <machine/soundcard.h>
#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 <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <machine/soundcard.h>
#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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612070309.WAA02950>
