#include #include #include #include #include #include #include #include static void panic (const char *s) { fprintf (stderr, "oss: %s\n", s); exit (1); } /* PROC C.oss.init (VAL INT sample.rate, INT fd) */ void _oss_init (int *w) { int speed = w[0]; int channels = 1; int format = AFMT_S16_LE; int fd; fd = open ("/dev/dsp", O_RDWR | O_NONBLOCK); 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"); *(int *) w[1] = fd; }