doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

linux.c (1342B)


      1 static const char rcsid[] = "$Id: linux.c,v 1.3 1997/01/26 07:45:01 b1 Exp $";
      2 #include <errno.h>
      3 #include <stdlib.h>
      4 #include <stdio.h>
      5 #include <fcntl.h>
      6 #include <unistd.h>
      7 #include <sys/ioctl.h>
      8 #include <linux/soundcard.h>
      9 #include "soundsrv.h"
     10 int	audio_fd;
     11 void
     12 myioctl(int fd, int command, int* arg)
     13 {   
     14     int rc;
     15     rc = ioctl(fd, command, arg);  
     16     if (rc < 0) {
     17 		fprintf(stderr, "ioctl(dsp,%d,arg) failed\n", command);
     18 		fprintf(stderr, "errno=%d\n", errno);
     19 		exit(-1);
     20     }
     21 }
     22 void
     23 I_InitMusic(void)
     24 {
     25 }
     26 void
     27 I_InitSound(int samplerate, int samplesize)
     28 {
     29     int i;
     30     audio_fd = open("/dev/dsp", O_WRONLY);
     31     if (audio_fd < 0) fprintf(stderr, "Could not open /dev/dsp\n");
     32     i = 11 | (2 << 16);                                           
     33     myioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &i);
     34     myioctl(audio_fd, SNDCTL_DSP_RESET, 0);
     35     i=11025;
     36     myioctl(audio_fd, SNDCTL_DSP_SPEED, &i);
     37     i=1;    
     38     myioctl(audio_fd, SNDCTL_DSP_STEREO, &i);
     39     myioctl(audio_fd, SNDCTL_DSP_GETFMTS, &i);
     40     if (i&=AFMT_S16_LE) myioctl(audio_fd, SNDCTL_DSP_SETFMT, &i);
     41     else fprintf(stderr, "Could not play signed 16 data\n");
     42 }
     43 void
     44 I_SubmitOutputBuffer(void* samples, int samplecount)
     45 {
     46     write(audio_fd, samples, samplecount*4);
     47 }
     48 void
     49 I_ShutdownSound(void)
     50 {
     51     close(audio_fd);
     52 }
     53 void
     54 I_ShutdownMusic(void)
     55 {
     56 }