home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 2: Collection B / 17Bit_Collection_B.iso / files / 1365.dms / in.adf / BOORANG / BoomSound.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-21  |  2.3 KB  |  120 lines

  1. USHORT *LoadSample();
  2. USHORT *AllocateMem();
  3. void    KillSounds(), StartSound(), UpdateSounds();
  4.  
  5. USHORT *waveform[NUMSAMPLES];
  6. USHORT wavelength[NUMSAMPLES];
  7. USHORT *dmaconw = (USHORT *)0xDFF096;
  8. USHORT inuse[4] = {0,0,0,0};
  9.  
  10. ULONG *audioaddr[4] =
  11. {
  12.  {(ULONG *)0xDFF0A0}, {(ULONG *)0xDFF0B0}, {(ULONG *)0xDFF0C0},
  13.  {(ULONG *)0xDFF0D0},
  14. };
  15.  
  16. USHORT *audiolen[4] =
  17. {
  18.  {(USHORT *)0xDFF0A4}, {(USHORT *)0xDFF0B4}, {(USHORT *)0xDFF0C4},
  19.  {(USHORT *)0xDFF0D4},
  20. };
  21.  
  22. USHORT *audioper[4] =
  23. {
  24.  {(USHORT *)0xDFF0A6}, {(USHORT *)0xDFF0B6}, {(USHORT *)0xDFF0C6},
  25.  {(USHORT *)0xDFF0D6},
  26. };
  27.  
  28. USHORT *audiovol[4] =
  29. {
  30.  {(USHORT *)0xDFF0A8}, {(USHORT *)0xDFF0B8}, {(USHORT *)0xDFF0C8},
  31.  {(USHORT *)0xDFF0D8},
  32. };
  33.  
  34. USHORT *LoadSample(filename,length)
  35. char *filename;
  36. USHORT *length;
  37. {
  38.   FILE *file;
  39.   USHORT *buffer;
  40.   ULONG size;
  41.  
  42.   if ((file=fopen(filename,"r"))==NULL) return(NULL);
  43.   fseek(file,0L,2);
  44.   size = ftell(file) & ~1L;
  45.   fseek(file,0L,0);
  46.   if ((buffer=AllocateMem(size,MEMF_CHIP))==NULL)
  47.     {
  48.      fclose(file);
  49.      return(NULL);
  50.     }
  51.   *length=(USHORT)(fread((UBYTE *)buffer,1,(int)size,file)>>1);
  52.   fclose(file);
  53.   return(buffer);
  54. }
  55.  
  56. USHORT *AllocateMem(size,requirements)
  57. ULONG size, requirements;
  58. {
  59.   if (AvailMem(requirements)-size<=32000L) return(NULL);
  60.   return((void *)AllocMem(size,requirements));
  61. }
  62.  
  63. void KillSounds()
  64. {
  65.  register int i;
  66.  
  67.  *dmaconw=0x000F;
  68.  for (i=0;i<NUMSAMPLES;i++)
  69.   if (waveform[i]) FreeMem(waveform[i],wavelength[i]<<1);
  70. }
  71.  
  72. void StartSound(locat,len,jiffs,per,vol,chan)
  73. USHORT *locat;
  74. USHORT len;
  75. USHORT jiffs,per,vol,chan;
  76. {
  77.  if (locat!=NULL)
  78.   {
  79.    if (inuse[chan]==0)
  80.      {
  81.       inuse[chan]=jiffs;
  82.       *audioaddr[chan]=(ULONG)locat;
  83.       *audiolen[chan]=len;
  84.       *audioper[chan]=per;
  85.       *audiovol[chan]=vol;
  86.       switch (chan)
  87.        {
  88.         case 0: *dmaconw=0x8201;break;
  89.         case 1: *dmaconw=0x8202;break;
  90.         case 2: *dmaconw=0x8204;break;
  91.         case 3: *dmaconw=0x8208;break;
  92.         default: break;
  93.        }
  94.      }
  95.   }
  96. }
  97.  
  98. void UpdateSounds()
  99. {
  100.  register int i;
  101.  
  102.  for (i=0;i<4;i++)
  103.    {
  104.     if (inuse[i]!=0)
  105.       {
  106.        inuse[i]--;
  107.        if (inuse[i]==0)
  108.          {
  109.           switch (i)
  110.            {
  111.             case 0: *dmaconw=0x1;break;
  112.             case 1: *dmaconw=0x2;break;
  113.             case 2: *dmaconw=0x4;break;
  114.             case 3: *dmaconw=0x8;break;
  115.            }
  116.          }
  117.       }
  118.    }
  119. }
  120.