home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / imlib / port / linux / lnx_sdrv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-02  |  2.1 KB  |  100 lines

  1. /*     Sound driver, (C) 1994 Jonathan Clark    */
  2. #include <sys/ipc.h>
  3. #include <sys/shm.h>
  4. #include <signal.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <linux/soundcard.h>
  10. #include <sys/ioctl.h>
  11. #include <sys/stat.h>
  12. #include <sys/types.h>
  13. #include <sys/time.h>
  14. #include <string.h>
  15. #include <signal.h>
  16.  
  17. #define uchar unsigned char
  18.  
  19. #define BUF_BITS 9
  20. #define BUF_SIZE (1<<BUF_BITS)
  21. #define NUM_CHANNELS 8
  22. #define SAMPLE_SPEED 11025
  23.  
  24.  
  25. int s_dev,full_pot=0,start_seq;
  26.  
  27. int sound_init();
  28. void output_samples(uchar *buffer, int size);
  29. void sound_uninit();
  30.  
  31. #include "../sgi/gen_drv.c"         // include generic sound driver code, hackish I know, but I'm outa time :)
  32.  
  33.  
  34. int sound_init() 
  35. {  
  36.   int i;  
  37.   s_dev=open("/dev/dsp",O_WRONLY,0);
  38.   if (s_dev<0)
  39.   {
  40.     fprintf(stderr,"SNDDRV : Unable to open /dev/dsp, sound effects disabled\n"
  41.                "   **Make sure no other process is using this (perhaps old lnx_sdrv?) **\n");    
  42.     return 0;  
  43.   }
  44.   
  45.  
  46.   i = 0x00020000|BUF_BITS;    /* 2 fragments of 2^BUF_BITS bytes */
  47.   ioctl(s_dev, SNDCTL_DSP_SETFRAGMENT, &i);
  48.  
  49.   i = 8;     // samples are 8 bit
  50.   if (ioctl(s_dev, SNDCTL_DSP_SAMPLESIZE, &i)<0)
  51.   {
  52.     fprintf(stderr,"SNDDRV : Sample size 8 failed, sound effects disabled\n");    
  53.     close(s_dev);
  54.     s_dev=-1;    
  55.     return 0;    
  56.   }
  57.  
  58.   i = SAMPLE_SPEED; 
  59.   if (ioctl(s_dev, SNDCTL_DSP_SPEED, &i)<0)
  60.   {
  61.     fprintf(stderr,"SNDDRV : dsp_speed failed, sound effects disabled\n");    
  62.     close(s_dev);
  63.     s_dev=-1;    
  64.     return 0;    
  65.   }
  66.  
  67.   i = 0;     // no stero
  68.   if (ioctl(s_dev, SNDCTL_DSP_STEREO, &i)<0)
  69.   {
  70.     fprintf(stderr,"SNDDRV : Sample size 8 failed, sound effects disabled\n");    
  71.     close(s_dev);
  72.     s_dev=-1;    
  73.     return 0;    
  74.   }
  75.  
  76.  
  77.  
  78.   int j;
  79.   uchar *vd=volume_table;
  80.   for (;i<32;i++) 
  81.   {
  82.     for (j=0;j<256;j++,vd++)
  83.       *vd=(j-128)*i/31+128;
  84.   }
  85.   return 1;
  86.  
  87. }
  88.  
  89.  
  90. void output_samples(uchar *buffer, int size)
  91. {
  92.   write(s_dev, buf, size);
  93. }
  94.  
  95.  
  96. void sound_uninit()
  97. {
  98.   close(s_dev);
  99. }
  100.