Date: Sat, 7 Dec 1996 15:14:19 +0000 () From: "Lenzi, Sergio" <lenzi@bsi.com.br> To: S.Brandenburg@tu-bs.de Cc: Lady Ada <ladyada@xenu.com>, freebsd-questions@FreeBSD.ORG Subject: Re: O si o [sound question] Message-ID: <Pine.BSF.3.91.961207150958.6634D-100000@sergio> In-Reply-To: <32A8740C.41C67EA6@algieba.ts.rz.tu-bs.de>
next in thread | previous in thread | raw e-mail | index | archive | help
I have the same problem with the .au files. even with some "samples". I have written 2 programs (record) and (play) that records music or other whings from the dsp. this programs work great... use record [sample rate] < /dev/dsp > file --------------------------record program----------- #include <stdio.h> #include <sys/file.h> #include <stdlib.h> #include <sys/ioctl.h> #include <signal.h> #include <time.h> #include <machine/soundcard.h> static int tot = 0; static float k; #define BUFFSZ 4096 static void closeall(int x) { fprintf(stderr, "End ok total bytes:%d, [%6.2 Kbps]\n", tot,k); exit(0); } main(int ac, char **av) { int r, h, n, t1, t2; char *dev; char area[BUFFSZ]; h = fileno(stdin); if (ac < 2) r=18000; else r = atoi(av[1]); if (ioctl(h, SOUND_PCM_WRITE_RATE, &r) < 0) { perror("set ioctl"); exit(1); } if (ioctl(h, SOUND_PCM_READ_RATE, &r) < 0) { perror("read ioctl"); exit(1); } fprintf(stderr, "dsp rate:%d\n", r); signal(SIGINT, closeall); t1 = time(NULL); fwrite(&r, sizeof(r), 1, stdout); while ((n = fread(area, 1, BUFFSZ, stdin)) > 0) { tot += n; fwrite(area, 1, n, stdout); t2 = time(NULL); k = t2 - t1; if (k == 0) k = 1; k *= 1000.0; fprintf(stderr, "%6.2f bps\r", (float) tot / k); } return (0); } -----------------------play program use play < file > /dev/dsp------- #include <stdio.h> #include <sys/file.h> #include <stdlib.h> #include <sys/ioctl.h> #include <signal.h> #include <time.h> #include <machine/soundcard.h> #define BUFFSZ 8192 static int tot = 0; static float k=0; static void closeall(int x) { fprintf(stderr, "End ok total bytes:%d [%6.2f Kbps]\n", tot,k); exit(0); } main(int ac, char **av) { int r, h, n, k, t1, t2; char *dev; char area[BUFFSZ]; h = fileno(stdout); fread(&r, sizeof(r), 1, stdin); if (ioctl(h, SOUND_PCM_WRITE_RATE, &r) < 0) { perror("set ioctl"); exit(1); } if (ioctl(h, SOUND_PCM_READ_RATE, &r) < 0) { perror("read ioctl"); exit(1); } fprintf(stderr, "dsp rate:%d\n", r); signal(SIGINT, closeall); t1 = time(NULL); while ((n = fread(area, 1, BUFFSZ, stdin))) { tot += n; fwrite(area, 1, n, stdout); fflush(stdout); t2 = time(NULL); k = t2 - t1; if (k == 0) k = 1; k *= 1000; fprintf(stderr, "%.8d [%6.2f]\r", tot, (float)tot / k); } fprintf(stderr, "End ok total bytes:%d\n", tot); return (0); } Sergio Lenzi. Unix consult.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.961207150958.6634D-100000>