home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / atari / atari800-0.8.6 / sound.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-10  |  2.6 KB  |  154 lines

  1. #ifndef AMIGA
  2. #include "config.h"
  3. #endif
  4.  
  5. #ifdef VOXWARE
  6. #include <fcntl.h>
  7. #include <sys/ioctl.h>
  8. #include <sys/soundcard.h>
  9.  
  10. #include "pokey11.h"
  11.  
  12. static char *rcsid = "$Id: sound.c,v 1.5 1998/02/21 15:20:42 david Exp $";
  13.  
  14. /* 0002 = 2 Fragments */
  15. /* 0007 = means each fragment is 2^2 or 128 bytes */
  16. /* See voxware docs in /usr/src/linux/drivers/sound for more info */
  17.  
  18. #define FRAG_SPEC 0x0002000a
  19.  
  20. #define FALSE 0
  21. #define TRUE 1
  22.  
  23. static char dsp_buffer[44100];
  24. static int sndbufsize;
  25.  
  26. static sound_enabled = TRUE;
  27. static int dsp_fd;
  28.  
  29. static int dsp_sample_rate;
  30. static int dsp_sample_rate_divisor = 35;
  31. static int AUDCTL = 0x00;
  32. static int AUDF[4] =
  33. {0, 0, 0, 0};
  34. static int AUDC[4] =
  35. {0, 0, 0, 0};
  36.  
  37. void Voxware_Initialise(int *argc, char *argv[])
  38. {
  39.     int i, j;
  40.  
  41.     for (i = j = 1; i < *argc; i++) {
  42.         if (strcmp(argv[i], "-sound") == 0)
  43.             sound_enabled = TRUE;
  44.         else if (strcmp(argv[i], "-nosound") == 0)
  45.             sound_enabled = FALSE;
  46.         else if (strcmp(argv[i], "-dsp_divisor") == 0)
  47.             sscanf(argv[++i], "%d", &dsp_sample_rate_divisor);
  48.         else
  49.             argv[j++] = argv[i];
  50.     }
  51.  
  52.     *argc = j;
  53.  
  54.     if (sound_enabled) {
  55.         int channel;
  56.         int dspbits;
  57.         unsigned int formats;
  58.         int tmp;
  59.  
  60.         dsp_fd = open("/dev/dsp", O_WRONLY, 0777);
  61.         if (dsp_fd == -1) {
  62.             perror("/dev/dsp");
  63.             exit(1);
  64.         }
  65.         /*
  66.          * Get sound formats
  67.          */
  68.  
  69.         ioctl(dsp_fd, SNDCTL_DSP_GETFMTS, &formats);
  70.  
  71.         /*
  72.          * Set sound of sound fragment to special?
  73.          */
  74.  
  75.         tmp = FRAG_SPEC;
  76.         ioctl(dsp_fd, SNDCTL_DSP_SETFRAGMENT, &tmp);
  77.  
  78.         /*
  79.          * Get preferred buffer size
  80.          */
  81.  
  82.         ioctl(dsp_fd, SNDCTL_DSP_GETBLKSIZE, &sndbufsize);
  83.  
  84.         /*
  85.          * Set to 8bit sound
  86.          */
  87.  
  88.         dspbits = 8;
  89.         ioctl(dsp_fd, SNDCTL_DSP_SAMPLESIZE, &dspbits);
  90.         ioctl(dsp_fd, SOUND_PCM_READ_BITS, &dspbits);
  91.  
  92.         /*
  93.          * Set sample rate
  94.          */
  95.  
  96.         ioctl(dsp_fd, SNDCTL_DSP_SPEED, &dsp_sample_rate);
  97.         ioctl(dsp_fd, SOUND_PCM_READ_RATE, &dsp_sample_rate);
  98.  
  99.         Pokey_sound_init(FREQ_17_EXACT, dsp_sample_rate);
  100.     }
  101. }
  102.  
  103. void Voxware_Exit(void)
  104. {
  105.     if (sound_enabled)
  106.         close(dsp_fd);
  107. }
  108.  
  109. void Voxware_UpdateSound(void)
  110. {
  111.     if (sound_enabled) {
  112.         sndbufsize = dsp_sample_rate / dsp_sample_rate_divisor;
  113.  
  114.         Pokey_process(dsp_buffer, sndbufsize);
  115.         /*
  116.          * Send sound buffer to DSP device
  117.          */
  118.  
  119.         write(dsp_fd, dsp_buffer, sndbufsize);
  120.     }
  121. }
  122.  
  123. void Atari_AUDC(int channel, int byte)
  124. {
  125.     channel--;
  126.     Update_pokey_sound(0xd201 + channel + channel, byte);
  127. }
  128.  
  129. void Atari_AUDF(int channel, int byte)
  130. {
  131.     channel--;
  132.     Update_pokey_sound(0xd200 + channel + channel, byte);
  133. }
  134.  
  135. void Atari_AUDCTL(int byte)
  136. {
  137.     Update_pokey_sound(0xd208, byte);
  138. }
  139.  
  140. #else
  141. void Atari_AUDC(int channel, int byte)
  142. {
  143. }
  144.  
  145. void Atari_AUDF(int channel, int byte)
  146. {
  147. }
  148.  
  149. void Atari_AUDCTL(int byte)
  150. {
  151. }
  152.  
  153. #endif
  154.