[Liboss-commit] CVS: liboss/src osscat.c,1.11,1.12
Brought to you by:
thesin
|
From: Justin <th...@us...> - 2002-11-06 20:14:46
|
Update of /cvsroot/liboss/liboss/src
In directory usw-pr-cvs1:/tmp/cvs-serv7363/src
Modified Files:
osscat.c
Log Message:
Works much much better, gonna see if I can get mpg123 to work now
Index: osscat.c
===================================================================
RCS file: /cvsroot/liboss/liboss/src/osscat.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- osscat.c 6 Nov 2002 19:10:23 -0000 1.11
+++ osscat.c 6 Nov 2002 20:14:43 -0000 1.12
@@ -4,52 +4,92 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <string.h>
/* FIXME: Add capability for recording with 'libosscat /dev/audio > somefile' */
/* How to play the sound */
-#define BUF_SIZE 1024
+#define BUF_SIZE ESD_BUF_SIZE
#define DEVICE "/dev/dsp"
/* What kind of sound is this, anyway? */
/* NB: .wav is usually {1, 16, 20500, 0} */
-#define STEREO 0
-#define BITS 16
-#define RATE 20500
+#define STEREO ESD_STEREO
+#define BITS ESD_BITS16
+#define RATE ESD_DEFAULT_RATE
#define ENDIAN LITTLE_ENDIAN
int main(int argc, char **argv)
{
- int fd, play, format, stereo, speed, sz;
+ int retval = 0, arg = 0;
+ int play, sz;
+
+ int stereo = STEREO, speed = RATE;
+ int bits = BITS;
+
char buf[BUF_SIZE];
+
+ FILE *source = NULL;
+ char *name = NULL;
- if (argc != 2) {
- fprintf(stderr, "Usage: osscat file\n");
- exit(1);
- }
-
- if ((fd = open(argv[1], O_RDONLY, 0)) < 0) {
- fprintf(stderr, "File %s could not be opened.\n", argv[1]);
- exit(1);
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (!strcmp("-h",argv[arg]))
+ {
+ printf("usage:\n\t%s {-b} [-m} [-r freq] < file\n",
+ argv[0]);
+ exit(0);
+ }
+ else if (!strcmp("-b", argv[arg]))
+ bits = ESD_BITS8;
+ else if (!strcmp("-m", argv[arg]))
+ stereo = ESD_MONO;
+ else if (!strcmp("-r", argv[arg]))
+ {
+ arg++;
+ speed = atoi(argv[arg]);
+ } else if (source) {
+ printf("%s: ignoring extra file '%s'\n", argv[0],
+ argv[arg]);
+ } else {
+ name = argv[arg];
+ if ((source = fopen(name, "r")) == NULL)
+ {
+ printf("%s: couldn't open sound file: %s\n",
+ argv[0], name);
+ return 1;
+ }
+ }
}
-
+
+ if (!source)
+ source = stdin;
+
if ((play = open(DEVICE, O_WRONLY, 0)) < 0) {
fprintf(stderr, "%s could not be opened.\n", DEVICE);
exit(1);
}
-
- format = (BITS == 16) ? AFMT_S16_NE : AFMT_S8;
- ioctl(play, SNDCTL_DSP_SETFMT, &format);
- stereo = STEREO;
- ioctl(play, SNDCTL_DSP_STEREO, &stereo);
- speed = RATE;
- ioctl(play, SNDCTL_DSP_SPEED, &speed);
-
- while ( (sz = read(fd, buf, BUF_SIZE)) > 0 ) {
- liboss_write(play, buf, sz); /* if it errors, keep going */
+ int format = (bits == 16) ? AFMT_S16_NE : AFMT_S8;
+ retval = ioctl(play, SNDCTL_DSP_SETFMT, &format);
+ if (retval < 0)
+ return retval;
+
+ retval = ioctl(play, SNDCTL_DSP_STEREO, &stereo);
+ if (retval < 0)
+ return retval;
+
+ retval = ioctl(play, SNDCTL_DSP_SPEED, &speed);
+ if (retval < 0)
+ return retval;
+
+ while ( (sz = fread(buf, 1, BUF_SIZE, source)) > 0 ) {
+ if (liboss_write(play, buf, sz) <= 0)
+ return 1;
}
return 0;
|