#include #include #include #include #include #include #include #include static int fd; static void panic (const char *s) { fprintf (stderr, "oss: %s\n", s); exit (1); } /* PROC C.oss.init (VAL INT sample.rate) */ void _oss_init (int *w) { int speed = w[0]; int channels = 2; int format = AFMT_S16_LE; fd = open ("/dev/dsp", O_RDWR); if (fd < 0) panic ("cannot open /dev/dsp"); if (ioctl (fd, SNDCTL_DSP_SETFMT, &format) < 0) panic ("cannot set format"); if (ioctl (fd, SNDCTL_DSP_CHANNELS, &channels) < 0) panic ("cannot set channels"); if (ioctl (fd, SNDCTL_DSP_SPEED, &speed) < 0) panic ("cannot set speed"); } /* PROC B.oss.play (VAL []INT16 data) */ void _oss_play (int *w) { unsigned short *data = (unsigned short *) w[0]; int count = w[1]; while (count > 0) { int r = write (fd, (const char *) data, count * 2); if (r < 0) panic ("write failed"); count -= r; } }