home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / sonido / mod-0.000 / mod-0 / mod / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-02  |  1.6 KB  |  77 lines

  1. /*
  2.  *  init.c - Initializes the sounddriver.
  3.  *
  4.  *  (C) 1994 Mikael Nordqvist (d91mn@efd.lth.se, mech@df.lth.se)
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11. #include <sys/types.h>
  12. #include <fcntl.h>
  13. #include <sys/ioctl.h>
  14. #include <limits.h>
  15. #include <sys/soundcard.h>
  16. #include <sys/ultrasound.h>
  17. #include <errno.h>
  18. #include <sys/time.h>
  19.  
  20. #include "mod.h"
  21.  
  22. /* Define a large bufffer (so there are no unwanted flushes) */
  23. #define MY_SEQ_BUF_LEN 4096
  24.  
  25. SEQ_DEFINEBUF(MY_SEQ_BUF_LEN);
  26. int seqfd, mixerfd, gus_dev=-42;
  27.  
  28. extern struct options opt;
  29.  
  30. void init_sound(void)
  31. {
  32.     int nr, i;
  33.     struct synth_info si;
  34.     int mixer_devmask;
  35.  
  36.     if((seqfd=open("/dev/sequencer", O_RDWR, 0)) == -1)
  37.     error("Unable to open sequencer.\n");
  38.  
  39.     fcntl(seqfd, F_SETFL, O_NONBLOCK);
  40.  
  41.     if(ioctl(seqfd, SNDCTL_SEQ_NRSYNTHS, &nr) == -1)
  42.     error("Unable to find out # of synth-devices.\n");
  43.  
  44.     for(i=0; i < nr; ++i) {
  45.     si.device=i;
  46.     if(ioctl(seqfd, SNDCTL_SYNTH_INFO, &si) == -1)
  47.         error("Unable to get synth_info.\n");
  48.     
  49.     if(si.synth_type == SYNTH_TYPE_SAMPLE &&
  50.       si.synth_subtype == SAMPLE_TYPE_GUS) {
  51.         gus_dev=i;
  52.         break;
  53.     }
  54.     }
  55.  
  56.     if(gus_dev == -42)
  57.     error("Unable to find a GUS on this system.\n");
  58.  
  59.     ioctl(seqfd, SNDCTL_SEQ_RESET, 0);
  60.     
  61.     if((mixerfd=open(MIXER_NAME, O_RDWR, 0)) != -1) {
  62.     if(!(ioctl(mixerfd, SOUND_MIXER_READ_DEVMASK, &mixer_devmask) != -1 &&
  63.          (mixer_devmask & SOUND_MASK_SYNTH)))
  64.     {
  65.         close(mixerfd);
  66.         mixerfd=-1;
  67.     }
  68.     }
  69. }
  70.  
  71. void cleanup_sound(void) 
  72. {
  73.     if(mixerfd != -1)
  74.     close(mixerfd);
  75.     close (seqfd);
  76. }
  77.