[Liboss-commit] CVS: liboss/src osscat.c,1.4,1.5
Brought to you by:
thesin
|
From: Dave V. <va...@us...> - 2002-10-19 08:11:17
|
Update of /cvsroot/liboss/liboss/src
In directory usw-pr-cvs1:/tmp/cvs-serv1268/src
Modified Files:
osscat.c
Log Message:
Woohoo, it WORKS!!! Just 'osscat somewavfile.wav' should play a nice
sound, assuming the wav file was made with right params. Most of the ones
in /sw/share/sounds should work fine.
Index: osscat.c
===================================================================
RCS file: /cvsroot/liboss/liboss/src/osscat.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- osscat.c 19 Oct 2002 07:02:01 -0000 1.4
+++ osscat.c 19 Oct 2002 08:11:14 -0000 1.5
@@ -1,16 +1,28 @@
#include "soundcard.h"
+#include <machine/endian.h>
+#include <machine/byte_order.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
/* FIXME: Add capability for recording with 'libosscat /dev/audio > somefile' */
+
+/* How to play the sound */
#define BUF_SIZE 1024
#define DEVICE "/dev/dsp"
+/* What kind of sound is this, anyway? */
+/* NB: .wav is usually {1, 16, 20500, 0} */
+#define STEREO 1
+#define BITS 16
+#define RATE 20500
+#define ENDIAN LITTLE_ENDIAN
+
+
int main(int argc, char **argv)
{
- int fd, play, format, channels, speed;
+ int fd, play, format, stereo, speed, sz;
char buf[BUF_SIZE];
if (argc != 2) {
@@ -28,15 +40,22 @@
exit(1);
}
- format = AFMT_S16_LE;
+ format = (BITS == 16) ? AFMT_S16_NE : AFMT_S8;
ioctl(play, SNDCTL_DSP_SETFMT, &format);
- channels = 2;
- ioctl(play, SNDCTL_DSP_CHANNELS, &channels);
- speed = 41100;
+ stereo = STEREO;
+ ioctl(play, SNDCTL_DSP_STEREO, &stereo);
+ speed = RATE;
ioctl(play, SNDCTL_DSP_SPEED, &speed);
- while (read(fd, buf, BUF_SIZE) > 0) {
- write(play, buf, BUF_SIZE); /* if it errors, keep going */
+ while ( (sz = read(fd, buf, BUF_SIZE)) > 0 ) {
+
+#if BYTE_ORDER != ENDIAN
+ short* i;
+ for (i = (short*)buf; i < (short*)(buf + sz); ++i)
+ *i = NXSwapShort(*i);
+#endif
+
+ write(play, buf, sz); /* if it errors, keep going */
}
return 0;
|