home *** CD-ROM | disk | FTP | other *** search
/ Audio Toolkit / Audio_Toolkit_Walnut_Creek_September_1997.iso / mac / unix / linux / sb16agc.c < prev    next >
C/C++ Source or Header  |  1997-01-29  |  1KB  |  68 lines

  1. /* sb16agc - enable/disable AGC on Soundblaster 16
  2.  * PD by RJM 96/1/5
  3.  *
  4.  * compile with 'cc -o sb16agc sb16agc.c'
  5.  * install with 'install -o root -m 4511 sb16agc /usr/local/bin'
  6.  *
  7.  * THIS IS A REVOLTING HACK!
  8.  * (Based on dosemu debug output from 'sb16set /agc:-')
  9.  * DO NOT USE THIS *UNLESS*:
  10.  * - you have a Soundblaster 16; and
  11.  * - 'cat /dev/sndstat' says "SoundBlaster16 at 0x220 ..."
  12.  *    (or in newer kernels, "Sound Blaster at 0x220 ...")
  13.  *
  14.  * Even then, I should add a disclaimer. This program works fine for
  15.  * me, but don't hold me responsible if your machine explodes. :-)
  16.  *
  17.  * Note that this only affects the mic socket - line-in is always
  18.  * free of AGC interference (not to mention being stereo rather than
  19.  * the mic socket's mono).
  20.  */
  21.  
  22. #include <stdio.h>
  23. #include <unistd.h>
  24.  
  25.  
  26. static void inline outb(char value, unsigned short port)
  27. {
  28. __asm__ volatile ("outb %0,%1"
  29.   ::"a" ((char) value),"d" ((unsigned short) port));
  30. }
  31.  
  32.  
  33. void die(char *str)
  34. {
  35. fprintf(stderr,"Couldn't %s.\n",str);
  36. }
  37.  
  38.  
  39. void usage()
  40. {
  41. printf("usage: sb16agc [on|off]\n");
  42. exit(1);
  43. }
  44.  
  45.  
  46. int main(int argc,char *argv[])
  47. {
  48. int disable=0;
  49.  
  50. if(ioperm(0x224,2,1)==-1) die("get I/O permissions (not setuid root?)");
  51.  
  52. if(argc!=2) usage(),exit(1);
  53.  
  54. if(strcmp(argv[1],"on")==0)
  55.   disable=0;
  56. else
  57.   if(strcmp(argv[1],"off")==0)
  58.     disable=1;
  59.   else
  60.     usage(),exit(1);
  61.  
  62. outb(0x43,0x224);
  63. usleep(10000);
  64. outb(disable,0x225);
  65.  
  66. exit(0);
  67. }
  68.